1 | const fs = require('fs');
|
2 | const {promisify} = require('@parcel/utils');
|
3 | const path = require('path');
|
4 | const {mkdirp} = require('@parcel/fs');
|
5 |
|
6 | class Packager {
|
7 | constructor(bundle, bundler) {
|
8 | this.bundle = bundle;
|
9 | this.bundler = bundler;
|
10 | this.options = bundler.options;
|
11 | }
|
12 |
|
13 | static shouldAddAsset() {
|
14 | return true;
|
15 | }
|
16 |
|
17 | async setup() {
|
18 |
|
19 | if (this.bundle.name.includes(path.sep)) {
|
20 | await mkdirp(path.dirname(this.bundle.name));
|
21 | }
|
22 |
|
23 | this.dest = fs.createWriteStream(this.bundle.name);
|
24 | this.dest.write = promisify(this.dest.write.bind(this.dest));
|
25 | this.dest.end = promisify(this.dest.end.bind(this.dest));
|
26 | }
|
27 |
|
28 | async write(string) {
|
29 | await this.dest.write(string);
|
30 | }
|
31 |
|
32 | async start() {}
|
33 |
|
34 |
|
35 | async addAsset(asset) {
|
36 | throw new Error('Must be implemented by subclasses');
|
37 | }
|
38 |
|
39 | getSize() {
|
40 | return this.dest.bytesWritten;
|
41 | }
|
42 |
|
43 | async end() {
|
44 | await this.dest.end();
|
45 | }
|
46 | }
|
47 |
|
48 | module.exports = Packager;
|