Skip to content

Commit

Permalink
feat(generator): Add ionic-cli support. Closes #112
Browse files Browse the repository at this point in the history
  • Loading branch information
diegonetto committed Oct 6, 2014
1 parent fe04e3a commit f6f9e0f
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 70 deletions.
150 changes: 81 additions & 69 deletions templates/common/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,37 +59,27 @@ module.exports = function (grunt) {
watch: {
bower: {
files: ['bower.json'],
tasks: ['wiredep']
tasks: ['wiredep', 'newer:copy:app']
},
html: {
files: ['<%%= yeoman.app %>/**/*.html'],
tasks: ['newer:copy:app']
},
js: {
files: ['<%%= yeoman.app %>/<%%= yeoman.scripts %>/**/*.js'],
tasks: ['newer:jshint:all'],
options: {
livereload: true
}
tasks: ['newer:copy:app', 'newer:jshint:all']
},<% if (compass) { %>
compass: {
files: ['<%%= yeoman.app %>/<%%= yeoman.styles %>/**/*.{scss,sass}'],
tasks: ['compass:server', 'autoprefixer']
tasks: ['compass:server', 'autoprefixer', 'newer:copy:tmp']
},<% } else { %>
styles: {
files: ['<%%= yeoman.app %>/<%%= yeoman.styles %>/**/*.css'],
tasks: ['newer:copy:styles', 'autoprefixer']
tasks: ['newer:copy:styles', 'autoprefixer', 'newer:copy:tmp']
},<% } %>
gruntfile: {
files: ['Gruntfile.js'],
tasks: ['ngconstant:development']
},
livereload: {
options: {
livereload: '<%%= connect.options.livereload %>'
},
files: [
'<%%= yeoman.app %>/*.html',
'<%%= yeoman.app %>/templates/**/*.html',
'.tmp/<%%= yeoman.styles %>/**/*.css',
'<%%= yeoman.app %>/<%%= yeoman.images %>/**/*.{png,jpg,jpeg,gif,webp,svg}'
]
tasks: ['ngconstant:development', 'newer:copy:app']
}
},

Expand All @@ -98,17 +88,7 @@ module.exports = function (grunt) {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: 'localhost',
livereload: 35729
},
livereload: {
options: {
open: true,
base: [
'.tmp',
'<%%= yeoman.app %>'
]
}
hostname: 'localhost'
},
dist: {
options: {
Expand Down Expand Up @@ -179,7 +159,7 @@ module.exports = function (grunt) {
}<% if (compass) { %>,
sass: {
src: ['<%%= yeoman.app %>/styles/{,*/}*.{scss,sass}'],
ignorePath: /(\.\.\/){1,2}bower_components\//
ignorePath: /(\.\.\/){1,2}lib\//
}<% } %>
},

Expand All @@ -189,21 +169,21 @@ module.exports = function (grunt) {
options: {
sassDir: '<%%= yeoman.app %>/<%%= yeoman.styles %>',
cssDir: '.tmp/<%%= yeoman.styles %>',
generatedImagesDir: '.tmp/img/generated',
imagesDir: '<%%= yeoman.app %>/img',
generatedImagesDir: '.tmp/<%%= yeoman.images %>/generated',
imagesDir: '<%%= yeoman.app %>/<%%= yeoman.images %>',
javascriptsDir: '<%%= yeoman.app %>/<%%= yeoman.scripts %>',
fontsDir: '<%%= yeoman.app %>/<%%= yeoman.styles %>/fonts',
importPath: '<%%= yeoman.app %>/bower_components',
httpImagesPath: '/img',
httpGeneratedImagesPath: '/img/generated',
importPath: '<%%= yeoman.app %>/lib',
httpImagesPath: '/<%%= yeoman.images %>',
httpGeneratedImagesPath: '/<%%= yeoman.images %>/generated',
httpFontsPath: '/<%%= yeoman.styles %>/fonts',
relativeAssets: false,
assetCacheBuster: false,
raw: 'Sass::Script::Number.precision = 10\n'
},
dist: {
options: {
generatedImagesDir: '<%%= yeoman.dist %>/img/generated'
generatedImagesDir: 'www/<%%= yeoman.images %>/generated'
}
},
server: {
Expand Down Expand Up @@ -275,7 +255,7 @@ module.exports = function (grunt) {
cwd: '<%%= yeoman.app %>',
dest: 'www',
src: [
'images/**/*.{png,jpg,jpeg,gif,webp,svg}',
'<%%= yeoman.images %>/**/*.{png,jpg,jpeg,gif,webp,svg}',
'*.html',
'templates/**/*.html',
'fonts/*'
Expand All @@ -295,7 +275,7 @@ module.exports = function (grunt) {
},
fonts: {
expand: true,
cwd: 'app/bower_components/ionic/release/fonts/',
cwd: 'app/lib/ionic/release/fonts/',
dest: '<%%= yeoman.app %>/fonts/',
src: '*'
},
Expand All @@ -305,11 +285,20 @@ module.exports = function (grunt) {
dest: '.tmp/<%%= yeoman.styles %>/',
src: '{,*/}*.css'
},
all: {
app: {
expand: true,
cwd: '<%%= yeoman.app %>',
dest: 'www/',
src: [
'**/*',
'!**/*.(scss,sass,css)',
]
},
tmp: {
expand: true,
cwd: '<%%= yeoman.app %>/',
src: '**',
dest: 'www/'
cwd: '.tmp',
dest: 'www/',
src: '**/*'
}
},

Expand Down Expand Up @@ -367,13 +356,13 @@ module.exports = function (grunt) {
basePath: '',
frameworks: ['mocha', 'chai'],
files: [
'<%%= yeoman.app %>/bower_components/angular/angular.js',
'<%%= yeoman.app %>/bower_components/angular-animate/angular-animate.js',
'<%%= yeoman.app %>/bower_components/angular-sanitize/angular-sanitize.js',
'<%%= yeoman.app %>/bower_components/angular-ui-router/release/angular-ui-router.js',
'<%%= yeoman.app %>/bower_components/ionic/release/js/ionic.js',
'<%%= yeoman.app %>/bower_components/ionic/release/js/ionic-angular.js',
'<%%= yeoman.app %>/bower_components/angular-mocks/angular-mocks.js',
'<%%= yeoman.app %>/lib/angular/angular.js',
'<%%= yeoman.app %>/lib/angular-animate/angular-animate.js',
'<%%= yeoman.app %>/lib/angular-sanitize/angular-sanitize.js',
'<%%= yeoman.app %>/lib/angular-ui-router/release/angular-ui-router.js',
'<%%= yeoman.app %>/lib/ionic/release/js/ionic.js',
'<%%= yeoman.app %>/lib/ionic/release/js/ionic-angular.js',
'<%%= yeoman.app %>/lib/angular-mocks/angular-mocks.js',
'<%%= yeoman.app %>/<%%= yeoman.scripts %>/**/*.js',
'test/mock/**/*.js',
'test/spec/**/*.js'
Expand Down Expand Up @@ -420,10 +409,8 @@ module.exports = function (grunt) {

});

// Register tasks for all Cordova commands, but namespace
// the cordova:build since we already have a build task.
// Register tasks for all Cordova commands
_.functions(cordova).forEach(function (name) {
name = (name === 'build') ? 'cordova:build' : name;
grunt.registerTask(name, function () {
this.args.unshift(name.replace('cordova:', ''));
// Handle URL's being split up by Grunt because of `:` characters
Expand All @@ -441,7 +428,7 @@ module.exports = function (grunt) {
grunt.log.error(data);
});
child.on('close', function (code) {
code = (name === 'cordova:build') ? true : code ? false : true;
code = code ? false : true;
done(code);
});
});
Expand All @@ -452,12 +439,12 @@ module.exports = function (grunt) {
// over to www/. Last step is running cordova prepare so we can refresh the ripple
// browser tab to see the changes. Technically ripple runs `cordova prepare` on browser
// refreshes, but at this time you would need to re-run the emulator to see changes.
grunt.registerTask('ripple', ['wiredep', 'copy:all', 'ripple-emulator']);
grunt.registerTask('ripple', ['wiredep', 'newer:copy:app', 'ripple-emulator']);
grunt.registerTask('ripple-emulator', function () {
grunt.config.set('watch', {
all: {
files: _.flatten(_.pluck(grunt.config.get('watch'), 'files')),
tasks: ['copy:all', 'prepare']
tasks: ['newer:copy:app', 'prepare']
}
});

Expand Down Expand Up @@ -488,32 +475,60 @@ module.exports = function (grunt) {
return grunt.task.run(['watch']);
});

// Wrap ionic-cli commands
grunt.registerTask('ionic', function() {
var script = path.resolve('./node_modules/ionic/bin/', 'ionic');
var flags = process.argv.splice(3);
var child = spawn(script, this.args.concat(flags));
child.stdout.on('data', function (data) {
grunt.log.writeln(data);
});
child.stderr.on('data', function (data) {
grunt.log.error(data);
});
process.on('exit', function (code) {
child.kill('SIGINT');
process.exit(code);
});

return grunt.task.run(['watch']);
});
grunt.registerTask('serve', function (target) {
if (target === 'dist') {
return grunt.task.run(['build', 'connect:dist:keepalive']);
if (target === 'compress') {
return grunt.task.run(['compress', 'ionic:serve']);
}

grunt.task.run([
'clean:server',
'clean',
'ngconstant:development',
'wiredep',
'concurrent:server',
'autoprefixer',
'connect:livereload',
'watch'
'newer:copy:app',
'newer:copy:tmp',
'ionic:serve'
]);
});
grunt.registerTask('emulate', function() {
return grunt.task.run(['ionic:emulate:' + this.args.join()]);
});
grunt.registerTask('run', function() {
return grunt.task.run(['ionic:run:' + this.args.join()]);
});
grunt.registerTask('build', function() {
return grunt.task.run(['ionic:build:' + this.args.join()]);
});

grunt.registerTask('test', [
'clean:server',
'clean',
'concurrent:test',
'autoprefixer',
'karma:unit:start',
'watch:karma'
]);

grunt.registerTask('build', [
'clean:dist',
grunt.registerTask('compress', [
'clean',
'ngconstant:production',
'wiredep',
'useminPrepare',
Expand All @@ -525,17 +540,14 @@ module.exports = function (grunt) {
'cssmin',
'uglify',
'usemin',
'htmlmin',
'cordova:build'
'htmlmin'
]);

grunt.registerTask('cordova', ['copy:all', 'cordova:build']);

grunt.registerTask('coverage', ['karma:continuous', 'connect:coverage:keepalive']);

grunt.registerTask('default', [
'newer:jshint',
'karma:continuous',
'build'
'compress'
]);
};
2 changes: 1 addition & 1 deletion templates/common/_bowerrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"directory": "<%= appPath %>/bower_components"
"directory": "<%= appPath %>/lib"
}
1 change: 1 addition & 0 deletions templates/common/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"glob": "~4.0.5",
"grunt-autoprefixer": "~0.4.0",
"grunt-wiredep": "^1.7.0",
"ionic": "^1.2.7",
"grunt-concurrent": "~0.4.1",
"grunt-contrib-clean": "~0.5.0",<% if (compass) { %>
"grunt-contrib-compass": "~0.6.0",<% } %>
Expand Down

0 comments on commit f6f9e0f

Please sign in to comment.