154 lines
3.7 KiB
JavaScript
154 lines
3.7 KiB
JavaScript
var childProcess = require('child_process');
|
|
|
|
module.exports = function(grunt) {
|
|
|
|
grunt.initConfig({
|
|
pkg: grunt.file.readJSON('package.json'),
|
|
|
|
jshint: {
|
|
options: {
|
|
jshintrc: '.jshintrc',
|
|
force: true
|
|
},
|
|
files: [
|
|
'lib/**/!(parser).js'
|
|
]
|
|
},
|
|
|
|
clean: ["dist", "lib/handlebars/compiler/parser.js"],
|
|
|
|
copy: {
|
|
dist: {
|
|
options: {
|
|
processContent: function(content, path) {
|
|
return grunt.template.process('/*!\n\n <%= pkg.name %> v<%= pkg.version %>\n\n<%= grunt.file.read("LICENSE") %>\n@license\n*/\n')
|
|
+ content;
|
|
}
|
|
},
|
|
files: [
|
|
{expand: true, cwd: 'dist/', src: ['*.js'], dest: 'dist/'}
|
|
]
|
|
},
|
|
cdnjs: {
|
|
files: [
|
|
{expand: true, cwd: 'dist/', src: ['*.js'], dest: 'dist/cdnjs'}
|
|
]
|
|
},
|
|
components: {
|
|
files: [
|
|
{expand: true, cwd: 'components/', src: ['**'], dest: 'dist/components'},
|
|
{expand: true, cwd: 'dist/', src: ['*.js'], dest: 'dist/components'}
|
|
]
|
|
}
|
|
},
|
|
|
|
transpile: {
|
|
amd: {
|
|
type: "amd",
|
|
anonymous: true,
|
|
files: [{
|
|
expand: true,
|
|
cwd: 'lib/',
|
|
src: '**/!(index).js',
|
|
dest: 'dist/amd/'
|
|
}]
|
|
},
|
|
|
|
cjs: {
|
|
type: 'cjs',
|
|
files: [{
|
|
expand: true,
|
|
cwd: 'lib/',
|
|
src: '**/!(index).js',
|
|
dest: 'dist/cjs/'
|
|
}]
|
|
}
|
|
},
|
|
|
|
packager: {
|
|
options: {
|
|
export: 'Handlebars'
|
|
},
|
|
|
|
global: {
|
|
files: [{
|
|
cwd: 'lib/',
|
|
expand: true,
|
|
src: ['handlebars*.js'],
|
|
dest: 'dist/'
|
|
}]
|
|
}
|
|
},
|
|
requirejs: {
|
|
options: {
|
|
optimize: "none",
|
|
baseUrl: "dist/amd/"
|
|
},
|
|
dist: {
|
|
options: {
|
|
name: "handlebars",
|
|
out: "dist/handlebars.amd.js"
|
|
}
|
|
},
|
|
runtime: {
|
|
options: {
|
|
name: "handlebars.runtime",
|
|
out: "dist/handlebars.runtime.amd.js"
|
|
}
|
|
}
|
|
},
|
|
|
|
uglify: {
|
|
options: {
|
|
mangle: true,
|
|
compress: true,
|
|
preserveComments: 'some'
|
|
},
|
|
dist: {
|
|
files: [{
|
|
cwd: 'dist/',
|
|
expand: true,
|
|
src: ['handlebars*.js'],
|
|
dest: 'dist/',
|
|
rename: function(dest, src) {
|
|
return dest + src.replace(/\.js$/, '.min.js');
|
|
}
|
|
}]
|
|
}
|
|
}
|
|
});
|
|
|
|
// Build a new version of the library
|
|
this.registerTask('build', "Builds a distributable version of the current project", [
|
|
'jshint',
|
|
'clean',
|
|
'parser',
|
|
'node',
|
|
'globals']);
|
|
|
|
this.registerTask('amd', ['transpile:amd', 'requirejs']);
|
|
this.registerTask('node', ['transpile:cjs']);
|
|
this.registerTask('globals', ['packager-fork']);
|
|
|
|
this.registerTask('release', 'Build final packages', ['amd', 'uglify', 'copy:dist', 'copy:components', 'copy:cdnjs']);
|
|
|
|
// Load tasks from npm
|
|
grunt.loadNpmTasks('grunt-contrib-clean');
|
|
grunt.loadNpmTasks('grunt-contrib-copy');
|
|
grunt.loadNpmTasks('grunt-contrib-requirejs');
|
|
grunt.loadNpmTasks('grunt-contrib-jshint');
|
|
grunt.loadNpmTasks('grunt-contrib-uglify');
|
|
grunt.loadNpmTasks('grunt-es6-module-transpiler');
|
|
|
|
grunt.task.loadTasks('tasks');
|
|
|
|
grunt.registerTask('packager-fork', function() {
|
|
// Allows us to run the packager task out of process to work around the multiple
|
|
// traceur exec issues
|
|
grunt.util.spawn({grunt: true, args: ['--stack', 'packager'], opts: {stdio: 'inherit'}}, this.async());
|
|
});
|
|
grunt.registerTask('bench', ['metrics']);
|
|
|
|
grunt.registerTask('default', ['build', 'test', 'release']);
|
|
};
|