-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.js
110 lines (83 loc) · 2.39 KB
/
run.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
110
// Generated by CoffeeScript 1.3.3
/**
Configuration
*/
var closureBuilder, coffeeCompile, createConfig, di_config_file, di_write_file, dir, exec, fs, getCoffeeScriptFile, namespace, spacer;
dir = './';
di_config_file = dir + 'app/DependencyInjection/config.json';
di_write_file = dir + 'app/DependencyInjection/config.coffee';
spacer = ' ';
namespace = 'DI.config';
/**
Require modules
*/
exec = require('child_process').exec;
fs = require('fs');
/**
Task 1
Read JSON config a creates CoffeeScript config file
*/
createConfig = function() {
return fs.readFile(di_config_file, 'utf8', function(err, data) {
var output;
if (err) {
return console.log(err);
}
output = getCoffeeScriptFile(di_write_file, namespace, JSON.parse(data));
return fs.writeFile(di_write_file, output, function(err) {
if (err) {
return console.log(err);
} else {
return console.log("CoffeeScript config file saved to path " + di_write_file);
}
});
});
};
/**
Task 2
CoffeeScripts compilation.
*/
coffeeCompile = 'coffee --bare --compile ./';
/**
Task 3
Closure build.
*/
closureBuilder = 'closure-library/closure/bin/build/closurebuilder.py\
--root=closure-library/\
--root=app/ \
--namespace="app.start"\
--output_mode=compiled\
--compiler_jar=compiler.jar\
> app-compiled.js';
/**
Generate CoffeeScript config file.
Helper
*/
getCoffeeScriptFile = function(filePath, namespace, services) {
var args, config, output, service;
output = "goog.provide '" + namespace + "'\n\n";
config = "config =\n";
for (service in services) {
args = services[service];
config += "\n" + spacer + "'" + service + "':\n";
config += spacer + spacer + "'class': " + args["class"] + "\n";
output += "goog.require '" + args["class"] + "'\n";
if (args["arguments"] !== void 0) {
config += spacer + spacer + "'arguments': ['";
config += args["arguments"].join("', '");
config += "']\n";
}
}
output += "\n" + config + "\nlowerKeys = (config) ->\n for key, service of config\n key = new String key\n config[key.toLowerCase()] = service\n return config\n\n" + namespace + " = lowerKeys config";
return output;
};
/**
Run tasks
*/
createConfig();
exec(coffeeCompile, function() {
return console.log('CoffeeScript compile done.');
});
exec(closureBuilder, function() {
return console.log('Google Closure compile done.');
});