aeria-populate 0.0.23 → 0.0.25
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/cli.js +38 -2
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getDatabase, insert, createContext } from 'aeria';
|
|
1
|
+
import { getDatabase, insert, createContext, getValueFromPath } from 'aeria';
|
|
2
2
|
import { parseArgs, styleText, inspect } from 'node:util';
|
|
3
3
|
import * as fs from 'node:fs';
|
|
4
4
|
import * as yaml from 'yaml';
|
|
@@ -37,8 +37,43 @@ const isValidFrontmatterObject = (value) => {
|
|
|
37
37
|
&& typeof value.unique === 'string'
|
|
38
38
|
&& typeof value.document === 'object');
|
|
39
39
|
};
|
|
40
|
+
const parseInterpolationFallback = (text, obj) => {
|
|
41
|
+
if ((text.startsWith('"') && text.endsWith('"')) ||
|
|
42
|
+
(text.startsWith("'") && text.endsWith("'"))) {
|
|
43
|
+
return text.slice(1, -1);
|
|
44
|
+
}
|
|
45
|
+
if (!isNaN(Number(text))) {
|
|
46
|
+
return text;
|
|
47
|
+
}
|
|
48
|
+
switch (text) {
|
|
49
|
+
case 'true':
|
|
50
|
+
case 'false': {
|
|
51
|
+
return text;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return getValueFromPath(obj, text);
|
|
55
|
+
};
|
|
56
|
+
const interpolate = (text) => {
|
|
57
|
+
const INTERPOLATION_OBJECT = {
|
|
58
|
+
env: process.env,
|
|
59
|
+
};
|
|
60
|
+
return text.replace(/{{\s*([^}]+)\s*}}/g, (_, expr) => {
|
|
61
|
+
if (typeof expr !== 'string') {
|
|
62
|
+
return '';
|
|
63
|
+
}
|
|
64
|
+
const [path, fallback] = expr.split('||').map((s) => s.trim());
|
|
65
|
+
let value = getValueFromPath(INTERPOLATION_OBJECT, path);
|
|
66
|
+
if (value === undefined && fallback) {
|
|
67
|
+
value = parseInterpolationFallback(fallback, INTERPOLATION_OBJECT);
|
|
68
|
+
}
|
|
69
|
+
return value !== undefined && value !== null
|
|
70
|
+
? String(value)
|
|
71
|
+
: '';
|
|
72
|
+
});
|
|
73
|
+
};
|
|
40
74
|
const parseMarkdown = async (text) => {
|
|
41
|
-
const
|
|
75
|
+
const interpolatedText = interpolate(text);
|
|
76
|
+
const [, frontmatterString, ...splitContent] = interpolatedText.split('---');
|
|
42
77
|
let content = splitContent.join('---').trim();
|
|
43
78
|
if (opts.compileMarkdown) {
|
|
44
79
|
content = await markdown.parse(content);
|
|
@@ -112,6 +147,7 @@ const visitFile = async (file) => {
|
|
|
112
147
|
};
|
|
113
148
|
}
|
|
114
149
|
catch (err) {
|
|
150
|
+
console.log(styleText(['red'], 'x'), 'error when visiting', file);
|
|
115
151
|
console.trace(err);
|
|
116
152
|
}
|
|
117
153
|
return {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aeria-populate",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.25",
|
|
5
5
|
"description": "",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"keywords": [],
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"aeria": "file:../aeria"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"aeria": "^0.0.
|
|
23
|
+
"aeria": "^0.0.349"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"chokidar": "^5.0.0",
|