xertz 0.56.0 → 0.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/builder.js +19 -0
- package/dist/cli.js +46 -8
- package/dist/configHelper.js +6 -2
- package/dist/generators/contentGenerator.js +58 -2
- package/package.json +8 -4
- package/scaffold/package.json +1 -1
package/dist/builder.js
CHANGED
|
@@ -38,6 +38,7 @@ class Builder {
|
|
|
38
38
|
layoutsDirectory;
|
|
39
39
|
stylesDirectory;
|
|
40
40
|
distDirectory;
|
|
41
|
+
contentGenerator;
|
|
41
42
|
constructor(baseDirectory) {
|
|
42
43
|
this.baseDirectory = baseDirectory;
|
|
43
44
|
this.contentDirectory = this.baseDirectory;
|
|
@@ -46,6 +47,8 @@ class Builder {
|
|
|
46
47
|
this.distDirectory = path.join(this.baseDirectory, Builder.distDirectoryName);
|
|
47
48
|
}
|
|
48
49
|
async start() {
|
|
50
|
+
this.contentGenerator = undefined;
|
|
51
|
+
(0, configHelper_1.clearConfigFileCache)();
|
|
49
52
|
let baseConfig = (0, configHelper_1.loadConfigFile)(this.baseDirectory);
|
|
50
53
|
if (!baseConfig) {
|
|
51
54
|
throw Error(`Config file not found in ${this.baseDirectory}.`);
|
|
@@ -56,6 +59,22 @@ class Builder {
|
|
|
56
59
|
// Content - process the content files
|
|
57
60
|
const contentGenerator = new contentGenerator_1.ContentGenerator(baseConfig, styles, this.stylesDirectory, this.layoutsDirectory, this.contentDirectory, this.distDirectory);
|
|
58
61
|
await contentGenerator.generateAll();
|
|
62
|
+
this.contentGenerator = contentGenerator;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Returns true if the rebuild was incremental
|
|
66
|
+
*/
|
|
67
|
+
async rebuild(changedFilePaths) {
|
|
68
|
+
const requiresFullBuild = changedFilePaths.some(f => f.startsWith(this.layoutsDirectory + path.sep) ||
|
|
69
|
+
f.startsWith(this.stylesDirectory + path.sep) ||
|
|
70
|
+
path.basename(f) == "_config.yml");
|
|
71
|
+
if (!requiresFullBuild &&
|
|
72
|
+
this.contentGenerator &&
|
|
73
|
+
(await this.contentGenerator.regenerate(changedFilePaths))) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
await this.start();
|
|
77
|
+
return false;
|
|
59
78
|
}
|
|
60
79
|
}
|
|
61
80
|
exports.Builder = Builder;
|
package/dist/cli.js
CHANGED
|
@@ -117,7 +117,6 @@ Commands:
|
|
|
117
117
|
console.log(`[init]: Installing packages...`);
|
|
118
118
|
(0, child_process_1.execSync)(`npm install --silent`, { cwd: targetDirectoryPath, env: {} });
|
|
119
119
|
console.log(`[init]: Done! Run \`cd ${targetDirectoryName} && npx xertz serve\` and start blogging.`);
|
|
120
|
-
process.exit();
|
|
121
120
|
}
|
|
122
121
|
newCommand(title) {
|
|
123
122
|
console.log(`[new]: Start`);
|
|
@@ -139,9 +138,8 @@ This is a new post.
|
|
|
139
138
|
});
|
|
140
139
|
console.log(`[new]: Done! Created ${postPath}`);
|
|
141
140
|
}
|
|
142
|
-
async build(exit = true) {
|
|
141
|
+
async build(exit = true, builder = new builder_1.Builder(this.cwd)) {
|
|
143
142
|
console.log(`[build]: Start`);
|
|
144
|
-
const builder = new builder_1.Builder(this.cwd);
|
|
145
143
|
await builder.start();
|
|
146
144
|
console.log(`[build]: Success!`);
|
|
147
145
|
if (exit) {
|
|
@@ -150,16 +148,39 @@ This is a new post.
|
|
|
150
148
|
}
|
|
151
149
|
async serveCommand(preferredPortNumber) {
|
|
152
150
|
console.log(`[serve]: Start`);
|
|
153
|
-
|
|
151
|
+
const builder = new builder_1.Builder(this.cwd);
|
|
152
|
+
await this.build(false, builder);
|
|
154
153
|
const distFolder = path.join(this.cwd, builder_1.Builder.distDirectoryName);
|
|
154
|
+
const changedFilePaths = new Set();
|
|
155
|
+
let fullBuildRequired = false;
|
|
156
|
+
let rebuildTimer;
|
|
157
|
+
let rebuilding = Promise.resolve();
|
|
155
158
|
chokidar
|
|
156
159
|
.watch([path.join(this.cwd)], {
|
|
157
160
|
ignoreInitial: true,
|
|
158
|
-
ignored:
|
|
161
|
+
ignored: [
|
|
162
|
+
distFolder,
|
|
163
|
+
path.join(this.cwd, "node_modules"),
|
|
164
|
+
path.join(this.cwd, ".git")
|
|
165
|
+
]
|
|
159
166
|
})
|
|
160
|
-
.on("all", (event,
|
|
161
|
-
|
|
162
|
-
|
|
167
|
+
.on("all", (event, changedPath) => {
|
|
168
|
+
if (event == "add" || event == "change") {
|
|
169
|
+
changedFilePaths.add(changedPath);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
// Deletes and new directories can leave stale output, so start clean
|
|
173
|
+
fullBuildRequired = true;
|
|
174
|
+
}
|
|
175
|
+
// Editors often emit several events per save; batch them into one rebuild
|
|
176
|
+
clearTimeout(rebuildTimer);
|
|
177
|
+
rebuildTimer = setTimeout(() => {
|
|
178
|
+
const filePaths = [...changedFilePaths];
|
|
179
|
+
const fullBuild = fullBuildRequired;
|
|
180
|
+
changedFilePaths.clear();
|
|
181
|
+
fullBuildRequired = false;
|
|
182
|
+
rebuilding = rebuilding.then(() => this.rebuild(builder, filePaths, fullBuild));
|
|
183
|
+
}, 100);
|
|
163
184
|
});
|
|
164
185
|
const expressApp = express();
|
|
165
186
|
expressApp.use(express.static(distFolder));
|
|
@@ -167,6 +188,23 @@ This is a new post.
|
|
|
167
188
|
expressApp.listen(portNumber);
|
|
168
189
|
console.log(`[serve]: Listening on http://localhost:${portNumber}`);
|
|
169
190
|
}
|
|
191
|
+
async rebuild(builder, changedFilePaths, fullBuild) {
|
|
192
|
+
console.log(`[serve]: Change detected`);
|
|
193
|
+
const startTime = Date.now();
|
|
194
|
+
try {
|
|
195
|
+
let incremental = false;
|
|
196
|
+
if (fullBuild) {
|
|
197
|
+
await builder.start();
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
incremental = await builder.rebuild(changedFilePaths);
|
|
201
|
+
}
|
|
202
|
+
console.log(`[serve]: ${incremental ? "Incremental" : "Full"} rebuild done in ${Date.now() - startTime}ms`);
|
|
203
|
+
}
|
|
204
|
+
catch (err) {
|
|
205
|
+
console.error(`[serve]: Build failed - ${err}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
170
208
|
async updateCommand() {
|
|
171
209
|
console.log(`[update]: Start`);
|
|
172
210
|
// Update xertz depedency to latest version in package.json
|
package/dist/configHelper.js
CHANGED
|
@@ -23,12 +23,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.loadConfigFile = void 0;
|
|
26
|
+
exports.loadConfigFile = exports.clearConfigFileCache = void 0;
|
|
27
27
|
const path = __importStar(require("path"));
|
|
28
28
|
const fs = __importStar(require("fs"));
|
|
29
29
|
const fse = __importStar(require("fs-extra"));
|
|
30
30
|
const yaml = __importStar(require("js-yaml"));
|
|
31
|
-
|
|
31
|
+
let cachedConfigFiles = {};
|
|
32
|
+
function clearConfigFileCache() {
|
|
33
|
+
cachedConfigFiles = {};
|
|
34
|
+
}
|
|
35
|
+
exports.clearConfigFileCache = clearConfigFileCache;
|
|
32
36
|
function loadConfigFile(sourceDirectory) {
|
|
33
37
|
if (!cachedConfigFiles[sourceDirectory]) {
|
|
34
38
|
const configFilePath = path.join(sourceDirectory, "_config.yml");
|
|
@@ -56,6 +56,8 @@ class ContentGenerator {
|
|
|
56
56
|
baseTemplateData;
|
|
57
57
|
templateGenerator;
|
|
58
58
|
ampGenerator;
|
|
59
|
+
pages = [];
|
|
60
|
+
generatedDirectories = new Map();
|
|
59
61
|
constructor(baseConfig, styles, stylesDirectory, layoutsDirectory, sourceDirectory, destDirectory) {
|
|
60
62
|
this.styles = styles;
|
|
61
63
|
this.stylesDirectory = stylesDirectory;
|
|
@@ -70,9 +72,9 @@ class ContentGenerator {
|
|
|
70
72
|
this.ampGenerator = new ampGenerator_1.AmpGenerator(this.baseSourceDirectory, this.baseDestDirectory, this.templateManager);
|
|
71
73
|
}
|
|
72
74
|
async generateAll() {
|
|
73
|
-
await this.generate(this.baseConfig, this.baseSourceDirectory, this.baseDestDirectory);
|
|
75
|
+
this.pages = await this.generate(this.baseConfig, this.baseSourceDirectory, this.baseDestDirectory);
|
|
74
76
|
}
|
|
75
|
-
async generate(config, sourceDirectory, destDirectory) {
|
|
77
|
+
async generate(config, sourceDirectory, destDirectory, recursive = true) {
|
|
76
78
|
const originalDestDirectory = destDirectory;
|
|
77
79
|
let sourceDirectoryConfig = (0, configHelper_1.loadConfigFile)(sourceDirectory);
|
|
78
80
|
// Merge any _config.yml file in current directory with baseConfig to gather config for current directory
|
|
@@ -95,12 +97,20 @@ class ContentGenerator {
|
|
|
95
97
|
destDirectory = path.join(destDirectory, currentDirectoryPageConfig.slug);
|
|
96
98
|
}
|
|
97
99
|
}
|
|
100
|
+
this.generatedDirectories.set(sourceDirectory, {
|
|
101
|
+
config,
|
|
102
|
+
destDirectory: originalDestDirectory,
|
|
103
|
+
pageConfig: currentDirectoryPageConfig
|
|
104
|
+
});
|
|
98
105
|
fse.ensureDirSync(destDirectory);
|
|
99
106
|
const sourceDirectoryFileNames = fs.readdirSync(sourceDirectory);
|
|
100
107
|
// Process asset files
|
|
101
108
|
this.processAssetFiles(sourceDirectory, sourceDirectoryFileNames, destDirectory, isContentPackageDirectory);
|
|
102
109
|
// Process markdown content files
|
|
103
110
|
const pages = await this.processContentFiles(sourceDirectory, sourceDirectoryFileNames, destDirectory, currentDirectoryPageConfig, isContentPackageDirectory);
|
|
111
|
+
if (!recursive) {
|
|
112
|
+
return pages;
|
|
113
|
+
}
|
|
104
114
|
// Traverse subdirectories if this is not a content package directory
|
|
105
115
|
if (!isContentPackageDirectory) {
|
|
106
116
|
const subDirectoryNames = sourceDirectoryFileNames.filter(f => {
|
|
@@ -125,6 +135,52 @@ class ContentGenerator {
|
|
|
125
135
|
}
|
|
126
136
|
return pages;
|
|
127
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Returns false when the changes can't be applied incrementally and a full build is needed
|
|
140
|
+
*/
|
|
141
|
+
async regenerate(changedFilePaths) {
|
|
142
|
+
const directoriesToRegenerate = new Set();
|
|
143
|
+
for (let changedFilePath of changedFilePaths) {
|
|
144
|
+
if (this.isIgnoredPath(changedFilePath)) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const sourceDirectory = path.dirname(changedFilePath);
|
|
148
|
+
let generatedDirectory = sourceDirectory;
|
|
149
|
+
while (!this.generatedDirectories.has(generatedDirectory) &&
|
|
150
|
+
generatedDirectory != path.dirname(generatedDirectory)) {
|
|
151
|
+
generatedDirectory = path.dirname(generatedDirectory);
|
|
152
|
+
}
|
|
153
|
+
const isInContentPackageDirectory = fse.existsSync(path.join(generatedDirectory, "index.md"));
|
|
154
|
+
if (!this.generatedDirectories.has(generatedDirectory) ||
|
|
155
|
+
(generatedDirectory != sourceDirectory && !isInContentPackageDirectory)) {
|
|
156
|
+
// A new directory that was not part of the last build
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
directoriesToRegenerate.add(generatedDirectory);
|
|
160
|
+
}
|
|
161
|
+
const templateDirectories = new Set();
|
|
162
|
+
for (let sourceDirectory of directoriesToRegenerate) {
|
|
163
|
+
const { config, destDirectory } = this.generatedDirectories.get(sourceDirectory);
|
|
164
|
+
const pages = await this.generate(config, sourceDirectory, destDirectory, false);
|
|
165
|
+
this.pages = this.pages
|
|
166
|
+
.filter(p => path.dirname(p.source) != sourceDirectory)
|
|
167
|
+
.concat(pages);
|
|
168
|
+
for (let directory = sourceDirectory; this.generatedDirectories.has(directory); directory = path.dirname(directory)) {
|
|
169
|
+
templateDirectories.add(directory);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
for (let sourceDirectory of templateDirectories) {
|
|
173
|
+
const { destDirectory, pageConfig } = this.generatedDirectories.get(sourceDirectory);
|
|
174
|
+
this.templateGenerator.generate(sourceDirectory, destDirectory, pageConfig, this.pages.filter(p => p.source.startsWith(sourceDirectory + path.sep)));
|
|
175
|
+
}
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
isIgnoredPath(filePath) {
|
|
179
|
+
return path
|
|
180
|
+
.relative(this.baseSourceDirectory, filePath)
|
|
181
|
+
.split(path.sep)
|
|
182
|
+
.some(segment => this.ignorePrefixes.some(i => segment.startsWith(i)));
|
|
183
|
+
}
|
|
128
184
|
processAssetFiles(sourceDirectory, sourceDirectoryFileNames, destDirectory, recursive = false) {
|
|
129
185
|
const assetFileNames = sourceDirectoryFileNames.filter(f => this.ignorePrefixes.findIndex(i => f.startsWith(i)) == -1 &&
|
|
130
186
|
!this.assetIgnoreExtensions.includes(path.extname(f).substr(1)) &&
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xertz",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.58.0",
|
|
4
4
|
"description": "A static site generator written in TypeScript",
|
|
5
5
|
"author": "Brady Holt",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/bradymholt/xertz.git"
|
|
10
|
+
},
|
|
7
11
|
"publishConfig": {
|
|
8
12
|
"access": "public"
|
|
9
13
|
},
|
|
@@ -23,16 +27,16 @@
|
|
|
23
27
|
"prepublishOnly": "tsc"
|
|
24
28
|
},
|
|
25
29
|
"dependencies": {
|
|
26
|
-
"@bradymholt/ampify": "^1.
|
|
30
|
+
"@bradymholt/ampify": "^1.4.0",
|
|
27
31
|
"chokidar": "^3.5.3",
|
|
28
|
-
"dateformat": "^5.
|
|
32
|
+
"dateformat": "^4.5.1",
|
|
29
33
|
"express": "^4.18.1",
|
|
30
34
|
"fs-extra": "^10.1.0",
|
|
31
35
|
"gray-matter": "^4.0.3",
|
|
32
36
|
"handlebars": "^4.7.7",
|
|
33
37
|
"js-yaml": "^4.1.0",
|
|
34
38
|
"marked": "^4.0.17",
|
|
35
|
-
"package-json": "^
|
|
39
|
+
"package-json": "^6.5.0",
|
|
36
40
|
"prismjs": "^1.28.0",
|
|
37
41
|
"sass": "^1.52.3"
|
|
38
42
|
},
|
package/scaffold/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"tmp_init","version":"1.0.0","description":"A site built with xertz.","dependencies":{"xertz":"0.
|
|
1
|
+
{"name":"tmp_init","version":"1.0.0","description":"A site built with xertz.","dependencies":{"xertz":"0.56.0"}}
|