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.

100 lines
2.1 KiB

11 years ago
'use strict';
module.exports = function (grunt){
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
es6transpiler: {
core: {
10 years ago
src: 'Ply.es6',
11 years ago
dest: 'Ply.js'
}
},
10 years ago
export: {
src: "src/Ply.es6",
dst: "Ply.es6"
},
11 years ago
watch: {
scripts: {
files: 'src/*.es6',
10 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: {
10 years ago
'<%= pkg.exportName %>.min.js': ['Ply.js']
11 years ago
}
}
}
});
10 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);
});
11 years ago
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-qunit-istanbul');
grunt.loadNpmTasks('grunt-es6-transpiler');
grunt.loadNpmTasks('grunt-contrib-uglify');
10 years ago
grunt.registerTask('es', ['export', 'es6transpiler']);
11 years ago
grunt.registerTask('build', ['es', 'qunit']);
grunt.registerTask('min', ['uglify']);
grunt.registerTask('default', ['build', 'min']);
11 years ago
};