Created
December 11, 2014 13:33
-
-
Save blueskyfish/93f6ebb512c16ab334bc to your computer and use it in GitHub Desktop.
Basic Grunt / Npm / Bower 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": "Application", | |
"version": "0.0.1", | |
"homepage": "http://www.example.com", | |
"description": "Description for Application", | |
"keywords": [ | |
"Application" | |
], | |
"authors": [ | |
"Author <[email protected]>" | |
], | |
"license": "MIT", | |
"dependencies": { | |
"jquery": "2.1.1", | |
"angular": "1.3.5", | |
"angular-route": "1.3.5", | |
"angular-touch": "1.3.5", | |
"angular-sanitize": "1.3.5", | |
"angular-translate": "2.4.2", | |
"angular-translate-loader-static-files": "2.4.2", | |
"components-font-awesome": "4.2.0", | |
"angular-mocks": "1.3.5" | |
} | |
} |
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
module.exports = function (grunt) { | |
var _stage = grunt.option('stage') || 'dev', | |
_basePath, | |
_todayDate = grunt.template.today('yyyy-mm-dd'), | |
_todayTime = grunt.template.today('HH-MM-ss'), | |
_replacePattern = []; | |
switch (_stage.toLowerCase()) { | |
case 'prod': | |
case 'dev': | |
_basePath = '/restful'; | |
break; | |
case 'test': | |
_basePath = '/test/restful'; | |
break; | |
} | |
_replacePattern.push( | |
{ | |
match: 'baseRestPath', | |
replacement: _basePath | |
}, | |
{ | |
match: 'todayDate', | |
replacement: _todayDate | |
}, | |
{ | |
match: 'todayTime', | |
replacement: _todayTime | |
} | |
); | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), | |
names: { | |
date: _todayDate, | |
time: _todayTime | |
}, | |
// Watch to the change of the files | |
watch: { | |
options: { | |
atBegin: false, | |
livereload: true | |
}, | |
css: { | |
files: 'app/assets/css/**/*.less', | |
tasks: ['less:server'] | |
}, | |
i18n: { | |
files: 'app/assets/i18n/**/*.json', | |
tasks: [] | |
}, | |
js: { | |
files: [ | |
'app/assets/js/**/*.js' | |
], | |
tasks: ['jshint:server', 'concat:server', 'replace:app'] | |
}, | |
html: { | |
files: 'app/**/*.html', | |
tasks: ['ngtemplates:server'] | |
} | |
}, // watch | |
processhtml: { | |
options: { | |
recursive: true | |
}, | |
dest: { | |
files: { | |
'dest/index.html': ['.tmp/shadow/index.html'] | |
} | |
} | |
}, // processhtml | |
// Connection deliveries the application to the browser | |
connect: { | |
proxies: [ | |
{ | |
context: '/restful', | |
host: 'localhost', | |
port: 9001, | |
https: false, | |
xforward: false, | |
rewrite: { | |
'^/restful/(.*)$': '/services/$1' | |
} | |
} | |
], | |
server: { | |
options: { | |
port: 9000, | |
hostname: 'localhost', | |
livereload: 35729, | |
middleware: function (connect) { | |
var proxyRequest = require('grunt-connect-proxy/lib/utils').proxyRequest; | |
return [ | |
proxyRequest, | |
connect.static('.tmp'), | |
connect().use('/bower_components', connect.static('./bower_components')), | |
connect().use('/others', connect.static('./others')), | |
connect.static('app') | |
]; | |
} | |
} | |
}, | |
dest: { | |
options: { | |
port: 9010, | |
base: 'dest', | |
keepalive: true, | |
middleware: function (connect) { | |
var proxyRequest = require('grunt-connect-proxy/lib/utils').proxyRequest; | |
return [ | |
proxyRequest, | |
connect.static('dest') | |
]; | |
} | |
} | |
}, | |
docs: { | |
options: { | |
port: 9020, | |
base: 'docs' | |
} | |
} | |
}, // connect | |
replace: { | |
app: { | |
options: { | |
patterns: _replacePattern | |
}, | |
files: [ | |
{ | |
expand: true, | |
flatten: true, | |
src: ['.tmp/shadow/application.js'], | |
dest: '.tmp/assets/js/' | |
} | |
] | |
}, | |
dest: { | |
options: { | |
patterns: _replacePattern | |
}, | |
files: [ | |
{ | |
expand: true, | |
flatten: true, | |
src: ['.tmp/shadow/application.js'], | |
dest: '.tmp/shadow/replace/' | |
}, | |
{ | |
expand: true, | |
flatten: true, | |
src: ['app/index.html'], | |
dest: '.tmp/shadow/' | |
} | |
] | |
} | |
}, | |
// Concat files together in a place | |
concat: { | |
options: { | |
separator: '\n;' | |
}, | |
dest: { | |
files: { | |
'dest/assets/js/others.min.js': [ | |
'add/non/bower/components.js' | |
], | |
'dest/assets/js/vendor.min.js': [ | |
'bower_components/jquery/dist/jquery.min.js', | |
'bower_components/angular/angular.min.js', | |
'bower_components/angular-route/angular-route.min.js', | |
'bower_components/angular-touch/angular-touch.min.js', | |
'bower_components/angular-sanitize/angular-sanitize.min.js', | |
'bower_components/angular-translate/angular-translate.min.js', | |
'bower_components/angular-translate-loader-static-files/angular-translate-loader-static-files.min.js' | |
], | |
'.tmp/shadow/application.js': [ | |
'app/assets/js/_core.js', | |
'app/assets/js/app.js', | |
'app/assets/js/_values/**/*.js', | |
'app/assets/js/_providers/**/*.js', | |
'app/assets/js/_config/**/*.js', | |
'app/assets/js/_services/**/*.js', | |
'app/assets/js/_controllers/**/*.js', | |
'app/assets/js/_filters/**/*.js', | |
'app/assets/js/_directives/**/*.js', | |
'app/assets/js/_run/**/*.js' | |
] | |
} | |
}, | |
server: { | |
files: { | |
'.tmp/shadow/application.js': [ | |
'app/assets/js/_core.js', | |
'app/assets/js/app.js', | |
'app/assets/js/_values/**/*.js', | |
'app/assets/js/_providers/**/*.js', | |
'app/assets/js/_config/**/*.js', | |
'app/assets/js/_services/**/*.js', | |
'app/assets/js/_controllers/**/*.js', | |
'app/assets/js/_filters/**/*.js', | |
'app/assets/js/_directives/**/*.js', | |
'app/assets/js/_run/**/*.js' | |
] | |
} | |
} | |
}, | |
// Copies files to the place | |
copy: { | |
server: { | |
files: [ | |
{ | |
expand: true, | |
cwd: 'bower_components/components-font-awesome/fonts', | |
src: ['*.*'], | |
dest: '.tmp/assets/fonts' | |
} | |
] | |
}, | |
dest: { | |
files: [ | |
{ | |
expand: true, | |
cwd: 'bower_components/components-font-awesome/fonts', | |
src: ['*.*'], | |
dest: 'dest/assets/fonts' | |
}, | |
{ | |
expand: true, | |
cwd: 'app/assets/images', | |
src: ['**/*.*'], | |
dest: 'dest/assets/images' | |
}, | |
{ | |
expand: true, | |
cwd: 'app/assets/i18n', | |
src: ['*.*'], | |
dest: 'dest/assets/i18n' | |
} | |
] | |
} | |
}, // copy | |
ngtemplates: { | |
options: { | |
module: 'app' | |
}, | |
server: { | |
cwd: 'app', | |
src: [ | |
'_views/**/*.html' | |
], | |
dest: '.tmp/assets/js/templates.js' | |
}, | |
dest: { | |
options: { | |
htmlmin: { | |
collapseBooleanAttributes: true, | |
collapseWhitespace: true, | |
removeAttributeQuotes: true, | |
removeComments: true, // Only if you don't use comment directives! | |
removeEmptyAttributes: true, | |
removeRedundantAttributes: true, | |
removeScriptTypeAttributes: true, | |
removeStyleLinkTypeAttributes: true | |
} | |
}, | |
cwd: 'app', | |
src: [ | |
'_views/**/*.html' | |
], | |
dest: 'dest/assets/js/templates.js' | |
} | |
}, // ngtemplates | |
uglify: { | |
options: { | |
mangle: false | |
}, | |
dest: { | |
files: { | |
'dest/assets/js/application.min.js': '.tmp/shadow/replace/application.js', | |
'dest/assets/js/modernizr.min.js': 'bower_components/modernizr/modernizr.js' | |
} | |
}, | |
beforeDest: { | |
files: { | |
'.tmp/shadow/jquery.ui.touch-punch-improved.min.js': 'bower_components/jquery-ui-touch-punch-improved/jquery.ui.touch-punch-improved.js', | |
'.tmp/shadow/chartjs-directive.min.js': 'bower_components/angular-chartjs-directive/chartjs-directive.js' | |
} | |
} | |
}, // uglify | |
cssmin: { | |
dest: { | |
files: { | |
'dest/assets/css/vendor.min.css': [ | |
'bower_components/foundation/css/normalize.css', | |
'bower_components/foundation/css/foundation.css', | |
'bower_components/components-font-awesome/css/font-awesome.css' | |
] | |
} | |
} | |
}, // cssmin | |
clean: { | |
server: ['.tmp'], | |
dest: ['dest'], | |
docs: ['docs'] | |
}, | |
// less compile the less files into one css (here is "application.css" | |
less: { | |
options: { | |
paths: ['app/assets/css'] | |
}, | |
server: { | |
files: { | |
'.tmp/assets/css/application.css': 'app/assets/css/application.less' | |
} | |
}, | |
dest: { | |
options: { | |
cleancss: true | |
}, | |
files: { | |
'dest/assets/css/application.min.css': 'app/assets/css/application.less' | |
} | |
} | |
}, // less | |
jshint: { | |
options: { | |
laxbreak: true, | |
smarttabs: true, | |
bitwise: true, | |
curly: true, | |
eqeqeq: true, | |
evil: true, | |
es3: true, | |
strict: true, | |
undef:true, | |
latedef: true, | |
predef: [ | |
'CryptoJS' | |
], | |
globals: { | |
angular: true | |
} | |
}, | |
server: { | |
src: [ | |
'app/assets/js/**/*.js' | |
] | |
} | |
}, // jshint | |
karma: { | |
test: { | |
singleRun: true, | |
browsers: ['PhantomJS'], | |
configFile: 'config/karma.config.js' | |
} | |
}, // karma | |
compress: { | |
dest: { | |
options: { | |
archive: '../archives/app-<%= names.date %>-<%= names.time %>.zip', | |
pretty: true, | |
comment: 'Deployment of "Application" on <%= names.date %> <%= names.time %>' | |
}, | |
files: [ | |
{ | |
expand: true, | |
cwd: 'dest/', | |
src: ['**/*.*'], | |
dest: '.' | |
} | |
] | |
} | |
}, // compress | |
docular: { | |
useHtml5Mode: false, | |
docular_webapp_target: './docs', | |
groups: [ | |
{ | |
groupTitle: 'Application', | |
docular_webapp_target: './docs', | |
groupId: 'app', | |
groupIcon: 'icon-book', | |
groups: [ | |
{ | |
id: 'api', | |
title: 'API', | |
files: grunt.file.expand(['app/assets/js/**/*.js']) | |
} | |
] | |
} | |
] | |
} // docular | |
}); | |
// load the npm task into the grunt runtime | |
grunt.loadNpmTasks('grunt-contrib-connect'); | |
grunt.loadNpmTasks('grunt-connect-proxy'); | |
grunt.loadNpmTasks('grunt-contrib-watch'); | |
grunt.loadNpmTasks('grunt-contrib-copy'); | |
grunt.loadNpmTasks('grunt-contrib-clean'); | |
grunt.loadNpmTasks('grunt-contrib-less'); | |
grunt.loadNpmTasks('grunt-contrib-concat'); | |
grunt.loadNpmTasks('grunt-contrib-cssmin'); | |
grunt.loadNpmTasks('grunt-contrib-uglify'); | |
grunt.loadNpmTasks('grunt-contrib-compress'); | |
grunt.loadNpmTasks('grunt-angular-templates'); | |
grunt.loadNpmTasks('grunt-processhtml'); | |
grunt.loadNpmTasks('grunt-contrib-jshint'); | |
grunt.loadNpmTasks('grunt-karma'); | |
grunt.loadNpmTasks('grunt-replace'); | |
grunt.loadNpmTasks('grunt-docular'); | |
grunt.registerTask('serve', [ | |
'clean:server', | |
'concat:server', | |
'replace:app', | |
'less:server', | |
'copy:server', | |
'jshint:server', | |
'ngtemplates:server', | |
'configureProxies:server', | |
'connect:server', | |
'watch' | |
]); | |
grunt.registerTask('dest', [ | |
'clean:dest', | |
'less:dest', | |
'uglify:beforeDest', | |
'concat:dest', | |
'replace:dest', | |
'uglify:dest', | |
'cssmin:dest', | |
'copy:dest', | |
'ngtemplates:dest', | |
'processhtml:dest', | |
'compress:dest' | |
]); | |
grunt.registerTask('dest-serve', [ | |
'configureProxies:dest', | |
'connect:dest' | |
]); | |
grunt.registerTask('test', [ | |
'jshint:server', | |
'karma:test' | |
]); | |
grunt.registerTask('docs', [ | |
'clean:docs', | |
'jshint:server', | |
'docular', | |
'connect:docs', | |
'watch:docs' | |
]); | |
grunt.registerTask('default', function () { | |
grunt.log.warn('| nothing to start...'); | |
grunt.log.warn('| ---------------------------------------------------------------------------'); | |
grunt.log.warn('| usage:'); | |
grunt.log.warn('| grunt serve starts the internal server at http://localhost:9000/'); | |
}) | |
}; |
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": "Application", | |
"version": "0.0.1", | |
"author": "Author <[email protected]>", | |
"keywords": ["Application"], | |
"homepage": "http://www.example.com", | |
"license": "MIT", | |
"description": "Description for Application", | |
"dependencies": { | |
}, | |
"devDependencies": { | |
"grunt": "~0.4.5", | |
"grunt-contrib-connect": "~0.8.0", | |
"grunt-connect-proxy": "~0.1.11", | |
"grunt-contrib-watch": "~0.6.1", | |
"grunt-contrib-copy": "~0.5.0", | |
"grunt-contrib-less": "~0.11.4", | |
"grunt-contrib-clean": "~0.6.0", | |
"grunt-contrib-concat": "~0.5.0", | |
"grunt-contrib-uglify": "~0.6.0", | |
"grunt-contrib-cssmin": "~0.10.0", | |
"grunt-contrib-compress": "~0.12.0", | |
"grunt-processhtml": "~0.3.3", | |
"grunt-angular-templates": "~0.5.7", | |
"grunt-contrib-jshint": "~0.10.0", | |
"grunt-karma": "~0.9.0", | |
"grunt-replace": "~0.8.0", | |
"grunt-ngdocs": "0.2.6", | |
"karma": "~0.12.0", | |
"karma-jasmine": "~0.2.0", | |
"karma-phantomjs-launcher": "~0.1.4", | |
"karma-chrome-launcher": "~0.1.5" | |
}, | |
"repository": { | |
"type": "git", | |
"url": "https://github.com/path/to/git.git" | |
}, | |
"private": true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment