angular-property-binder
Version:
Bind property and keep safe the reference
160 lines (141 loc) • 3.35 kB
JavaScript
var paths = {};
var Path = require('path');
paths.base = Path.normalize(__dirname);
function Grunt(grunt) {
var tasks = [
'grunt-babel',
'grunt-add-comment',
'grunt-contrib-concat',
'grunt-wrap',
'grunt-contrib-uglify'
];
for (var i = 0; i < tasks.length; i++)
grunt.loadNpmTasks(tasks[i]);
require('time-grunt')(grunt);
var pathOption = getPathOption(grunt);
var Configuration = {};
Configuration.package = grunt.file.readJSON('package.json');
Configuration.babel = {
options: {
sourceMap: false
},
all: {
files: [{
expand: true,
cwd: paths.base,
ext: '.js',
src: (pathOption ? pathOption.name : ['**/*.es6']),
dest: paths.base
}]
},
dist: {
options: {
blacklist:['useStrict']
},
files: [{
expand: true,
cwd: paths.base,
ext: '.js',
src: (pathOption ? pathOption.name : ['**/*.es6']),
dest: paths.base
}]
}
};
Configuration.add_comment = {
common: {
options: {
comments: ['Autogenerated, do not edit. All changes will be undone.'],
prepend: true,
syntaxes: {
'.js': '//'
}
},
files: [{
expand: true,
src: (pathOption ? [pathOption.name.replace('.es6', '.js')] : ['lib/**/*.js']),
}]
},
dist: {
options: {
comments: [
'<%= package.name %>',
'version: <%= package.version %>',
'author: <%= package.author %>',
'generated: ' + new Date(),
'Autogenerated, do not edit. All changes will be undone.'],
prepend: true,
syntaxes: {
'.js': '//'
}
},
files: [{
expand: true,
src: ['dist/*.js'],
}]
},
strict: {
options: {
comments: ['use strict;'],
prepend: true,
syntaxes: {
'.js': ['"','";']
}
},
src: ['dist/<%= package.name %>.js'],
dest: 'dist/<%= package.name %>.js'
}
};
Configuration.uglify = {
options: {
enclose: {
'window': 'window',
'window.document': 'document',
'window.angular': 'angular'
},
mangle: {
except: ['angular']
}
},
dist: {
src: 'dist/<%= package.name %>.js',
dest: 'dist/<%= package.name %>.min.js'
}
};
Configuration.concat = {
dist: {
src: [
'lib/core.js',
'lib/providers/binder.js',
'lib/services/binder.js'
],
dest: 'dist/<%= package.name %>.js'
}
};
Configuration.wrap = {
dist: {
options: {
seperator: '\n',
indent: '\t',
wrapper: ['(function (window,document,angular) {\n', '\n})(window,window.document,window.angular);']
},
src: [
'dist/<%= package.name %>.js'
],
dest: 'dist/<%= package.name %>.js'
}
};
grunt.initConfig(Configuration);
grunt.registerTask('es6', ['babel:all', 'add_comment:common']);
grunt.registerTask('dev', ['babel:all']);
grunt.registerTask('build', ['babel:dist', 'concat:dist', 'add_comment:strict', 'uglify:dist', 'wrap:dist', 'add_comment:dist']);
}
module.exports = Grunt;
function getPathOption(grunt) {
var pathOption = false;
if (grunt.option('path')) {
pathOption = {};
pathOption.name = Path.normalize(grunt.option('path')).replace(paths.base, '').slice(1);
pathOption.extension = Path.extname(grunt.option('path'));
}
return pathOption;
}