forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.js
More file actions
90 lines (74 loc) · 2.22 KB
/
bundle.js
File metadata and controls
90 lines (74 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
const {
tools: { makeBundle, copyFile }
} = require("devtools-launchpad/index");
const sourceMapAssets = require("devtools-source-map/assets");
const path = require("path");
var fs = require("fs");
const rimraf = require("rimraf");
const projectPath = path.resolve(__dirname, "..");
const bundlePath = path.join(projectPath, "./dist");
const clientPath = path.join(projectPath, "../");
const watch = false;
const updateAssets = true;
process.env.NODE_ENV = "production";
function moveFile(src, dest, opts) {
if (!fs.existsSync(src)) {
return;
}
copyFile(src, dest, opts);
rimraf.sync(src);
}
async function bundle() {
makeBundle({
outputPath: bundlePath,
projectPath,
watch,
updateAssets,
onFinish: () => onBundleFinish()
})
.then(() => {
console.log("[copy-assets] bundle is done");
})
.catch(err => {
console.log(
"[copy-assets] Uhoh, something went wrong. " +
"The error was written to assets-error.log"
);
fs.writeFileSync("assets-error.log", JSON.stringify(err, null, 2));
});
}
function onBundleFinish() {
console.log("[copy-assets] copy shared bundles to client/shared");
moveFile(
path.join(bundlePath, "source-map-worker.js"),
path.join(clientPath, "shared/source-map/worker.js"),
{ cwd: projectPath }
);
for (const filename of Object.keys(sourceMapAssets)) {
moveFile(
path.join(bundlePath, "source-map-worker-assets", filename),
path.join(clientPath, "shared/source-map/assets", filename),
{ cwd: projectPath }
);
}
moveFile(
path.join(bundlePath, "source-map-index.js"),
path.join(clientPath, "shared/source-map/index.js"),
{ cwd: projectPath }
);
moveFile(
path.join(bundlePath, "reps.js"),
path.join(clientPath, "shared/components/reps/reps.js"),
{ cwd: projectPath }
);
moveFile(
path.join(bundlePath, "reps.css"),
path.join(clientPath, "shared/components/reps/reps.css"),
{ cwd: projectPath }
);
console.log("[copy-assets] done");
}
bundle();