55ad26c2 by Adam Heath

Built files now going into dist/build, and an atomic-rename/symlink

technique is used to update the published files.
1 parent 8f636a83
......@@ -9,7 +9,7 @@ module.exports = function (grunt) {
var _ = require('lodash');
grunt.registerTask('revconfig', function revconfig() {
var prefix = grunt.template.process('dist/scripts/');
var prefix = grunt.template.process('dist/build/scripts/');
var pattern = prefix + '**/*.{js,html}';
var files = grunt.file.expand(pattern);
var lines = [
......@@ -47,7 +47,7 @@ module.exports = function (grunt) {
// ---
if (config.useRev) {
var prefix = grunt.template.process('dist/scripts/');
var prefix = grunt.template.process('dist/build/scripts/');
var pattern = prefix + '**/*.{js,html}';
var files = grunt.file.expand(pattern);
lines = [
......@@ -133,7 +133,7 @@ module.exports = function (grunt) {
dot: true,
src: [
holyGrailTmp,
'dist/*',
'dist/build/*',
'!dist/.git*'
]
}]
......@@ -146,7 +146,7 @@ module.exports = function (grunt) {
expand: true,
dot: true,
cwd: 'src',
dest: 'dist',
dest: 'dist/build',
src: [
'WEB-INF/{,*/}*.*',
'*.{ico,png,txt}',
......@@ -277,7 +277,7 @@ module.exports = function (grunt) {
expand: true,
dot: true,
cwd: htmlSourceDir,
dest: 'dist',
dest: 'dist/build',
src: [
'{,*/}*.{html,php}',
]
......@@ -295,7 +295,7 @@ module.exports = function (grunt) {
if (true) {
initConfig.useminPrepare = {
options: {
dest: 'dist'
dest: 'dist/build'
},
html: {
options: {
......@@ -306,14 +306,14 @@ module.exports = function (grunt) {
};
initConfig.usemin = {
options: {
dirs: ['dist']
dirs: ['dist/build']
},
html: {
options: {
dirs: ['dist'],
assetsDirs: ['dist'],
dirs: ['dist/build'],
assetsDirs: ['dist/build'],
},
src: ['dist/!(scripts){,**/}*.html'],
src: ['dist/build/!(scripts){,**/}*.html'],
},
};
initConfig.clean.montyPython.files[0].src.push('.grunt/usemin');
......@@ -322,9 +322,9 @@ module.exports = function (grunt) {
//options: _.extend({}, mpConfig.htmlmin.options),
files: [{
expand: true,
cwd: 'dist',
cwd: 'dist/build',
src: '{,*/}*.html',
dest: 'dist'
dest: 'dist/build'
}]
}
};
......@@ -344,13 +344,13 @@ module.exports = function (grunt) {
};
initConfig.clean.montyPython.files[0].src.push('.grunt/usemin-css');
initConfig.usemin.css = _.map(mpConfig.css.options.dirs, function (value) {
return 'dist/' + value + '/{,**/}*.css';
return 'dist/build/' + value + '/{,**/}*.css';
});
if (mpConfig.useRev) {
initConfig.rev.css = {
files: {
src: _.map(mpConfig.css.options.dirs, function (value) {
return 'dist/' + value + '/{,**/}*.css';
return 'dist/build/' + value + '/{,**/}*.css';
}),
}
};
......@@ -365,7 +365,7 @@ module.exports = function (grunt) {
expand: true,
cwd: 'src/' + value,
src: '{,**/}*.{gif,jpeg,jpg,png}',
dest: 'dist/' + value,
dest: 'dist/build/' + value,
};
}),
}
......@@ -377,7 +377,7 @@ module.exports = function (grunt) {
expand: true,
cwd: 'src/' + value,
src: '{,**/}*.svg',
dest: 'dist/' + value,
dest: 'dist/build/' + value,
};
}),
}
......@@ -387,7 +387,7 @@ module.exports = function (grunt) {
expand: true,
dot: true,
cwd: 'src',
dest: 'dist',
dest: 'dist/build',
src: _.map(mpConfig.images.options.dirs, function (value) {
return value + '/{,**/}*.*';
}),
......@@ -397,7 +397,7 @@ module.exports = function (grunt) {
initConfig.rev.img = {
files: {
src: _.map(mpConfig.images.options.dirs, function (value) {
return 'dist/' + value + '/{,**/}*.{gif,jpeg,jpg,png,webp}';
return 'dist/build/' + value + '/{,**/}*.{gif,jpeg,jpg,png,webp}';
}),
}
};
......@@ -420,8 +420,8 @@ module.exports = function (grunt) {
files: [{
expand: true,
dot: true,
cwd: 'dist/' + mpConfig.bower.directory,
dest: 'dist/' + mpConfig.bower.directory,
cwd: 'dist/build/' + mpConfig.bower.directory,
dest: 'dist/build/' + mpConfig.bower.directory,
src: [
'**/*.js',
]
......@@ -431,24 +431,24 @@ module.exports = function (grunt) {
if (mpConfig.useRev) {
initConfig.rev.dist.files.push({
src: [
'dist/' + mpConfig.bower.directory + '/**/*.js',
'!dist/' + mpConfig.bower.directory + '/requirejs/require.js',
'dist/scripts/**/*.js',
'!dist/scripts/config.js',
'!dist/scripts/defaults/**/*.js',
'dist/build/' + mpConfig.bower.directory + '/**/*.js',
'!dist/build/' + mpConfig.bower.directory + '/requirejs/require.js',
'dist/build/scripts/**/*.js',
'!dist/build/scripts/config.js',
'!dist/build/scripts/defaults/**/*.js',
],
});
initConfig.rev.requirejs = {
files: {
src: [
'dist/' + mpConfig.bower.directory + '/requirejs/require.js',
'dist/build/' + mpConfig.bower.directory + '/requirejs/require.js',
],
},
};
}
initConfig.concat.requirejs = {
files: [{
dest: 'dist/' + mpConfig.bower.directory + '/requirejs/require.js',
dest: 'dist/build/' + mpConfig.bower.directory + '/requirejs/require.js',
src: [
'src/scripts/config.js',
'.grunt/holygrail/scripts/requirejs-config.js',
......@@ -479,7 +479,7 @@ module.exports = function (grunt) {
skipDirOptimize: true,
//generateSourceMaps: true,
dir: 'dist/scripts',
dir: 'dist/build/scripts',
locale: 'en-us',
paths: {
'defaults': 'empty:',
......@@ -499,6 +499,35 @@ module.exports = function (grunt) {
'check',
]);
grunt.registerTask('deploy', 'deploy the built output', function() {
var fs = require('fs');
var current = fs.existsSync('dist/current') && fs.readlinkSync('dist/current');
var target;
if (current === 'a') {
target = 'b';
} else if (current === 'b') {
target = 'a';
} else {
current = undefined;
target = 'a';
}
if (fs.existsSync('dist/' + target)) {
grunt.file.delete('dist/' + target);
}
fs.renameSync('dist/build', 'dist/' + target);
if (fs.existsSync('dist/next-current')) {
fs.unlinkSync('dist/next-current');
}
fs.symlinkSync(target, 'dist/next-current');
fs.renameSync('dist/next-current', 'dist/current');
if (current) {
if (fs.statSync('dist/deploy-old')) {
grunt.file.delete('dist/deploy-old');
}
fs.renameSync('dist/' + current, 'dist/deploy-old');
}
});
grunt.registerTask('build', 'build the system', function() {
var buildList = [
'check',
......@@ -559,6 +588,7 @@ module.exports = function (grunt) {
buildList.push('usemin:html'); // montyPython
buildList.push('usemin:css'); // montyPython
buildList.push('htmlmin'); // montyPython
buildList.push('deploy'); // montyPython
grunt.task.run(buildList);
});
......