-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
54 lines (48 loc) · 1.93 KB
/
build.js
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
const { execSync } = require('child_process');
const path = require('path');
const fs = require('fs');
const { promisify } = require('util');
const ncp = promisify(require('ncp').ncp);
console.log("10% - Read setup.json;");
const config = JSON.parse(fs.readFileSync('setup.json', 'utf8'));
console.log("20% - Check build parameters;");
const buildType = process.argv[2] || 'Debug';
if (!buildType || (buildType !== 'Debug' && buildType !== 'Release')) {
console.error("Usage: node build.js <Debug|Release>");
process.exit(1);
}
console.log("35% - Branching by parameter;");
const buildConfig = config[buildType.toLowerCase()];
if (!buildConfig) {
console.error(`Error: Unknown build type: ${buildType}`);
process.exit(1);
}
try {
console.log(`50% - Switching to the compiler directory: ${process.cwd()};`);
process.chdir(config.fasmPath);
console.log(`55% - Try to build;`);
let command = ``;
if (buildType.toLowerCase() != "release")
command = `fasm ${buildConfig.input} ${buildConfig.output} -s ${buildConfig.folder}tactickgame.fas`
else
command = `fasm ${buildConfig.input} ${buildConfig.output}`
execSync(command, { stdio: 'inherit' });
console.log(`85% - Success`);
console.log(`100% - Return in work directory: ${process.cwd()};`);
process.chdir(config.projectDir);
const sourceFolder = path.join(config.projectDir, config.copy.srcFolder);
const destFolder = path.join(buildConfig.folder, config.copy.destFolder);
console.log(`0% - Start copy source from ${sourceFolder} to ${destFolder}`);
ncp(sourceFolder, destFolder, { clobber: false })
.then(() => {
console.log(`100% - Files copied successfully from ${sourceFolder} to ${destFolder}`);
process.exit(0);
})
.catch(err => {
console.error(`Error copying files: ${err}`);
process.exit(1);
});
} catch (error) {
console.error(`Error: ${error.message}`);
process.exit(1);
}