@podosoft/podokit-template-engine 0.1.1 → 0.2.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/index.d.ts +7 -0
- package/dist/index.js +20 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,13 @@ export declare function resolveOutputName(name: string): string;
|
|
|
19
19
|
* as needed. Binary files are copied verbatim.
|
|
20
20
|
*/
|
|
21
21
|
export declare function copyTemplate(srcDir: string, destDir: string, vars: TemplateVars): void;
|
|
22
|
+
/**
|
|
23
|
+
* Insert `text` on its own line immediately after the first line containing
|
|
24
|
+
* `marker`, preserving the marker line and its indentation. No-op if `text`
|
|
25
|
+
* is already present (so re-applying a module is idempotent). Throws if the
|
|
26
|
+
* marker is not found.
|
|
27
|
+
*/
|
|
28
|
+
export declare function insertAtMarker(content: string, marker: string, text: string): string;
|
|
22
29
|
/**
|
|
23
30
|
* Deep-merge `overlay` onto `base`. Objects merge recursively, arrays are
|
|
24
31
|
* concatenated and de-duplicated, and scalar overlay values win. Neither input
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.renderTokens = renderTokens;
|
|
4
4
|
exports.resolveOutputName = resolveOutputName;
|
|
5
5
|
exports.copyTemplate = copyTemplate;
|
|
6
|
+
exports.insertAtMarker = insertAtMarker;
|
|
6
7
|
exports.mergePackageJson = mergePackageJson;
|
|
7
8
|
const node_fs_1 = require("node:fs");
|
|
8
9
|
const node_path_1 = require("node:path");
|
|
@@ -52,6 +53,25 @@ function copyTemplate(srcDir, destDir, vars) {
|
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Insert `text` on its own line immediately after the first line containing
|
|
58
|
+
* `marker`, preserving the marker line and its indentation. No-op if `text`
|
|
59
|
+
* is already present (so re-applying a module is idempotent). Throws if the
|
|
60
|
+
* marker is not found.
|
|
61
|
+
*/
|
|
62
|
+
function insertAtMarker(content, marker, text) {
|
|
63
|
+
if (content.includes(text)) {
|
|
64
|
+
return content;
|
|
65
|
+
}
|
|
66
|
+
const lines = content.split("\n");
|
|
67
|
+
const index = lines.findIndex((line) => line.includes(marker));
|
|
68
|
+
if (index === -1) {
|
|
69
|
+
throw new Error(`Marker not found: ${marker}`);
|
|
70
|
+
}
|
|
71
|
+
const indent = lines[index].match(/^\s*/)?.[0] ?? "";
|
|
72
|
+
lines.splice(index, 0, `${indent}${text}`);
|
|
73
|
+
return lines.join("\n");
|
|
74
|
+
}
|
|
55
75
|
function isPlainObject(value) {
|
|
56
76
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
57
77
|
}
|