-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy.js
109 lines (79 loc) · 2.5 KB
/
deploy.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* global require, console */
var fs, scriptsFilePath, template;
var minify = require("minify");
var exec = require("child_process").exec;
fs = require('fs');
scriptsFilePath = 'scripts.json';
template = "" + fs.readFileSync('deploy-template.tpl');
function mkdirSync (path) {
try {
fs.mkdirSync(path);
}
catch (e) {
if (e.code != 'EEXIST') {
throw e;
}
}
};
function processScriptsFileFn (data) {
var json;
try {
json = JSON.parse(data);
}
catch (e) {
console.log('Parsing file ' + scriptsFilePath + ' as JSON failed!');
console.log('Error was:' + e);
return;
}
concatJsFiles(json.files);
};
function concatJsFiles (files) {
var coreFile, moduleName, fullFile;
coreFile = '';
function fn (path) {
function concFn (data) {
coreFile += "" + removeUnwantedSections(data);
};
concFn(fs.readFileSync('./' + path, 'utf-8'));
};
for (moduleName in files) {
fn(files[moduleName]);
}
coreFile = template.replace("{{content}}", coreFile);
fullFile = fs.readFileSync("./libs/using.js/using.js", "utf-8") + coreFile;
writeFileFn(coreFile, "enjoy-core");
writeFileFn(fullFile, "enjoy");
exec("docco -o docs/ bin/enjoy-core.js", function () {
exec("mv docs/enjoy-core.html docs/index.html", function () {
console.log("Documentation created.");
});
});
};
function writeFileFn (contents, fileNameBase) {
function makeErrorFn (successText) {
return function (err) {
if (err) {
console.log(err);
return;
}
console.log(successText);
};
}
mkdirSync('./bin');
fs.writeFile('./bin/' + fileNameBase + '.js', contents, makeErrorFn('File created.'));
minify('./bin/' + fileNameBase + '.js', function(error, data) {
if (error) {
console.log(error);
}
else {
fs.writeFile('./bin/' + fileNameBase + '.min.js', data,
makeErrorFn("Minified file created."));
}
});
}
function removeUnwantedSections (fileContents) {
fileContents = fileContents.
replace(/\/\*<ON_DEPLOY_REMOVE>\*\/[\s\S]*\/\*<\/ON_DEPLOY_REMOVE>\*\//g, "");
return fileContents;
}
processScriptsFileFn(fs.readFileSync(scriptsFilePath, 'utf-8'));