You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.3 KiB

11 years ago
'use strict';
module.exports = function (grunt){
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
version: {
src: ['src/Ply.es6']
},
11 years ago
es6transpiler: {
core: {
11 years ago
src: 'Ply.es6',
11 years ago
dest: 'Ply.js'
}
},
11 years ago
export: {
src: "src/Ply.es6",
dst: "Ply.es6"
},
11 years ago
watch: {
scripts: {
files: 'src/*.es6',
11 years ago
tasks: ['es'],
11 years ago
options: { interrupt: true }
}
},
qunit: {
all: ['tests/*.html'],
options: {
'--web-security': 'no',
coverage: {
src: ['Ply.js', 'Ply.ui.js'],
instrumentedFiles: 'temp/',
htmlReport: 'report/coverage',
coberturaReport: 'report/',
11 years ago
linesThresholdPct: 90,
statementsThresholdPct: 90,
functionsThresholdPct: 90,
branchesThresholdPct: 90
11 years ago
}
}
},
uglify: {
options: {
banner: '/*! <%= pkg.exportName %> <%= pkg.version %> - <%= pkg.license %> | <%= pkg.repository.url %> */\n'
},
dist: {
files: {
11 years ago
'<%= pkg.exportName %>.min.js': ['Ply.js']
11 years ago
}
}
}
});
11 years ago
grunt.registerTask('export', 'Export es6 to js', function () {
function file(rel, name) {
return rel.split('/').slice(0, -1).concat(name).join('/') + '.es6';
}
function parse(src, pad) {
grunt.log.writeln((pad || '') + 'Parse file:', src);
return grunt.file.read(src)
.replace(/module\.exports\s*=\s*([\s\S]+);/, '$1')
.replace(/require\('(.*?)'\);?/g, function (_, name) {
return parse(file(src, name), ' ');
})
.replace(/\/+\s+&import\s+"(.*?)".*?\n/g, function (_, name) {
return parse(file(src, name), ' ');
})
.trim()
;
}
var config = grunt.config(this.name);
var content = parse(config.src).replace(/;;;[^\n]+/g, '');
grunt.log.writeln(new Array(50).join('-'));
grunt.log.oklns('Write file:', config.dst);
grunt.file.write(config.dst, content);
});
grunt.loadNpmTasks('grunt-version');
11 years ago
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-qunit-istanbul');
grunt.loadNpmTasks('grunt-es6-transpiler');
grunt.loadNpmTasks('grunt-contrib-uglify');
11 years ago
grunt.registerTask('es', ['export', 'es6transpiler']);
11 years ago
grunt.registerTask('build', ['es', 'qunit']);
grunt.registerTask('min', ['uglify']);
grunt.registerTask('quick', ['es', 'min']);
grunt.registerTask('default', ['version', 'build', 'min']);
11 years ago
};