1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
6 |
|
7 | const fs = require('fs');
|
8 |
|
9 | const _require = require('@parcel/utils'),
|
10 | promisify = _require.promisify;
|
11 |
|
12 | const path = require('path');
|
13 |
|
14 | const _require2 = require('@parcel/fs'),
|
15 | mkdirp = _require2.mkdirp;
|
16 |
|
17 | class 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 |
|
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 | }
|
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 |
|
76 | module.exports = Packager; |
\ | No newline at end of file |