1.1.0 • Published 11 years ago
gulpsi v1.1.0
GulPsi
Gulp based build system (for angular):
- packages (local or installed via npm / bower)
- angular-module dependency aggregation
- bower dependency aggregation
- full sourcemap support
- workarounds for common gulp/sourcemap/watch problems
- easy configurable and customizable
Tasks
app: Generate theangular.module("appName", [...deps...])definition and combines your angular codeassets: Copy the assetsbower: Update thebower.jsonwith aggregated package dependenciesclean: Cleanup your build directoryjshint: Lint your codeless: Compile LESS and combine CSSlivereload: Livereload :)ngTemplates: Concat all html templates into atemplates.js. Supports overwriting of templates comming from npm_modulesprocessIndexHtml: Copy and rewrite theindex.htmlto use the minified files and set theng-appnamewatch: A helper-task to react on filechanges
Installation
Theres no npm package yet
npm install gulp
npm install psi-4ward/gulpsiUsage
gulp -hshow the helpgulp buildbuilds your app (into public folder)gulp devbuild, start watchers and livereloadgulp servestart builtin webservergulp boweraggregate the bower dependencies and update bower.json
Configuration
Module's gulpsi.json
{
// define dependencies
"dependencies": {
// this gets merged into the angular.module("app", [ ...dependcies... ]);
"angular": ["ui-router"],
// your bower dependencies
"bower": {
"angular": {
"version": "~1.3.9",
// files gets merged into your lib.js
"js": "angular/angular.js"
},
"bootstrap": {
"version": "~3.3.0",
// could be an array with many files
"js": [
"bootstrap/js/affix.js",
"bootstrap/js/dropdown.js",
"bootstrap/js/tooltip.js"
],
// @import this less file
// "less": "bootstrap/less/bootstrap.less"
// @import (inline) this css files
"css": [
"bootstrap/dist/css/bootstrap.css",
"bootstrap/dist/css/bootstrap-theme.css"
]
}
}
},
// @import this less file(s)
"less": "less/test.less",
// "css": [ ... ]
// tells the processIndexHtml task that this module
// has the entrypoint file "index.html"
"indexHtml": true
}Buildsystem config
You can configure the buildsystem using the gulpfile.js see defaults.js for possible values.
Or configure a localTask folder for your local task files.
You have some global variables to make the life easier:
gulp: reference to gulprunSequence: run-sequencegutil: gulp-util_: lodash$config: the configuration$packages: all module configurations
gulpfile.js example
global['gulp'] = require('gulp');
var $config = require('gulpsi');
// define particular apps
var common = ['angular/base', 'angular/theme', 'angular/psi-notify'];
var apps = {
admin: ['angular/angular-psi-csv', 'angular/admin'],
editor: ['angular/editor', 'angular/chat'],
visitor: ['angular/visitor', 'angular/visitor'],
};
// add "--app" cli argument support
$config.commanderOpts.push(['--app <app>', 'Build a particular app']);
// packages containing only angular files, no subfolder necessary
$config.subfolder.angular = '';
// the beforeLoad Hook is triggered after cli-argument parse but before config parsing
$config.beforeLoad = function() {
if(['clean', 'bower', 'jshint', 'serve'].indexOf($config.argv.args[0]) > -1) {
// use every package for this common tasks
$config.localPackages = ['angular/*'];
} else {
// some --app argument validation
if(!$config.argv.app) {
gutil.log(gutil.colors.red('Error') + ': --app argument missing');
$config.help(); process.exit(1);
} else if (Object.keys(apps).indexOf($config.argv.app) === -1) {
gutil.log(gutil.colors.red('Error') + ': invalid app name! Use one of: ' + Object.keys(apps).join(', '));
$config.help(); process.exit(1);
}
// use only defined package directories
$config.localPackages = common.concat(apps[$config.argv.app]);
// build to app subfolder
$config.dest = 'public/' + $config.argv.app;
}
};
// Add haml support to ngTemplates using the getSources and pipe Hooks
var haml = require('gulp-haml');
$config.taskHooks.ngTemplates = {
getSources: function() {
var sources = [];
// create globbing pattern for each module
$packages.forEach(function(cfg) {
sources.push($config.basePath + cfg.folder + $config.subfolder.angular + '/**/*.html');
sources.push($config.basePath + cfg.folder + $config.subfolder.angular + '/**/*.haml');
// exclude the index.html using a negative-globbing pattern
if(cfg.indexHtml) sources.push('!' + $config.basePath + cfg.folder + $config.subfolder.angular + '/index.html');
});
return sources;
},
pipe: function(stream) {
var h = haml({compiler: 'creationix'});
h.on('error', function(e) {
gutil.log(
gutil.colors.red('Error')
+ " '" + gutil.colors.cyan('haml') + "' "
+ gutil.colors.red(e.toString())
);
});
return stream.pipe(h);
}
};
// Deploy Task
gulp.task('deploy', function() {
// ....
});TODO:
- Create a task to inject config into app (like api-url for dev-systems)
1.1.0
11 years ago