Skip to content

Commit

Permalink
Adds a really rough start --incremental that probably won’t be good e…
Browse files Browse the repository at this point in the history
…nough for most people. Processes everything but only writes what triggered in --watch/--serve
  • Loading branch information
zachleat committed Sep 7, 2019
1 parent f5b878e commit 6e294bd
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 20 deletions.
1 change: 1 addition & 0 deletions cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ try {
elev.setConfigPathOverride(argv.config);
elev.setPathPrefix(argv.pathprefix);
elev.setDryRun(argv.dryrun);
elev.setIncrementalBuild(argv.incremental);
elev.setPassthroughAll(argv.passthroughall);
elev.setFormats(argv.formats);

Expand Down
47 changes: 30 additions & 17 deletions src/Eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ class Eleventy {
this.isDryRun = !!isDryRun;
}

/**
* Sets the incremental build mode.
*
* @method
* @param {Boolean} isIncremental - Shall Eleventy run in incremental build mode and only write the files that trigger watch updates
*/
setIncrementalBuild(isIncremental) {
this.isIncremental = !!isIncremental;
}

/**
* Updates the passthrough mode of Eleventy.
*
Expand Down Expand Up @@ -204,25 +214,19 @@ class Eleventy {
let ret = [];

let writeCount = this.writer.getWriteCount();
let pretendWriteCount = this.writer.getPretendWriteCount();
let copyCount = this.writer.getCopyCount();
if (this.isDryRun) {
ret.push("Pretended to");
}
if (copyCount) {
if (!this.isDryRun && copyCount) {
ret.push(
`${this.isDryRun ? "Copy" : "Copied"} ${copyCount} ${simplePlural(
copyCount,
"item",
"items"
)} and`
`Copied ${copyCount} ${simplePlural(copyCount, "item", "items")} /`
);
}
if (pretendWriteCount) {
ret.push(`Processed ${writeCount + pretendWriteCount},`);
}

ret.push(
`${this.isDryRun ? "Process" : "Processed"} ${writeCount} ${simplePlural(
writeCount,
"file",
"files"
)}`
`Wrote ${writeCount} ${simplePlural(writeCount, "file", "files")}`
);

let time = ((new Date() - this.start) / 1000).toFixed(2);
Expand Down Expand Up @@ -398,6 +402,10 @@ Arguments:

this.active = true;

let isInclude =
path &&
TemplatePath.startsWithSubPath(path, this.eleventyFiles.getIncludesDir());

let localProjectConfigPath = config.getLocalProjectConfigFile();
// reset and reload global configuration :O
if (path === localProjectConfigPath) {
Expand All @@ -408,17 +416,22 @@ Arguments:
await this.restart();
this.watchTargets.clearDependencyRequireCache();

if (path && !isInclude && this.isIncremental) {
this.writer.setIncrementalFile(path);
}

await this.write();

if (path && !isInclude && this.isIncremental) {
this.writer.resetIncrementalFile();
}

this.watchTargets.reset();
await this._initWatchDependencies();

// Add new deps to chokidar
this.watcher.add(this.watchTargets.getNewTargetsSinceLastReset());

let isInclude =
path &&
TemplatePath.startsWithSubPath(path, this.eleventyFiles.getIncludesDir());
this.eleventyServe.reload(path, isInclude);

this.active = false;
Expand Down
3 changes: 2 additions & 1 deletion src/EleventyCommandCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class EleventyCommandCheck {
"dryrun",
"help",
"serve",
"passthroughall"
"passthroughall",
"incremental"
];

this.args = argv;
Expand Down
27 changes: 25 additions & 2 deletions src/TemplateWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function TemplateWriter(
this.isVerbose = true;
this.isDryRun = false;
this.writeCount = 0;
this.pretendWriteCount = 0;

// TODO can we get rid of this? It’s only used for tests in getFileManager()
this.passthroughAll = isPassthroughAll;
Expand All @@ -41,6 +42,7 @@ TemplateWriter.prototype.overrideConfig = function(config) {

TemplateWriter.prototype.restart = function() {
this.writeCount = 0;
this.pretendWriteCount = 0;
debugDev("Resetting counts to 0");
};

Expand Down Expand Up @@ -77,7 +79,13 @@ TemplateWriter.prototype._createTemplate = function(path) {
);

tmpl.setIsVerbose(this.isVerbose);
tmpl.setDryRun(this.isDryRun);

// --incremental only writes files that trigger a build during --watch
if (this.incrementalFile && path !== this.incrementalFile) {
tmpl.setDryRun(true);
} else {
tmpl.setDryRun(this.isDryRun);
}

/*
* Sample filter: arg str, return pretty HTML string
Expand Down Expand Up @@ -131,7 +139,11 @@ TemplateWriter.prototype._writeTemplate = async function(mapEntry) {
let tmpl = mapEntry.template;
// we don’t re-use the map templateContent because it doesn’t include layouts
return tmpl.writeMapEntry(mapEntry).then(() => {
this.writeCount += tmpl.getWriteCount();
if (tmpl.isDryRun) {
this.pretendWriteCount += tmpl.getWriteCount();
} else {
this.writeCount += tmpl.getWriteCount();
}
});
};

Expand Down Expand Up @@ -207,6 +219,13 @@ TemplateWriter.prototype.setDryRun = function(isDryRun) {
.setDryRun(this.isDryRun);
};

TemplateWriter.prototype.setIncrementalFile = function(incrementalFile) {
this.incrementalFile = incrementalFile;
};
TemplateWriter.prototype.resetIncrementalFile = function() {
this.incrementalFile = null;
};

TemplateWriter.prototype.getCopyCount = function() {
return this.getFileManager()
.getPassthroughManager()
Expand All @@ -217,4 +236,8 @@ TemplateWriter.prototype.getWriteCount = function() {
return this.writeCount;
};

TemplateWriter.prototype.getPretendWriteCount = function() {
return this.pretendWriteCount;
};

module.exports = TemplateWriter;

0 comments on commit 6e294bd

Please sign in to comment.