1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | var path = require( "path" );
|
25 | var _ = require( "lodash" );
|
26 | var request = require('request');
|
27 | var async = require( "async" );
|
28 | var fs = require( "fs" );
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | var jsdocTestPages = {
|
42 | dest : "./testdocs",
|
43 | tutorials : "./fixtures/tutorials",
|
44 | template : "./template",
|
45 | config : "./fixtures/testdocs.conf.json",
|
46 | options : " --lenient --verbose --recurse"
|
47 | };
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | var jsdocExamplePages = {
|
55 | src : ["./fixtures/", "./README.md"],
|
56 | dest : "./themes",
|
57 | tutorials : "./fixtures/tutorials",
|
58 | template : "./template",
|
59 | config : "./fixtures/example.conf.json",
|
60 | options : " --lenient --verbose --recurse"
|
61 | };
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | var projectDocs = {
|
68 | src : ["./Gruntfile.js", "./README.md", "./template/publish.js"],
|
69 | dest : "./dox",
|
70 | tutorials : "",
|
71 | template : "./template",
|
72 | config : "./template/jsdoc.conf.json",
|
73 | options : " --lenient --verbose --recurse --private"
|
74 | };
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | function jsdocCommand( jsdoc ) {
|
82 | var cmd = [];
|
83 | cmd.unshift( jsdoc.options );
|
84 | if ( jsdoc.tutorials.length > 0 ) {
|
85 | cmd.push( "-u " + path.resolve( jsdoc.tutorials ) );
|
86 | }
|
87 | cmd.push( "-d " + path.resolve( jsdoc.dest ) );
|
88 | cmd.push( "-t " + path.resolve( jsdoc.template ) );
|
89 | cmd.push( "-c " + path.resolve( jsdoc.config ) );
|
90 | _.each( jsdoc.src, function ( src ) {
|
91 | cmd.push( path.resolve( src ) );
|
92 | } );
|
93 | cmd.unshift( path.resolve( "./node_modules/jsdoc/jsdoc" ) );
|
94 | cmd.unshift( "node" );
|
95 |
|
96 | return cmd.join( " " );
|
97 | }
|
98 |
|
99 | var tasks = {
|
100 | shell : {
|
101 | options : {
|
102 | stdout : true,
|
103 | stderr : true
|
104 | },
|
105 | |
106 |
|
107 |
|
108 |
|
109 |
|
110 | testdocs : {
|
111 | command : jsdocCommand( jsdocTestPages )
|
112 | },
|
113 | |
114 |
|
115 |
|
116 |
|
117 |
|
118 | dox : {
|
119 | command : jsdocCommand( projectDocs )
|
120 | },
|
121 | release1 : {
|
122 | command : [
|
123 | "touch Gruntfile.js",
|
124 | "git add .",
|
125 | 'git commit -m "ready for release"',
|
126 | ].join( ";" )
|
127 |
|
128 | },
|
129 | release2 : {
|
130 | command : ["npm version patch",
|
131 | "git push",
|
132 | "git push --tags",
|
133 | "npm publish"
|
134 | ].join( "&&" )
|
135 | }
|
136 | },
|
137 | jsdoc : {
|
138 | testdocs : {
|
139 | src : ['fixtures/**.js', "./README.md"],
|
140 | jsdoc : "./node_modules/jsdoc/jsdoc.js",
|
141 | options : {
|
142 | destination : './testdocs',
|
143 | rescurse : true,
|
144 | "private" : true,
|
145 | "template" : "./template",
|
146 | "configure" : "./template/jsdoc.conf.json"
|
147 | }
|
148 | }
|
149 | },
|
150 | |
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 | less : {
|
158 | dev : {
|
159 | files : {
|
160 | "template/static/styles/site.<%= jsdocConf.templates.theme %>.css" : "styles/main.less"
|
161 | }
|
162 | }
|
163 | },
|
164 | copy : {
|
165 | docs : {
|
166 | files : [
|
167 | {expand : true, cwd : "dox/", src : ['**'], dest : '../docstrap-dox/'},
|
168 | {expand : true, cwd : "themes/", src : ['**'], dest : '../docstrap-dox/themes'}
|
169 | ]
|
170 | }
|
171 | },
|
172 | uglify : {
|
173 | template : {
|
174 | files : {
|
175 | 'template/static/scripts/docstrap.lib.js' : [
|
176 | 'bower_components/jquery/dist/jquery.min.js',
|
177 | 'bower_components/sunlight/src/sunlight.js',
|
178 | 'bower_components/sunlight/src/lang/sunlight.xml.js',
|
179 | 'bower_components/sunlight/src/**/*.js',
|
180 |
|
181 | 'bower_components/jquery.scrollTo/jquery.scrollTo.min.js',
|
182 | 'bower_components/jquery.localScroll/jquery.localScroll.min.js',
|
183 | 'bower_components/bootstrap/dist/js/bootstrap.min.js'
|
184 | ]
|
185 | }
|
186 | }
|
187 | }
|
188 | };
|
189 |
|
190 | module.exports = function ( grunt ) {
|
191 | tasks.jsdocConf = grunt.file.readJSON( 'template/jsdoc.conf.json' );
|
192 |
|
193 | grunt.initConfig( tasks );
|
194 |
|
195 | grunt.loadNpmTasks( 'grunt-contrib-less' );
|
196 | grunt.loadNpmTasks( 'grunt-shell' );
|
197 | grunt.loadNpmTasks( 'grunt-contrib-copy' );
|
198 | grunt.loadNpmTasks( 'grunt-contrib-uglify' );
|
199 |
|
200 | grunt.registerTask( "default", ["docs"] );
|
201 |
|
202 | |
203 |
|
204 |
|
205 |
|
206 |
|
207 | grunt.registerTask( "docs", "Create the project documentation", ["shell:dox"] );
|
208 | |
209 |
|
210 |
|
211 |
|
212 |
|
213 | grunt.registerTask( "dev", "Compile the CSS and create the project documentation", ["less", "shell:dox"] );
|
214 | |
215 |
|
216 |
|
217 |
|
218 |
|
219 | grunt.registerTask( "testdocs", "Builds the main less file and then generates the test documents", ["less:dev", "shell:testdocs"] );
|
220 | |
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 | grunt.registerTask( "build", "Builds the whole shebang. Which means creating testdocs, the bootswatch samples and then resetting the styles directory", ["uglify:template", "testdocs", "shell:dox", "bootswatch", "examples", "apply", "copy"] );
|
227 | |
228 |
|
229 |
|
230 |
|
231 |
|
232 | grunt.registerTask( "apply", "Applies the theme in the conf file and applies it to the styles directory", function () {
|
233 | var def = {
|
234 | less : "http://bootswatch.com/" + tasks.jsdocConf.templates.theme + "/bootswatch.less",
|
235 | lessVariables : "http://bootswatch.com/" + tasks.jsdocConf.templates.theme + "/variables.less"
|
236 | };
|
237 | grunt.registerTask( "swatch-apply", _.partial( applyTheme, grunt, def ) );
|
238 | grunt.task.run( ["swatch-apply"] );
|
239 | } );
|
240 | |
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 | grunt.registerTask( "bootswatch", "Grab all Bootswatch themes and create css from each one based on the main.less in the styles directory", function () {
|
247 | var toRun = [];
|
248 |
|
249 | var done = this.async();
|
250 | getBootSwatchList( function ( err, list ) {
|
251 | if ( err ) {return done( err );}
|
252 |
|
253 | _.each( list.themes, function ( entry ) {
|
254 |
|
255 | toRun.push( "swatch" + entry.name );
|
256 | grunt.registerTask( "swatch" + entry.name, _.partial( applyTheme, grunt, entry ) );
|
257 |
|
258 | var key = "template/static/styles/site." + entry.name.toLowerCase() + ".css";
|
259 | var def = {};
|
260 | def[key] = "styles/main.less";
|
261 | tasks.less["swatch" + entry.name] = {
|
262 | files : def
|
263 | };
|
264 | toRun.push( "less:swatch" + entry.name );
|
265 | } );
|
266 | grunt.task.run( toRun );
|
267 | done();
|
268 | } );
|
269 |
|
270 | } );
|
271 | |
272 |
|
273 |
|
274 |
|
275 |
|
276 | grunt.registerTask( "examples", "Create samples from the themes", function () {
|
277 | var toRun = [];
|
278 | var done = this.async();
|
279 | getBootSwatchList( function ( err, list ) {
|
280 | if ( err ) {return done( err );}
|
281 |
|
282 | _.each( list.themes, function ( entry ) {
|
283 | var conf = grunt.file.readJSON( './fixtures/example.conf.json' );
|
284 | conf.templates.theme = entry.name.toLowerCase();
|
285 | grunt.file.write( "tmp/example.conf." + conf.templates.theme + ".json", JSON.stringify( conf, null, 4 ) );
|
286 |
|
287 | var jsdenv = _.cloneDeep( jsdocExamplePages );
|
288 | jsdenv.config = "./tmp/example.conf." + conf.templates.theme + ".json";
|
289 | jsdenv.dest = "./themes/" + conf.templates.theme;
|
290 | tasks.shell["example" + conf.templates.theme] = {
|
291 | command : jsdocCommand( jsdenv )
|
292 | };
|
293 | toRun.push( "shell:example" + conf.templates.theme );
|
294 | } );
|
295 |
|
296 | grunt.registerTask( "cleanup", "", function () {
|
297 | grunt.file["delete"]( "tmp/" );
|
298 | } );
|
299 | toRun.push( "cleanup" );
|
300 | grunt.task.run( toRun );
|
301 | done();
|
302 | } );
|
303 |
|
304 | } );
|
305 |
|
306 | grunt.registerTask( "release", "Create the project documentation", ["shell:release1", "shell:release2"] );
|
307 | };
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 | function applyTheme( grunt, definition ) {
|
324 |
|
325 |
|
326 | var webProtocol = tasks.jsdocConf.templates.protocol || "//";
|
327 | var done = this.async();
|
328 | async.waterfall( [
|
329 | function ( cb ) {
|
330 | getBootSwatchComponent( definition.less, function ( err, swatch ) {
|
331 | if ( err ) {return cb( err );}
|
332 | var fullPath = path.join( __dirname, "styles/bootswatch.less" );
|
333 | fs.writeFile( fullPath, swatch.replace( "http://", webProtocol ), cb );
|
334 | } );
|
335 | },
|
336 | function ( cb ) {
|
337 | getBootSwatchComponent( definition.lessVariables, function ( err, swatch ) {
|
338 | if ( err ) {return cb( err );}
|
339 | var fullPath = path.join( __dirname, "styles/variables.less" );
|
340 | fs.writeFile( fullPath, swatch.replace( "http://", webProtocol ), cb );
|
341 | } );
|
342 | }
|
343 | ], done );
|
344 | }
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 | function getBootSwatchList( done ) {
|
357 | request('http://api.bootswatch.com/3/', function(error, response, body) {
|
358 | if (error) {
|
359 | return done(error);
|
360 | }
|
361 | done(null, JSON.parse(body));
|
362 | });
|
363 | }
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 | function getBootSwatchComponent( url, done ) {
|
376 | var body = "";
|
377 | var req = request(url, function ( error, response, body ) {
|
378 | if (error) {
|
379 | return done(error);
|
380 | }
|
381 | done(null, body);
|
382 | });
|
383 | }
|