Skip to content

Commit 1cd46bc

Browse files
Prettified.
1 parent 3cd0b0b commit 1cd46bc

File tree

1 file changed

+46
-50
lines changed

1 file changed

+46
-50
lines changed

scripts/buildScripts.js

Lines changed: 46 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,76 @@
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');
44

55
// Configuration file path
6-
const CONFIG_FILE = path.join(__dirname, "build-config.json");
6+
const CONFIG_FILE = path.join(__dirname, 'build-config.json');
77

88
// Default configuration
99
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 }
1713
};
1814

1915
// Create default config if it doesn't exist
2016
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+
}
2521
}
2622

2723
// Get the list of scripts to run
2824
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+
});
4036
}
4137

4238
// Run all enabled scripts
4339
function runBuildScripts() {
44-
console.log("🚀 Running build scripts...");
40+
console.log('🚀 Running build scripts...');
4541

46-
const scripts = getScriptsToRun();
42+
const scripts = getScriptsToRun();
4743

48-
scripts.forEach((scriptPath) => {
49-
const fullPath = path.join(__dirname, scriptPath);
44+
scripts.forEach((scriptPath) => {
45+
const fullPath = path.join(__dirname, scriptPath);
5046

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+
}
5551

56-
console.log(`▶️ Running: ${scriptPath}`);
52+
console.log(`▶️ Running: ${scriptPath}`);
5753

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+
});
7167

72-
console.log("✨ Build scripts completed");
68+
console.log('✨ Build scripts completed');
7369
}
7470

7571
// Run the function if this is the main module
7672
if (require.main === module) {
77-
runBuildScripts();
73+
runBuildScripts();
7874
}
7975

8076
module.exports = runBuildScripts;

0 commit comments

Comments
 (0)