-
-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Big v3.0.0 Project Slipstream Changes (#3074)
- Loading branch information
Showing
391 changed files
with
4,504 additions
and
7,990 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
#!/usr/bin/env node | ||
|
||
// This file intentionally uses older code conventions to be as friendly | ||
// as possible with error messaging to folks on older runtimes. | ||
|
||
const pkg = require("./package.json"); | ||
require("please-upgrade-node")(pkg, { | ||
message: function (requiredVersion) { | ||
return ( | ||
"Eleventy " + pkg.version + " requires Node " + | ||
requiredVersion + | ||
". You will need to upgrade Node to use Eleventy!" | ||
); | ||
}, | ||
}); | ||
|
||
const debug = require("debug")("Eleventy:cmd"); | ||
|
||
(async function() { | ||
const { default: EleventyErrorHandler } = await import("./src/EleventyErrorHandler.js"); | ||
const { default: EleventyBaseError } = await import("./src/EleventyBaseError.js"); | ||
|
||
class EleventyCommandCheckError extends EleventyBaseError {} | ||
|
||
try { | ||
let errorHandler = new EleventyErrorHandler(); | ||
const argv = require("minimist")(process.argv.slice(2), { | ||
string: ["input", "output", "formats", "config", "pathprefix", "port", "to"], | ||
boolean: [ | ||
"quiet", | ||
"version", | ||
"watch", | ||
"dryrun", | ||
"help", | ||
"serve", | ||
"incremental", | ||
"ignore-initial", | ||
], | ||
default: { | ||
quiet: null, | ||
"ignore-initial": false, | ||
}, | ||
unknown: function (unknownArgument) { | ||
throw new EleventyCommandCheckError( | ||
`We don’t know what '${unknownArgument}' is. Use --help to see the list of supported commands.` | ||
); | ||
}, | ||
}); | ||
|
||
debug("command: eleventy %o", argv); | ||
const { Eleventy } = await import("./src/Eleventy.js"); | ||
|
||
process.on("unhandledRejection", (error, promise) => { | ||
errorHandler.fatal(error, "Unhandled rejection in promise"); | ||
}); | ||
process.on("uncaughtException", (error) => { | ||
errorHandler.fatal(error, "Uncaught exception"); | ||
}); | ||
process.on("rejectionHandled", (promise) => { | ||
errorHandler.warn(promise, "A promise rejection was handled asynchronously"); | ||
}); | ||
|
||
if (argv.version) { | ||
console.log(Eleventy.getVersion()); | ||
} else if (argv.help) { | ||
console.log(Eleventy.getHelp()); | ||
} else { | ||
let elev = new Eleventy(argv.input, argv.output, { | ||
source: "cli", | ||
// --quiet and --quiet=true both resolve to true | ||
quietMode: argv.quiet, | ||
configPath: argv.config, | ||
pathPrefix: argv.pathprefix, | ||
runMode: argv.serve ? "serve" : argv.watch ? "watch" : "build", | ||
dryRun: argv.dryrun, | ||
}); | ||
|
||
// reuse ErrorHandler instance in Eleventy | ||
errorHandler = elev.errorHandler; | ||
|
||
// careful, we can’t use async/await here to error properly | ||
// with old node versions in `please-upgrade-node` above. | ||
elev | ||
.init() | ||
.then(function () { | ||
if (argv.to === "json" || argv.to === "ndjson") { | ||
// override logging output | ||
elev.setIsVerbose(false); | ||
} | ||
|
||
elev.setIgnoreInitial(argv["ignore-initial"]); | ||
elev.setIncrementalBuild(argv.incremental); | ||
elev.setFormats(argv.formats); | ||
|
||
try { | ||
if (argv.serve) { | ||
let shouldStartServer = true; | ||
elev | ||
.watch() | ||
.catch((e) => { | ||
// Build failed but error message already displayed. | ||
shouldStartServer = false; | ||
// A build error occurred and we aren’t going to --serve | ||
errorHandler.fatal(e, "Eleventy CLI Error"); | ||
}) | ||
.then(function () { | ||
if (shouldStartServer) { | ||
elev.serve(argv.port); | ||
} | ||
}); | ||
} else if (argv.watch) { | ||
elev.watch().catch((e) => { | ||
// A build error occurred and we aren’t going to --watch | ||
errorHandler.fatal(e, "Eleventy CLI Error"); | ||
}); | ||
} 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") { | ||
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) { | ||
let errorHandler = new EleventyErrorHandler(); | ||
errorHandler.fatal(e, "Eleventy CLI Fatal Error"); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.