UNPKG

1.73 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
6
7const fs = require('fs');
8
9const _require = require('@parcel/utils'),
10 promisify = _require.promisify;
11
12const path = require('path');
13
14const _require2 = require('@parcel/fs'),
15 mkdirp = _require2.mkdirp;
16
17class Packager {
18 constructor(bundle, bundler) {
19 this.bundle = bundle;
20 this.bundler = bundler;
21 this.options = bundler.options;
22 }
23
24 static shouldAddAsset() {
25 return true;
26 }
27
28 setup() {
29 var _this = this;
30
31 return (0, _asyncToGenerator2.default)(function* () {
32 // Create sub-directories if needed
33 if (_this.bundle.name.includes(path.sep)) {
34 yield mkdirp(path.dirname(_this.bundle.name));
35 }
36
37 _this.dest = fs.createWriteStream(_this.bundle.name);
38 _this.dest.write = promisify(_this.dest.write.bind(_this.dest));
39 _this.dest.end = promisify(_this.dest.end.bind(_this.dest));
40 })();
41 }
42
43 write(string) {
44 var _this2 = this;
45
46 return (0, _asyncToGenerator2.default)(function* () {
47 yield _this2.dest.write(string);
48 })();
49 }
50
51 start() {
52 return (0, _asyncToGenerator2.default)(function* () {})();
53 } // eslint-disable-next-line no-unused-vars
54
55
56 addAsset(asset) {
57 return (0, _asyncToGenerator2.default)(function* () {
58 throw new Error('Must be implemented by subclasses');
59 })();
60 }
61
62 getSize() {
63 return this.dest.bytesWritten;
64 }
65
66 end() {
67 var _this3 = this;
68
69 return (0, _asyncToGenerator2.default)(function* () {
70 yield _this3.dest.end();
71 })();
72 }
73
74}
75
76module.exports = Packager;
\No newline at end of file