Skip to content

Instantly share code, notes, and snippets.

@maggiben
Last active August 29, 2015 13:57
Show Gist options
  • Save maggiben/9891432 to your computer and use it in GitHub Desktop.
Save maggiben/9891432 to your computer and use it in GitHub Desktop.
ang-bp
{
"strict": true,
"undef": true,
"unused": true,
"node": true,
"globals": {
"describe": true,
"it": true,
"beforeEach": true,
"afterEach": true
}
}
// Include gulp
var gulp = require('gulp')
, clean = require('gulp-clean')
, jshint = require('gulp-jshint')
, concat = require('gulp-concat')
, watch = require('gulp-watch')
, uglify = require('gulp-uglify')
, changelog = require('gulp-conventional-changelog')
, bump = require('gulp-bump')
, recess = require('gulp-recess')
, less = require('gulp-less')
, ngmin = require('gulp-ngmin')
, html2js = require('gulp-html2js')
, mocha = require('gulp-mocha')
, header = require('gulp-header')
, flatten = require('gulp-flatten')
, notify = require("gulp-notify")
, rename = require('gulp-rename');
var userConfig = require( './build.config.js' );
var pkg = require('./package.json');
var banner = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' */',
''].join('\n');
/**
* The directories to delete when `gulp clean` is executed.
*/
gulp.task('clean', function() {
return gulp.src([userConfig.build_dir, userConfig.compile_dir], {read: false})
.pipe(clean());
});
/**
* The `copy` task just copies files from A to B. We use it here to copy
* our project assets (images, fonts, etc.) and javascripts into
* `build_dir`, and then to copy the assets to `compile_dir`.
*/
gulp.task('copy', function() {
gulp.src('**', { cwd: 'src/assets' })
.pipe(gulp.dest(userConfig.build_dir + '/assets/'));
if(userConfig.vendor_files.assets.length)
gulp.src(userConfig.vendor_files.assets, { cwd: '.' })
.pipe(flatten())
.pipe(gulp.dest(userConfig.build_dir + '/assets/'));
if(userConfig.app_files.js.length)
gulp.src(userConfig.app_files.js, { cwd: '.' })
.pipe(gulp.dest(userConfig.build_dir + '/'));
if(userConfig.vendor_files.js.length)
gulp.src(userConfig.vendor_files.js, { cwd: '.' })
.pipe(gulp.dest(userConfig.build_dir + '/'));
gulp.src('**', { cwd: userConfig.build_dir + '/assets' })
.pipe(gulp.dest(userConfig.compile_dir + '/assets'));
});
/**
* `grunt concat` concatenates multiple source files into a single file.
*/
gulp.task('concat', function() {
if(userConfig.vendor_files.css.length)
gulp.src(userConfig.vendor_files.css, { cwd: '.' })
.pipe(gulp.dest(userConfig.build_dir + '/assets/'));
/*
src: [
'<%= vendor_files.css %>',
'<%= recess.build.dest %>'
],
dest: '<%= recess.build.dest %>'
*/
});
gulp.task('scripts', function() {
options: {
banner: '<%= meta.banner %>'
},
src: [
'<%= vendor_files.js %>',
'module.prefix',
'<%= build_dir %>/src/**/*.js',
'<%= html2js.app.dest %>',
'<%= html2js.common.dest %>',
'module.suffix'
],
dest: '<%= compile_dir %>/assets/<%= pkg.name %>-<%= pkg.version %>.js'
return gulp.src([].concat(userConfig.app_files.js, userConfig.vendor_files.js))
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
.pipe(concat('main.js'))
.pipe(gulp.dest('dist/assets/js'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest('dist/assets/js'))
.pipe(livereload(server))
.pipe(notify({ message: 'Scripts task complete' }));
});
/**
* `recess` handles our LESS compilation and uglification automatically.
* Only our `main.less` file is included in compilation; all other files
* must be imported from this file.
*/
gulp.task('recess', function() {
/* Dev Build */
return gulp.src(userConfig.app_files.less)
.pipe(recess({
strictPropertyOrder: false, // Complains if not strict property order
noIDs: false, // Doesn't complain about using IDs in your stylesheets
noJSPrefix: true, // Doesn't complain about styling .js- prefixed classnames
noOverqualifying: false, // Doesn't complain about overqualified selectors (ie: div#foo.bar)
noUnderscores: false, // Doesn't complain about using underscores in your class names
noUniversalSelectors: false, // Doesn't complain about using the universal * selector
zeroUnits: true // Doesn't complain if you add units to values of 0
}))
.pipe(less({
compile: true,
compress: true,
noUnderscores: false,
noIDs: false,
zeroUnits: false
}))
.pipe(gulp.dest(userConfig.build_dir + '/assets/' + pkg.name + '-' + pkg.version + '.css'));
/*.pipe(notify({
message: "Generated file: <%= file.relative %> @ <%= options.date %>",
templateOptions: {
definesate: new Date()
}
}));
*/
});
/**
* `jshint` defines the rules of our linter as well as which files we
* should check. This file, all javascript sources, and all our unit tests
* are linted based on the policies listed in `options`. But we can also
* specify exclusionary patterns by prefixing them with an exclamation
* point (!); this is useful when code comes from a third party but is
* nonetheless inside `src/`.
*/
gulp.task('jshint', function() {
return gulp.src([].concat(userConfig.app_files.js, userConfig.app_files.jsunit, '.gulpfile.js'))
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'));
});
/**
* HTML2JS is a Gulp plugin that takes all of your template files and
* places them into JavaScript files as strings that are added to
* AngularJS's template cache. This means that the templates too become
* part of the initial payload as one JavaScript file. Neat!
*/
gulp.task('html2js', function() {
/**
* These are the templates from `src/app`.
*/
gulp.src([].concat(userConfig.app_files.atpl))
.pipe(html2js({
outputModuleName: 'templates-app',
useStrict: true,
htmlmin: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeAttributeQuotes: false,
removeComments: true,
removeEmptyAttributes: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true
}
}))
.pipe(concat('templates-app.js'))
.pipe(gulp.dest(userConfig.build_dir));
/**
* These are the templates from `src/common`.
*/
gulp.src([].concat(userConfig.app_files.ctpl))
.pipe(html2js({
outputModuleName: 'templates-common',
useStrict: true
}))
.pipe(concat('templates-common.js'))
.pipe(gulp.dest(userConfig.build_dir));
});
// Default Task
gulp.task('default', ['clean', 'jshint', 'html2js', 'copy']);
{
"author": "Benjamin Maggi",
"name": "ang-boilerplate",
"version": "0.1.0",
"homepage": "http://bit.ly/ang-boilerplate",
"licenses": {
"type": "MIT",
"url": "https://raw.github.com/maggiben/ang-boilerplate/master/LICENSE"
},
"bugs": "https://github.com/maggiben/ang-boilerplate/issues",
"repository": {
"type": "git",
"url": "[email protected]:maggiben/ang-boilerplate.git"
},
"dependencies": {},
"devDependencies": {
"gulp": "~3",
"gulp-clean": "~0.2",
"gulp-jshint": "~1.5",
"gulp-concat": "~2.2",
"gulp-watch": "~0.5",
"gulp-uglify": "~0.2",
"gulp-conventional-changelog": "~0.1",
"gulp-bump": "~0.1",
"gulp-recess": "~0.3",
"gulp-less": "~1.2",
"gulp-mocha": "~0.4",
"gulp-ngmin": "~0.1",
"gulp-html2js": "~0.1",
"gulp-header": "~1",
"gulp-flatten": "~0.0.2",
"gulp-notify": "~1.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment