@kirigami/php-prepros 1.7.0 → 1.7.1
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/README.md +11 -0
- package/package.json +1 -1
- package/src/prepros.js +19 -7
package/README.md
CHANGED
|
@@ -34,6 +34,7 @@ Part of the **Kirigami** project ecosystem.
|
|
|
34
34
|
- [@kirigami/php-prepros](#kirigamiphp-prepros)
|
|
35
35
|
- [Overview](#overview)
|
|
36
36
|
- [Table of contents](#table-of-contents)
|
|
37
|
+
- [What's new in 1.7.1](#whats-new-in-171)
|
|
37
38
|
- [What's new in 1.7.0](#whats-new-in-170)
|
|
38
39
|
- [What's new in 1.6.0](#whats-new-in-160)
|
|
39
40
|
- [What's new in 1.4.0](#whats-new-in-140)
|
|
@@ -107,6 +108,16 @@ Part of the **Kirigami** project ecosystem.
|
|
|
107
108
|
|
|
108
109
|
---
|
|
109
110
|
|
|
111
|
+
## What's new in 1.7.1
|
|
112
|
+
|
|
113
|
+
- **No side effects on import.** `kirigami.yaml` is now loaded on first use
|
|
114
|
+
(`render()` / `sitemap()` / `runenv()` / `processImages()`), not while the
|
|
115
|
+
module is being imported. `import '@kirigami/php-prepros'` from a directory
|
|
116
|
+
with no project no longer throws — which is what made `kiri build --help` /
|
|
117
|
+
`kiri export --help` / `kiri run --help` crash instead of printing their help.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
110
121
|
## What's new in 1.7.0
|
|
111
122
|
|
|
112
123
|
- **`META`** class — a `<head>` SEO / social metadata generator, the companion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kirigami/php-prepros",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "PHP preprocessor for the Kirigami static site generator. Compile PHP page templates to clean, deployable HTML — with zero server dependency.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kirigami",
|
package/src/prepros.js
CHANGED
|
@@ -12,16 +12,25 @@ const __modules = new Map;
|
|
|
12
12
|
const __project = process.cwd();
|
|
13
13
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
14
14
|
const __configpath = path.join(__project, 'kirigami.yaml');
|
|
15
|
-
let __root
|
|
16
|
-
let __php
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
let __root = null;
|
|
16
|
+
let __php = null;
|
|
17
|
+
let __config = null;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
// Load and cache kirigami.yaml on first use. Deferred (not run at import) so
|
|
21
|
+
// `import '@kirigami/php-prepros'` has no side effects — e.g. `kiri build -h`
|
|
22
|
+
// can pull the module in with no project on disk.
|
|
23
|
+
const loadConfig = async () => {
|
|
24
|
+
if (__config) return __config;
|
|
25
|
+
if (!fs.existsSync(__configpath)) throw `Config file not found: ${__configpath}`;
|
|
26
|
+
__config = await walkFile(__configpath);
|
|
27
|
+
if (!__config) throw `Invalid config file: ${__configpath}`;
|
|
28
|
+
return __config;
|
|
29
|
+
}
|
|
22
30
|
|
|
23
31
|
|
|
24
32
|
const getPHPInstance = async () => {
|
|
33
|
+
const config = await loadConfig();
|
|
25
34
|
if(!__php) {
|
|
26
35
|
if(config?.kirigami?.root === undefined) throw `Missing prepros:root property in config file: ${__configpath}`;
|
|
27
36
|
__root = path.join(__project, config.kirigami.root);
|
|
@@ -100,6 +109,7 @@ const getPHPInstance = async () => {
|
|
|
100
109
|
|
|
101
110
|
|
|
102
111
|
const mountPath = async (localPath, virtualDir, php) => {
|
|
112
|
+
const config = await loadConfig();
|
|
103
113
|
php = php || await getPHPInstance();
|
|
104
114
|
if(!path.isAbsolute(localPath)) localPath = path.join(__project, localPath);
|
|
105
115
|
virtualDir = virtualDir || path.posix.join('/project', localPath.replace(__project + path.sep, ''));
|
|
@@ -251,6 +261,7 @@ const processImages = async (jobs = []) => {
|
|
|
251
261
|
|
|
252
262
|
|
|
253
263
|
const render = async (file = '.', phpIncludes = []) => {
|
|
264
|
+
const config = await loadConfig();
|
|
254
265
|
const target = path.resolve(config?.kirigami?.root, file);
|
|
255
266
|
const fsvm = path.join('/project', config?.kirigami?.root, file).replace(/\\/g, '/');
|
|
256
267
|
await mountPath(target);
|
|
@@ -278,6 +289,7 @@ const render = async (file = '.', phpIncludes = []) => {
|
|
|
278
289
|
|
|
279
290
|
|
|
280
291
|
const sitemap = async () => {
|
|
292
|
+
const config = await loadConfig();
|
|
281
293
|
await mountPath(config?.kirigami?.root);
|
|
282
294
|
return run(['sitemap']);
|
|
283
295
|
}
|