52
await ensureDir(tempPath); // Create temp dir for this new build
53
};
54
55
-const build = async (tempPath, manifestPath) => {
55
+const build = async (tempPath, manifestPath, envExtension = {}) => {
56
const binPath = join(tempPath, 'bin');
57
const zipPath = join(tempPath, 'zip');
58
+ const mergedEnv = {...process.env, ...envExtension};
59
60
const webpackPath = join(__dirname, 'node_modules', '.bin', 'webpack');
61
execSync(
62
`${webpackPath} --config webpack.config.js --output-path ${binPath}`,
63
{
64
cwd: __dirname,
64
- env: process.env,
65
+ env: mergedEnv,
66
stdio: 'inherit',
67
},
68
);
70
`${webpackPath} --config webpack.backend.js --output-path ${binPath}`,
71
{
72
cwd: __dirname,
72
- env: process.env,
73
+ env: mergedEnv,
74
stdio: 'inherit',
75
},
76
);
133
await remove(tempPath); // Clean up temp directory and files
134
};
135
136
+const SUPPORTED_BUILDS = ['chrome', 'firefox', 'edge'];
137
+
138
const main = async buildId => {
139
+ if (!SUPPORTED_BUILDS.includes(buildId)) {
140
+ throw new Error(
141
+ `Unexpected build id - "${buildId}". Use one of ${JSON.stringify(
142
+ SUPPORTED_BUILDS,
143
+ )}.`,
144
+ );
145
+ }
146
+
147
const root = join(__dirname, buildId);
148
const manifestPath = join(root, 'manifest.json');
149
const destinationPath = join(root, 'build');
150
151
+ const envExtension = {
152
+ IS_CHROME: buildId === 'chrome',
153
+ IS_FIREFOX: buildId === 'firefox',
154
+ IS_EDGE: buildId === 'edge',
155
+ };
156
+
157
try {
158
const tempPath = join(__dirname, 'build', buildId);
159
await ensureLocalBuild();
160
await preProcess(destinationPath, tempPath);
144
- await build(tempPath, manifestPath);
161
+ await build(tempPath, manifestPath, envExtension);
162
163
const builtUnpackedPath = join(destinationPath, 'unpacked');
164
await postProcess(tempPath, destinationPath);