Boar Tasks for client side
This repository contains Gulp-based tasks to make client-side applications easier. It can be used with any client side framework which supports the CommonJS or AMD pattern.
These tasks are helpers, you have to define your build tasks in your project's gulpfile.js
. You can find examples in our existing services or workshop material.
Usually we create a tasks.config.js
file which is for override the default task settings.
Sample config file
// tasks.config.js moduleexports = staticServer: port: 8081 client: app: buildPattern: 'client/app/app.js' testPattern: 'client/app/**/*.spec.js' stylesheets: buildPattern: 'client/stylesheets/app.styl' ;
Sample gulpfile
// gulpfile.js let gulp = ;let runSequence = ; let config = ;let tasks = ; gulp; gulp; gulp;gulp;gulp;gulp;gulp;gulp;gulp;gulp;
Available tasks
Build tasks
Clean
It is used to remove files from the build target directory.
Deploy
Pushes the current codebase to the production branch. Usually it initiate a deploying process.
Redirector tasks
Save
Saves the given revision to the Emarsys Redirector service - allowing to control user caches above Amazon S3 and Cloudfront.
Default configuration
Configredirector = url: argvredirectorUrl || processenvREDIRECTOR_URL name: argvredirectorName || processenvREDIRECTOR_NAME target: argvredirectorTarget || processenvREDIRECTOR_TARGET apiSecret: argvredirectorApiSecret || processenvREDIRECTOR_API_SECRET;
Usage
gulp; // Revision can be calculated before the task rungulp;
S3 tasks
Publish
It gzip the current codebase and pushes to Amazon S3
Default configuration
Configs3 = copyPattern: 'dist/**/*' bucket: argvs3Bucket || processenvS3_BUCKET withGzip: true headers: 'Cache-Control': 'max-age=315360000, no-transform, public' 'x-amz-acl': 'bucket-owner-full-control' ;
Usage
gulp;
Client tasks
Copy static
Copy static files into the dist
folder.
Default configuration
Configclient = static: copyPattern: 'client/static/**/*' target: ConfigbuildassetsPath
Usage
gulp;
Build stylesheets
Copying and pre-processing stylesheets using stylus.
Default configuration
Configclient = stylesheets: buildPattern: 'client/stylesheets/*.styl' watchPattern: 'client/stylesheets/**/*' target: ConfigbuildassetsPath + 'stylesheets/' plugins: includeCSS: true autoprefixer: browsers: 'ie 9' 'ie 10' 'last 2 versions' cascade: false
Usage
gulp;
Build stylesheets with denying errors
It is the same as the buildStylesheets
task but it is not exiting on stylesheet error. It is suggested to use for smooth development experience.
Usage
gulp;
Build scripts
It is used to build JavaScript files. It uses Webpack and Babel to compile ES6 code to ES5. Finally it creates a single JavaScript file with all of required files.
Default configuration
Configclient = app: path: 'client/app/' extensions: '.js' buildPattern: 'client/app/!(*.spec).js' testPattern: 'client/app/**/*.spec.js' testModules: watchPattern: 'client/app/**/*' viewPattern: 'client/app/views/**/*.jade' vendorPattern: 'client/vendors.js' target: ConfigbuildassetsPath + 'scripts/' vendors: codeStylePattern: 'client/app/**/*.js' loaders: test: /\.js$/ loader: 'babel' exclude: // test: /\.jade$/ loader: 'jade-loader?self' test: /\.json$/ loader: 'json-loader'
Usage
gulp;
Build scripts with denying errors
It is the same as the buildScripts
task but it is not exiting on script compilation error. It is suggested to use for smooth development experience.
Usage
gulp;
Concatenate vendors
It concatenates all of the listed vendor files and create a vendors.js
on the client.app.target
path from the configuration.
Default configuration
Configclient = app: target: ConfigbuildassetsPath + 'scripts/' vendors:
Usage
gulp;
Building an app with multiple entry points
If you have an app with multiple entry points, you can configure buildPattern
as an array of strings.
Configclient = app: buildPattern: 'client/app/!(*.spec).js' 'other/dir/!(*.spec).js' ;
If you have entry points used somewhere else where vendors.js
is not available - eg. a web worker -, you can configure buildPattern
to build those entry points with the webpack module loading logic included.
Configclient = app: buildPattern: 'client/app/!(*.spec).js' pattern: 'client/workers/!(*.spec).js' splitVendor: false ;
Test
Run all the tests found in the codebase using Karma.
Default configuration
Configclient = testConfigPath: process + '/karma.conf.js'
Usage
gulp;
Code style
Check code style using ESLint on the selected JavaScript files.
Default configuration
Configclient = app: codeStylePattern: 'client/app/**/*.js'
Usage
gulp;
Stylesheets code style
Check code style on the selected stylesheets using Stylint.
Default configuration
Configclient = stylesheets: codeStyle: pattern: 'client/stylesheets/**/*.styl' config: rules: depthLimit: 3 efficient: false indentPref: 2 namingConvention: 'lowercase-dash' noImportant: true quotePref: 'double' sortOrder: 'alphabetical' valid: false
Usage
gulp;
Template code style
Check code style on the selected template files using pug-lint.
Default configuration
Configclient = app: templateCodeStylePattern: 'client/app/**/*.jade'
Code style rules
Install pug-lint-config-emarsys
to your project and create a file in your project's root called .pug-lintrc
with the following content:
{
"extends": "emarsys"
}
Usage
gulp;
Security checks
Check package.json's dependencies section against known vulnerable libraries. This will only generate warnings on the console.
Usage
gulp;
Dummy server to provide assets
It is for development purposes - serving static asset files.
Default configuration
ConfigstaticServer = port: processenvPORT || 8080;
Usage
gulp; // It can be reloaded with reloadStaticServergulp;