xertz 0.57.0 → 0.59.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 +62 -17
- package/dist/configHelper.js +6 -2
- package/dist/generators/contentGenerator.js +58 -2
- package/package.json +10 -9
- 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
|
@@ -30,11 +30,17 @@ const builder_1 = require("./builder");
|
|
|
30
30
|
const path = __importStar(require("path"));
|
|
31
31
|
const fse = __importStar(require("fs-extra"));
|
|
32
32
|
const chokidar = __importStar(require("chokidar"));
|
|
33
|
-
const package_json_1 = __importDefault(require("package-json"));
|
|
34
33
|
const child_process_1 = require("child_process");
|
|
35
34
|
const express = require("express");
|
|
36
|
-
const
|
|
35
|
+
const package_json_1 = __importDefault(require("../package.json"));
|
|
37
36
|
const dateHelper_1 = require("./dateHelper");
|
|
37
|
+
async function fetchLatestPackageInfo(name) {
|
|
38
|
+
const response = await fetch(`https://registry.npmjs.org/${name}/latest`);
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
throw new Error(`npm registry returned ${response.status} for ${name}`);
|
|
41
|
+
}
|
|
42
|
+
return (await response.json());
|
|
43
|
+
}
|
|
38
44
|
class cli {
|
|
39
45
|
scaffoldDirectoryName = "scaffold";
|
|
40
46
|
scaffoldContentExampleFileName = "YYYY-MM-DD-my-first-post.md";
|
|
@@ -59,7 +65,7 @@ Commands:
|
|
|
59
65
|
`);
|
|
60
66
|
}
|
|
61
67
|
async run() {
|
|
62
|
-
console.log(`${
|
|
68
|
+
console.log(`${package_json_1.default.name} - Version: ${package_json_1.default.version}`);
|
|
63
69
|
this.watchSignal();
|
|
64
70
|
const command = this.args[0] || "build";
|
|
65
71
|
switch (command) {
|
|
@@ -110,7 +116,7 @@ Commands:
|
|
|
110
116
|
const scaffoldFile = path.join(scaffoldDirectory, "package.json");
|
|
111
117
|
const scaffoldPackageContent = JSON.parse(fse.readFileSync(scaffoldFile, "utf8"));
|
|
112
118
|
scaffoldPackageContent.name = targetDirectoryName;
|
|
113
|
-
const latestPackageInfo = await (
|
|
119
|
+
const latestPackageInfo = await fetchLatestPackageInfo(package_json_1.default.name);
|
|
114
120
|
scaffoldPackageContent.dependencies.xertz = latestPackageInfo.version;
|
|
115
121
|
fse.writeFileSync(scaffoldFile, JSON.stringify(scaffoldPackageContent));
|
|
116
122
|
// Run npm install
|
|
@@ -138,9 +144,8 @@ This is a new post.
|
|
|
138
144
|
});
|
|
139
145
|
console.log(`[new]: Done! Created ${postPath}`);
|
|
140
146
|
}
|
|
141
|
-
async build(exit = true) {
|
|
147
|
+
async build(exit = true, builder = new builder_1.Builder(this.cwd)) {
|
|
142
148
|
console.log(`[build]: Start`);
|
|
143
|
-
const builder = new builder_1.Builder(this.cwd);
|
|
144
149
|
await builder.start();
|
|
145
150
|
console.log(`[build]: Success!`);
|
|
146
151
|
if (exit) {
|
|
@@ -149,16 +154,39 @@ This is a new post.
|
|
|
149
154
|
}
|
|
150
155
|
async serveCommand(preferredPortNumber) {
|
|
151
156
|
console.log(`[serve]: Start`);
|
|
152
|
-
|
|
157
|
+
const builder = new builder_1.Builder(this.cwd);
|
|
158
|
+
await this.build(false, builder);
|
|
153
159
|
const distFolder = path.join(this.cwd, builder_1.Builder.distDirectoryName);
|
|
160
|
+
const changedFilePaths = new Set();
|
|
161
|
+
let fullBuildRequired = false;
|
|
162
|
+
let rebuildTimer;
|
|
163
|
+
let rebuilding = Promise.resolve();
|
|
154
164
|
chokidar
|
|
155
165
|
.watch([path.join(this.cwd)], {
|
|
156
166
|
ignoreInitial: true,
|
|
157
|
-
ignored:
|
|
167
|
+
ignored: [
|
|
168
|
+
distFolder,
|
|
169
|
+
path.join(this.cwd, "node_modules"),
|
|
170
|
+
path.join(this.cwd, ".git")
|
|
171
|
+
]
|
|
158
172
|
})
|
|
159
|
-
.on("all", (event,
|
|
160
|
-
|
|
161
|
-
|
|
173
|
+
.on("all", (event, changedPath) => {
|
|
174
|
+
if (event == "add" || event == "change") {
|
|
175
|
+
changedFilePaths.add(changedPath);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
// Deletes and new directories can leave stale output, so start clean
|
|
179
|
+
fullBuildRequired = true;
|
|
180
|
+
}
|
|
181
|
+
// Editors often emit several events per save; batch them into one rebuild
|
|
182
|
+
clearTimeout(rebuildTimer);
|
|
183
|
+
rebuildTimer = setTimeout(() => {
|
|
184
|
+
const filePaths = [...changedFilePaths];
|
|
185
|
+
const fullBuild = fullBuildRequired;
|
|
186
|
+
changedFilePaths.clear();
|
|
187
|
+
fullBuildRequired = false;
|
|
188
|
+
rebuilding = rebuilding.then(() => this.rebuild(builder, filePaths, fullBuild));
|
|
189
|
+
}, 100);
|
|
162
190
|
});
|
|
163
191
|
const expressApp = express();
|
|
164
192
|
expressApp.use(express.static(distFolder));
|
|
@@ -166,17 +194,34 @@ This is a new post.
|
|
|
166
194
|
expressApp.listen(portNumber);
|
|
167
195
|
console.log(`[serve]: Listening on http://localhost:${portNumber}`);
|
|
168
196
|
}
|
|
197
|
+
async rebuild(builder, changedFilePaths, fullBuild) {
|
|
198
|
+
console.log(`[serve]: Change detected`);
|
|
199
|
+
const startTime = Date.now();
|
|
200
|
+
try {
|
|
201
|
+
let incremental = false;
|
|
202
|
+
if (fullBuild) {
|
|
203
|
+
await builder.start();
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
incremental = await builder.rebuild(changedFilePaths);
|
|
207
|
+
}
|
|
208
|
+
console.log(`[serve]: ${incremental ? "Incremental" : "Full"} rebuild done in ${Date.now() - startTime}ms`);
|
|
209
|
+
}
|
|
210
|
+
catch (err) {
|
|
211
|
+
console.error(`[serve]: Build failed - ${err}`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
169
214
|
async updateCommand() {
|
|
170
215
|
console.log(`[update]: Start`);
|
|
171
216
|
// Update xertz depedency to latest version in package.json
|
|
172
|
-
const latestNpmPackageInfo = await (
|
|
217
|
+
const latestNpmPackageInfo = await fetchLatestPackageInfo(package_json_1.default.name);
|
|
173
218
|
const packageFile = path.join(this.cwd, "package.json");
|
|
174
219
|
const sitePackageInfo = JSON.parse(fse.readFileSync(packageFile, "utf8"));
|
|
175
|
-
sitePackageInfo.dependencies[
|
|
220
|
+
sitePackageInfo.dependencies[package_json_1.default.name] =
|
|
176
221
|
latestNpmPackageInfo.version;
|
|
177
222
|
fse.writeFileSync(packageFile, JSON.stringify(sitePackageInfo, null, 2));
|
|
178
223
|
(0, child_process_1.execSync)(`npm install --silent`, { cwd: this.cwd });
|
|
179
|
-
console.log(`[update]: Successfully updated ${
|
|
224
|
+
console.log(`[update]: Successfully updated ${package_json_1.default.name} to version ${latestNpmPackageInfo.version}.`);
|
|
180
225
|
}
|
|
181
226
|
/* Misc */
|
|
182
227
|
watchSignal() {
|
|
@@ -185,11 +230,11 @@ This is a new post.
|
|
|
185
230
|
});
|
|
186
231
|
}
|
|
187
232
|
async checkForUpdates() {
|
|
188
|
-
const latestNpmPackageInfo = await (
|
|
233
|
+
const latestNpmPackageInfo = await fetchLatestPackageInfo(package_json_1.default.name);
|
|
189
234
|
const sitePackageInfo = JSON.parse(fse.readFileSync(path.join(this.cwd, "package.json"), "utf8"));
|
|
190
235
|
if (latestNpmPackageInfo.version !=
|
|
191
|
-
sitePackageInfo.dependencies[
|
|
192
|
-
console.log("\x1b[33m%s", `New version is available (${latestNpmPackageInfo.version}). Run \`npx ${
|
|
236
|
+
sitePackageInfo.dependencies[package_json_1.default.name]) {
|
|
237
|
+
console.log("\x1b[33m%s", `New version is available (${latestNpmPackageInfo.version}). Run \`npx ${package_json_1.default.name} update\` to update.`, "\x1b[0m");
|
|
193
238
|
}
|
|
194
239
|
}
|
|
195
240
|
exitWithError(errorMessage) {
|
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,14 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xertz",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.59.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
|
},
|
|
10
14
|
"engines": {
|
|
11
|
-
"node": ">=
|
|
15
|
+
"node": ">=18"
|
|
12
16
|
},
|
|
13
17
|
"main": "index.js",
|
|
14
18
|
"bin": "bin/start.js",
|
|
@@ -24,7 +28,7 @@
|
|
|
24
28
|
},
|
|
25
29
|
"dependencies": {
|
|
26
30
|
"@bradymholt/ampify": "^1.4.0",
|
|
27
|
-
"chokidar": "^
|
|
31
|
+
"chokidar": "^4.0.3",
|
|
28
32
|
"dateformat": "^4.5.1",
|
|
29
33
|
"express": "^4.18.1",
|
|
30
34
|
"fs-extra": "^10.1.0",
|
|
@@ -32,7 +36,6 @@
|
|
|
32
36
|
"handlebars": "^4.7.7",
|
|
33
37
|
"js-yaml": "^4.1.0",
|
|
34
38
|
"marked": "^4.0.17",
|
|
35
|
-
"package-json": "^6.5.0",
|
|
36
39
|
"prismjs": "^1.28.0",
|
|
37
40
|
"sass": "^1.52.3"
|
|
38
41
|
},
|
|
@@ -40,15 +43,13 @@
|
|
|
40
43
|
"@types/dateformat": "^5.0.0",
|
|
41
44
|
"@types/express": "^4.17.13",
|
|
42
45
|
"@types/fs-extra": "^9.0.13",
|
|
43
|
-
"@types/jest": "^
|
|
46
|
+
"@types/jest": "^30.0.0",
|
|
44
47
|
"@types/js-yaml": "^4.0.5",
|
|
45
48
|
"@types/marked": "^4.0.3",
|
|
46
49
|
"@types/node": "^18.0.0",
|
|
47
|
-
"@types/package-json": "^5.0.1",
|
|
48
50
|
"@types/prismjs": "^1.26.0",
|
|
49
|
-
"jest": "^
|
|
50
|
-
"
|
|
51
|
-
"ts-jest": "^28.0.5",
|
|
51
|
+
"jest": "^30.5.2",
|
|
52
|
+
"ts-jest": "^29.4.15",
|
|
52
53
|
"ts-node": "^10.8.1",
|
|
53
54
|
"typescript": "^4.7.4"
|
|
54
55
|
}
|
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.58.0"}}
|