Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

chore(build): switch build to grunt 0.4 #211

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 37 additions & 29 deletions grunt.js → Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
var fs = require('fs');
var markdown = require('node-markdown').Markdown;

module.exports = function(grunt) {

grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');

// Project configuration.
grunt.initConfig({
ngversion: '1.0.5',
bsversion: '2.3.1',
srcModules: [], //to be filled in by find-modules task
tplModules: [],
pkg:'<json:package.json>',
pkg: grunt.file.readJSON('package.json'),
dist: 'dist',
filename: 'ui-bootstrap',
meta: {
modules: 'angular.module("ui.bootstrap", [<%= srcModules %>]);',
tplmodules: 'angular.module("ui.bootstrap.tpls", [<%= tplModules %>]);',
all: 'angular.module("ui.bootstrap", ["ui.bootstrap.tpls", <%= srcModules %>]);'
},
lint: {
files: ['grunt.js','src/**/*.js']
},
watch: {
files: ['<config:lint.files>', 'template/**/*.html'],
files: ['<%= jshint.files %>', 'template/**/*.html'],
tasks: 'before-test test-run'
},
concat: {
dist: {
src: ['<banner:meta.modules>'],
options: {
banner: '<%= meta.modules %>\n'
},
src: [],
dest: '<%= dist %>/<%= filename %>-<%= pkg.version %>.js'
},
dist_tpls: {
src: ['<banner:meta.all>', '<banner:meta.tplmodules>'],
options: {
banner: '<%= meta.all %>\n<%= meta.tplmodules %>\n'
},
src: [],
dest: '<%= dist %>/<%= filename %>-tpls-<%= pkg.version %>.js'
}
},
min: {
uglify: {
dist:{
src:['<%= dist %>/<%= filename %>-<%= pkg.version %>.js'],
dest:'<%= dist %>/<%= filename %>-<%= pkg.version %>.min.js'
Expand All @@ -48,25 +54,28 @@ module.exports = function(grunt) {
src: ['template/**/*.html']
},
jshint: {
files: ['grunt.js','src/**/*.js'],
options: {
curly: true,
immed: true,
newcap: true,
noarg: true,
sub: true,
boss: true,
eqnull: true
},
globals: {}
eqnull: true,
globals: {
angular: true
}
}
}
});

//register before and after test tasks so we've don't have to change cli options on the goole's CI server
grunt.registerTask('before-test', 'lint html2js');
grunt.registerTask('after-test', 'build site');
grunt.registerTask('before-test', ['jshint', 'html2js']);
grunt.registerTask('after-test', ['build', 'site']);

// Default task.
grunt.registerTask('default', 'before-test test after-test');
grunt.registerTask('default', ['before-test', 'test', 'after-test']);

//Common ui.bootstrap module containing all modules for src and templates
//findModule: Adds a given module to config
Expand Down Expand Up @@ -140,18 +149,17 @@ module.exports = function(grunt) {
srcFiles = ['src/*/*.js'];
tplFiles = ['template/*/*.html.js'];

grunt.file.expandDirs('src/*').forEach(function(dir) {
grunt.file.expand({filter: 'isDirectory'}, 'src/*').forEach(function(dir) {
findModule(dir.split('/')[1]);
});
}
grunt.config('concat.dist.src', grunt.config('concat.dist.src').concat(srcFiles));
grunt.config('concat.dist_tpls.src', grunt.config('concat.dist_tpls.src').concat(srcFiles).concat(tplFiles));

grunt.task.run('concat min');
grunt.task.run(['concat', 'uglify']);
});

grunt.registerTask('site', 'Create grunt demo site from every module\'s files', function() {
this.requires('concat html2js');

function breakup(text, separator) {
return text.replace(/[A-Z]/g, function (match) {
Expand All @@ -165,26 +173,26 @@ module.exports = function(grunt) {
});
}

var modules = grunt.file.expandDirs('src/*').map(function(dir) {
var modules = grunt.file.expand({filter: 'isDirectory'}, 'src/*').map(function(dir) {
var moduleName = dir.split("/")[1];
if (fs.existsSync(dir + "docs")) {
if (grunt.file.isDir(dir + "/docs")) {
return {
name: moduleName,
displayName: ucwords(breakup(moduleName, ' ')),
js: grunt.file.expand(dir + "docs/*.js").map(grunt.file.read).join(''),
html: grunt.file.expand(dir + "docs/*.html").map(grunt.file.read).join(''),
description: grunt.file.expand(dir + "docs/*.md").map(grunt.file.read).map(markdown).join('')
js: grunt.file.expand(dir + "/docs/*.js").map(grunt.file.read).join(''),
html: grunt.file.expand(dir + "/docs/*.html").map(grunt.file.read).join(''),
description: grunt.file.expand(dir + "/docs/*.md").map(grunt.file.read).map(markdown).join('')
};
}
}).filter(function(module){
return module !== undefined;
});

var templateFiles = grunt.file.expand("template/**/*.html.js");

grunt.file.write(
'dist/index.html',
grunt.template.process(grunt.file.read('misc/demo-template.html'), {
grunt.template.process(grunt.file.read('misc/demo-template.html'), {data: {
modules: modules,
templateModules: templateFiles.map(function(fileName) {
return "'"+fileName.substr(0, fileName.length - 3)+"'";
Expand All @@ -193,7 +201,7 @@ module.exports = function(grunt) {
version : grunt.config('pkg.version'),
ngversion: grunt.config('ngversion'),
bsversion: grunt.config('bsversion')
})
}})
);

grunt.file.expand('misc/demo-assets/*.*').forEach(function(path) {
Expand All @@ -213,10 +221,10 @@ module.exports = function(grunt) {
return content.replace(/"/g, '\\"').replace(/\n/g, '" +\n "').replace(/\r/g, '');
}
function html2js(template) {
grunt.file.write(template + ".js", grunt.template.process(TPL, {
grunt.file.write(template + ".js", grunt.template.process(TPL, {data: {
file: template,
content: escapeContent(grunt.file.read(template))
}));
}}));
}
grunt.registerMultiTask('html2js', 'Generate js versions of html template', function() {
var files = grunt._watch_changed_files || grunt.file.expand(this.data);
Expand All @@ -228,7 +236,7 @@ module.exports = function(grunt) {
var testacularCmd = process.platform === 'win32' ? 'testacular.cmd' : 'testacular';
var args = [command].concat(options);
var done = grunt.task.current.async();
var child = grunt.utils.spawn({
var child = grunt.util.spawn({
cmd: testacularCmd,
args: args
}, function(err, result, code) {
Expand Down
38 changes: 0 additions & 38 deletions node_modules/node-markdown/LICENSE

This file was deleted.

57 changes: 0 additions & 57 deletions node_modules/node-markdown/README.md

This file was deleted.

12 changes: 0 additions & 12 deletions node_modules/node-markdown/examples/test.js

This file was deleted.

Loading