Skip to content

Commit

Permalink
chore(build): sync with ssv-core - several changes/refactoring to b…
Browse files Browse the repository at this point in the history
…uild

- added reporters/browsers as args
- fixed an issue with karma taking long in executing tests (appveyor)
  • Loading branch information
stephenlautier committed Jun 9, 2016
1 parent 9e1c216 commit 0c84b3c
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 44 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test_script:
- npm --version
# run tests
- gulp lint
- gulp test
- gulp test --reporters mocha,appveyor

# Don't actually build.
build: off
Expand Down
10 changes: 8 additions & 2 deletions build/args.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var yargs = require("yargs");
const yargs = require("yargs");

const config = require("./config");

var argv = yargs
.alias("rel", "release")
Expand All @@ -8,11 +10,15 @@ var argv = yargs
.default("bump", "patch")

.default("versionSuffix", "rc")
.default("reporters", config.test.reporters)
.default("browsers", config.test.browsers)

.argv;

module.exports = {
bump: argv.bump,
versionSuffix: argv.versionSuffix,
isRelease: argv.rel
isRelease: argv.rel,
reporters: argv.reporters,
browsers: [].concat(argv.browsers)
};
6 changes: 5 additions & 1 deletion build/paths.js → build/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require("path");
const fs = require("fs");

const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8'));
const pkg = JSON.parse(fs.readFileSync("./package.json", "utf-8"));
const srcRoot = "src";
const typings = "typings/index.d.ts";

Expand All @@ -17,6 +17,10 @@ module.exports = {
testTs: `./${srcRoot}/**/*.spec.ts`,
karmaConfig: `karma.conf.js`
},
test: {
reporters: ["mocha"],
browsers: ["Chrome"]
},
doc: "./doc",
packageName: pkg.name
};
5 changes: 3 additions & 2 deletions build/main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const gulp = require("gulp");
const paths = require("./paths");

const config = require("./config");

require("require-dir")("./tasks");

gulp.task("default", () => {

console.log(`======== ${paths.packageName} ========`);
console.log(`======== ${config.packageName} ========`);

});
12 changes: 6 additions & 6 deletions build/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const plumber = require("gulp-plumber");
const merge = require("merge2");

const args = require("../args");
const paths = require("../paths");
const config = require("../config");

