Skip to content

Commit

Permalink
Adds runMode to eleventy global data. Fixes #2770
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jan 24, 2023
1 parent 4504820 commit 99140d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
7 changes: 1 addition & 6 deletions cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ try {
quietMode: argv.quiet,
configPath: argv.config,
pathPrefix: argv.pathprefix,
runMode: argv.serve ? "serve" : argv.watch ? "watch" : "build",
});

// reuse ErrorHandler instance in Eleventy
Expand All @@ -78,12 +79,6 @@ try {
elev.setIncrementalBuild(argv.incremental);
elev.setFormats(argv.formats);

if (argv.serve) {
elev.setRunMode("serve");
} else if (argv.watch) {
elev.setRunMode("watch");
}

// careful, we can’t use async/await here to error properly
// with old node versions in `please-upgrade-node` above.
elev
Expand Down
17 changes: 9 additions & 8 deletions src/Eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,23 @@ class Eleventy {
* @member {Boolean} - Running in serverless mode
* @default false
*/

// This needs to happen before `getEnvironmentVariableValues` below.
if ("isServerless" in options) {
this.isServerless = !!options.isServerless;
} else {
this.isServerless = !!process.env.AWS_LAMBDA_FUNCTION_NAME;
}

/**
* @member {String} - One of build, serve, or watch
* @default "build"
*/
this.runMode = options.runMode || "build";

/**
* @member {Object} - Initialize Eleventy environment variables
* @default null
*/
// both this.isServerless and this.runMode need to be set before this
this.env = this.getEnvironmentVariableValues();
this.initializeEnvironmentVariables(this.env);

Expand All @@ -109,12 +114,6 @@ class Eleventy {
*/
this.verboseModeSetViaCommandLineParam = false;

/**
* @member {String} - One of build, serve, or watch
* @default "build"
*/
this.runMode = "build";

/**
* @member {Boolean} - Is Eleventy running in verbose mode?
* @default true
Expand Down Expand Up @@ -468,6 +467,7 @@ Verbose Output: ${this.verboseMode}`);
getEnvironmentVariableValues() {
let values = {
source: this.source,
runMode: this.runMode,
};
let configPath = this.eleventyConfig.getLocalProjectConfigFile();
if (configPath) {
Expand Down Expand Up @@ -495,6 +495,7 @@ Verbose Output: ${this.verboseMode}`);
debug("Setting process.env.ELEVENTY_ROOT: %o", env.root);

process.env.ELEVENTY_SOURCE = env.source;
process.env.ELEVENTY_RUN_MODE = env.runMode;

// https://github.com/11ty/eleventy/issues/1957
// Note: when using --serve, ELEVENTY_SERVERLESS is also set in Serverless.js
Expand Down

0 comments on commit 99140d8

Please sign in to comment.