-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.js
143 lines (105 loc) · 3.03 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* release script with jake tasks.
*
* run from project root!
*/
var sys = require('sys');
var exec = require('child_process').exec;
var fs = require('fs');
var nodefy = require('nodefy');
var ncp = require('ncp').ncp;
var docco = require('docco');
var rimraf = require('rimraf');
var buildify = require('buildify');
//execute from root.
var RELEASE_DIR = './release/';
var NODE_DIR = RELEASE_DIR + 'node/';
var addGoogleAnalytics = function(content) {
var nb = buildify();
var ga = nb
.load('./build/parts/googleAnalytics.frag')
.content;
return content.replace('</head>', ga + "</head>");
};
var addLicense = function(content) {
var nb = buildify();
var lic = nb
.load('./build/parts/mitlicense.frag')
.content;
return lic + content;
};
function copy(from, to) {
fs
.createReadStream(from)
.pipe(fs.createWriteStream(to));
}
desc('setup');
task('setup', function() {
fs.mkdir(RELEASE_DIR, function() {
console.log('made release dir');
complete();
});
}, true);
desc('build node package');
task('nodeModule', ['setup'], function() {
nodefy.batchConvert('./src/*.js', NODE_DIR, function(err, results) {
if (err) {
console.log('node failed.', err);
return;
}
copy('./build/node-package.json', NODE_DIR + 'package.json');
copy('./README.md', NODE_DIR + 'README.md');
complete();
});
});
desc('build jsdoc');
task('jsdoc', ['setup'], function() {
//build jsdoc
exec('"./node_modules/.bin/jsdoc" ./src/ ./README.md -d ./release/jsdoc -t "./build/jsdoctemplate"', function(err, stdout, sterr) {
if (err || sterr) {
console.log('jsdoc failed.', err, sterr);
}
var b = buildify();
b
.load('./release/jsdoc/index.html')
.perform(addGoogleAnalytics)
.save('./release/jsdoc/index.html');
complete();
});
}, true);
desc('build demo');
task('demo', ['setup'], function() {
exec('node ./node_modules/requirejs/bin/r.js -o build/amd-profile-demo.js', function(err, stdout, sterr) {
if (err || sterr) {
console.error('demo minification failed.', err);
return;
}
var b = buildify();
b
.load("./release/index.html")
.perform(function(content) {
content = content.replace(/.*<!--amdloader-->([\s\S]*?)\<!--amdloader-->/g, '<script type="text/javascript" src="./require.js"></script>');
content = content.replace(/.*<!--bootstrap-->([\s\S]*?)\<!--bootstrap-->/g, '<script type="text/javascript" src="./main.js"></script>');
return content;
})
.save("./release/index.html");
//add ga
b = buildify();
b
.load("./release/index.html")
.perform(addGoogleAnalytics)
.save("./release/index.html");
b = buildify();
b
.load("./release/main.js")
.perform(addLicense)
.save("./release/main.js");
b = buildify();
b
.load("./bower_components/requirejs/require.js")
.save("./release/require.js");
complete();
});
}, true);
desc('build release');
task('release', ['demo','jsdoc','nodeModule']);