Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arbitrary JavaScript Template Types #314

Merged
merged 43 commits into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b712a9d
Initial
zachleat May 10, 2018
b32133c
Adds examples for template literals, vue.js templates, viperhtml temp…
zachleat May 10, 2018
cc6231f
Add string support to js templates
zachleat May 10, 2018
9ce6136
Merge branch 'master' into js-tmpl
zachleat Jun 14, 2018
f33ba8c
Better support for buffers returned from js templates, adds data supp…
zachleat Jun 14, 2018
69e4fd5
Merge branch 'master' into js-tmpl
zachleat Nov 21, 2018
eadea66
Normalize on .11ty.js
zachleat Nov 21, 2018
0cf377d
Cleanup
zachleat Nov 22, 2018
e4b1c8f
Not sure why this list style changed.
zachleat Nov 22, 2018
aefbe80
Merge branch 'master' into js-tmpl
zachleat Nov 22, 2018
dc666fd
Switch to `11ty.js` for key so as not to conflict with existing `js` …
zachleat Nov 26, 2018
cdffa8c
Adds extension aliasing to fix #207 although the current incarnation …
zachleat Nov 30, 2018
987159c
Move config refs into TemplateEngine
zachleat Nov 30, 2018
aa1a799
Fixes #320
zachleat Nov 30, 2018
cbb5097
Convert to ES6 class
zachleat Nov 30, 2018
c6c11b5
Try out a universal filter/shortcode/helper/function on a JavaScript …
zachleat Nov 30, 2018
91f385d
Rogue console logs
zachleat Nov 30, 2018
617820f
Test javascriptFunctions available on this. in render functions for J…
zachleat Dec 1, 2018
f82656e
Simpler file renames
zachleat Dec 2, 2018
fe131dd
Keep other methods accessible from class render methods and functions
zachleat Dec 2, 2018
0467866
Async function test
zachleat Dec 2, 2018
955487e
Async data function
zachleat Dec 2, 2018
9072cbc
Works with buffers
zachleat Dec 2, 2018
91f5b58
Fix `requires` and clear require cache when watching.
zachleat Dec 2, 2018
c1e4011
Fix test paths after localpath change.
zachleat Dec 2, 2018
24cadab
More efficient and more tests.
zachleat Dec 3, 2018
6700bf0
Merge branch 'master' into js-tmpl
zachleat Dec 4, 2018
39c1df5
Adds permalink test (currently failing)
zachleat Dec 5, 2018
2a43a44
Fix console error output on one passing test
zachleat Dec 5, 2018
8d754d1
Adds support for 11ty.js permalinks
zachleat Dec 6, 2018
17f4f5b
Adds tests for renderData with JavaScript template types.
zachleat Dec 7, 2018
1bd9545
Start
zachleat Dec 17, 2018
9b9dfa5
Start of #325
zachleat Dec 17, 2018
d85c609
Fixes #347
zachleat Dec 18, 2018
8f28976
Upgrades to ava 1.0
zachleat Dec 18, 2018
f0d318a
Merge branch 'issue-347' into js-tmpl
zachleat Dec 18, 2018
783ef95
Husky changes
zachleat Dec 18, 2018
838e6a7
Generic ignore: prefix in lexer
zachleat Dec 18, 2018
0351123
Upgrades deps, restore exitCode in test so pre-push doesn’t fail.
zachleat Dec 18, 2018
b73af8c
Removes glob-watcher middle-man and use upstream dependency instead (…
zachleat Dec 19, 2018
b4eb3f2
Test for #161
zachleat Dec 20, 2018
d70abd6
Fixes #118 Fixes #325 (new stuff for 11ty.js templates)
zachleat Dec 21, 2018
32fc454
Merge branch 'master' into js-tmpl
zachleat Dec 21, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ In the interest of fostering an open and welcoming environment, we as contributo

Examples of behavior that contributes to creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
- The use of sexualized language or imagery and unwelcome sexual attention or advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic address, without explicit permission
- Other conduct which could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

Expand Down
2 changes: 1 addition & 1 deletion cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ try {
cmdCheck.hasUnknownArguments();

let elev = new Eleventy(argv.input, argv.output);
elev.setConfigPath(argv.config);
elev.setConfigPathOverride(argv.config);
elev.setPathPrefix(argv.pathprefix);
elev.setDryRun(argv.dryrun);
elev.setPassthroughAll(argv.passthroughall);
Expand Down
3 changes: 2 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module.exports = function(config) {
"pug",
"njk",
"html",
"jstl"
"jstl",
"11ty.js"
],
// if your site lives in a subdirectory, change this
pathPrefix: "/",
Expand Down
30 changes: 20 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
"scripts": {
"default": "cd playground && npx eleventy --input=. --output=_site",
"test": "npx nyc ava",
"coverage": "npm run test && npx nyc report --reporter=json-summary && cp coverage/coverage-summary.json docs-src/_data/coverage.json && node cmd.js --config=docs-src/.eleventy.docs.js",
"precommit": "lint-staged",
"prepush": "npx ava"
"coverage": "npm run test && npx nyc report --reporter=json-summary && cp coverage/coverage-summary.json docs-src/_data/coverage.json && node cmd.js --config=docs-src/.eleventy.docs.js"
},
"author": {
"name": "Zach Leatherman",
Expand All @@ -53,9 +51,10 @@
"files": [
"test/*.js"
],
"source": [
"sources": [
"**/.eleventyignore",
"src/**/*.js"
"src/**/*.js",
"test/stubs/**"
]
},
"lint-staged": {
Expand All @@ -65,22 +64,26 @@
]
},
"devDependencies": {
"ava": "^0.25.0",
"@11ty/eleventy-plugin-syntaxhighlight": "^2.0.0",
"ava": "^1.0.1",
"husky": "^1.0.1",
"lint-staged": "^7.3.0",
"lint-staged": "^8.1.0",
"markdown-it-emoji": "^1.4.0",
"nyc": "^13.0.1",
"prettier": "1.14.3",
"@11ty/eleventy-plugin-syntaxhighlight": "^2.0.0"
"prettier": "^1.15.3",
"viperhtml": "^2.12.0",
"vue": "^2.5.16",
"vue-server-renderer": "^2.5.16"
},
"dependencies": {
"browser-sync": "^2.24.7",
"chalk": "^2.4.1",
"chokidar": "^2.0.4",
"debug": "^4.0.1",
"dependency-tree": "^6.3.0",
"ejs": "^2.6.1",
"fast-glob": "^2.2.2",
"fs-extra": "^7.0.0",
"glob-watcher": "^5.0.1",
"gray-matter": "^4.0.1",
"hamljs": "^0.6.2",
"handlebars": "^4.0.12",
Expand All @@ -90,6 +93,7 @@
"luxon": "^1.4.1",
"markdown-it": "^8.4.2",
"minimist": "^1.2.0",
"moo": "^0.5.0",
"multimatch": "^2.1.0",
"mustache": "^2.3.0",
"normalize-path": "^3.0.0",
Expand All @@ -103,5 +107,11 @@
"slugify": "^1.3.1",
"time-require": "^0.1.2",
"valid-url": "^1.0.9"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"pre-push": "npx ava"
}
}
}
110 changes: 99 additions & 11 deletions src/Eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const TemplateData = require("./TemplateData");
const TemplateWriter = require("./TemplateWriter");
const EleventyErrorHandler = require("./EleventyErrorHandler");
const EleventyServe = require("./EleventyServe");
const EleventyWatchTargets = require("./EleventyWatchTargets");
const EleventyFiles = require("./EleventyFiles");
const templateCache = require("./TemplateCache");
const simplePlural = require("./Util/Pluralize");
Expand All @@ -23,6 +24,10 @@ function Eleventy(input, output) {

this.rawInput = input;
this.rawOutput = output;

this.watchTargets = new EleventyWatchTargets();
this.watchTargets.watchJavaScriptDependencies = this.config.watchJavaScriptDependencies;

this.initDirs();
}

