-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (58 loc) · 2.9 KB
/
index.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
55
56
57
58
59
60
61
var fs = require('fs-extra');
var webBridge = require('clockwork-web-bridge');
var walk = require('walk');
function build(path, outPath) {
return new Promise(function (resolve, reject) {
webBridge(path, outPath).then(function (folderName) {
//Copy template
fs.renameSync(folderName, folderName + "#content");
fs.copySync(__dirname + "/template", folderName);
fs.copySync(folderName + "#content", folderName + "/ClockworkUWPTemplate/game");
//Replace platform utils
fs.copySync(__dirname + "/template/ClockworkUWPTemplate/game/clockwork/platformUtil.js", folderName + "/ClockworkUWPTemplate/game/clockwork/platformUtil.js");
//Replace runtime polyfill
var RTpolyfill = fs.readFileSync(folderName + "/ClockworkUWPTemplate/game/clockwork/RTpolyfill.js", 'utf-8');
var RTpolyfillForUWP = fs.readFileSync(__dirname +"/template/ClockworkUWPTemplate/game/clockwork/RTpolyfill.js", 'utf-8');
RTpolyfill = RTpolyfill.replace(/CLOCKWORKRT.API.appPath([^]*)$/, RTpolyfillForUWP);
fs.writeFileSync(folderName + "/ClockworkUWPTemplate/game/clockwork/RTpolyfill.js", RTpolyfill, 'utf-8');
//Clean
fs.removeSync(folderName + "#content");
//UWP project
console.log("Creating .jsconfig");
var jsproj = fs.readFileSync(folderName + "/ClockworkUWPTemplate/ClockworkUWPTemplate.jsproj", 'utf-8');
var files = "";
var listener = {
listeners: {
names: function (root, nodeNamesArray) {
nodeNamesArray.sort(function (a, b) {
if (a > b) return 1;
if (a < b) return -1;
return 0;
});
}
, directories: function (root, dirStatsArray, next) {
next();
},
file: function (root, fileStats, next) {
var relativePath = (root.replace(/\\/g,"/") +"/" +fileStats.name).replace(folderName + "/ClockworkUWPTemplate/", "");
files += ' <Content Include="' + relativePath + '" />\n';
next();
}, errors: function (root, nodeStatsArray, next) {
next();
}
}
};
walk.walkSync(folderName + "/ClockworkUWPTemplate/game", listener);
jsproj = jsproj.replace("<!--GAME FILES-->", files);
fs.writeFileSync(folderName + "/ClockworkUWPTemplate/ClockworkUWPTemplate.jsproj", jsproj, 'utf-8');
resolve();
});
});
}
module.exports = build;
if (require.main === module) {
var userArguments = process.argv.slice(2);
if (userArguments.length == 1) {
build(userArguments[0], "");
}
}