2016-11-22 00:52:41 +02:00
|
|
|
import gulp from "gulp";
|
|
|
|
import cp from "child_process";
|
|
|
|
import gutil from "gulp-util";
|
|
|
|
import postcss from "gulp-postcss";
|
|
|
|
import cssImport from "postcss-import";
|
|
|
|
import cssnext from "postcss-cssnext";
|
|
|
|
import BrowserSync from "browser-sync";
|
|
|
|
import webpack from "webpack";
|
|
|
|
import webpackConfig from "./webpack.conf";
|
2017-09-12 03:10:31 +03:00
|
|
|
import inquirer from "inquirer";
|
|
|
|
import toml from "tomljs";
|
|
|
|
import fs from "fs";
|
|
|
|
import path from "path";
|
|
|
|
import kebabCase from "lodash.kebabcase";
|
|
|
|
import tomlify from "tomlify-j0.4";
|
2016-11-22 00:52:41 +02:00
|
|
|
|
|
|
|
const browserSync = BrowserSync.create();
|
2017-09-13 02:06:47 +03:00
|
|
|
const platform = getPlatform(process.platform);
|
|
|
|
const hugoBin = `./bin/hugo_0.26_${platform}_amd64${platform === "windows" ? ".exe" : ""}`;
|
2017-09-12 03:10:31 +03:00
|
|
|
const defaultArgs = ["-s", "site", "-v"];
|
|
|
|
const buildArgs = ["-d", "../dist"];
|
2016-11-22 00:52:41 +02:00
|
|
|
|
|
|
|
gulp.task("hugo", (cb) => buildSite(cb));
|
|
|
|
gulp.task("hugo-preview", (cb) => buildSite(cb, ["--buildDrafts", "--buildFuture"]));
|
|
|
|
|
|
|
|
gulp.task("build", ["css", "js", "hugo"]);
|
|
|
|
gulp.task("build-preview", ["css", "js", "hugo-preview"]);
|
|
|
|
|
|
|
|
gulp.task("css", () => (
|
|
|
|
gulp.src("./src/css/*.css")
|
|
|
|
.pipe(postcss([cssnext(), cssImport({from: "./src/css/main.css"})]))
|
|
|
|
.pipe(gulp.dest("./dist/css"))
|
|
|
|
.pipe(browserSync.stream())
|
|
|
|
));
|
|
|
|
|
|
|
|
gulp.task("js", (cb) => {
|
|
|
|
const myConfig = Object.assign({}, webpackConfig);
|
|
|
|
|
|
|
|
webpack(myConfig, (err, stats) => {
|
|
|
|
if (err) throw new gutil.PluginError("webpack", err);
|
|
|
|
gutil.log("[webpack]", stats.toString({
|
|
|
|
colors: true,
|
|
|
|
progress: true
|
|
|
|
}));
|
|
|
|
browserSync.reload();
|
|
|
|
cb();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task("server", ["hugo", "css", "js"], () => {
|
|
|
|
browserSync.init({
|
|
|
|
server: {
|
|
|
|
baseDir: "./dist"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
gulp.watch("./src/js/**/*.js", ["js"]);
|
|
|
|
gulp.watch("./src/css/**/*.css", ["css"]);
|
|
|
|
gulp.watch("./site/**/*", ["hugo"]);
|
|
|
|
});
|
|
|
|
|
2017-09-12 03:10:31 +03:00
|
|
|
gulp.task("new-incident", (cb) => {
|
|
|
|
const file = fs.readFileSync("site/config.toml").toString();
|
|
|
|
const config = toml(file);
|
|
|
|
|
|
|
|
const questions = [{
|
|
|
|
type: "input",
|
|
|
|
name: "name",
|
|
|
|
message: "What is the cause of the incident?",
|
|
|
|
validate: (value) => {
|
|
|
|
if (value.length > 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "You must have a cause title!";
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
type: "list",
|
|
|
|
name: "severity",
|
|
|
|
message: "What is the severity of the incident?",
|
|
|
|
choices: ["under-maintenance", "degraded-performance", "partial-outage", "major-outage"]
|
|
|
|
}, {
|
|
|
|
type: "checkbox",
|
|
|
|
name: "affected",
|
|
|
|
message: "What are the affected systems?",
|
|
|
|
choices: config.params.systems,
|
|
|
|
validate: (value) => {
|
|
|
|
if (value.length > 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "You must have an affected system?!";
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
type: "input",
|
|
|
|
name: "description",
|
|
|
|
message: "Add a terse description of the incident"
|
|
|
|
}, {
|
|
|
|
type: "confirm",
|
|
|
|
name: "open",
|
|
|
|
message: "Open the incident for editing?",
|
|
|
|
default: false
|
|
|
|
}];
|
|
|
|
|
|
|
|
inquirer.prompt(questions).then((answers) => {
|
|
|
|
let args = ["new", `incidents${path.sep}${kebabCase(answers.name)}.md`];
|
|
|
|
args = args.concat(defaultArgs);
|
|
|
|
|
|
|
|
const hugo = cp.spawn(hugoBin, args, {stdio: "pipe"});
|
|
|
|
hugo.stdout.on("data", (data) => {
|
|
|
|
const message = data.toString();
|
|
|
|
|
|
|
|
if (message.indexOf(" created") === -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const path = message.split(" ")[0];
|
|
|
|
|
|
|
|
const incident = fs.readFileSync(path).toString();
|
|
|
|
const frontMatter = toml(incident);
|
|
|
|
|
|
|
|
frontMatter.severity = answers.severity;
|
|
|
|
frontMatter.affectedsystems = answers.affected;
|
|
|
|
frontMatter.title = answers.name.replace(/-/g, " ");
|
|
|
|
|
|
|
|
const content = generateFrontMatter(frontMatter, answers);
|
|
|
|
|
|
|
|
fs.writeFileSync(path, content);
|
|
|
|
|
|
|
|
if (!answers.open) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let cmd = "xdg-open";
|
2017-09-13 02:06:47 +03:00
|
|
|
switch (platform) {
|
2017-09-12 03:10:31 +03:00
|
|
|
case "darwin": {
|
|
|
|
cmd = "open";
|
|
|
|
break;
|
|
|
|
}
|
2017-09-13 02:06:47 +03:00
|
|
|
case "windows": {
|
2017-09-12 03:10:31 +03:00
|
|
|
cmd = "start";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
cmd = "xdg-open";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cp.exec(`${cmd} ${path}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
hugo.on("close", (code) => {
|
|
|
|
if (code === 0) {
|
|
|
|
cb();
|
|
|
|
} else {
|
|
|
|
cb("new incident creation failed");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-09-13 02:06:47 +03:00
|
|
|
function getPlatform(platform) {
|
2018-01-14 22:51:20 +02:00
|
|
|
switch (platform) {
|
|
|
|
case "win32":
|
|
|
|
case "win64": {
|
|
|
|
return "windows";
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
return platform;
|
2017-09-13 02:06:47 +03:00
|
|
|
}
|
2018-01-14 22:51:20 +02:00
|
|
|
}
|
2017-09-13 02:06:47 +03:00
|
|
|
}
|
|
|
|
|
2017-09-12 03:10:31 +03:00
|
|
|
function generateFrontMatter(frontMatter, answers) {
|
|
|
|
return `+++
|
|
|
|
${tomlify(frontMatter, null, 2)}
|
|
|
|
+++
|
|
|
|
${answers.description}`;
|
|
|
|
}
|
|
|
|
|
2016-11-22 00:52:41 +02:00
|
|
|
function buildSite(cb, options) {
|
2017-09-12 03:10:31 +03:00
|
|
|
let args = options ? defaultArgs.concat(options) : defaultArgs;
|
|
|
|
args = args.concat(buildArgs);
|
2016-11-22 00:52:41 +02:00
|
|
|
|
2017-09-12 03:10:31 +03:00
|
|
|
// cp needs to be in site directory
|
2016-11-22 00:52:41 +02:00
|
|
|
return cp.spawn(hugoBin, args, {stdio: "inherit"}).on("close", (code) => {
|
|
|
|
if (code === 0) {
|
|
|
|
browserSync.reload();
|
|
|
|
cb();
|
|
|
|
} else {
|
|
|
|
browserSync.notify("Hugo build failed :(");
|
|
|
|
cb("Hugo build failed");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|