Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions gulp/modules/add-watch-for-file-reload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = function(gulp, config, browserSync, changeEvent) {

function addWatchForFileReload(isDev) {
/**
* Add watches to build and reload using browser-sync.
* Use this XOR the browser-sync option.files, not both.
* @param {Boolean} isDev - dev or build mode
*/
if (isDev) {
gulp.watch([config.less], ['styles', browserSync.reload]);
gulp.watch([config.client + '**/*', '!' + config.less], browserSync.reload)
.on('change', function(event) { changeEvent(event); });
}
else {
gulp.watch([config.less, config.js, config.html], ['build', browserSync.reload])
.on('change', function(event) { changeEvent(event); });
}
}

return addWatchForFileReload;

};
18 changes: 18 additions & 0 deletions gulp/modules/bytediff-formatter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = function (formatPercent) {

/**
* Formatter for bytediff to display the size changes after processing
* @param {Object} data - byte data
* @return {String} Difference in bytes, formatted
*/
function bytediffFormatter(data) {
var difference = (data.savings > 0) ? ' smaller.' : ' larger.';
return data.fileName + ' went from ' +
(data.startSize / 1000).toFixed(2) + ' kB to ' +
(data.endSize / 1000).toFixed(2) + ' kB and is ' +
formatPercent(1 - data.percent, 2) + '%' + difference;
}

return bytediffFormatter;

};
13 changes: 13 additions & 0 deletions gulp/modules/change-event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = function (log, config) {
/**
* When files change, log it
* @param {Object} event - event that fired
*/
function changeEvent(event) {
var srcPattern = new RegExp('/.*(?=/' + config.source + ')/');
log('File ' + event.path.replace(srcPattern, '') + ' ' + event.type);
}

return changeEvent;

};
15 changes: 15 additions & 0 deletions gulp/modules/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = function (util, log, del) {

/**
* Delete all files in a given path
* @param {Array} path - array of paths to delete
* @param {Function} done - callback when complete
*/
function clean(path, done) {
log('Cleaning: ' + util.colors.blue(path));
del(path, done);
}

return clean;

};
181 changes: 181 additions & 0 deletions gulp/modules/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
module.exports = function(bowerConfiguration) {
var client = 'src/client/';
var server = './src/server/';
var clientApp = client + 'app/';
var report = './report/';
var root = './';
var specRunnerFile = 'specs.html';
var temp = './.tmp/';
var wiredep = require('wiredep');
var bowerFiles = wiredep({devDependencies: true})['js'];
var bower = {
json: bowerConfiguration,
directory: './bower_components/',
ignorePath: '../..'
};
var nodeModules = 'node_modules';

var config = {
/**
* File paths
*/
// all javascript that we want to vet
alljs: [
'./src/**/*.js',
'./*.js'
],
build: './build/',
client: client,
css: temp + 'styles.css',
fonts: bower.directory + 'font-awesome/fonts/**/*.*',
html: client + '**/*.html',
htmltemplates: clientApp + '**/*.html',
images: client + 'images/**/*.*',
index: client + 'index.html',
// app js, with no specs
js: [
clientApp + '**/*.module.js',
clientApp + '**/*.js',
'!' + clientApp + '**/*.spec.js'
],
jsOrder: [
'**/app.module.js',
'**/*.module.js',
'**/*.js'
],
less: client + 'styles/styles.less',
report: report,
root: root,
server: server,
source: 'src/',
stubsjs: [
bower.directory + 'angular-mocks/angular-mocks.js',
client + 'stubs/**/*.js'
],
temp: temp,

/**
* optimized files
*/
optimized: {
app: 'app.js',
lib: 'lib.js'
},

/**
* plato
*/
plato: {js: clientApp + '**/*.js'},

/**
* browser sync
*/
browserReloadDelay: 1000,

/**
* template cache
*/
templateCache: {
file: 'templates.js',
options: {
module: 'app.core',
root: 'app/',
standAlone: false
}
},

/**
* Bower and NPM files
*/
bower: bower,
packages: [
'./package.json',
'./bower.json'
],

/**
* specs.html, our HTML spec runner
*/
specRunner: client + specRunnerFile,
specRunnerFile: specRunnerFile,

/**
* The sequence of the injections into specs.html:
* 1 testlibraries
* mocha setup
* 2 bower
* 3 js
* 4 spechelpers
* 5 specs
* 6 templates
*/
testlibraries: [
nodeModules + '/mocha/mocha.js',
nodeModules + '/chai/chai.js',
nodeModules + '/sinon-chai/lib/sinon-chai.js'
],
specHelpers: [client + 'test-helpers/*.js'],
specs: [clientApp + '**/*.spec.js'],
serverIntegrationSpecs: [client + '/tests/server-integration/**/*.spec.js'],

/**
* Node settings
*/
nodeServer: './src/server/app.js',
defaultPort: '7203'
};

/**
* wiredep and bower settings
*/
config.getWiredepDefaultOptions = function() {
var options = {
bowerJson: config.bower.json,
directory: config.bower.directory,
ignorePath: config.bower.ignorePath
};
return options;
};

/**
* karma settings
*/
config.karma = getKarmaOptions();

return config;

////////////////

function getKarmaOptions() {
var options = {
files: [].concat(
bowerFiles,
config.specHelpers,
clientApp + '**/*.module.js',
clientApp + '**/*.js',
temp + config.templateCache.file,
config.serverIntegrationSpecs
),
exclude: [],
coverage: {
dir: report + 'coverage',
reporters: [
// reporters not supporting the `file` property
{type: 'html', subdir: 'report-html'},
{type: 'lcov', subdir: 'report-lcov'},
// reporters supporting the `file` property, use `subdir` to directly
// output them in the `dir` directory.
// omit `file` to output to the console.
// {type: 'cobertura', subdir: '.', file: 'cobertura.txt'},
// {type: 'lcovonly', subdir: '.', file: 'report-lcovonly.txt'},
// {type: 'teamcity', subdir: '.', file: 'teamcity.txt'},
//{type: 'text'}, //, subdir: '.', file: 'text.txt'},
{type: 'text-summary'} //, subdir: '.', file: 'text-summary.txt'}
]
},
preprocessors: {}
};
options.preprocessors[clientApp + '**/!(*.spec)+(.js)'] = ['coverage'];
return options;
}
};
13 changes: 13 additions & 0 deletions gulp/modules/error-logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = function (log) {
/**
* Log an error message and emit the end of a task
*/
function errorLogger(error) {
log('*** Start of Error ***');
log(error);
log('*** End of Error ***');
this.emit('end');
}

return errorLogger;
};
15 changes: 15 additions & 0 deletions gulp/modules/format-percent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = function () {

/**
* Format a number as a percentage
* @param {Number} num Number to format as a percent
* @param {Number} precision Precision of the decimal
* @return {String} Formatted perentage
*/
function formatPercent(num, precision) {
return (num * 100).toFixed(precision);
}

return formatPercent;

};
25 changes: 25 additions & 0 deletions gulp/modules/get-header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = function (Package, header) {

/**
* Format and return the header for files
* @return {String} Formatted file header
*/
function getHeader() {
// var pkg = require('./package.json');
var template = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @authors <%= pkg.authors %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' */',
''
].join('\n');
return header(template, {
pkg: Package
});
}

