|
1 | | -const fs = require("fs"); |
2 | | -const path = require("path"); |
3 | | -const { execSync } = require("child_process"); |
| 1 | +const fs = require('fs'); |
| 2 | +const path = require('path'); |
| 3 | +const { execSync } = require('child_process'); |
4 | 4 |
|
5 | 5 | // Configuration file path |
6 | | -const CONFIG_FILE = path.join(__dirname, "build-config.json"); |
| 6 | +const CONFIG_FILE = path.join(__dirname, 'build-config.json'); |
7 | 7 |
|
8 | 8 | // Default configuration |
9 | 9 | const DEFAULT_CONFIG = { |
10 | | - scripts: [ |
11 | | - "setupBatteryOptimizations.js", |
12 | | - "notificationSounds.ts", |
13 | | - "setupExceptionHandler.js", |
14 | | - ], |
15 | | - // Add enabled: false to disable a script without removing it from the list |
16 | | - // Example: { path: "scriptName.js", enabled: false } |
| 10 | + scripts: ['setupBatteryOptimizations.js', 'notificationSounds.ts', 'setupExceptionHandler.js'], |
| 11 | + // Add enabled: false to disable a script without removing it from the list |
| 12 | + // Example: { path: "scriptName.js", enabled: false } |
17 | 13 | }; |
18 | 14 |
|
19 | 15 | // Create default config if it doesn't exist |
20 | 16 | function ensureConfigExists() { |
21 | | - if (!fs.existsSync(CONFIG_FILE)) { |
22 | | - fs.writeFileSync(CONFIG_FILE, JSON.stringify(DEFAULT_CONFIG, null, 2)); |
23 | | - console.log(`Created default build config at ${CONFIG_FILE}`); |
24 | | - } |
| 17 | + if (!fs.existsSync(CONFIG_FILE)) { |
| 18 | + fs.writeFileSync(CONFIG_FILE, JSON.stringify(DEFAULT_CONFIG, null, 2)); |
| 19 | + console.log(`Created default build config at ${CONFIG_FILE}`); |
| 20 | + } |
25 | 21 | } |
26 | 22 |
|
27 | 23 | // Get the list of scripts to run |
28 | 24 | function getScriptsToRun() { |
29 | | - ensureConfigExists(); |
30 | | - const config = JSON.parse(fs.readFileSync(CONFIG_FILE, "utf8")); |
31 | | - return config.scripts |
32 | | - .filter((script) => { |
33 | | - if (typeof script === "string") return true; |
34 | | - return script.enabled !== false; |
35 | | - }) |
36 | | - .map((script) => { |
37 | | - if (typeof script === "string") return script; |
38 | | - return script.path; |
39 | | - }); |
| 25 | + ensureConfigExists(); |
| 26 | + const config = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8')); |
| 27 | + return config.scripts |
| 28 | + .filter((script) => { |
| 29 | + if (typeof script === 'string') return true; |
| 30 | + return script.enabled !== false; |
| 31 | + }) |
| 32 | + .map((script) => { |
| 33 | + if (typeof script === 'string') return script; |
| 34 | + return script.path; |
| 35 | + }); |
40 | 36 | } |
41 | 37 |
|
42 | 38 | // Run all enabled scripts |
43 | 39 | function runBuildScripts() { |
44 | | - console.log("🚀 Running build scripts..."); |
| 40 | + console.log('🚀 Running build scripts...'); |
45 | 41 |
|
46 | | - const scripts = getScriptsToRun(); |
| 42 | + const scripts = getScriptsToRun(); |
47 | 43 |
|
48 | | - scripts.forEach((scriptPath) => { |
49 | | - const fullPath = path.join(__dirname, scriptPath); |
| 44 | + scripts.forEach((scriptPath) => { |
| 45 | + const fullPath = path.join(__dirname, scriptPath); |
50 | 46 |
|
51 | | - if (!fs.existsSync(fullPath)) { |
52 | | - console.error(`❌ Script not found: ${fullPath}`); |
53 | | - return; |
54 | | - } |
| 47 | + if (!fs.existsSync(fullPath)) { |
| 48 | + console.error(`❌ Script not found: ${fullPath}`); |
| 49 | + return; |
| 50 | + } |
55 | 51 |
|
56 | | - console.log(`▶️ Running: ${scriptPath}`); |
| 52 | + console.log(`▶️ Running: ${scriptPath}`); |
57 | 53 |
|
58 | | - try { |
59 | | - if (scriptPath.endsWith(".ts")) { |
60 | | - // For TypeScript files, use ts-node |
61 | | - execSync(`npx ts-node ${fullPath}`, { stdio: "inherit" }); |
62 | | - } else { |
63 | | - // For JavaScript files, use node |
64 | | - execSync(`node ${fullPath}`, { stdio: "inherit" }); |
65 | | - } |
66 | | - console.log(`✅ Completed: ${scriptPath}`); |
67 | | - } catch (error) { |
68 | | - console.error(`❌ Error running ${scriptPath}:`, error.message); |
69 | | - } |
70 | | - }); |
| 54 | + try { |
| 55 | + if (scriptPath.endsWith('.ts')) { |
| 56 | + // For TypeScript files, use ts-node |
| 57 | + execSync(`npx ts-node ${fullPath}`, { stdio: 'inherit' }); |
| 58 | + } else { |
| 59 | + // For JavaScript files, use node |
| 60 | + execSync(`node ${fullPath}`, { stdio: 'inherit' }); |
| 61 | + } |
| 62 | + console.log(`✅ Completed: ${scriptPath}`); |
| 63 | + } catch (error) { |
| 64 | + console.error(`❌ Error running ${scriptPath}:`, error.message); |
| 65 | + } |
| 66 | + }); |
71 | 67 |
|
72 | | - console.log("✨ Build scripts completed"); |
| 68 | + console.log('✨ Build scripts completed'); |
73 | 69 | } |
74 | 70 |
|
75 | 71 | // Run the function if this is the main module |
76 | 72 | if (require.main === module) { |
77 | | - runBuildScripts(); |
| 73 | + runBuildScripts(); |
78 | 74 | } |
79 | 75 |
|
80 | 76 | module.exports = runBuildScripts; |
0 commit comments