Resume/gulpfile.js

61 lines
1.5 KiB
JavaScript
Raw Normal View History

2023-07-25 16:16:36 -04:00
const { src, dest, watch, series, pipe } = require("gulp");
2023-05-11 16:05:53 -04:00
const bs = require("browser-sync").create();
const fs = require("fs");
const path = require("path");
const resumePath = path.join(__dirname, "resume.json");
2023-07-25 16:16:36 -04:00
const templateFile = path.join(__dirname, "theme/template.ejs");
//const sass = require("gulp-sass")(require("sass"));
const sass = require("sass");
const ejs = require('ejs');
2023-05-11 16:05:53 -04:00
2023-07-25 16:16:36 -04:00
function setup(cb) {
let dir = path.join(__dirname, "dev");
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
cb();
2023-03-27 14:58:00 -04:00
}
2023-05-11 16:05:53 -04:00
function css(cb) {
2023-07-25 16:16:36 -04:00
// src("./theme/**/*.scss")
// .pipe(sass().on("error", sass.logError))
// .pipe(dest("./dev"));
2023-05-11 16:05:53 -04:00
2023-07-25 16:16:36 -04:00
cb();
2023-05-11 16:05:53 -04:00
}
function html(cb) {
const resume = JSON.parse(fs.readFileSync("./resume.json", "utf-8"));
2023-07-25 16:16:36 -04:00
let css = sass.compile("./theme/style.scss");
let devBKG = sass.compile("./theme/devbkg.scss");
css.tagOpen = "<style>"
css.tagClose = "</style>"
css.devBKG = devBKG.css;
2023-05-11 16:05:53 -04:00
2023-07-25 16:16:36 -04:00
fs.writeFileSync(
path.join(__dirname, "dev/template.html"),
ejs.render(fs.readFileSync(templateFile, {encoding: "utf-8"}), {resume: resume, css: css})
);
2023-03-27 14:58:00 -04:00
2023-05-11 16:05:53 -04:00
cb();
2023-03-27 14:58:00 -04:00
}
2023-05-11 16:05:53 -04:00
function serve() {
2023-03-27 14:58:00 -04:00
bs.init({
server: {
2023-05-11 16:05:53 -04:00
baseDir: "./dev",
index: "template.html",
2023-03-27 14:58:00 -04:00
},
ui: false,
2023-05-11 16:05:53 -04:00
open: false,
});
2023-03-27 14:58:00 -04:00
2023-07-25 16:16:36 -04:00
watch(["./theme/**/*.ejs", "./resume.json"], html);
watch(["./theme/**/*.scss"], css);
2023-05-11 16:05:53 -04:00
bs.watch("./dev/*.html").on("change", bs.reload);
2023-07-25 16:16:36 -04:00
bs.watch("./dev/*.css").on("change", bs.reload);
2023-03-27 14:58:00 -04:00
}
2023-05-11 16:05:53 -04:00
exports.default = series(setup, css, html, serve);