We have an angular 4 project and we're trying to add some e2e tests using gulp, nightwatch and cucumber but every time we run the tests the following error happens:
$ gulp e2e-tests
[11:15:12] Using gulpfile ~project/path/gulpfile.js
[11:15:12] Starting 'e2e-tests'...
[11:15:12] Starting 'e2e-scenarios'...
[11:15:12] log file
[11:15:12] Starting nightwatch...
Starting selenium server... started - PID: 18742
There was an error while starting the test runner:
Error: Cannot find module 'e2e/step_definitions/xxxx.js'
at Function.Module._resolveFilename (module.js:555:15)
at Function.Module._load (module.js:482:25)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at /project/path/node_modules/cucumber/lib/cli/index.js:163:16
at Array.forEach (<anonymous>)
Below is the configuration we have:
nightwatch.conf
var seleniumServer = require('selenium-server');
const chromedriver = require('chromedriver');
require('nightwatch-cucumber')({
cucumberArgs: ['--require', 'e2e/step_definitions', '--format', 'json:reports/cucumber.json', 'e2e/features']
});
module.exports = {
// Loads nightwatch-cucumber configuration into main nightwatch.js conf
custom_commands_path: '',
custom_assertions_path: '',
page_objects_path: '',
live_output: false,
disable_colors: false,
// Sets configuration for Selenium Server
selenium: {
start_process: true,
server_path: seleniumServer.path,
host: '127.0.0.1',
port: 4444,
cli_args : {
"webdriver.chrome.driver" : chromedriver.path
}
},
// Sets config options for different testing environments defined by the user
test_settings: {
default: {
launch_url: '',
selenium_port: 4444,
selenium_host: '127.0.0.1',
silent: true,
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true
},
'screenshots': {
enabled: true,
on_error: true,
on_failure: true,
path: '/screenshots'
}
},
chrome: {
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true
}
}
}
};
package.json
"devDependencies": {
"#angular/cli": "~1.6.0",
"#angular/compiler-cli": "^4.3.2",
"#angular/language-service": "^4.3.2",
"#types/jasmine": "~2.5.53",
"#types/jasminewd2": "~2.0.2",
"#types/node": "^6.0.104",
"codelyzer": "~3.0.1",
"gulp": "^3.9.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.4.2",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"selenium-webdriver": "^4.0.0-alpha.1",
"ts-node": "~3.0.4",
"tslint": "~5.3.2",
"typescript": "~2.3.3"
}
gulpfile.js
var gulp = require('gulp');
var nightwatch = require('gulp-nightwatch');
var reporter = require('gulp-protractor-cucumber-html-report');
var runSequence = require('run-sequence');
gulp.task('default', function() {
return console.log('Starting gulp tasks…');
});
gulp.task('login', function() {
return gulp.src('')
.pipe(nightwatch({
configFile: 'nightwatch.conf.js'
}))
});
//E2E tasks
gulp.task('e2e-scenarios', [], function e2e() {
let tags = '';
let skipTags = '';
let tagIndex = process.argv.indexOf("--tag");
let skipTagIndex = process.argv.indexOf("--skiptags");
if (tagIndex > -1) {
tags = process.argv[tagIndex + 1];
tags = '--tag ' + tags;
}
if (skipTagIndex > -1) {
skipTags = process.argv[skipTagIndex + 1];
skipTags = '--skiptags ' + skipTags;
}
return gulp.src('')
.pipe(nightwatch({
configFile: 'nightwatch.conf.js',
cliArgs: [tags, skipTags]
}));
});
gulp.task('e2e-report', function () {
return gulp.src('./reports/cucumber.json')
.pipe(reporter({
dest: 'reports/'
}));
});
gulp.task('e2e-tests', function (done) {
runSequence('e2e-scenarios', 'e2e-report', function () {
done();
});
});
And this is the project Structure
Project
enter image description here
Please help me to find out what is causing this issue.
Related
I'm trying to avoid duplicate code by using a variable object inside a Gruntfile with a set of specified parameters. I apologize if this is declared incorrectly, as I'm not entirely sure how to create an object variable in gruntjs. The goal is to use sonarProperties inside the sonarRunner config. In the if block, add some additional lines, and the else block, just use sonarProperties. Unfortunately my syntax is incorrect. Is this even possible? I'm basing it off of a gulpfile and would like to do something similar.
Sample gulpfile:
const packageName = require('./package.json').name;
gulp.task('sonar', callback => {
let sonarProperties = {
// #################################################
// # General Configuration
// #################################################
'sonar.projectKey': `microservice:${packageName}`,
'sonar.sourceEncoding': 'UTF-8',
'sonar.login': process.env.SONAR_TOKEN,
// #################################################
// # Javascript Configuration
// #################################################
'sonar.language': 'javascript',
'sonar.sources': 'src',
'sonar.tests': 'test',
'sonar.javascript.lcov.reportPaths': 'coverage/lcov.info',
'sonar.coverage.exclusions': 'src/**/*.spec.js',
};
if (process.env.SONAR_ANALYSIS_TYPE === 'pr') {
sonarProperties = {
...sonarProperties, // #################################################
// # Github Configuration
// #################################################
'sonar.pullrequest.provider': 'github',
'sonar.pullrequest.branch': process.env.branch,
'sonar.pullrequest.key': process.env.pr_numbers,
'sonar.pullrequest.base': process.env.base_branch,
'sonar.pullrequest.github.repository': process.env.repo,
'sonar.scm.revision': process.env.sha,
};
}
Here's the pertinent points of my gruntfile:
sonarProperties: [{
projectKey: 'microservice:<%= pkg.name %>',
projectName: 'Microservice - <%= pkg.name %>',
sourceEncoding: 'UTF-8',
login: 'admin',
password: 'admin',
host: {
url: 'http://localhost:9000/'
},
language: 'js',
sources: 'js',
tests: 'test',
testExecutionReportPaths: 'test_coverage_reporter/report.xml',
javascript: {
lcov: {
reportPaths: 'test_coverage/lcov.info'
}
},
}],
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sonarRunner: {
analysis: {
options: {
debug: true,
separator: '\n',
sonar: (function() {
if (process.env.SONAR_ANALYSIS_TYPE === 'pr') {
return {
...sonarProperties
moreParams: someData,
};
} else {
return {
// use just sonarProperties
};
}
}())
}
}
}
});
I was able to create the function with the following:
grunt.registerTask('sonar', function () {
let sonarProperties = {
// #################################################
// # General Configuration
// #################################################
..
}
And declaring it as a callback from the beginning as a grunt task.
I need to install args before the session. On a specific tag must be transmitted a specific screen resolution. I tried to implement beforeSession, but the necessary arg is not in chromeOptions.args when starting the session.
I tried two version:
1.
beforeSession:
beforeSession: function(){
if(argv.tags ===("#virtualFront")){
exports.config.capabilities[0].chromeOptions.args.push('--window-size=1080,1920');
} else{
exports.config.capabilities[0].chromeOptions.args.push(' --start-maximized');
}
console.log("it is from config beforeSession: "+exports.config.capabilities[0].chromeOptions.args);
},
suite.cucumber.wdio.conf:
browserName: 'chrome',
chromeOptions: {
args: ['--incognito',],
binary: '/Program Files (x86)/Google/Chrome/Application/chrome.exe'
},
BeforeSession:
beforeSession: function(){
if(argv.tags ===("#virtualFront")){
argv.optionChrome = '--window-size=1080,1920';
} else{
argv.optionChrome=' --start-maximized';
}
console.log("it is from config beforeSession: "+exports.config.capabilities[0].chromeOptions.args);
},
suite.cucumber.wdio.conf:
{
browserName: 'chrome',
chromeOptions: {
args: ['--incognito',argv.optionChrome, ],
binary: '/Program Files (x86)/Google/Chrome/Application/chrome.exe'
},
When I use 2 version args asigned to null
The solution was to add the script to the beginning of suite.cucumber.wdio.conf:
let chromeOpts = ['--incognito'];
if (argv.tags ==="#virtualFont"){
chromeOpts +=` --window-size=1080,1920`
}else chromeOpts +=` --start-maximized`;
and:
chromeOptions: {
args: [ chromeOpts, ],
binary: '/Program Files (x86)/Google/Chrome/Application/chrome.exe'
//for windows7
},
Here is the error message after I try to run my app
[15:32:01] Starting 'default'...
[15:32:01] Plumber found unhandled error:
GulpUglifyError: unable to minify JavaScript
Caused by: SyntaxError: Unexpected token keyword «function», expected
punc «,»
File: /home/*******/myfile.js Line: 81
my gulp file:
const gulp = require('gulp')
const uglify = require('gulp-uglify')
const babel = require('gulp-babel')
const plumber = require('gulp-plumber')
const del = require('del')
gulp.task('default', ['conf'], () => gulp.src('src/app/**/*.js')
.pipe(plumber())
.pipe(babel())
.pipe(uglify())
.pipe(gulp.dest('dist')))
gulp.task('conf', ['package'], () => gulp.src('./src/conf/*').pipe(gulp.dest('dist/conf')))
gulp.task('package', ['clean'], () => gulp.src(['./package.json']).pipe(gulp.dest('dist/')))
gulp.task('clean', () => del(['dist/**/*']))
If I correctly understand the problem, my code has to be transpiled to es5 by babel, so here is the .babelrc
{
"plugins": [
"transform-class-properties",
"babel-plugin-transform-runtime",
"transform-es2015-shorthand-properties",
["babel-plugin-root-import", {
"rootPathSuffix": "src/app"
}]
],
"presets": ["es2015"]
}
Here is the code from line 81 (where the comments begin) from myfile.js.
export default class Scraper {
// ...
/**
* Converts a html string to a cheerio object
* #param {String} html The html string
* #return {Object} The cheerio object
*/
htmlToDom(html) {
// https://bugs.chromium.org/p/v8/issues/detail?id=2869
// https://github.com/cheeriojs/cheerio/issues/263
if(typeof global.gc === 'function') {
global.gc()
html = (' ' + html).substr(1)
}
return cheerio.load(html)
}
static absolute(location, relative) {
//...
}
First I thought maybe the shorthanded version causing the problem, but I have transform-es2015-shorthand-properties installed, and in an older project I use the very same skeleton, without this plugin.
Update
"dependencies": {
"babel-plugin-transform-class-properties": "^6.24.1",
"bunyan": "^1.8.10",
"cheerio": "^1.0.0-rc.2",
"colors": "^1.1.2",
"js-yaml": "^3.12.0",
"pg": "^7.4.3",
"puppeteer": "^1.5.0",
"sequelize": "^4.38.0",
"sequelize-connect": "^2.1.1"
},
"devDependencies": {
"ava": "^0.19.1",
"babel-plugin-root-import": "^6.1.0",
"babel-plugin-transform-es2015-shorthand-properties": "^6.24.1",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-latest": "^6.24.1",
"babel-register": "^6.24.1",
"coveralls": "^2.13.0",
"del": "^2.2.2",
"esdoc": "^0.5.2",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"gulp-plumber": "^1.1.0",
"gulp-uglify": "^2.1.2",
"mkdir-recursive": "^0.4.0",
"nyc": "^11.2.0",
"sinon": "^2.1.0",
"standard": "^10.0.1",
"wait-on": "^3.2.0"
},
uninstalling and reinstalling gulp-uglify did the trick for me.
You may want to try adding babel-plugin-transform-async-to-generator
yarn add babel-plugin-transform-async-to-generator -D
.babelrc : "plugins": ["babel-plugin-transform-async-to-generator"]
Background
I am trying to transpile my ES6 js to ES5 js. When I visit the https://babeljs.io/repl webpage to test out what babel should output for the preset option es2015 it outputs JavaScript that is different than what gulp-babel outputs.
Input ES6 JavaScript
// eslint-disable-next-line no-unused-vars
function getStars() {
// Round the number like "3.5k" https://stackoverflow.com/a/9461657
const round = num => (num > 999 ? `${(num / 1000).toFixed(1)}k` : num);
// Add the most recent star count to the repositories.
// eslint-disable-next-line no-undef
document.querySelectorAll('.repositories .repo a').forEach(async (a) => {
const link = a;
const name = link.getAttribute('href').split('/').slice(-2).join('/');
const url = `https://api.github.com/repos/${name}`;
const { starGazersCount } = await fetch(url).then(res => res.json());
if (!starGazersCount) return;
link.querySelector('.stars').innerText = `${'⭐️ '}${round(starGazersCount)}`;
});
}
babeljs.io output ~Desired Output~
'use strict';
// eslint-disable-next-line no-unused-vars
function getStars() {
// Round the number like "3.5k" https://stackoverflow.com/a/9461657
var round = function round(num) {
return num > 999 ? (num / 1000).toFixed(1) + 'k' : num;
};
// Add the most recent star count to the repositories.
// eslint-disable-next-line no-undef
document.querySelectorAll('.repositories .repo a').forEach(async function (a) {
var link = a;
var name = link.getAttribute('href').split('/').slice(-2).join('/');
var url = 'https://api.github.com/repos/' + name;
var _ref = await fetch(url).then(function (res) {
return res.json();
}),
starGazersCount = _ref.starGazersCount;
if (!starGazersCount) return;
link.querySelector('.stars').innerText = '⭐️ ' + round(starGazersCount);
});
}
gulp-babel output
"use strict";
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
(function () {
function r(e, n, t) {
function o(i, f) {
if (!n[i]) {
if (!e[i]) {
var c = "function" == typeof require && require;
if (!f && c) return c(i, !0);
if (u) return u(i, !0);
var a = new Error("Cannot find module '" + i + "'");
throw a.code = "MODULE_NOT_FOUND", a;
}
var p = n[i] = {
exports: {}
};
e[i][0].call(p.exports, function (r) {
var n = e[i][1][r];
return o(n || r);
}, p, p.exports, r, e, n, t);
}
return n[i].exports;
}
for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) {
o(t[i]);
}
return o;
}
return r;
})()({
1: [function (require, module, exports) {
// eslint-disable-next-line no-unused-vars
function getStars() {
// Round the number like "3.5k" https://stackoverflow.com/a/9461657
var round = function round(num) {
return num > 999 ? "".concat((num / 1000).toFixed(1), "k") : num;
}; // Add the most recent star count to the repositories.
// eslint-disable-next-line no-undef
document.querySelectorAll('.repositories .repo a').forEach(
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee(a) {
var link, name, url, _ref2, starGazersCount;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
link = a;
name = link.getAttribute('href').split('/').slice(-2).join('/');
url = "https://api.github.com/repos/".concat(name);
_context.next = 5;
return fetch(url).then(function (res) {
return res.json();
});
case 5:
_ref2 = _context.sent;
starGazersCount = _ref2.starGazersCount;
if (starGazersCount) {
_context.next = 9;
break;
}
return _context.abrupt("return");
case 9:
link.querySelector('.stars').innerText = '⭐️ '.concat(round(starGazersCount));
case 10:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
}());
}
}, {}]
}, {}, [1]);
⚠️Notice how the gulp-babel output contains polyfill functions such as _asyncToGenerator & asyncGeneratorStep.
Why does the online babel editor not output this when using the es2015 preset?
Other Useful files
Below is my .babelrc:
{
"presets": [
"#babel/preset-env"
]
}
Below is my package.json:
{
"devDependencies": {
"#babel/core": "^7.0.0",
"#babel/preset-env": "^7.0.0",
"babel-eslint": "^10.0.1",
"babel-preset-env": "^1.7.0",
"bower": "^1.8.2",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"gulp-babel": "^8.0.0",
"gulp-changed": "^3.2.0",
"gulp-cssnano": "^2.1.2",
"gulp-error-handle": "^1.0.0",
"gulp-eslint": "^5.0.0",
"gulp-gh-pages": "^0.5.4",
"gulp-htmlmin": "^5.0.1",
"gulp-imagemin": "^5.0.3",
"gulp-include": "^2.3.1",
"gulp-notify": "^3.2.0",
"gulp-plumber": "^1.1.0",
"gulp-postcss": "^8.0.0",
"gulp-pug": "^4.0.1",
"gulp-rename": "^1.2.2",
"gulp-sass": "*",
"gulp-size": "^3.0.0",
"gulp-sourcemaps": "^2.6.*",
"gulp-strip-css-comments": "^2.0.0",
"gulp-strip-debug": "^3.0.0",
"gulp-surge": "^0.1.0",
"gulp-terser": "^1.1.5",
"gulp-util": "^3.0.8",
"localtunnel": "^1.8.3",
"main-bower-files": "^2.13.1",
"path": "^0.12.7",
"postcss-cli": "^6.0.1",
"run-sequence": "^2.2.1",
"yarn": "^1.12.3"
},
"dependencies": {
"animate.css": "latest",
"argv": "^0.0.2",
"autoprefixer": "^9.3.1",
"babel-polyfill": "^6.26.0",
"browser-sync": "^2.18.13",
"browserify": "^16.2.3",
"bulma": "latest",
"del": "^3.0.0",
"gulp": "^3.9.1",
"gulp-load-plugins": "^1.5.0",
"hamburgers": "latest",
"hover": "latest",
"imagemin-pngquant": "^6.0.0",
"isinviewport": "latest",
"jquery": "latest",
"lost": "^8.2.0",
"minimist": "^1.2.0",
"moment": "^2.22.2",
"node-bourbon": "^4.2.8",
"node-neat": "^2.0.0-beta.0",
"psi": "^3.1.0",
"require-dir": "^1.1.0",
"rucksack-css": "^1.0.2",
"vanilla-lazyload": "latest",
"vinyl-buffer": "^1.0.1",
"vinyl-ftp": "^0.6.0",
"vinyl-source-stream": "^2.0.0"
}
}
Below is my js task for gulp:
'use-strict';
const gulp = require('gulp');
const $ = require('gulp-load-plugins')({ lazy: true });
const browserify = require('browserify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const paths = require('../../paths.js');
const config = require('../../config.js')();
gulp.task('eslint', () => {
console.log('-> Running eslint');
// Select files
gulp.src(`${paths.to.js.in}/**/*.js`)
// Prevent pipe breaking caused by errors from gulp plugins
.pipe($.plumber())
// Check for lint errors
.pipe($.eslint())
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe($.eslint.format())
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failAfterError last.
.pipe($.eslint.failAfterError());
});
gulp.task('js', ['eslint'], () => {
const env = ((config.environment || process.env.NODE_ENV || 'development').trim().toLowerCase() !== 'production');
console.log(`-> Compiling JavaScript for ${config.environment}`);
// Obtain a readable stream containing the processed browserified bundle
const bundle = browserify({
entries: paths.to.js.in,
debug: env,
})
.bundle()
// Convert browserify stream to a gulp-readable steam & buffer
.pipe(source(config.js.name))
.pipe(buffer());
if (env) {
// Select bundle
bundle
// Initialize sourcemaps
.pipe($.sourcemaps.init())
// Prevent pipe breaking caused by errors from gulp plugins
.pipe($.plumber())
// Concatenate includes
.pipe($.include({
includePaths: [`${paths.to.js.in}`],
}))
// Transpile
.pipe($.babel())
// Catch errors
.pipe($.errorHandle())
// Save sourcemaps
.pipe($.sourcemaps.write('.'))
// Save unminified file
.pipe(gulp.dest(`${paths.to.js.out}`));
} else {
// Select bundle
bundle
// Prevent pipe breaking caused by errors from gulp plugins
.pipe($.plumber())
// Concatenate includes
.pipe($.include({
includePaths: [`${paths.to.js.in}`],
}))
// Transpile
.pipe($.babel())
// Catch errors
.pipe($.errorHandle())
// Show file-size before compression
.pipe($.size({ title: 'Javascript In Size' }))
// Optimize and minify
.pipe($.terser())
// Show file-size after compression
.pipe($.size({ title: 'Javascript Out Size' }))
// Append suffix
.pipe($.rename({
suffix: '.min',
}))
// Save minified file
.pipe(gulp.dest(`${paths.to.js.out}`));
}
});
#babel/preset-env is not the same thing as #babel/preset-es2015 - the former turns plugins on and off based on your targeted browser compatibility metrics (which you can customize).
The docs say that if you don't explicitly specify the targets in the preset's config, the following defaults will be used:
Sidenote, if no targets are specified, #babel/preset-env behaves exactly the same as #babel/preset-es2015, #babel/preset-es2016 and #babel/preset-es2017 together (or the deprecated babel-preset-latest).
#babel/preset-es2015 alone, on the other hand, will only compile features that were added in the ES2015 version of the spec. This does not include newer features, such as async/await! If you want all of the features added since then, you will have to add all of the yearly presets. For this reason, it's recommended that you use the env preset.
If you switch https://babeljs.io to the #babel/preset-env preset (which is a seperate section below the list of yearly presets), you get the same output.
I've been following this tutorial Angular2, Bootstrap, Yeoman, Gulp, tutorial and I get up to the frontend task section, but then something happens when I try to test the code locally.
Whenever I use npm start I run the following code, but end up getting the blank webpage with Cannot GET/
Folder Structure:
> my-vzlr
> -build
> -node_modules
> -src
> --app
> ---app.js
> ---index.html
> ---main.js
> --electron
> --fonts
> --images
> --styles
> -gulpfile.js
> -package.json
Package.json:
> { "name": "my-vzlr", "version": "0.0.0", "private": true,
> "scripts": {
> "start": "gulp clean && gulp frontend && gulp dev",
> "build": "gulp clean && gulp frontend" }, "dependencies": {
> "angular2": "2.0.0-beta.2",
> "traceur": "0.0.102",
> "es6-promise": "^3.0.2",
> "es6-shim": "^0.33.3",
> "rxjs": "5.0.0-beta.0",
> "zone.js": "0.5.10",
> "reflect-metadata": "0.1.2",
> "systemjs": "0.19.6" }, "devDependencies": {
> "del": "^2.2.2",
> "gulp": "3.9.0",
> "gulp-rename": "1.2.2",
> "gulp-symdest": "^1.0.0",
> "gulp-traceur": "0.17.2",
> "gulp-webserver": "0.9.1" } }
Gulpfile.JS
var gulp = require('gulp'),
del = require('del'),
rename = require('gulp-rename'),
traceur = require('gulp-traceur'),
webserver = require('gulp-webserver'),
symdest = require('gulp-symdest');
var config = {
sourceDir: 'src',
buildDir: 'build',
packagesDir: 'packages',
npmDir: 'node_modules'
};
gulp.task('clean', function() {
return del(config.buildDir + '/**/*', { force: true });
});
// run init tasks
//gulp.task('default', ['dependencies', 'js', 'html', 'css']);
// run development task
gulp.task('dev', ['dev:watch', 'dev:serve']);
// serve the build dir
gulp.task('dev:serve', function () {
gulp.src(config.buildDir)
.pipe(webserver({
open: true
}));
});
// watch for changes and run the relevant task
gulp.task('dev:watch', function() {
gulp.watch(config.sourceDir + '/**/*.js', ['frontend:js']);
gulp.watch(config.sourceDir + '/**/*.html', ['frontend:html']);
gulp.watch(config.sourceDir + '/**/*.css', ['frontend:css']);
});
gulp.task('frontend', [
'frontend:dependencies',
'frontend:js',
'frontend:html',
'frontend:css'
]);
// move dependencies into build dir
gulp.task('frontend:dependencies', function() {
return gulp.src([
config.npmDir + '/traceur/bin/traceur-runtime.js',
config.npmDir + '/systemjs/dist/system-csp-production.src.js',
config.npmDir + '/systemjs/dist/system.js',
config.npmDir + '/reflect-metadata/Reflect.js',
config.npmDir + '/angular2/bundles/angular2.js',
config.npmDir + '/angular2/bundles/angular2-polyfills.js',
config.npmDir + '/rxjs/bundles/Rx.js',
config.npmDir + '/angular2/bundles/router.js',
config.npmDir + '/es6-shim/es6-shim.min.js',
config.npmDir + '/es6-shim/es6-shim.map'
])
.pipe(gulp.dest(config.buildDir + '/lib'));
});
// transpile & move js
gulp.task('frontend:js', function() {
return gulp.src( config.sourceDir + '/**/*.js')
.pipe(rename({
extname: ''
}))
.pipe(traceur({
modules: 'instantiate',
moduleName: true,
annotations: true,
types: true,
memberVariables: true
}))
.pipe(rename({
extname: '.js'
}))
.pipe(gulp.dest(config.buildDir));
});
// move html
gulp.task('frontend:html', function() {
return gulp.src(config.sourceDir + '/**/*.html')
.pipe(gulp.dest(config.buildDir))
});
// move css
gulp.task('frontend:css', function() {
return gulp.src(config.sourceDir + '/**/*.css')
.pipe(gulp.dest(config.buildDir))
});
So the short of it is to make sure the app is structured so Gulp can move all the files it needs to