Skip to content

Commit

Permalink
switch to gulp for devops
Browse files Browse the repository at this point in the history
  • Loading branch information
apowers313 committed Oct 10, 2020
1 parent 130a7f7 commit f7a24ea
Show file tree
Hide file tree
Showing 5 changed files with 6,559 additions and 263 deletions.
6 changes: 4 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ module.exports = {
"wrap-iife": ["error", "inside"],
"consistent-return": "error",
"no-template-curly-in-string": "error",
"no-promise-executor-return": "error",
// TODO: gulp-eslint is running outdated eslint
// "no-promise-executor-return": "error",
"eqeqeq": "error",
"dot-notation": "error",
"dot-location": ["error", "property"],
Expand Down Expand Up @@ -77,7 +78,8 @@ module.exports = {
"nonblock-statement-body-position": ["error", "beside"],
"no-mixed-operators": ["error", {allowSamePrecedence: true}],
"default-case": "error",
"default-case-last": "error",
// TODO: gulp-eslint is running outdated eslint
// "default-case-last": "error",
"default-param-last": "error",
"no-multiple-empty-lines": ["error", {max: 1, maxBOF: 0, maxEOF: 1}],
"padding-line-between-statements": ["error", {blankLine: "always", prev: "*", next: "class"}, {blankLine: "always", prev: "class", next: "*"}],
Expand Down
107 changes: 107 additions & 0 deletions bs-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
|--------------------------------------------------------------------------
| Browser-sync config file
|--------------------------------------------------------------------------
|
| For up-to-date information about the options:
| http://www.browsersync.io/docs/options/
|
| There are more options than you see here, these are just the ones that are
| set internally. See the website for more info.
|
|
*/
module.exports = {
ui: {
port: 3001,
},
files: false,
watchEvents: [
"change",
],
watch: false,
ignore: [],
single: false,
watchOptions: {
ignoreInitial: true,
},
server: false,
proxy: false,
port: 3000,
middleware: false,
serveStatic: [],
ghostMode: {
clicks: true,
scroll: true,
location: true,
forms: {
submit: true,
inputs: true,
toggles: true,
},
},
logLevel: "info",
logPrefix: "Browsersync",
logConnections: false,
logFileChanges: true,
logSnippet: true,
rewriteRules: [],
open: "local",
browser: "default",
cors: false,
xip: false,
hostnameSuffix: false,
reloadOnRestart: false,
notify: true,
scrollProportionally: true,
scrollThrottle: 0,
scrollRestoreTechnique: "window.name",
scrollElements: [],
scrollElementMapping: [],
reloadDelay: 0,
reloadDebounce: 500,
reloadThrottle: 0,
plugins: [],
injectChanges: true,
startPath: null,
minify: true,
host: null,
localOnly: false,
codeSync: true,
timestamps: true,
clientEvents: [
"scroll",
"scroll:element",
"input:text",
"input:toggles",
"form:submit",
"form:reset",
"click",
],
socket: {
socketIoOptions: {
log: false,
},
socketIoClientConfig: {
reconnectionAttempts: 50,
},
path: "/browser-sync/socket.io",
clientPath: "/browser-sync",
namespace: "/browser-sync",
clients: {
heartbeatTimeout: 5000,
},
},
tagNames: {
less: "link",
scss: "link",
css: "link",
jpg: "img",
jpeg: "img",
png: "img",
svg: "img",
gif: "img",
js: "script",
},
injectNotification: false,
};
134 changes: 134 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/* eslint-disable jsdoc/require-jsdoc */

const {watch, src, dest, series, parallel} = require("gulp");
const mocha = require("gulp-mocha");
const eslint = require("gulp-eslint");
const jsdoc = require("gulp-jsdoc3");
// const istanbul = require("gulp-istanbul"); // gulp-istanbul is broken; hasn't been updated in 3 years
// const exec = require("gulp-exec");
let {exec, spawn} = require("child_process");
const browserSync = require("browser-sync").create();

const sources = ["src/*.js", "lib/*.js"];
const tests = ["test/*.js"];
const support = ["gulpfile.js", "package.json", ".eslintrc.js", "docs.json"];
const js = [... sources, ... tests];
const css = ["./jsdoc.css"];
const markdown = ["**/*.md"];
const documentation = [... sources, ... markdown, ... css];
const all = [... sources, ... tests, ... support];
const jsDocConfig = require("./.jsdoc-conf.json");

/* ************
* TESTING
**************/
function test(testReporter = "spec") {
return src(tests)
.pipe(mocha({reporter: testReporter}))
.on("error", function(err) {
console.log(err.stack);
});
}

function watchTest() {
return watch(all, test.bind(null, "min"));
}

/* ************
* LINT
**************/
function lint() {
return src(js)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
}

function watchLint() {
return watch(all, function() {
return src(js)
.pipe(eslint())
.pipe(eslint.format());
});
}

/* ************
* COVERAGE
**************/
function runIstanbul(done) {
let cmd = "nyc";
let args = [
"--reporter=text",
"--reporter=html",
"mocha",
];
let opts = {
stdio: "inherit",
};
spawn(cmd, args, opts);
done();
}

const coverage = runIstanbul;

function coverageRefresh() {
return watch(js, runIstanbul);
}

function coverageBrowserSync() {
browserSync.init({
server: {
baseDir: "./coverage",
},
});

watch("coverage/*").on("change", browserSync.reload);
watch("coverage/*").on("add", browserSync.reload);
}

const watchCoverage = parallel(coverageBrowserSync, coverageRefresh);

/* ************
* DOCS
**************/
function docsBuild() {
return src(documentation, {read: false})
.pipe(jsdoc(jsDocConfig));
}

const docs = series(docsBuild, copyCss);

function copyCss() {
return src("jsdoc.css")
.pipe(dest("./docs"));
}

function docsBrowserSync() {
browserSync.init({
server: {
baseDir: "./docs",
},
});

watch("docs/*").on("change", browserSync.reload);
watch("docs/*").on("add", browserSync.reload);
}

function docsRefresh() {
watch(css, copyCss);
watch(documentation, docsBuild);
}

const watchDocs = parallel(docsBrowserSync, docsRefresh);

module.exports = {
test,
lint,
coverage,
docs,
"default": watchTest,
"dev:test": watchTest,
"dev:lint": watchLint,
"dev:coverage": watchCoverage,
"dev:docs": watchDocs,
};
Loading

0 comments on commit f7a24ea

Please sign in to comment.