Expand All @@ -49,7 +54,11 @@ Eleventy.prototype.setPathPrefix = function(pathPrefix) {
}
};

Eleventy.prototype.setConfigPath = function(configPath) {
Eleventy.prototype.setWatchTargets = function(watchTargets) {
this.watchTargets = watchTargets;
};

Eleventy.prototype.setConfigPathOverride = function(configPath) {
if (configPath) {
this.configPath = configPath;

Expand Down Expand Up @@ -131,6 +140,7 @@ Eleventy.prototype.init = async function() {
formats,
this.isPassthroughAll
);
this.eleventyFiles.init();

this.templateData = new TemplateData(this.inputDir);
this.eleventyFiles.setTemplateData(this.templateData);
Expand Down Expand Up @@ -235,8 +245,16 @@ Eleventy.prototype._watch = async function(path) {
config.resetOnWatch();

await this.restart();
this.watchTargets.clearDependencyRequireCache();

await this.write();

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

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

let isInclude =
path && TemplatePath.contains(path, this.eleventyFiles.getIncludesDir());
this.eleventyServe.reload(path, isInclude);
Expand All @@ -252,27 +270,87 @@ Eleventy.prototype._watch = async function(path) {
}
};

Eleventy.prototype.getWatcher = function() {
return this.watcher;
};

Eleventy.prototype.initWatch = async function() {
this.watchTargets.add(this.eleventyFiles.getGlobWatcherFiles());

// Watch the local project config file
this.watchTargets.add(config.getLocalProjectConfigFile());

// Template and Directory Data Files
this.watchTargets.add(
await this.eleventyFiles.getGlobWatcherTemplateDataFiles()
);

await this._initWatchDependencies();
};

Eleventy.prototype._initWatchDependencies = async function() {
if (!this.watchTargets.watchJavaScriptDependencies) {
return;
}

let dataDir = this.templateData.getDataDir();
function filterOutGlobalDataFiles(path) {
return !dataDir || path.indexOf(dataDir) === -1;
}

// Template files .11ty.js
this.watchTargets.addDependencies(this.eleventyFiles.getWatchPathCache());

// Config file dependencies
this.watchTargets.addDependencies(
config.getLocalProjectConfigFile(),
filterOutGlobalDataFiles.bind(this)
);

// Deps from Global Data (that aren’t in the global data directory, everything is watched there)
this.watchTargets.addDependencies(
this.templateData.getWatchPathCache(),
filterOutGlobalDataFiles.bind(this)
);

this.watchTargets.addDependencies(
await this.eleventyFiles.getWatcherTemplateJavaScriptDataFiles()
);
};

Eleventy.prototype.getWatchedFiles = async function() {
return this.watchTargets.getTargets();
};

Eleventy.prototype.watch = async function() {
const chokidar = require("chokidar");
const EleventyWatchTargets = require("./EleventyWatchTargets");

this.active = false;
this.queuedToRun = false;

// Note that watching indirectly depends on this for fetching dependencies from JS files
// See: TemplateWriter:pathCache and EleventyWatchTargets
await this.write();

const watch = require("glob-watcher");
await this.initWatch();

let rawFiles = this.eleventyFiles.getGlobWatcherFiles();
// Watch the local project config file
rawFiles.push(config.getLocalProjectConfigFile());
rawFiles = rawFiles.concat(
await this.eleventyFiles.getGlobWatcherTemplateDataFiles()
);
// TODO improve unwatching if JS dependencies are removed (or files are deleted)
let rawFiles = await this.getWatchedFiles();
debug("Watching for changes to: %o", rawFiles);

console.log("Watching…");
let watcher = watch(rawFiles, {
ignored: this.eleventyFiles.getGlobWatcherIgnores()
let ignores = this.eleventyFiles.getGlobWatcherIgnores();
debug("Watching but ignoring changes to: %o", ignores);

let watcher = chokidar.watch(rawFiles, {
ignored: ignores,
ignoreInitial: true
});

console.log("Watching…");

this.watcher = watcher;

async function watchRun(path) {
try {
await this._watch(path);
Expand All @@ -291,6 +369,16 @@ Eleventy.prototype.watch = async function() {
console.log("File added:", path);
await watchRun.call(this, path);
});

process.on(
"SIGINT",
function() {
debug("Cleaning up chokidar and browsersync (if exists) instances.");
this.eleventyServe.close();
this.watcher.close();
process.exit();
}.bind(this)
);
};

Eleventy.prototype.serve = function(port) {
Expand Down
Loading