Built files now going into dist/build, and an atomic-rename/symlink
technique is used to update the published files.
Showing
1 changed file
with
58 additions
and
28 deletions
... | @@ -9,7 +9,7 @@ module.exports = function (grunt) { | ... | @@ -9,7 +9,7 @@ module.exports = function (grunt) { |
9 | var _ = require('lodash'); | 9 | var _ = require('lodash'); |
10 | 10 | ||
11 | grunt.registerTask('revconfig', function revconfig() { | 11 | grunt.registerTask('revconfig', function revconfig() { |
12 | var prefix = grunt.template.process('dist/scripts/'); | 12 | var prefix = grunt.template.process('dist/build/scripts/'); |
13 | var pattern = prefix + '**/*.{js,html}'; | 13 | var pattern = prefix + '**/*.{js,html}'; |
14 | var files = grunt.file.expand(pattern); | 14 | var files = grunt.file.expand(pattern); |
15 | var lines = [ | 15 | var lines = [ |
... | @@ -47,7 +47,7 @@ module.exports = function (grunt) { | ... | @@ -47,7 +47,7 @@ module.exports = function (grunt) { |
47 | 47 | ||
48 | // --- | 48 | // --- |
49 | if (config.useRev) { | 49 | if (config.useRev) { |
50 | var prefix = grunt.template.process('dist/scripts/'); | 50 | var prefix = grunt.template.process('dist/build/scripts/'); |
51 | var pattern = prefix + '**/*.{js,html}'; | 51 | var pattern = prefix + '**/*.{js,html}'; |
52 | var files = grunt.file.expand(pattern); | 52 | var files = grunt.file.expand(pattern); |
53 | lines = [ | 53 | lines = [ |
... | @@ -133,7 +133,7 @@ module.exports = function (grunt) { | ... | @@ -133,7 +133,7 @@ module.exports = function (grunt) { |
133 | dot: true, | 133 | dot: true, |
134 | src: [ | 134 | src: [ |
135 | holyGrailTmp, | 135 | holyGrailTmp, |
136 | 'dist/*', | 136 | 'dist/build/*', |
137 | '!dist/.git*' | 137 | '!dist/.git*' |
138 | ] | 138 | ] |
139 | }] | 139 | }] |
... | @@ -146,7 +146,7 @@ module.exports = function (grunt) { | ... | @@ -146,7 +146,7 @@ module.exports = function (grunt) { |
146 | expand: true, | 146 | expand: true, |
147 | dot: true, | 147 | dot: true, |
148 | cwd: 'src', | 148 | cwd: 'src', |
149 | dest: 'dist', | 149 | dest: 'dist/build', |
150 | src: [ | 150 | src: [ |
151 | 'WEB-INF/{,*/}*.*', | 151 | 'WEB-INF/{,*/}*.*', |
152 | '*.{ico,png,txt}', | 152 | '*.{ico,png,txt}', |
... | @@ -277,7 +277,7 @@ module.exports = function (grunt) { | ... | @@ -277,7 +277,7 @@ module.exports = function (grunt) { |
277 | expand: true, | 277 | expand: true, |
278 | dot: true, | 278 | dot: true, |
279 | cwd: htmlSourceDir, | 279 | cwd: htmlSourceDir, |
280 | dest: 'dist', | 280 | dest: 'dist/build', |
281 | src: [ | 281 | src: [ |
282 | '{,*/}*.{html,php}', | 282 | '{,*/}*.{html,php}', |
283 | ] | 283 | ] |
... | @@ -295,7 +295,7 @@ module.exports = function (grunt) { | ... | @@ -295,7 +295,7 @@ module.exports = function (grunt) { |
295 | if (true) { | 295 | if (true) { |
296 | initConfig.useminPrepare = { | 296 | initConfig.useminPrepare = { |
297 | options: { | 297 | options: { |
298 | dest: 'dist' | 298 | dest: 'dist/build' |
299 | }, | 299 | }, |
300 | html: { | 300 | html: { |
301 | options: { | 301 | options: { |
... | @@ -306,14 +306,14 @@ module.exports = function (grunt) { | ... | @@ -306,14 +306,14 @@ module.exports = function (grunt) { |
306 | }; | 306 | }; |
307 | initConfig.usemin = { | 307 | initConfig.usemin = { |
308 | options: { | 308 | options: { |
309 | dirs: ['dist'] | 309 | dirs: ['dist/build'] |
310 | }, | 310 | }, |
311 | html: { | 311 | html: { |
312 | options: { | 312 | options: { |
313 | dirs: ['dist'], | 313 | dirs: ['dist/build'], |
314 | assetsDirs: ['dist'], | 314 | assetsDirs: ['dist/build'], |
315 | }, | 315 | }, |
316 | src: ['dist/!(scripts){,**/}*.html'], | 316 | src: ['dist/build/!(scripts){,**/}*.html'], |
317 | }, | 317 | }, |
318 | }; | 318 | }; |
319 | initConfig.clean.montyPython.files[0].src.push('.grunt/usemin'); | 319 | initConfig.clean.montyPython.files[0].src.push('.grunt/usemin'); |
... | @@ -322,9 +322,9 @@ module.exports = function (grunt) { | ... | @@ -322,9 +322,9 @@ module.exports = function (grunt) { |
322 | //options: _.extend({}, mpConfig.htmlmin.options), | 322 | //options: _.extend({}, mpConfig.htmlmin.options), |
323 | files: [{ | 323 | files: [{ |
324 | expand: true, | 324 | expand: true, |
325 | cwd: 'dist', | 325 | cwd: 'dist/build', |
326 | src: '{,*/}*.html', | 326 | src: '{,*/}*.html', |
327 | dest: 'dist' | 327 | dest: 'dist/build' |
328 | }] | 328 | }] |
329 | } | 329 | } |
330 | }; | 330 | }; |
... | @@ -344,13 +344,13 @@ module.exports = function (grunt) { | ... | @@ -344,13 +344,13 @@ module.exports = function (grunt) { |
344 | }; | 344 | }; |
345 | initConfig.clean.montyPython.files[0].src.push('.grunt/usemin-css'); | 345 | initConfig.clean.montyPython.files[0].src.push('.grunt/usemin-css'); |
346 | initConfig.usemin.css = _.map(mpConfig.css.options.dirs, function (value) { | 346 | initConfig.usemin.css = _.map(mpConfig.css.options.dirs, function (value) { |
347 | return 'dist/' + value + '/{,**/}*.css'; | 347 | return 'dist/build/' + value + '/{,**/}*.css'; |
348 | }); | 348 | }); |
349 | if (mpConfig.useRev) { | 349 | if (mpConfig.useRev) { |
350 | initConfig.rev.css = { | 350 | initConfig.rev.css = { |
351 | files: { | 351 | files: { |
352 | src: _.map(mpConfig.css.options.dirs, function (value) { | 352 | src: _.map(mpConfig.css.options.dirs, function (value) { |
353 | return 'dist/' + value + '/{,**/}*.css'; | 353 | return 'dist/build/' + value + '/{,**/}*.css'; |
354 | }), | 354 | }), |
355 | } | 355 | } |
356 | }; | 356 | }; |
... | @@ -365,7 +365,7 @@ module.exports = function (grunt) { | ... | @@ -365,7 +365,7 @@ module.exports = function (grunt) { |
365 | expand: true, | 365 | expand: true, |
366 | cwd: 'src/' + value, | 366 | cwd: 'src/' + value, |
367 | src: '{,**/}*.{gif,jpeg,jpg,png}', | 367 | src: '{,**/}*.{gif,jpeg,jpg,png}', |
368 | dest: 'dist/' + value, | 368 | dest: 'dist/build/' + value, |
369 | }; | 369 | }; |
370 | }), | 370 | }), |
371 | } | 371 | } |
... | @@ -377,7 +377,7 @@ module.exports = function (grunt) { | ... | @@ -377,7 +377,7 @@ module.exports = function (grunt) { |
377 | expand: true, | 377 | expand: true, |
378 | cwd: 'src/' + value, | 378 | cwd: 'src/' + value, |
379 | src: '{,**/}*.svg', | 379 | src: '{,**/}*.svg', |
380 | dest: 'dist/' + value, | 380 | dest: 'dist/build/' + value, |
381 | }; | 381 | }; |
382 | }), | 382 | }), |
383 | } | 383 | } |
... | @@ -387,7 +387,7 @@ module.exports = function (grunt) { | ... | @@ -387,7 +387,7 @@ module.exports = function (grunt) { |
387 | expand: true, | 387 | expand: true, |
388 | dot: true, | 388 | dot: true, |
389 | cwd: 'src', | 389 | cwd: 'src', |
390 | dest: 'dist', | 390 | dest: 'dist/build', |
391 | src: _.map(mpConfig.images.options.dirs, function (value) { | 391 | src: _.map(mpConfig.images.options.dirs, function (value) { |
392 | return value + '/{,**/}*.*'; | 392 | return value + '/{,**/}*.*'; |
393 | }), | 393 | }), |
... | @@ -397,7 +397,7 @@ module.exports = function (grunt) { | ... | @@ -397,7 +397,7 @@ module.exports = function (grunt) { |
397 | initConfig.rev.img = { | 397 | initConfig.rev.img = { |
398 | files: { | 398 | files: { |
399 | src: _.map(mpConfig.images.options.dirs, function (value) { | 399 | src: _.map(mpConfig.images.options.dirs, function (value) { |
400 | return 'dist/' + value + '/{,**/}*.{gif,jpeg,jpg,png,webp}'; | 400 | return 'dist/build/' + value + '/{,**/}*.{gif,jpeg,jpg,png,webp}'; |
401 | }), | 401 | }), |
402 | } | 402 | } |
403 | }; | 403 | }; |
... | @@ -420,8 +420,8 @@ module.exports = function (grunt) { | ... | @@ -420,8 +420,8 @@ module.exports = function (grunt) { |
420 | files: [{ | 420 | files: [{ |
421 | expand: true, | 421 | expand: true, |
422 | dot: true, | 422 | dot: true, |
423 | cwd: 'dist/' + mpConfig.bower.directory, | 423 | cwd: 'dist/build/' + mpConfig.bower.directory, |
424 | dest: 'dist/' + mpConfig.bower.directory, | 424 | dest: 'dist/build/' + mpConfig.bower.directory, |
425 | src: [ | 425 | src: [ |
426 | '**/*.js', | 426 | '**/*.js', |
427 | ] | 427 | ] |
... | @@ -431,24 +431,24 @@ module.exports = function (grunt) { | ... | @@ -431,24 +431,24 @@ module.exports = function (grunt) { |
431 | if (mpConfig.useRev) { | 431 | if (mpConfig.useRev) { |
432 | initConfig.rev.dist.files.push({ | 432 | initConfig.rev.dist.files.push({ |
433 | src: [ | 433 | src: [ |
434 | 'dist/' + mpConfig.bower.directory + '/**/*.js', | 434 | 'dist/build/' + mpConfig.bower.directory + '/**/*.js', |
435 | '!dist/' + mpConfig.bower.directory + '/requirejs/require.js', | 435 | '!dist/build/' + mpConfig.bower.directory + '/requirejs/require.js', |
436 | 'dist/scripts/**/*.js', | 436 | 'dist/build/scripts/**/*.js', |
437 | '!dist/scripts/config.js', | 437 | '!dist/build/scripts/config.js', |
438 | '!dist/scripts/defaults/**/*.js', | 438 | '!dist/build/scripts/defaults/**/*.js', |
439 | ], | 439 | ], |
440 | }); | 440 | }); |
441 | initConfig.rev.requirejs = { | 441 | initConfig.rev.requirejs = { |
442 | files: { | 442 | files: { |
443 | src: [ | 443 | src: [ |
444 | 'dist/' + mpConfig.bower.directory + '/requirejs/require.js', | 444 | 'dist/build/' + mpConfig.bower.directory + '/requirejs/require.js', |
445 | ], | 445 | ], |
446 | }, | 446 | }, |
447 | }; | 447 | }; |
448 | } | 448 | } |
449 | initConfig.concat.requirejs = { | 449 | initConfig.concat.requirejs = { |
450 | files: [{ | 450 | files: [{ |
451 | dest: 'dist/' + mpConfig.bower.directory + '/requirejs/require.js', | 451 | dest: 'dist/build/' + mpConfig.bower.directory + '/requirejs/require.js', |
452 | src: [ | 452 | src: [ |
453 | 'src/scripts/config.js', | 453 | 'src/scripts/config.js', |
454 | '.grunt/holygrail/scripts/requirejs-config.js', | 454 | '.grunt/holygrail/scripts/requirejs-config.js', |
... | @@ -479,7 +479,7 @@ module.exports = function (grunt) { | ... | @@ -479,7 +479,7 @@ module.exports = function (grunt) { |
479 | skipDirOptimize: true, | 479 | skipDirOptimize: true, |
480 | //generateSourceMaps: true, | 480 | //generateSourceMaps: true, |
481 | 481 | ||
482 | dir: 'dist/scripts', | 482 | dir: 'dist/build/scripts', |
483 | locale: 'en-us', | 483 | locale: 'en-us', |
484 | paths: { | 484 | paths: { |
485 | 'defaults': 'empty:', | 485 | 'defaults': 'empty:', |
... | @@ -499,6 +499,35 @@ module.exports = function (grunt) { | ... | @@ -499,6 +499,35 @@ module.exports = function (grunt) { |
499 | 'check', | 499 | 'check', |
500 | ]); | 500 | ]); |
501 | 501 | ||
502 | grunt.registerTask('deploy', 'deploy the built output', function() { | ||
503 | var fs = require('fs'); | ||
504 | var current = fs.existsSync('dist/current') && fs.readlinkSync('dist/current'); | ||
505 | var target; | ||
506 | if (current === 'a') { | ||
507 | target = 'b'; | ||
508 | } else if (current === 'b') { | ||
509 | target = 'a'; | ||
510 | } else { | ||
511 | current = undefined; | ||
512 | target = 'a'; | ||
513 | } | ||
514 | if (fs.existsSync('dist/' + target)) { | ||
515 | grunt.file.delete('dist/' + target); | ||
516 | } | ||
517 | fs.renameSync('dist/build', 'dist/' + target); | ||
518 | if (fs.existsSync('dist/next-current')) { | ||
519 | fs.unlinkSync('dist/next-current'); | ||
520 | } | ||
521 | fs.symlinkSync(target, 'dist/next-current'); | ||
522 | fs.renameSync('dist/next-current', 'dist/current'); | ||
523 | if (current) { | ||
524 | if (fs.statSync('dist/deploy-old')) { | ||
525 | grunt.file.delete('dist/deploy-old'); | ||
526 | } | ||
527 | fs.renameSync('dist/' + current, 'dist/deploy-old'); | ||
528 | } | ||
529 | }); | ||
530 | |||
502 | grunt.registerTask('build', 'build the system', function() { | 531 | grunt.registerTask('build', 'build the system', function() { |
503 | var buildList = [ | 532 | var buildList = [ |
504 | 'check', | 533 | 'check', |
... | @@ -559,6 +588,7 @@ module.exports = function (grunt) { | ... | @@ -559,6 +588,7 @@ module.exports = function (grunt) { |
559 | buildList.push('usemin:html'); // montyPython | 588 | buildList.push('usemin:html'); // montyPython |
560 | buildList.push('usemin:css'); // montyPython | 589 | buildList.push('usemin:css'); // montyPython |
561 | buildList.push('htmlmin'); // montyPython | 590 | buildList.push('htmlmin'); // montyPython |
591 | buildList.push('deploy'); // montyPython | ||
562 | 592 | ||
563 | grunt.task.run(buildList); | 593 | grunt.task.run(buildList); |
564 | }); | 594 | }); | ... | ... |
-
Please register or sign in to post a comment