Last active
August 29, 2015 14:17
-
-
Save desaiuditd/63c23d9cb3705e7b9037 to your computer and use it in GitHub Desktop.
Grunt Deploy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated on 2014-04-08 using generator-angular 0.8.0 | |
'use strict'; | |
// # Globbing | |
// for performance reasons we're only matching one level down: | |
// 'test/spec/{,*/}*.js' | |
// use this if you want to recursively match all subfolders: | |
// 'test/spec/**/*.js' | |
module.exports = function (grunt) { | |
// Load grunt tasks automatically | |
require('load-grunt-tasks')(grunt); | |
// Time how long tasks take. Can help when optimizing build times | |
require('time-grunt')(grunt); | |
// Define the configuration for all the tasks | |
grunt.initConfig({ | |
// Project settings | |
yeoman: { | |
// configurable paths | |
app: require('./bower.json').appPath || 'app', | |
dist: 'dist' | |
}, | |
// Watches files for changes and runs tasks based on the changed files | |
watch: { | |
bower: { | |
files: ['bower.json'], | |
tasks: ['bowerInstall'] | |
}, | |
js: { | |
files: ['<%= yeoman.app %>/scripts/{,*/}*.js'], | |
tasks: [], | |
options: { | |
livereload: false | |
} | |
}, | |
jsTest: { | |
files: ['test/spec/{,*/}*.js'], | |
tasks: ['newer:jshint:test', 'karma'] | |
}, | |
compass: { | |
files: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'], | |
tasks: ['compass:server', 'autoprefixer'] | |
}, | |
gruntfile: { | |
files: ['Gruntfile.js'] | |
}, | |
livereload: { | |
options: { | |
livereload: '<%= connect.options.livereload %>' | |
}, | |
files: [] | |
} | |
}, | |
// The actual grunt server settings | |
connect: { | |
options: { | |
port: grunt.option('port') || 9000, | |
// Change this to '0.0.0.0' to access the server from outside. | |
hostname: '0.0.0.0', | |
//Modrewrite for html5mode | |
middleware: function(connect, options) { | |
var optBase = (typeof options.base === 'string') ? [options.base] : options.base; | |
return [require('connect-modrewrite')(['!(\\..+)$ / [L]'])] | |
.concat(optBase.map(function(path){ return connect.static(path); })); | |
} | |
}, | |
start: { | |
options: { | |
open: true, | |
base: [ | |
'.tmp', | |
'<%= yeoman.app %>' | |
] | |
} | |
}, | |
test: { | |
options: { | |
port: 9001, | |
base: [ | |
'.tmp', | |
'test', | |
'<%= yeoman.app %>' | |
] | |
} | |
}, | |
dist: { | |
options: { | |
base: '<%= yeoman.dist %>' | |
} | |
} | |
}, | |
// Make sure code styles are up to par and there are no obvious mistakes | |
jshint: { | |
options: { | |
jshintrc: '.jshintrc', | |
reporter: require('jshint-stylish') | |
}, | |
all: [ | |
'Gruntfile.js', | |
'<%= yeoman.app %>/scripts/{,*/}*.js' | |
], | |
test: { | |
options: { | |
jshintrc: 'test/.jshintrc' | |
}, | |
src: ['test/spec/{,*/}*.js'] | |
} | |
}, | |
// Empties folders to start fresh | |
clean: { | |
dist: { | |
files: [{ | |
dot: true, | |
src: [ | |
'.tmp', | |
'<%= yeoman.dist %>/*', | |
'!<%= yeoman.dist %>/.git*' | |
] | |
}] | |
}, | |
server: '.tmp' | |
}, | |
// Add vendor prefixed styles | |
autoprefixer: { | |
options: { | |
browsers: ['last 1 version'] | |
}, | |
dist: { | |
files: [{ | |
expand: true, | |
cwd: '.tmp/styles/', | |
src: '{,*/}*.css', | |
dest: '.tmp/styles/' | |
}] | |
} | |
}, | |
// Automatically inject Bower components into the app | |
bowerInstall: { | |
app: { | |
src: ['<%= yeoman.app %>/index.html'], | |
ignorePath: '<%= yeoman.app %>/' | |
}, | |
sass: { | |
src: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'], | |
ignorePath: '<%= yeoman.app %>/bower_components/' | |
} | |
}, | |
// Compiles Sass to CSS and generates necessary files if requested | |
compass: { | |
options: { | |
sassDir: '<%= yeoman.app %>/styles', | |
cssDir: '.tmp/styles', | |
generatedImagesDir: '.tmp/images/generated', | |
imagesDir: '<%= yeoman.app %>/images', | |
javascriptsDir: '<%= yeoman.app %>/scripts', | |
fontsDir: '<%= yeoman.app %>/styles/fonts', | |
importPath: '<%= yeoman.app %>/bower_components', | |
httpImagesPath: '/images', | |
httpGeneratedImagesPath: '/images/generated', | |
httpFontsPath: '/styles/fonts', | |
relativeAssets: false, | |
assetCacheBuster: false, | |
raw: 'Sass::Script::Number.precision = 10\n' | |
}, | |
dist: { | |
options: { | |
generatedImagesDir: '<%= yeoman.dist %>/images/generated' | |
} | |
}, | |
server: { | |
options: { | |
debugInfo: true | |
} | |
} | |
}, | |
// Renames files for browser caching purposes | |
rev: { | |
dist: { | |
files: { | |
src: [ | |
'<%= yeoman.dist %>/scripts/{,*/}*.js', | |
'<%= yeoman.dist %>/styles/{,*/}*.css', | |
'<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}', | |
'<%= yeoman.dist %>/styles/fonts/*' | |
] | |
} | |
} | |
}, | |
// Reads HTML for usemin blocks to enable smart builds that automatically | |
// concat, minify and revision files. Creates configurations in memory so | |
// additional tasks can operate on them | |
useminPrepare: { | |
html: '<%= yeoman.app %>/index.html', | |
options: { | |
dest: '<%= yeoman.dist %>', | |
flow: { | |
html: { | |
steps: { | |
js: ['concat', 'uglifyjs'], | |
css: ['cssmin'] | |
}, | |
post: {} | |
} | |
} | |
} | |
}, | |
// Performs rewrites based on rev and the useminPrepare configuration | |
usemin: { | |
html: ['<%= yeoman.dist %>/{,*/}*.html'], | |
css: ['<%= yeoman.dist %>/styles/{,*/}*.css'], | |
options: { | |
assetsDirs: ['<%= yeoman.dist %>'] | |
} | |
}, | |
// The following *-min tasks produce minified files in the dist folder | |
cssmin: { | |
options: { | |
root: '<%= yeoman.app %>' | |
} | |
}, | |
imagemin: { | |
dist: { | |
files: [{ | |
expand: true, | |
cwd: '<%= yeoman.app %>/images', | |
src: '{,*/}*.{png,jpg,jpeg,gif}', | |
dest: '<%= yeoman.dist %>/images' | |
}] | |
} | |
}, | |
svgmin: { | |
dist: { | |
files: [{ | |
expand: true, | |
cwd: '<%= yeoman.app %>/images', | |
src: '{,*/}*.svg', | |
dest: '<%= yeoman.dist %>/images' | |
}] | |
} | |
}, | |
htmlmin: { | |
dist: { | |
options: { | |
collapseWhitespace: true, | |
collapseBooleanAttributes: true, | |
removeCommentsFromCDATA: true, | |
removeOptionalTags: true | |
}, | |
files: [{ | |
expand: true, | |
cwd: '<%= yeoman.dist %>', | |
src: ['*.html', 'views/{,*/}*.html'], | |
dest: '<%= yeoman.dist %>' | |
}] | |
} | |
}, | |
// ngmin tries to make the code safe for minification automatically by | |
// using the Angular long form for dependency injection. It doesn't work on | |
// things like resolve or inject so those have to be done manually. | |
ngmin: { | |
dist: { | |
files: [{ | |
expand: true, | |
cwd: '.tmp/concat/scripts', | |
src: '*.js', | |
dest: '.tmp/concat/scripts' | |
}] | |
} | |
}, | |
// Replace Google CDN references | |
cdnify: { | |
dist: { | |
html: ['<%= yeoman.dist %>/*.html'] | |
} | |
}, | |
// Copies remaining files to places other tasks can use | |
copy: { | |
dist: { | |
files: [{ | |
expand: true, | |
dot: true, | |
cwd: '<%= yeoman.app %>', | |
dest: '<%= yeoman.dist %>', | |
src: [ | |
'*.{ico,png,txt}', | |
'.htaccess', | |
'*.html', | |
'views/{,*/}*.html', | |
'images/{,*/}*.{webp}', | |
'fonts/*', | |
'bower_components/bootstrap/dist/fonts/*.*' // fix for glyphicons. | |
] | |
}, { | |
expand: true, | |
cwd: '.tmp/images', | |
dest: '<%= yeoman.dist %>/images', | |
src: ['generated/*'] | |
}] | |
}, | |
styles: { | |
expand: true, | |
cwd: '<%= yeoman.app %>/styles', | |
dest: '.tmp/styles/', | |
src: '{,*/}*.css' | |
} | |
}, | |
// Run some tasks in parallel to speed up the build process | |
concurrent: { | |
server: [ | |
'compass:server' | |
], | |
test: [ | |
'compass' | |
], | |
dist: [ | |
'compass:dist', | |
'imagemin', | |
'svgmin' | |
] | |
}, | |
browserSync: { | |
files: { | |
src: [ | |
'<%= yeoman.app %>/*.html', | |
'.tmp/styles/{,*/}*.css', | |
'{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js', | |
'<%= yeoman.app %>/images/{,*/}*.{gif,jpeg,jpg,png,svg,webp}' | |
], | |
}, | |
options: { | |
watchTask: true, | |
ghostMode: { | |
clicks: true, | |
location: true, | |
scroll: true, | |
forms: true | |
}, | |
proxy: { | |
host: "<%= host %>", | |
port: "<%= port %>" | |
} | |
}, | |
}, | |
// By default, your `index.html`'s <!-- Usemin block --> will take care of | |
// minification. These next options are pre-configured if you do not wish | |
// to use the Usemin blocks. | |
// cssmin: { | |
// dist: { | |
// files: { | |
// '<%= yeoman.dist %>/styles/main.css': [ | |
// '.tmp/styles/{,*/}*.css', | |
// '<%= yeoman.app %>/styles/{,*/}*.css' | |
// ] | |
// } | |
// } | |
// }, | |
// uglify: { | |
// dist: { | |
// files: { | |
// '<%= yeoman.dist %>/scripts/scripts.js': [ | |
// '<%= yeoman.dist %>/scripts/scripts.js' | |
// ] | |
// } | |
// } | |
// }, | |
// concat: { | |
// dist: {} | |
// }, | |
// Test settings | |
karma: { | |
unit: { | |
configFile: 'karma.conf.js', | |
singleRun: true | |
} | |
}, | |
sshconfig: grunt.file.readJSON('./config/deploy.json'), | |
sshexec: { | |
update_symlink: { | |
command: function () { | |
return 'cd <%= deployRoot %> && ' + | |
'if [ -L current ]; then rm current; fi && ' + | |
'ln -s <%= deployRoot %>/<%= deployDir %> current'; | |
} | |
}, | |
create_ios_build_symlink: { | |
command: function() { | |
return 'cd <%= deployRoot %> && ' + | |
'if [ ! -d shared ]; then mkdir -p shared/ios-builds; fi && ' + | |
'cd <%= deployRoot %>/current && ' + | |
'if [ ! -L ios-builds ]; then ln -s <%= deployRoot %>/shared/ios-builds ios-builds; fi' | |
} | |
}, | |
fix_permissions: { | |
command: function () { | |
return 'cd <%= deployRoot %>/current && ' + | |
'ls **.** | xargs chmod 644 && ' + | |
'ls -R ***/**.* | xargs chmod 644' | |
} | |
}, | |
cleanup: { | |
command: 'cd <%= deployRoot %>/releases && ls -tr | head -n -<%= sshconfig.keepReleases %> | xargs rm -rf' | |
} | |
}, | |
scp: { | |
root_files: { | |
files: [{ | |
cwd: './dist', | |
src: '**/*.*', | |
// path on the server | |
dest: '/home/brownbag/bagiq/<%= deployDir %>' | |
}] | |
}, | |
ios_enterprise_files: { | |
files: [{ | |
cwd: './app/ios-builds', | |
src: '**/*.*', | |
// path on the server | |
dest: '/home/brownbag/bagiq/shared/ios-builds' | |
}] | |
} | |
} | |
}); | |
grunt.registerTask('serve', function (target) { | |
if (target === 'dist') { | |
grunt.task.run(['build', 'connect:dist:keepalive']); | |
} | |
grunt.task.run([ | |
'clean:server', | |
'configure-app', | |
'bowerInstall', | |
'concurrent:server', | |
'autoprefixer', | |
'connect:start', | |
'watch' | |
]); | |
}); | |
grunt.registerTask('sync', function(host, port) { | |
host = host || "localhost"; | |
port = port || 9000; | |
grunt.task.run([ | |
'clean:server', | |
'configure-app', | |
'bowerInstall', | |
'concurrent:server', | |
'autoprefixer', | |
'connect:start', | |
'browserSync', | |
'watch' | |
]); | |
}); | |
grunt.registerTask('server', function(target) { | |
grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.'); | |
grunt.task.run(['serve:' + target]); | |
}); | |
grunt.registerTask('test', [ | |
'clean:server', | |
'concurrent:test', | |
'autoprefixer', | |
'connect:test', | |
'karma' | |
]); | |
grunt.registerTask('build', [ | |
'clean:dist', | |
'bowerInstall', | |
'configure-app', | |
'useminPrepare', | |
'concurrent:dist', | |
'autoprefixer', | |
'concat', | |
'ngmin', | |
'copy:dist', | |
'cdnify', | |
'cssmin', | |
'uglify', | |
// 'rev', | |
'usemin', | |
'htmlmin' | |
]); | |
grunt.registerTask('default', [ | |
'newer:jshint', | |
'test', | |
'build' | |
]); | |
grunt.loadNpmTasks("grunt-replace"); | |
grunt.loadNpmTasks('grunt-ssh'); | |
grunt.loadNpmTasks('grunt-scp'); | |
grunt.registerTask("configure-app", 'Configures application', function() { | |
if (!grunt.option('config')) grunt.option('config', 'development'); | |
var replaceOpts = { | |
options: { | |
patterns: [ | |
{ | |
json: grunt.file.readJSON('./config/environments/' + grunt.option('config') + '.json') | |
} | |
] | |
}, | |
files: [ | |
{ | |
expand: true, | |
flatten: true, | |
src: ['./config/config.js'], | |
dest: '<%= yeoman.app %>/scripts/services/' | |
} | |
] | |
}; | |
grunt.config("replace.application", replaceOpts); | |
grunt.task.run('replace:application'); | |
}); | |
grunt.registerTask('deploy', 'Build and deploy application', function() { | |
var sshConfig = grunt.config.get(['sshconfig', grunt.option('config')]); | |
sshConfig.agent = process.env.SSH_AUTH_SOCK; | |
var now = new Date(); | |
var month = "" + (now.getMonth() + 1); | |
var day = "" + now.getDate(); | |
var hours = "" + now.getHours(); | |
var minutes = "" + now.getMinutes(); | |
var seconds = "" + now.getSeconds(); | |
var deployDir = "releases/" + | |
now.getFullYear() + | |
(month.length < 2 ? "0" + month : month) + | |
(day.length < 2 ? "0" + day : day) + | |
(hours.length < 2 ? "0" + hours : hours) + | |
(minutes.length < 2 ? "0" + minutes : minutes) + | |
(seconds.length < 2 ? "0" + seconds : seconds); | |
grunt.config.set("deployRoot", sshConfig.path); | |
grunt.config.set("deployDir", deployDir); | |
grunt.log.writeln("Deploy to " + grunt.config.get('deployDir').toString()); | |
if (!grunt.config('sshconfig.keepReleases')) grunt.config("sshconfig.keepReleases", 20); | |
grunt.config('sshconfig.' + grunt.option('config') + '.agent', sshConfig.agent); | |
grunt.config('scp.options', sshConfig); | |
grunt.task.run("build"); | |
grunt.task.run("scp:root_files"); | |
grunt.task.run("sshexec:update_symlink"); | |
grunt.task.run("sshexec:create_ios_build_symlink"); | |
grunt.task.run("sshexec:fix_permissions"); | |
grunt.task.run("sshexec:cleanup"); | |
}); | |
grunt.registerTask('create_ios_build_symlink', "Creates symlink in active 'current' directory to ios-builds", function() { | |
var sshConfig = grunt.config.get(['sshconfig', grunt.option('config')]); | |
sshConfig.agent = process.env.SSH_AUTH_SOCK; | |
grunt.config.set("deployRoot", sshConfig.path); | |
grunt.config('sshconfig.' + grunt.option('config') + '.agent', sshConfig.agent); | |
grunt.config('scp.options', sshConfig); | |
grunt.task.run("sshexec:create_ios_build_symlink"); | |
}); | |
grunt.registerTask("upload_ios_enterprise_files", "Uploads new iOS enterprise installation files to the server", function() { | |
var sshConfig = grunt.config.get(['sshconfig', grunt.option('config')]); | |
sshConfig.agent = process.env.SSH_AUTH_SOCK; | |
grunt.config.set("deployRoot", sshConfig.path); | |
grunt.config('sshconfig.' + grunt.option('config') + '.agent', sshConfig.agent); | |
grunt.config('scp.options', sshConfig); | |
grunt.task.run("scp:ios_enterprise_files"); | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "biqapp", | |
"version": "0.0.0", | |
"dependencies": { }, | |
"devDependencies": { | |
"connect-modrewrite": "~0.5.11", | |
"grunt": "~0.4.1", | |
"grunt-autoprefixer": "~0.4.0", | |
"grunt-bower-install": "~1.0.0", | |
"grunt-browser-sync": "^1.1.2", | |
"grunt-concurrent": "~0.5.0", | |
"grunt-contrib-clean": "~0.5.0", | |
"grunt-contrib-compass": "~0.7.2", | |
"grunt-contrib-concat": "~0.3.0", | |
"grunt-contrib-connect": "~0.5.0", | |
"grunt-contrib-copy": "~0.4.1", | |
"grunt-contrib-cssmin": "~0.7.0", | |
"grunt-contrib-htmlmin": "~0.1.3", | |
"grunt-contrib-imagemin": "~0.3.0", | |
"grunt-contrib-jshint": "~0.7.1", | |
"grunt-contrib-uglify": "~0.2.0", | |
"grunt-contrib-watch": "~0.5.2", | |
"grunt-google-cdn": "~0.2.0", | |
"grunt-karma": "~0.8.2", | |
"grunt-newer": "~0.6.1", | |
"grunt-ngmin": "~0.0.2", | |
"grunt-replace": "~0.7.7", | |
"grunt-rev": "~0.1.0", | |
"grunt-scp": "~0.1.6", | |
"grunt-ssh": "~0.11.1", | |
"grunt-svgmin": "~0.2.0", | |
"grunt-usemin": "~2.0.0", | |
"jshint-stylish": "~0.1.3", | |
"karma": "~0.12.4", | |
"karma-jasmine": "~0.1.5", | |
"karma-ng-html2js-preprocessor": "~0.1.0", | |
"karma-ng-scenario": "~0.1.0", | |
"load-grunt-tasks": "~0.4.0", | |
"time-grunt": "~0.2.1" | |
}, | |
"engines": { | |
"node": ">=0.10.0" | |
}, | |
"scripts": { | |
"test": "grunt test" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment