Skip to content

Instantly share code, notes, and snippets.

@erotte
Last active July 30, 2016 02:38
Show Gist options
  • Save erotte/efc99083f0fae64c18c2 to your computer and use it in GitHub Desktop.
Save erotte/efc99083f0fae64c18c2 to your computer and use it in GitHub Desktop.
Generates an Ionic base app with Sass, CoffeeScript, Jade support
#!/usr/bin/env bash
# you might need to install ionic and cordova
# npm install -g cordova ionic
USAGE="Usage: ionic-app [AppPath/]AndName [ionic starter template]"
APP_TEMPLATE='tabs'
if [ $# == 0 ] ; then
echo $USAGE
exit 1;
fi
if [ $# == 2 ] ; then
APP_TEMPLATE=$2
echo "App Template is $APP_TEMPLATE"
fi
APP_PATH=$1
ionic start $APP_PATH $APP_TEMPLATE
cd $APP_PATH
current_dir = pwd
echo "current dir is: $pwd"
# echo "adding platform tools for iOS"
# ionic platform add ios
echo "adding platform tools for Android"
ionic platform add android
echo 'installing npm modules'
npm install
echo 'installing bower dependencies'
bower install
echo "preparing project for Sass usage"
ionic setup sass
echo "preparing project for CoffeeScript"
npm install --save-dev coffee-script
npm install --save-dev gulp-coffee
npm install --save-dev gulp-jade
npm install -g js2coffee
mkdir -p source/coffee
echo "init git repo and commit current status as a starting point…"
git init
git add .
git commit -a -m 'Initial commit: generated App with iOS, Android, Sass, CoffeeScript'
echo "converting ionic js files to CoffeeScript"
mkdir -p source/coffee
js2coffee www/js/app.js > source/coffee/app.coffee && rm www/js/app.js
js2coffee www/js/controllers.js > source/coffee/controllers.coffee && rm www/js/controllers.js
js2coffee www/js/services.js > source/coffee/services.coffee && rm www/js/services.js
echo "converting ionic templates to Jade"
mkdir -p source/jade/templates
html2jade www/*.html && mv www/*.jade source/jade/
html2jade --bodyless www/templates/*.html && mv www/templates/*.jade source/jade/templates/
echo "finally: write a modified gulpfile (original file is backed up to gulpfile.js.orig)"
mv gulpfile.js gulpfile.js.orig
cat > gulpfile.js <<_EOF_
var gulp = require('gulp');
var gutil = require('gulp-util');
var bower = require('bower');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var minifyCss = require('gulp-minify-css');
var rename = require('gulp-rename');
var sh = require('shelljs');
var coffee = require('gulp-coffee');
var jade = require('gulp-jade');
var paths = {
sass: ['./scss/**/*.scss'],
coffee: ['./source/coffee/**/*.coffee'],
jade: ['./source/jade/**/*.jade']
};
gulp.task('default', ['sass']);
gulp.task('sass', function(done) {
gulp.src('./scss/ionic.app.scss')
.pipe(sass({
errLogToConsole: true
}))
.pipe(gulp.dest('./www/css/'))
.pipe(minifyCss({
keepSpecialComments: 0
}))
.pipe(rename({ extname: '.min.css' }))
.pipe(gulp.dest('./www/css/'))
.on('end', done);
});
gulp.task('coffee', function(done) {
gulp.src(paths.coffee)
.pipe(coffee({bare: true})
.on('error', gutil.log.bind(gutil, 'Coffee Error')))
.pipe(concat('application.js'))
.pipe(gulp.dest('./www/js'))
.on('end', done)
});
gulp.task('jade', function(done) {
gulp.src(paths.jade)
.pipe(jade({
pretty: true
})
.on('error', gutil.log.bind(gutil, 'Jade Error')))
.pipe(gulp.dest('./www/'))
.on('end', done)
});
gulp.task('watch', function() {
gulp.watch(paths.sass, ['sass']);
gulp.watch(paths.coffee, ['coffee']);
gulp.watch(paths.jade, ['jade']);
});
gulp.task('install', ['git-check'], function() {
return bower.commands.install()
.on('log', function(data) {
gutil.log('bower', gutil.colors.cyan(data.id), data.message);
});
});
gulp.task('git-check', function(done) {
if (!sh.which('git')) {
console.log(
' ' + gutil.colors.red('Git is not installed.'),
'\n Git, the version control system, is required to download Ionic.',
'\n Download git here:', gutil.colors.cyan('http://git-scm.com/downloads') + '.',
'\n Once git is installed, run \'' + gutil.colors.cyan('gulp install') + '\' again.'
);
process.exit(1);
}
done();
});
_EOF_
echo "checking gulp tasks initially"
gulp sass
gulp coffee
gulp jade
echo 'done! '
echo 'TODO: edit index.jade and switch javascript includes to application.js instead of app, controllers, services.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment