-
Notifications
You must be signed in to change notification settings - Fork 0
/
premake.js
45 lines (37 loc) · 1.31 KB
/
premake.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
const fs = require('fs');
const path = require('path');
let obj_dir = path.resolve(__dirname, 'obj');
let build_dir = path.resolve(__dirname, 'build');
let prepareDeploy = process.argv.includes('prepare-deploy');
//-----------------------------------------
// Create missing directories for make
//-----------------------------------------
if (!fs.existsSync(obj_dir)) {
fs.mkdirSync(obj_dir);
console.log('Created directory: ' + obj_dir);
}
if (!fs.existsSync(build_dir)) {
fs.mkdirSync(build_dir);
console.log('Created directory: ', build_dir);
}
console.log('premake: executed successfully!');
//-----------------------------------------
// Prepare deployment
//-----------------------------------------
if (prepareDeploy) {
const glob = require('glob');
// Find existing html file to rename as 'index.html'
glob(build_dir + '/**/*.html', {}, (err, files) => {
if (!Array.isArray(files) || !files.length) return;
// Check if first index contains index.html
if (path.basename(files[0]) === 'index.html') {
// Remove this file index
files.splice(0, 1);
}
// Copy next file index to index.html
fs.copyFile(files[0], path.join(build_dir, 'index.html'), (err) => {
if (err) throw err;
console.info(`(${path.basename(files[0])}) was copied as (index.html)`);
});
});
}