Commit e71f2bfb authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Refactore les fichiers gulp.

Et améliore les logs.
parent 1a4f7a3b
import * as revealJS from "@inrae/reveal.js/gulpfile.esm";
import { dest, lastRun, parallel, series, src, watch } from "gulp";
import del from "del";
import drawio from "./lib/drawio";
import index from "./lib/index";
import pandoc from "./lib/pandoc";
import server from "gulp-server-livereload";
import wkhtmltopdf from "./lib/wkhtmltopdf";
const REVEALJS_URL = process.env.REVEALJS_URL || "reveal.js";
const SRC_DIR = process.env.SRC || "src";
const DEST_DIR = process.env.OUTPUT || "public";
const ASSET_GLOB = [
`${SRC_DIR}/**/*.{png,gif,jpg,svg}`,
__dirname + "/assets/**/*",
];
const PREZ_GLOB = `${SRC_DIR}/**/index.md`;
const GRAPH_GLOB = `${SRC_DIR}/**/*.drawio`;
const PDF_GLOB = `${DEST_DIR}/**/index.html`;
export const clean = () => del(`${DEST_DIR}/**`, { force: true });
export const assets = () =>
src(ASSET_GLOB, { since: lastRun(assets) }).pipe(dest(DEST_DIR));
export const prez = () =>
src(PREZ_GLOB)
.pipe(index())
.pipe(pandoc({ revealJSURL: REVEALJS_URL }))
.pipe(dest(DEST_DIR));
export const graphs = () =>
src(GRAPH_GLOB, { since: lastRun(graphs) })
.pipe(drawio())
.pipe(dest(DEST_DIR));
export const pdf = () => src(PDF_GLOB).pipe(wkhtmltopdf()).pipe(dest(DEST_DIR));
const noop = () => Promise.resolve(false);
export const [build_revealjs, watch_revealjs] = (function (url) {
if (url.startsWith("http")) {
return [noop, noop];
}
const SRC = `${__dirname}/node_modules/@inrae/reveal.js/public/**`;
const DST = DEST_DIR + "/" + url;
const copy_revealjs = () =>
src(SRC, { since: lastRun(copy_revealjs) }).pipe(dest(DST));
const _watch_revealjs = () => watch(SRC, copy_revealjs);
return [
series(revealJS.build, copy_revealjs),
parallel(revealJS.dev, _watch_revealjs),
];
})(REVEALJS_URL);
export const build = series(
clean,
parallel(build_revealjs, assets, prez, graphs),
pdf
);
const serve = () => {
src(DEST_DIR).pipe(
server({
host: process.env.SERVER_HOST || "localhost",
port: process.env.SERVER_PORT || 3000,
livereload: true,
})
);
};
const watch_prez = () => watch([PREZ_GLOB, __dirname + "/templates/**"], prez);
const watch_assets = () => watch(ASSET_GLOB, assets);
const watch_graphs = () => watch(GRAPH_GLOB, graphs);
const watch_pdf = () => watch(`${DEST_DIR}/**/*.{html,svg,jpg,gif,png}`, pdf);
export const dev = series(
build,
parallel(
serve,
watch_prez,
watch_assets,
watch_graphs,
watch_pdf,
watch_revealjs
)
);
export default build;
import { ASSET_GLOB, DEST_DIR, GRAPH_GLOB, PDF_GLOB, PREZ_GLOB, REVEALJS_URL } from "./config";
import { dest, lastRun, parallel, series, src } from "gulp";
import autoindex from "./plugins/autoindex";
import { build_revealjs } from "./revealjs";
import del from "del";
import drawio from "./plugins/drawio";
import pandoc from "./plugins/pandoc";
import spy from "./plugins/spy";
import wkhtmltopdf from "./plugins/wkhtmltopdf";
export const clean = () => del(`${DEST_DIR}/**`, { force: true });
export const assets = () =>
src(ASSET_GLOB, { since: lastRun(assets) }).pipe(dest(DEST_DIR)).pipe(spy());
export const prez = () =>
src(PREZ_GLOB)
.pipe(autoindex())
.pipe(pandoc({ revealJSURL: REVEALJS_URL }))
.pipe(dest(DEST_DIR)).pipe(spy());
export const graphs = () =>
src(GRAPH_GLOB, { since: lastRun(graphs) })
.pipe(drawio())
.pipe(dest(DEST_DIR)).pipe(spy());
export const pdf = () => src(PDF_GLOB).pipe(wkhtmltopdf()).pipe(dest(DEST_DIR)).pipe(spy());
export const build = series(
clean,
parallel(build_revealjs, assets, prez, graphs),
pdf
);
export default build;
import logger from "gulplog";
import { magenta } from "gulp-cli/lib/shared/ansi";
export const SRC_DIR = process.env.SRC || "src";
export const DEST_DIR = process.env.OUTPUT || "public";
logger.info(`Using input directory ${magenta(SRC_DIR)} ($SRC)`);
logger.info(`Using output directory ${magenta(DEST_DIR)} ($OUTPUT)`);
export const REVEALJS_URL = process.env.REVEALJS_URL || "reveal.js";
export const ASSET_GLOB = [
`${SRC_DIR}/**/*.{png,gif,jpg,svg}`,
__dirname + "/../assets/**/*",
];
export const PREZ_GLOB = `${SRC_DIR}/**/index.md`;
export const GRAPH_GLOB = `${SRC_DIR}/**/*.drawio`;
export const PDF_GLOB = `${DEST_DIR}/**/index.html`;
import { ASSET_GLOB, DEST_DIR, GRAPH_GLOB, PREZ_GLOB } from "./config";
import build, { assets, graphs, pdf, prez } from "./build";
import { parallel, series, src, watch } from "gulp";
import server from "gulp-server-livereload";
import { watch_revealjs } from "./revealjs";
const serve = () => {
src(DEST_DIR).pipe(
server({
host: process.env.SERVER_HOST || "localhost",
port: process.env.SERVER_PORT || 3000,
livereload: true,
})
);
};
const watch_prez = () => watch([PREZ_GLOB, __dirname + "/templates/**"], prez);
const watch_assets = () => watch(ASSET_GLOB, assets);
const watch_graphs = () => watch(GRAPH_GLOB, graphs);
const watch_pdf = () => watch(`${DEST_DIR}/**/*.{html,svg,jpg,gif,png}`, pdf);
export const dev = series(
build,
parallel(
serve,
watch_prez,
watch_assets,
watch_graphs,
watch_pdf,
watch_revealjs
)
);
export default dev;
export * from './build';
export * from './dev';
import build from './build';
export default build;
......@@ -5,7 +5,7 @@ import logger from "gulplog";
import { obj } from "through2";
import PluginError from "plugin-error";
const PLUGIN_NAME = "index";
const PLUGIN_NAME = "autoindex";
/**
* @param {ReadableStream} stream
......@@ -104,7 +104,7 @@ ${inputs
.join("\n")}`;
}
export default function index() {
export default function autoindex() {
const inputs = [];
return obj(
callbackify(async function (input) {
......
import { callbackify } from "util";
import exec from "./exec";
import exec from "../util/exec";
import fs from "fs";
import logger from "gulplog";
import { mkTempFile } from "./tempdir";
import { mkTempFile } from "../util/tempdir";
import { obj } from "through2";
import PluginError from "plugin-error";
import { withBinary } from "./optional";
import { withBinary } from "../util/optional";
const PLUGIN_NAME = "drawio";
......
import { callbackify, promisify } from "util";
import exec from "./exec";
import exec from "../util/exec";
import fs from "fs";
import logger from "gulplog";
import { merge } from "merge-anything";
import { mkTempFile } from "./tempdir";
import { mkTempFile } from "../util/tempdir";
import { obj } from "through2";
import path from "path";
import PluginError from "plugin-error";
......@@ -17,7 +16,7 @@ const DEFAULTS = {
slideLevel: 2,
tocDepth: 2,
revealJSURL: "reveal.js",
template: path.normalize(__dirname + "/../templates/revealjs.html"),
template: path.normalize(__dirname + "/../../templates/revealjs.html"),
variables: {
width: 1024,
height: 768,
......@@ -121,13 +120,6 @@ export default function pandoc(options = {}) {
});
output.contents = stdout;
logger.info(
"%s: %s -> %s",
PLUGIN_NAME,
input.relative,
output.relative
);
this.push(output);
}
)
......
import logger from "gulplog";
import { obj } from "through2";
import { relative } from "path";
export default function spy(limit = 5) {
let count = 0;
return obj(function(file, _enc, next) {
count++;
this.push(file);
next();
if (count > limit) {
return;
}
const input = file.history[0];
const output = file.path;
logger.info("%s -> %s", relative(file.cwd, input), relative(file.cwd, output));
}, (next) => {
next();
if (count > limit) {
logger.info("... and %d more files", count - 5);
}
});
}
import { callbackify } from "util";
import { createReadStream } from "fs";
import exec from "./exec";
import logger from "gulplog";
import { mkTempFile } from "./tempdir";
import exec from "../util/exec";
import { mkTempFile } from "../util/tempdir";
import { obj } from "through2";
import path from "path";
import PluginError from "plugin-error";
import { withBinary } from "./optional";
import { withBinary } from "../util/optional";
const PLUGIN_NAME = "wkhtmltopdf";
......@@ -58,12 +57,6 @@ export const wkhtmltopdf = withBinary(
];
await exec(PLUGIN_NAME, WKHTMLTOPDF_BINARY, execArgs);
logger.info(
"%s: %s -> %s",
PLUGIN_NAME,
input.relative,
output.relative
);
output.contents = createReadStream(output.path);
this.push(output);
......
import * as revealJS from "@inrae/reveal.js/gulpfile.esm";
import { dest, lastRun, parallel, series, src, watch } from "gulp";
import { DEST_DIR, REVEALJS_URL } from "./config";
import logger from "gulplog";
import { magenta } from "gulp-cli/lib/shared/ansi";
import path from "path";
import spy from "./plugins/spy";
const noop = () => Promise.resolve(false);
export const [build_revealjs, watch_revealjs] = (function (url) {
if (url.startsWith("http")) {
logger.info(`Using remote reveal.js at ${magenta(REVEALJS_URL)} ($REVEALJS_URL)`);
return [noop, noop];
}
const _SRC_DIR = path.normalize(`${__dirname}/../node_modules/@inrae/reveal.js/public`);
const SRC = `${_SRC_DIR}/**`;
const DST = path.normalize(DEST_DIR + "/" + url);
const copy_revealjs = () =>
src(SRC, { since: lastRun(copy_revealjs) }).pipe(dest(DST)).pipe(spy());
const _watch_revealjs = () => watch(SRC, copy_revealjs);
logger.info(`Building local ${DEST_DIR}/${magenta(path.relative(DEST_DIR, DST))} from ${path.relative(__dirname + '/..', _SRC_DIR + '/..')} ($REVEALJS_URL)`);
return [
series(revealJS.build, copy_revealjs),
parallel(revealJS.dev, _watch_revealjs),
];
})(REVEALJS_URL);
import * as colors from "gulp-cli/lib/shared/ansi";
import { execFile } from "child_process";
import logger from "gulplog";
......@@ -16,7 +17,7 @@ export default function exec(plugin_name, cmd, args, opts = {}) {
logger.debug("%s: %s terminated successfully", plugin_name, cmd);
return resolve({ stdout, stderr });
}
logger.error("%s: %s failed: %s", plugin_name, cmd, error.message);
logger.error("%s: %s failed: %s", plugin_name, cmd, colors.red(error.message));
logger.error("%s: command: `%s %s`", plugin_name, cmd, args.join(" "));
logger.error("%s: stdout:\n%s", plugin_name, stdout.toString());
logger.error("%s: stderr:\n%s", plugin_name, stderr.toString());
......
import logger from "gulplog";
import { magenta } from "gulp-cli/lib/shared/ansi";
import { obj } from "through2";
import which from "which";
......@@ -16,13 +17,13 @@ export function withBinary(envName, execName, resolve) {
const setting = process.env[envName] || execName;
const binary = which.sync(setting, { nothrow: true });
if (!binary) {
logger.info("%s not found (configure with %s)", execName, envName);
logger.info("Not using %s: binary not found ($%s)", execName, envName);
return noop;
}
logger.info(
"Using `%s` for %s (configure with %s)",
binary,
"Using %s %s ($%s)",
execName,
magenta(binary),
envName
);
return resolve(binary);
......
......@@ -5018,6 +5018,31 @@
}
}
},
"gulp-cli": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/gulp-cli/-/gulp-cli-2.2.0.tgz",
"integrity": "sha512-rGs3bVYHdyJpLqR0TUBnlcZ1O5O++Zs4bA0ajm+zr3WFCfiSLjGwoCBqFs18wzN+ZxahT9DkOK5nDf26iDsWjA==",
"requires": {
"ansi-colors": "^1.0.1",
"archy": "^1.0.0",
"array-sort": "^1.0.0",
"color-support": "^1.1.3",
"concat-stream": "^1.6.0",
"copy-props": "^2.0.1",
"fancy-log": "^1.3.2",
"gulplog": "^1.0.0",
"interpret": "^1.1.0",
"isobject": "^3.0.1",
"liftoff": "^3.1.0",
"matchdep": "^2.0.0",
"mute-stdout": "^1.0.0",
"pretty-hrtime": "^1.0.0",
"replace-homedir": "^1.0.0",
"semver-greatest-satisfied-range": "^1.1.0",
"v8flags": "^3.0.1",
"yargs": "^7.1.0"
}
},
"gulp-csso": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/gulp-csso/-/gulp-csso-4.0.1.tgz",
......
......@@ -2,17 +2,18 @@
"name": "@inrae/prezbuilder",
"version": "1.0.0",
"description": "Build INRAE-themed reveal.js presentations.",
"scripts": {
"build": "gulp build",
"dev": "gulp dev",
"lint": "eslint --color . && prettier --check . && depcheck ."
},
"keywords": [
"reveal.js",
"inrae"
],
"author": "Guillaume Perréal <guillaume.perreal@inrae.fr>",
"license": "MIT",
"scripts": {
"build": "gulp build",
"dev": "gulp dev",
"lint": "eslint --color . && prettier --check . && depcheck ."
},
"bin": "bin/prezbuilder",
"repository": {
"type": "git",
"url": "gitlab-ssh.irstea.fr:pole-is/tools/prezbuilder.js"
......@@ -26,6 +27,7 @@
"del": "^5.1.0",
"esm": "^3.2.25",
"gulp": "^4.0.2",
"gulp-cli": "^2.2.0",
"gulp-server-livereload": "^1.9.2",
"gulplog": "^1.0.0",
"merge-anything": "^3.0.3",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment