@jsonpages/cli 3.0.6 → 3.0.7
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/package.json +24 -29
- package/src/index.js +5 -6
- package/tsconfig.json +13 -0
- package/assets/src_tenant_alpha.sh +0 -3267
- package/src/projection.js +0 -76
package/src/projection.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cross-platform source projection: parses the deterministic shell script
|
|
3
|
-
* (heredoc format) and writes all files via Node.js fs. No shell execution.
|
|
4
|
-
* Single source of truth: assets/src_tenant_alpha.sh
|
|
5
|
-
*/
|
|
6
|
-
import fs from 'fs-extra';
|
|
7
|
-
import path from 'path';
|
|
8
|
-
import { fileURLToPath } from 'url';
|
|
9
|
-
|
|
10
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
-
|
|
12
|
-
const HEREDOC_MARKER = 'END_OF_FILE_CONTENT';
|
|
13
|
-
const HEREDOC_PATTERN = /cat << 'END_OF_FILE_CONTENT' > "([^"]+)"\n/g;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Parse shell script content (heredoc format) into a map of relativePath -> content.
|
|
17
|
-
* @param {string} shContent - Raw content of src_tenant_alpha.sh
|
|
18
|
-
* @returns {Record<string, string>}
|
|
19
|
-
*/
|
|
20
|
-
export function parseShToManifest(shContent) {
|
|
21
|
-
const manifest = Object.create(null);
|
|
22
|
-
let match;
|
|
23
|
-
while ((match = HEREDOC_PATTERN.exec(shContent)) !== null) {
|
|
24
|
-
const filePath = match[1];
|
|
25
|
-
const contentStart = match.index + match[0].length;
|
|
26
|
-
const contentEnd = findHeredocEnd(shContent, contentStart);
|
|
27
|
-
const content =
|
|
28
|
-
contentEnd === -1
|
|
29
|
-
? shContent.slice(contentStart)
|
|
30
|
-
: shContent.slice(contentStart, contentEnd);
|
|
31
|
-
manifest[filePath] = content;
|
|
32
|
-
}
|
|
33
|
-
return manifest;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function findHeredocEnd(text, fromIndex) {
|
|
37
|
-
let i = fromIndex;
|
|
38
|
-
while (i < text.length) {
|
|
39
|
-
const lineEnd = text.indexOf('\n', i);
|
|
40
|
-
const line = lineEnd === -1 ? text.slice(i) : text.slice(i, lineEnd);
|
|
41
|
-
if (line.trim() === HEREDOC_MARKER) {
|
|
42
|
-
return i;
|
|
43
|
-
}
|
|
44
|
-
i = lineEnd === -1 ? text.length : lineEnd + 1;
|
|
45
|
-
}
|
|
46
|
-
return -1;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Project all tenant source files into targetDir using only Node.js.
|
|
51
|
-
* Reads the script from scriptPath (default: CLI assets/src_tenant_alpha.sh).
|
|
52
|
-
* @param {string} targetDir - Absolute path to the new tenant directory
|
|
53
|
-
* @param {string} [scriptPath] - Optional path to .sh script (default: bundled asset)
|
|
54
|
-
* @returns {Promise<{ fileCount: number }>}
|
|
55
|
-
*/
|
|
56
|
-
export async function projectSrc(targetDir, scriptPath) {
|
|
57
|
-
const resolvedPath =
|
|
58
|
-
scriptPath ||
|
|
59
|
-
path.resolve(__dirname, '../assets/src_tenant_alpha.sh');
|
|
60
|
-
|
|
61
|
-
if (!(await fs.pathExists(resolvedPath))) {
|
|
62
|
-
throw new Error(`Projection script not found: ${resolvedPath}`);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const shContent = await fs.readFile(resolvedPath, 'utf8');
|
|
66
|
-
const manifest = parseShToManifest(shContent);
|
|
67
|
-
const entries = Object.entries(manifest);
|
|
68
|
-
|
|
69
|
-
for (const [relativePath, content] of entries) {
|
|
70
|
-
const absolutePath = path.join(targetDir, relativePath);
|
|
71
|
-
await fs.ensureDir(path.dirname(absolutePath));
|
|
72
|
-
await fs.writeFile(absolutePath, content, 'utf8');
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return { fileCount: entries.length };
|
|
76
|
-
}
|