forked from US-GHG-Center/interfaces-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-parcel.js
More file actions
37 lines (32 loc) · 1.09 KB
/
run-parcel.js
File metadata and controls
37 lines (32 loc) · 1.09 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
// run-parcel.js
const { execSync } = require('child_process');
const buildDir = process.argv[3];
const publicUrl = process.env.PUBLIC_URL;
if (!publicUrl) {
console.error(
'Error: PUBLIC_URL is not defined in your .env file or environment.'
);
console.error('Please define it (e.g., PUBLIC_URL="/my/custom/path").');
process.exit(1);
}
let parcelCommand;
const mode = process.argv[2];
switch (mode) {
case 'build':
parcelCommand = `parcel build --public-url "${publicUrl}" --dist-dir ${buildDir}`;
break;
case 'serve':
parcelCommand = `parcel --public-url "${publicUrl}"`;
break;
default:
console.error(`[run-parcel.js] ❌ Unknown mode: ${mode}`);
process.exit(1);
}
console.log(`[run-parcel.js] ▶ Running: ${parcelCommand}`);
try {
execSync(parcelCommand, { stdio: 'inherit' });
} catch (error) {
console.error(`[run-parcel.js] ❌ Parcel command failed for mode: ${mode}`);
// error object itself is already printed by execSync on failure when stdio is 'inherit'
process.exit(1); // Ensure script exits with error code
}