@palettelab/cli 0.3.14 → 0.3.15
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/lib/commands/init.js +31 -5
- package/package.json +1 -1
package/lib/commands/init.js
CHANGED
|
@@ -52,13 +52,39 @@ function copyLocalFallback(destDir, template) {
|
|
|
52
52
|
return true
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
function
|
|
55
|
+
function walkFiles(dir, visit) {
|
|
56
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
57
|
+
if (["node_modules", ".venv", ".palette", "dist", "__pycache__"].includes(entry.name)) continue
|
|
58
|
+
const abs = path.join(dir, entry.name)
|
|
59
|
+
if (entry.isDirectory()) {
|
|
60
|
+
walkFiles(abs, visit)
|
|
61
|
+
} else if (entry.isFile()) {
|
|
62
|
+
visit(abs)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function rewriteScaffold(destDir, slug, displayName) {
|
|
56
68
|
const manifestPath = path.join(destDir, "palette-plugin.json")
|
|
57
69
|
if (!fs.existsSync(manifestPath)) return
|
|
58
70
|
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"))
|
|
59
|
-
manifest.id
|
|
60
|
-
|
|
61
|
-
|
|
71
|
+
const originalId = manifest.id
|
|
72
|
+
if (originalId && originalId !== slug) {
|
|
73
|
+
walkFiles(destDir, (filePath) => {
|
|
74
|
+
try {
|
|
75
|
+
const before = fs.readFileSync(filePath, "utf8")
|
|
76
|
+
const after = before.split(originalId).join(slug)
|
|
77
|
+
if (after !== before) fs.writeFileSync(filePath, after)
|
|
78
|
+
} catch (_err) {
|
|
79
|
+
// Ignore non-text files. Templates are expected to be text, but this
|
|
80
|
+
// keeps init resilient if an image or binary fixture is added later.
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
const rewrittenManifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"))
|
|
85
|
+
rewrittenManifest.id = slug
|
|
86
|
+
rewrittenManifest.name = displayName
|
|
87
|
+
fs.writeFileSync(manifestPath, JSON.stringify(rewrittenManifest, null, 2) + "\n")
|
|
62
88
|
}
|
|
63
89
|
|
|
64
90
|
function getOpt(args, name) {
|
|
@@ -111,7 +137,7 @@ async function run(args, { cwd }) {
|
|
|
111
137
|
|
|
112
138
|
fs.cpSync(tmp, destDir, { recursive: true })
|
|
113
139
|
fs.rmSync(tmp, { recursive: true, force: true })
|
|
114
|
-
|
|
140
|
+
rewriteScaffold(destDir, slug, displayName)
|
|
115
141
|
|
|
116
142
|
console.log(`[pltt] created ${destDir}`)
|
|
117
143
|
console.log("[pltt] next steps:")
|