UNPKG

5.95 kBPlain TextView Raw
1var releaseTools = require('releasetools');
2var Step = require('step');
3var exec = require('child_process').exec;
4
5releaseTools.setOptions({
6 examplePaths: [
7 'lib/prettyjson.js'
8 ],
9 siteAssetsPaths: [
10 'site/images',
11 'site/javascripts',
12 'site/stylesheets'
13 ]
14});
15
16// Test task
17desc("execute tests");
18task("test", function() {
19 var spawn = require('child_process').spawn;
20 var child = spawn('npm', ['test']);
21
22 console.log('executing the tests...');
23
24 child.stderr.on('data', function(stderr) {
25 process.stderr.write(stderr);
26 });
27 child.stdout.on('data', function(stdout) {
28 process.stdout.write(stdout);
29 });
30 child.on('exit', function(code) {
31 if (code !== 0) {
32 fail(code);
33 } else {
34 console.log('Done!');
35 complete();
36 }
37 });
38}, true);
39
40
41// Lint task
42desc("execute JSHint checks");
43task("jshint", function() {
44 exec('node_modules/jshint/bin/jshint bin/ lib/ --config ".jshint"', function(err, stdout, stderr) {
45 if (err) {
46 console.log(err);
47 fail(err);
48 }
49 else {
50 console.log('Done!');
51 complete();
52 }
53 });
54}, true);
55
56// Auto tests task
57desc("auto execute tests");
58task("watch", function() {
59 var spawn = require('child_process').spawn;
60 var child = spawn('node_modules/mocha/bin/mocha', ['-w', '-G', '--reporter', 'spec']);
61
62 child.stderr.on('data', function(stderr) {
63 process.stderr.write(stderr);
64 });
65 child.stdout.on('data', function(stdout) {
66 process.stdout.write(stdout);
67 });
68 child.on('exit', function(code) {
69 if (code !== 0) {
70 fail(code);
71 } else {
72 console.log('Done!');
73 complete();
74 }
75 });
76}, true);
77
78desc("create test coverage file");
79task("test-cov", function() {
80 console.log('Creating test coverage file...');
81
82 Step(
83 function() {
84 exec('rm -fr lib-cov', this);
85 },
86 function(err, stdout, stderr) {
87 if (err) throw err;
88 exec('node_modules/jscoverage/bin/jscoverage lib lib-cov', this);
89 },
90 function(err, stdout, stderr) {
91 if (err) throw err;
92 exec('EXPRESS_COV=1 node_modules/mocha/bin/mocha -R html-cov > docs/coverage.html', this);
93 },
94 function(err, stdout, stderr) {
95 if (err) fail(err);
96 else {
97 console.log('Done!');
98 complete();
99 }
100 }
101 );
102}, true);
103
104// Namespace with all the release related tasks
105namespace('release', function() {
106
107 // Build task
108 desc('Modify the working copy with all the release information');
109 task('build', ['test', 'test-cov', 'jshint'], function(releaseType) {
110 Step(
111
112 // Update Changelog
113 function() {
114 console.log('Updating History.md file...');
115 releaseTools.updateChangelog(this);
116 },
117 // Update Contributors
118 function(err) {
119 if (err) throw err;
120 console.log('Updating AUTHORS file...');
121 releaseTools.updateAuthorsFile(this);
122 },
123 // Create Example HTML files
124 function(err) {
125 if (err) throw err;
126 console.log('creating examples documentation...');
127 releaseTools.createExamples(this);
128 },
129 function(err) {
130 if (err) fail(err);
131 else complete();
132 }
133 );
134 }, true);
135
136 // Create site task
137 desc('Create the public site');
138 task('site', function(releaseType) {
139 console.log('Creating the public site page...');
140 releaseTools.createSite(function(err) {
141 if (err) fail();
142 else complete();
143 });
144 }, true);
145
146 // Publish task
147 desc('Publish only the static site');
148 task('publish-site', ['site'], function() {
149 Step(
150 // Update gh-pages branch
151 function(err) {
152 if (err) throw err;
153 console.log('Merging changes into gh-pages branch...');
154 releaseTools.updatePagesBranch(this);
155 },
156 // Push to GitHub
157 function(err) {
158 if (err) throw err;
159 console.log('Pushing changes to GitHub...');
160 releaseTools.pushToGit(this);
161 },
162 function(err){
163 if (err) fail(err);
164 else complete();
165 }
166 );
167 }, true);
168
169 // Publish task
170 desc('Publish to GitHub and NPM the new version');
171 task('publish', ['test'] , function() {
172 Step(
173 // Check if the `History.md` is modified
174 // (to ensure that the `release:build` task has been already executed)
175 function() {
176 releaseTools.isWorkingCopyClean('History.md', this);
177 },
178
179 // Commit to Git
180 function(err, result) {
181 if (err) throw('Error while checking if the git tree is clean: ' + err);
182 if (result) throw('You must run jake release:build before publish');
183 console.log('Bumping version and creating git tag...');
184 releaseTools.commitToGit(this);
185 },
186
187 // Update gh-pages branch
188 function(err) {
189 if (err) throw err;
190 console.log('Merging changes into gh-pages branch...');
191 releaseTools.updatePagesBranch(this);
192 },
193
194 // Push to GitHub
195 function(err) {
196 if (err) throw err;
197 console.log('Pushing changes to GitHub...');
198 releaseTools.pushToGit(this);
199 },
200
201 // Publish to NPM
202 function(err) {
203 if (err) throw err;
204 console.log('Publishing NPM package...');
205 releaseTools.npmPublish(this);
206 },
207 function(err){
208 if (err) fail(err);
209 else complete();
210 }
211 );
212 }, true);
213
214 // Update package.json task
215 desc('Bump version in package.json');
216 task('bump', function(releaseType) {
217 releaseType = releaseType || 'patch';
218 console.log('Bumping version in package.json...');
219 releaseTools.updateVersionInPackageJson(releaseType, function(err, oldVersion, newVersion) {
220 if (err) {
221 return fail('Error while updating version in package.json: ' + err);
222 }
223 console.log(oldVersion + ' --> ' + newVersion);
224 console.log('Done!');
225 complete();
226 });
227 }, true);
228});
229
230desc('Default task is test');
231task('default', ['test'], function(){}, true);