On Github maxyermayank / workflow-automation
Created by Mayank Patel / @maxy_ermayank
Downloads dependencies using Git, HTTPS, ZIP, npm
Filename: package.json
Download node.js and follow installation guide
Find available package Here.
> npm install <package> -g installs package globally > npm install -g <package> use --save to save dependecy in package.json & -dev to lock package version > npm install <package> --save-dev
> npm init
{ "name": "project-name", "version": "1.0.0", "description": "Description goes here", "main": "index.html", "scripts": { "test": "gulp e2e" }, "repository": { "type": "git", "url": "https://example.com/project-name" }, "author": "Mayank Patel <maxy.ermayank@gmail.com>", "license": "MIT", "bugs": { "url": "https://example.com/project-name/issues" }, "homepage": "https://example.com/project-name", "dependencies": {}, "devDependencies": { "angular": "^1.3.15", "gulp": "^3.8.5", "gulp-connect": "^2.0.5", "gulp-shell": "^0.2.9", "karma": "^0.12.21", "karma-chrome-launcher": "^0.1.4", "karma-jasmine": "^0.1.5", "karma-requirejs": "^0.2.2", "lodash": "^2.4.1", "protractor": "^1.0.0", "requirejs": "^2.1.14" }, "engines": { "node": ">=0.8.0" }, "keywords": [ "gruntplugin" ], }
Filename: bower.json
Install Globally > npm install -g bower Install in your project > npm install bower
Packages available Here
bower install <package> bower install git://github.com/user/package.git bower install http://example.com/script.js
{ "name": "project-name", "version": "1.0.0", "author": "Mayank Patel <maxy.ermayank@gmail.com>", "homepage": "https://example.com/project-name", "description": "Description goes here", "main": "index.html", "license": "apache 2", "dependencies": { "angular": "1.3.15", "json3": "~3.2.4", "es5-shim": "~2.0.8", "angular-resource": "1.3.15", "d3": "3.3.x" }, "devDependencies": { "angular-mocks": "1.2.0-rc.1", "angular-scenario": "1.2.0-rc.1" } }
Install YO globally > npm install -g yo
> yo [?] What would you like to do? ›❯ Install a generator Run the Angular generator (0.4.0) Run the Backbone generator (0.1.9) Run the Blog generator (0.0.0) Run the jQuery generator (0.1.4) Run the Gruntfile generator (0.0.6) (Move up and down to reveal more choices)
yo jquery-boilerplate Boom. You just created a jQuery plugin.
Find available generators Here.
> npm install generator-bootstrap -g > yo bootstrap > npm install generator-webapp -g > yo webapp
> npm install generator-angular -g > yo angular > yo angular:view user > yo angular:controller user > yo angular:directive mydirective
Filename: gulpfile.js
Install Gulp in your project > npm install gulp --save
Install Gulp Globaly > npm install -g gulp
gulp.task('somename', function() { // Do stuff });
gulp.task('build', ['somename', 'test'];
> gulp build
gulp.src('client/templates/*.jade') .pipe(jade())
gulp.src(['src/**/*.js', 'test/spec/**/*.js']) .pipe(jshint())
gulp.src('./client/templates/*.jade') .pipe(jade()) .pipe(gulp.dest('./build/templates')) .pipe(minify()) .pipe(gulp.dest('./build/minified_templates'));
gulp.watch('app/**/*.js', ['test','reload']);
gulp.task('hello-world', function () { run('echo Hello World').exec() // prints "[echo] Hello World\n". .pipe(gulp.dest('build')) // Writes "Hello World\n" to output/echo. })
gulp.task('scripts', function () { return gulp.src('src/app/**/*.js') // <-- read from filesystem // In memory transform .pipe(jshint('.jshintrc')) // <-- lint the code .pipe(concat('app.min.js')) // <-- concatenate to one file .pipe(uglify()) // <-- minify the file .pipe(rev()) // <-- add revision to filename .pipe(gulp.dest('dist/app')); // <-- write to filesystem });
'use strict'; var gulp = require('gulp'), gutil = require('gulp-util'), del = require('del'), jshint = require('gulp-jshint'), ngAnnotate = require('gulp-ng-annotate'), concat = require('gulp-concat'), sourcemaps = require('gulp-sourcemaps'), uglify = require('gulp-uglify'), concatCss = require('gulp-concat-css'), minifyCSS = require('gulp-minify-css'), imagemin = require('gulp-imagemin'), minifyHtml = require('gulp-minify-html'), templateCache = require('gulp-angular-templatecache'), inject = require('gulp-inject'), arialinter = require('gulp-arialinter'), jasmine = require('gulp-jasmine'), protractor = require("gulp-protractor").protractor, webdriver_standalone = require("gulp-protractor").webdriver_standalone, header = require('gulp-header'), connect = require('gulp-connect'), open = require('gulp-open'); var port = 8001; //serve = require('gulp-serve'); var paths = { dist: 'dist', jsSource: ['src/scripts/*.js'], styleSource: ['src/css/main.css'], imagesSource: ['src/images/**/*.*'], htmlSource: ['src/views/**/*.html'], unitTestSource: ['test/unit/**/*.js'], e2eSource: ['test/e2e/*.js'], vendorScripts: [ 'bower_components/jquery/dist/jquery.min.js', 'bower_components/bootstrap/dist/js/bootstrap.min.js', 'bower_components/underscore/underscore-min.js', 'bower_components/angular/angular.min.js', 'bower_components/angular-resource/angular-resource.min.js', 'bower_components/angular-animate/angular-animate.min.js', 'bower_components/angular-messages/angular-messages.min.js', 'bower_components/angular-sanitize/angular-sanitize.min.js', 'bower_components/angular-aria/angular-aria.min.js' ], vendorStyles: [ 'bower_components/bootstrap/dist/css/bootstrap.min.css', 'bower_components/bootstrap/font-awesome/css/font-awesome.min.css' ] }; gulp.task('clean', function (cb) { del(paths.dist, cb); }); gulp.task('vendorScripts', function() { return gulp.src(paths.vendorScripts) .pipe(concat('scripts/vendor/vendor.js.gzip')) .pipe(uglify({compress : true})) .pipe(gulp.dest(paths.dist)); }); gulp.task('vendorStyles', function() { return gulp.src(paths.vendorStyles) .pipe(concatCss('css/vendor/vendor.css')) .pipe(gulp.dest(paths.dist)); }); gulp.task('lint', function() { return gulp.src(paths.jsSource) .pipe(jshint()) .pipe(jshint.reporter('default')); }); gulp.task('buildScript', function() { return gulp.src(paths.jsSource) .pipe(ngAnnotate({remove: true, add: true, single_quotes: true})) .pipe(concat('scripts/app.js')) .pipe(header('/** Copyright '+new Date().getFullYear()+' Author: Mayank Patel **/ \n')) .pipe(gulp.dest(paths.dist)); }); gulp.task('minifyScript', ['buildScript'], function() { return gulp.src('dist/scripts/app.js') .pipe(concat('scripts/app.min.js')) .pipe(sourcemaps.init()) .pipe(uglify()) .pipe(sourcemaps.write('/')) .pipe(gulp.dest('dist')); }); gulp.task('compressScript', ['minifyScript'], function() { return gulp.src('dist/scripts/app.min.js') .pipe(concat('scripts/app.min.js.gzip')) .pipe(uglify({compress : true})) .pipe(gulp.dest(paths.dist)); }); gulp.task('scripts', ['lint', 'compressScript'], function() { }); gulp.task('buildStyles', function() { return gulp.src(paths.styleSource) .pipe(concat('css/main.css')) .pipe(gulp.dest(paths.dist)); }); gulp.task('minifyStyles', ['buildStyles'], function() { return gulp.src('dist/css/main.css') .pipe(concat('css/main.min.css')) .pipe(sourcemaps.init()) .pipe(minifyCSS()) .pipe(sourcemaps.write('/')) .pipe(gulp.dest(paths.dist)); }); gulp.task('compressStyles', ['minifyStyles'], function() { return gulp.src('dist/css/main.min.css') .pipe(concat('css/main.min.css.gzip')) .pipe(uglify({compress : true})) .pipe(gulp.dest(paths.dist)); }); gulp.task('styles', ['minifyStyles'], function() { }); gulp.task('images', function() { return gulp.src(paths.imagesSource) .pipe(imagemin({progressive: true, optimizationLevel: 5, interlaced: true})) .pipe(gulp.dest('dist/images')); }); gulp.task('views', function() { gulp.src(paths.htmlSource) .pipe(arialinter({ level: 'AA' })) .pipe(templateCache({ module: 'blog', root: 'src/views' })) .pipe(gulp.dest('dist/scripts')); gulp.src('src/index.html') .pipe(arialinter({ level: 'AA' })) //.pipe(minifyHtml({ conditionals: true, spare:true })) .pipe(gulp.dest('dist')); gulp.src(['src/views/**/*']).pipe(minifyHtml()).pipe(gulp.dest('dist/views')); }); gulp.task('build', ['vendorScripts', 'vendorStyles', 'scripts', 'styles', 'images', 'views'], function() { }); gulp.task('test', function() { //gulp.src(paths.unitTestSource) //.pipe(jasmine({reporter: new reporters.JUnitXmlReporter()})); }); gulp.task('connect', function () { connect.server({ root: 'dist', port: port, livereload: true, // https: true, // middleware: function(connect, opt) { // return [ // // ... // ] // } }); }); gulp.task('open', function(){ var options = { url: 'http://localhost:' + port, //app: 'Google Chrome' app: 'Google Chrome Canary' // app: 'Firefox' // app: 'Safary' }; gulp.src('./dist/index.html') .pipe(open('', options)); }); gulp.task('serve', ['connect', 'open']); gulp.task('e2eTest', function() { gulp.task('webdriver_standalone', webdriver_standalone) gulp.src(paths.e2eSource) .pipe(protractor({ configFile: "test/protractor.conf.js", args: ['--baseUrl', 'http://localhost:8001/dist/index.html'] })) .on('error', function(e) { throw e }) }); gulp.task('watch', function() { gulp.watch(paths.jsSource, ['scripts']); gulp.watch(paths.imagesSource, ['images']); gulp.watch(paths.styleSource, ['styles']); gulp.watch(paths.htmlSource, ['views']); }); gulp.task('default', ['clean', 'build', 'test', 'serve']);//, 'e2eTest'
Filename: gruntfile.js
Install Grunt in your project > npm install grunt --save
Install Grunt-cli / Global install of Grunt command line > npm install -g grunt-cli
module.exports = function(grunt) { grunt.initConfig({ // Configuration des tâches }); // Enregistrement d'une tâche grunt.registerTask(taskName, [description, ] taskFunction) // Chargement d'un plugin grunt.loadNpmTasks('package'); };
Filename: brunch-config.js
> npm install -g brunch
//Create new skeleton of angular app brunch new https://github.com/scotch/angular-brunch-seed myapp //Install bower packages (css/js/etc) bower install //tell Brunch to watch your project and incrementally rebuild it when source files are changed brunch watch --server //builds a project for distribution. By default it enables minification brunch build --production
Filename: brocfile.js
Install Broccoli globaly > npm install --g broccoli-cli
Install Broccoli in your project > npm install --save-dev broccoli
var pickFiles = require('broccoli-static-compiler'); var mergeTrees = require('broccoli-merge-trees'); var EmberApp = require('ember-cli/lib/broccoli/ember-app'); var app = new EmberApp({ name: require('./package.json').name, minifyCSS: { enabled: true, options: {} }, getEnvJSON: require('./config/environment') }); // Use this to add additional libraries to the generated output files. app.import('vendor/ember-data/ember-data.js'); // If the library that you are including contains AMD or ES6 modules that // you would like to import into your application please specify an // object with the list of modules as keys along with the exports of each // module as its value. app.import('vendor/ic-ajax/dist/named-amd/main.js', { 'ic-ajax': [ 'default', 'defineFixture', 'lookupFixture', 'raw', 'request', ] }); var bootstrapTree = pickFiles('vendor/bootstrap/dist/css', { srcDir: '/', files: ['bootstrap.min.css'], destDir: '/assets' }); module.exports = mergeTrees([app.toTree(), bootstrapTree]);
Install jasmine globaly > npm install -g jasmine Install jasmine plugin for Grunt/Gulp > npm i grunt-jasmine-runner --save-dev > npm install gulp-jasmine --save-dev
describe("Test suite", function() { it("contains spec with an expectation", function() { expect(true).toBe(true); }); });
var gulp = require('gulp'); var jasmine = require('gulp-jasmine'); gulp.task('default', function () { return gulp.src('spec/test.js') .pipe(jasmine()); }); > gulp
Above matchers can be chained with the Not() function. e.g. not.toBe()
Install Karma command line tool globaly > npm install -g karma-cli Install Karma in project > npm install karma --save-dev
> karma init
module.exports = function(config) { config.set({ basePath: '', frameworks: ['jasmine','browserify'], files: ['test/spec/**/*Spec.coffee'], preprocessors: { 'test/spec/**/*.coffee': ['coffee', 'browserify'] }, port: 9876, browsers: ['Chrome', 'Firefox', 'PhantomJS'] }); };
> npm install istanbul > npm install grunt-istanbul --save-dev > npm install gulp-istanbul --save-dev
Install protractor globally > npm install protractor -g Install protractor in your project using Grunt > npm i grunt-protractor-runner --save-dev Install protractor in your project using Gulp > npm install gulp-protractor --save-dev Scaffolding is available through YO as well > npm install -g generator-protractor > yo protractor Update WebDriver > webdriver-manager update
exports.config = { seleniumAddress: 'http://localhost:4444/wd/hub', specs: ['spec.js'], multiCapabilities: [{ browserName: 'firefox' }, { browserName: 'chrome' }] }
describe('angularjs homepage', function() { var firstNumber = element(by.model('first')); var secondNumber = element(by.model('second')); var goButton = element(by.id('gobutton')); var latestResult = element(by.binding('latest')); var history = element.all(by.repeater('result in memory')); function add(a, b) { firstNumber.sendKeys(a); secondNumber.sendKeys(b); goButton.click(); } beforeEach(function() { browser.get('http://juliemr.github.io/protractor-demo/'); }); it('should have a history', function() { add(1, 2); add(3, 4); expect(history.last().getText()).toContain('1 + 2'); expect(history.first().getText()).toContain('3 + 4'); }); });
> webdriver-manager start > protractor <path to conf file>