gulp.task("build", (cb) => {
if (args.isRelease) {
Expand Down Expand Up @@ -44,7 +44,7 @@ gulp.task("ci", (cb) => {
// scripts
gulp.task("compile:ts", () => {
const tsProject = getTscProject();
const tsResult = gulp.src([...paths.src.typings, paths.src.ts, `!${paths.src.testTs}`])
const tsResult = gulp.src([...config.src.typings, config.src.ts, `!${config.src.testTs}`])
.pipe(plumber())
//.pipe(changed(paths.output.dist, { extension: ".js" }))
.pipe(sourcemaps.init())
Expand All @@ -53,15 +53,15 @@ gulp.task("compile:ts", () => {
return merge([
tsResult.js
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(`${paths.output.artifact}/amd`)),
.pipe(gulp.dest(`${config.output.artifact}/amd`)),
tsResult.dts
.pipe(gulp.dest(`${paths.output.artifact}/typings`))
.pipe(gulp.dest(`${config.output.artifact}/typings`))
]);
});

gulp.task("copy-dist", () => {
return gulp.src(`${paths.output.artifact}/**/*`)
.pipe(gulp.dest(`${paths.output.dist}`));
return gulp.src(`${config.output.artifact}/**/*`)
.pipe(gulp.dest(`${config.output.dist}`));
});

function getTscProject() {
Expand Down
6 changes: 3 additions & 3 deletions build/tasks/clean.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const gulp = require("gulp");
const del = require("del");

const paths = require("../paths");
const config = require("../config");

gulp.task("clean", ["clean:artifact", "clean:dist"]);

gulp.task("clean:artifact", () => {
return del(paths.output.artifact);
return del(config.output.artifact);
});

gulp.task("clean:dist", () => {
return del(paths.output.dist);
return del(config.output.dist);
});
6 changes: 3 additions & 3 deletions build/tasks/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ const util = require("gulp-util");
const runSeq = require("run-sequence");

const args = require("../args");
const paths = require("../paths");
const config = require("../config");

gulp.task("watch", () => {
if (args.isRelease) {
// ts
gulp.watch(paths.src.ts, () => {
gulp.watch([config.src.ts, `!${config.src.testTs}`], () => {
return runSeq(
"compile:ts",
"copy-dist"
Expand All @@ -17,7 +17,7 @@ gulp.task("watch", () => {
.on("error", swallowError);
} else {
// ts
gulp.watch(paths.src.ts, ["compile:ts"])
gulp.watch([config.src.ts, `!${config.src.testTs}`], ["compile:ts"])
.on("change", reportChange)
.on("error", swallowError);
}
Expand Down
4 changes: 2 additions & 2 deletions build/tasks/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const gulp = require("gulp");
const tslint = require("gulp-tslint");
const stylish = require("gulp-tslint-stylish");

const paths = require("../paths");
const config = require("../config");

gulp.task("lint", () => {
gulp.src(paths.src.ts)
gulp.src(config.src.ts)
.pipe(tslint())
.pipe(tslint.report(stylish, {
emitError: true,
Expand Down
20 changes: 10 additions & 10 deletions build/tasks/prepare-release.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var gulp = require("gulp");
var runSequence = require("run-sequence");
var conventionalChangelog = require("gulp-conventional-changelog");
var bump = require("gulp-bump");
var git = require("gulp-git");
var fs = require("fs");
const gulp = require("gulp");
const runSequence = require("run-sequence");
const conventionalChangelog = require("gulp-conventional-changelog");
const bump = require("gulp-bump");
const git = require("gulp-git");
const fs = require("fs");

var args = require("../args");
var paths = require("../paths");
const args = require("../args");
const config = require("../config");

var publishBranch;
gulp.task("prepare-release", (cb) => {
Expand Down Expand Up @@ -45,14 +45,14 @@ gulp.task("bump-version", () => {
});

gulp.task("changelog", () => {
return gulp.src(`${paths.doc}/CHANGELOG.md`, {
return gulp.src(`${config.doc}/CHANGELOG.md`, {
buffer: false
})
.pipe(conventionalChangelog({
preset: "angular",
releaseCount: 0
}))
.pipe(gulp.dest(`${paths.doc}`));
.pipe(gulp.dest(`${config.doc}`));
});

gulp.task("commit-changes", () => {
Expand Down
18 changes: 11 additions & 7 deletions build/tasks/test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
var config = require("../paths");
var gulp = require("gulp");
var gutil = require("gulp-util");
var Karma = require("karma").Server;
var path = require("path");
const gulp = require("gulp");
const gutil = require("gulp-util");
const Karma = require("karma").Server;
const path = require("path");

const config = require("../config");
var args = require("../args");

gulp.task("test", (cb) => {
runTests(true, cb);
Expand All @@ -13,11 +15,13 @@ gulp.task("tdd", (cb) => {
});

function runTests(singleRun, cb) {

gutil.log(gutil.colors.cyan(`Launching Karma... Reporters '${args.reporters}' ; Browsers '${args.browsers}'`));
new Karma({
configFile: path.join(__dirname, `../../${config.src.karmaConfig}`),
singleRun: singleRun,
autoWatch: !singleRun
autoWatch: !singleRun,
reporters: args.reporters,
browsers: args.browsers
}, (code) => {

// make sure failed karma tests cause gulp to exit non-zero
Expand Down
12 changes: 7 additions & 5 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const conf = require("./build/config");

module.exports = function (config) {
config.set({
basePath: "./",
Expand Down Expand Up @@ -33,7 +35,7 @@ module.exports = function (config) {
transpiler: "typescript"
},
serveFiles: [
"src/**/*.ts",
conf.src.ts,
"node_modules/**/*.js"
]
},
Expand All @@ -47,18 +49,18 @@ module.exports = function (config) {
"node_modules/zone.js/dist/jasmine-patch.js",
"node_modules/zone.js/dist/async-test.js",
"node_modules/zone.js/dist/fake-async-test.js",
"src/**/*.spec.ts",

conf.src.testTs,
"src/*.spec.ts"
],
exclude: [],
preprocessors: {},
reporters: ["mocha", "appveyor"],
reporters: ["mocha"], // note: gulp using config from config.js instead
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ["Chrome"],
browsers: ["Chrome"], // note: gulp using config from config.js instead
singleRun: false
});
};
8 changes: 6 additions & 2 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@
"double"
],
"radix": true,
"semicolon": [true, "always"],
"semicolon": [
true,
"always"
],
"triple-equals": [
true,
"allow-null-check"
Expand All @@ -92,7 +95,8 @@
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-module",
"check-seperator",
"check-type"
]
}
Expand Down

0 comments on commit 0c84b3c

Please sign in to comment.