@oss-ma/tpl 1.0.1 → 1.0.3
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/engine/copy.js
CHANGED
|
@@ -15,41 +15,71 @@ const TEXT_EXT = new Set([
|
|
|
15
15
|
".scss",
|
|
16
16
|
".txt",
|
|
17
17
|
".env",
|
|
18
|
-
".gitignore",
|
|
19
18
|
".editorconfig",
|
|
20
19
|
".gitattributes",
|
|
21
20
|
".cjs",
|
|
22
21
|
".mjs"
|
|
23
22
|
]);
|
|
23
|
+
// Files that ship without dot, but must be generated as dotfiles.
|
|
24
|
+
const DOTFILE_MAP = {
|
|
25
|
+
"gitignore": ".gitignore",
|
|
26
|
+
"editorconfig": ".editorconfig",
|
|
27
|
+
"gitattributes": ".gitattributes",
|
|
28
|
+
"prettierrc.json": ".prettierrc.json",
|
|
29
|
+
"env": ".env",
|
|
30
|
+
"env.example": ".env.example",
|
|
31
|
+
"nvmrc": ".nvmrc",
|
|
32
|
+
"node-version": ".node-version",
|
|
33
|
+
};
|
|
34
|
+
function mapDestName(name) {
|
|
35
|
+
if (name.startsWith("."))
|
|
36
|
+
return name;
|
|
37
|
+
return DOTFILE_MAP[name] ?? name;
|
|
38
|
+
}
|
|
24
39
|
function isTextFile(filePath) {
|
|
25
40
|
const ext = path.extname(filePath).toLowerCase();
|
|
26
41
|
if (TEXT_EXT.has(ext))
|
|
27
42
|
return true;
|
|
28
|
-
// Special dotfiles with no extension
|
|
29
43
|
const base = path.basename(filePath);
|
|
44
|
+
// Special cases without extension
|
|
30
45
|
if (base === "Dockerfile")
|
|
31
46
|
return true;
|
|
47
|
+
if (base === "gitignore")
|
|
48
|
+
return true;
|
|
49
|
+
if (base === "editorconfig")
|
|
50
|
+
return true;
|
|
51
|
+
if (base === "gitattributes")
|
|
52
|
+
return true;
|
|
53
|
+
if (base === "nvmrc")
|
|
54
|
+
return true;
|
|
55
|
+
if (base === "node-version")
|
|
56
|
+
return true;
|
|
32
57
|
return false;
|
|
33
58
|
}
|
|
59
|
+
async function copyOne(srcPath, destPath, vars) {
|
|
60
|
+
await fs.ensureDir(path.dirname(destPath));
|
|
61
|
+
if (isTextFile(srcPath)) {
|
|
62
|
+
const raw = await fs.readFile(srcPath, "utf8");
|
|
63
|
+
const rendered = renderString(raw, vars);
|
|
64
|
+
await fs.writeFile(destPath, rendered, "utf8");
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
await fs.copyFile(srcPath, destPath);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
34
70
|
export async function copyAndRenderDir(srcDir, destDir, vars) {
|
|
35
71
|
await fs.ensureDir(destDir);
|
|
36
72
|
const entries = await fs.readdir(srcDir, { withFileTypes: true });
|
|
37
|
-
for (const
|
|
38
|
-
const srcPath = path.join(srcDir,
|
|
39
|
-
const
|
|
40
|
-
|
|
73
|
+
for (const entry of entries) {
|
|
74
|
+
const srcPath = path.join(srcDir, entry.name);
|
|
75
|
+
const destName = mapDestName(entry.name);
|
|
76
|
+
const destPath = path.join(destDir, destName);
|
|
77
|
+
if (entry.isDirectory()) {
|
|
41
78
|
await copyAndRenderDir(srcPath, destPath, vars);
|
|
42
79
|
continue;
|
|
43
80
|
}
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const out = renderString(raw, vars);
|
|
48
|
-
await fs.outputFile(destPath, out, "utf8");
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
await fs.copyFile(srcPath, destPath);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
81
|
+
if (!entry.isFile())
|
|
82
|
+
continue;
|
|
83
|
+
await copyOne(srcPath, destPath, vars);
|
|
54
84
|
}
|
|
55
85
|
}
|
package/package.json
CHANGED