return getHeader;

};
18 changes: 18 additions & 0 deletions gulp/modules/get-node-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = function (config) {

function getNodeOptions(isDev) {
var port = process.env.PORT || config.defaultPort;
return {
script: config.nodeServer,
delayTime: 1,
env: {
'PORT': port,
'NODE_ENV': isDev ? 'dev' : 'build'
},
watch: [config.server]
};
}

return getNodeOptions;

};
21 changes: 21 additions & 0 deletions gulp/modules/inject-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = function (gulp, $inject, orderSrc) {

/**
* Inject files in a sorted sequence at a specified inject label
* @param {Array} src glob pattern for source files
* @param {String} label The label name
* @param {Array} order glob pattern for sort order of the files
* @returns {Stream} The stream
*/
function _inject(src, label, orderPattern) {
var options = {read: false};
if (label) {
options.name = 'inject:' + label;
}

return $inject(orderSrc(src, orderPattern), options);
}

return _inject;

};
19 changes: 19 additions & 0 deletions gulp/modules/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = function (util) {
/**
* Log a message or series of messages using chalk's blue color.
* Can pass in a string, object or array.
*/
function log(msg) {
if (typeof(msg) === 'object') {
for (var item in msg) {
if (msg.hasOwnProperty(item)) {
util.log(util.colors.blue(msg[item]));
}
}
} else {
util.log(util.colors.blue(msg));
}
}

return log;
};
21 changes: 21 additions & 0 deletions gulp/modules/notify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = function (_) {

var path = require('path');

/**
* Show OS level notification using node-notifier
*/
function notify(options) {
var notifier = require('node-notifier');
var notifyOptions = {
sound: 'Bottle',
contentImage: path.join(__dirname, 'gulp.png'),
icon: path.join(__dirname, 'gulp.png')
};
_.assign(notifyOptions, options);
notifier.notify(notifyOptions);
}

return notify;

};
Loading