Unverified Commit 40d76295 authored by Ken Hawkins's avatar Ken Hawkins Committed by GitHub
Browse files

fix: eleventy-command-process (#1257)

* fix: eleventy-command-process

with beta.1 eleventy has some changes in how its build process works, we'll need to update vf-extensions
parent ecfa0698
Pipeline #216119 failed with stages
in 7 minutes and 58 seconds
......@@ -24,7 +24,7 @@
],
"private": false,
"dependencies": {
"@11ty/eleventy": "0.12.1",
"@11ty/eleventy": "1.0.0-beta.8",
"@visual-framework/vf-config": "1.0.1-alpha.0",
"@visual-framework/vf-core": "^2.2.33",
"@visual-framework/vf-extensions": "^1.0.1",
......
#!/usr/bin/env node
// Forked from eleventy v0.9.0
// Forked from eleventy v1.0.0-beta.2
// This is a subtle fork for the main Eleventy cmd.js to behave as a module, returning `elev` so it can be npm-required
// It allows things like the below in gulp or paren node js; for more see https://github.com/khawkins98/gulp-eleventy-example
//
// let elevExtensions = require.resolve('@visual-framework/vf-extensions/');
// let elev = require(path.resolve(elevExtensions,'../11ty/eleventy-cmd.js'));
// elev.write().then( function() {
// console.log('Done building 11ty');
// yourCallBack();
// });
// The main difference is that we comment out `elev.write()` for build time, allowing this to be run by a parent process.
// Eleventy is build assuming it will be run from the command line, and we wish to use it as part of our gulp process.
const chalk = require("chalk"); // node 4+
// const chalk = require("chalk"); // node 8+
const debug = require("debug")("Eleventy:cmd");
if (process.env.DEBUG) {
require("time-require");
}
const EleventyErrorHandler = require("@11ty/eleventy/src/EleventyErrorHandler");
const argv = require("minimist")(process.argv.slice(2));
const Eleventy = require("@11ty/eleventy");
const EleventyCommandCheck = require("@11ty/eleventy/src/EleventyCommandCheck");
let elev = new Eleventy(argv.input, argv.output);
let elev;
try {
let errorHandler = new EleventyErrorHandler();
const EleventyCommandCheckError = require("@11ty/eleventy/src/EleventyCommandCheckError");
const argv = require("minimist")(process.argv.slice(2), {
string: [
"input",
"output",
"formats",
"config",
"pathprefix",
"port",
"to",
],
boolean: [
"quiet",
"version",
"watch",
"dryrun",
"help",
"serve",
"passthroughall",
"incremental",
],
default: {
quiet: null,
},
unknown: function (unknownArgument) {
// throw new EleventyCommandCheckError(
// `We don’t know what '${unknownArgument}' is. Use --help to see the list of supported commands.`
// );
},
});
// TODO fix debug output: `Eleventy:cmd command: eleventy [object Object] +0ms`
debug("command: eleventy ", argv.toString());
const Eleventy = require("@11ty/eleventy/src/Eleventy");
process.on("unhandledRejection", (error, promise) => {
EleventyErrorHandler.error(promise, "Unhandled rejection in promise");
errorHandler.fatal(error, "Unhandled rejection in promise");
});
process.on("uncaughtException", e => {
EleventyErrorHandler.fatal(e, "Uncaught exception");
process.on("uncaughtException", (error) => {
errorHandler.fatal(error, "Uncaught exception");
});
process.on("rejectionHandled", promise => {
EleventyErrorHandler.warn(
process.on("rejectionHandled", (promise) => {
errorHandler.warn(
promise,
"A promise rejection was handled asynchronously"
);
});
let cmdCheck = new EleventyCommandCheck(argv);
cmdCheck.hasUnknownArguments();
elev = new Eleventy(argv.input, argv.output, {
// --quiet and --quiet=true both resolve to true
quietMode: argv.quiet,
configPath: argv.config,
source: "cli",
});
elev.setConfigPathOverride(argv.config);
elev.setPathPrefix(argv.pathprefix);
elev.setDryRun(argv.dryrun);
elev.setPassthroughAll(argv.passthroughall);
elev.setFormats(argv.formats);
// reuse ErrorHandler instance in Eleventy
errorHandler = elev.errorHandler;
let isVerbose = process.env.DEBUG ? false : !argv.quiet;
elev.setIsVerbose('*');
if (argv.version) {
console.log(elev.getVersion());
} else if (argv.help) {
console.log(elev.getHelp());
} else {
if (argv.to === "json" || argv.to === "ndjson") {
// override logging output
elev.setIsVerbose(false);
}
elev.setPathPrefix(argv.pathprefix);
elev.setDryRun(argv.dryrun);
elev.setIncrementalBuild(argv.incremental);
elev.setPassthroughAll(argv.passthroughall);
elev.setFormats(argv.formats);
// careful, we can’t use async/await here to error properly
// with old node versions in `please-upgrade-node` above.
elev
.init()
.then(function () {
try {
if (argv.serve) {
let startBrowsersync = true;
elev
.watch()
.catch((e) => {
// Build failed but error message already displayed.
startBrowsersync = false;
// A build error occurred and we aren’t going to --serve
})
.then(function () {
if (startBrowsersync) {
// elev.watch(argv.port);
elev.serve(argv.port);
}
});
} else if (argv.watch) {
elev.watch().catch((e) => {
// A build error occurred and we aren’t going to --watch
});
} else {
if (argv.to === "json") {
elev.toJSON().then(function (result) {
console.log(JSON.stringify(result, null, 2));
});
} else if (argv.to === "ndjson") {
elev.toNDJSON().then(function (stream) {
stream.pipe(process.stdout);
});
} else if (!argv.to || argv.to === "fs") {
// we'll call elev.write from our gulp file directly
// elev.write();
} else {
throw new EleventyCommandCheckError(
`Invalid --to value: ${argv.to}. Supported values: \`fs\` (default), \`json\`, and \`ndjson\`.`
);
}
}
} catch (e) {
errorHandler.fatal(e, "Eleventy CLI Error");
}
})
.catch(errorHandler.fatal.bind(errorHandler));
}
} catch (e) {
EleventyErrorHandler.fatal(e, "Eleventy fatal error");
let errorHandler = new EleventyErrorHandler();
errorHandler.fatal(e, "Eleventy CLI Fatal Error");
}
elev
.init()
.then( function() {
if (argv.version) {
console.log(elev.getVersion());
} else if (argv.help) {
console.log(elev.getHelp());
} else if (argv.serve) {
// Serve is instead run by the parent JS
} else if (argv.watch) {
// Watch is instead run by the parent JS
} else {
// No default
}
})
.catch(EleventyErrorHandler.fatal);
module.exports = elev;
\ No newline at end of file
module.exports = elev;
## 2.0.0-alpha.0
* Support Eleventy 1.0.0 change in how its build process works
* https://github.com/visual-framework/vf-core/pull/1257
* https://github.com/11ty/eleventy/releases/tag/v0.12.1
### 1.0.1
* Dependency update.
......
......@@ -13,32 +13,30 @@ module.exports = function(gulp) {
// Init Eleventy
gulp.task("eleventy:init", function(done) {
elev = require("../11ty/eleventy-cmd.js");
console.log("eleventy:init is no longer required. You can remove it from your gulpfile.js");
done();
});
// Run eleventy for local development
gulp.task("eleventy:develop", function(done) {
console.log("eleventy:develop underway");
process.argv.push("--serve");
process.env.ELEVENTY_ENV = "development";
// You could instead use elev.write() here, but then you should add your own browsersync task
elev.watch().then(function() {
console.log("Eleventy loaded, serving to browser");
elev.serve("3000");
done();
});
elev = require("../11ty/eleventy-cmd.js");
});
// Run eleventy as a static build
gulp.task("eleventy:build", function(done) {
process.argv.push("--quiet");
process.env.ELEVENTY_ENV = "production";
elev.write().then(function() {
console.log("Done building 11ty");
done();
});
elev = require("../11ty/eleventy-cmd.js");
elev.init()
.then(function () {
elev.write().then(function() {
console.log("Done building 11ty");
done();
});
});
});
// Refresh eleventy
......
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