create-kide-app 0.3.3 → 0.3.4
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/index.js +30 -73
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -5,7 +5,6 @@ import { execFileSync, execSync, spawn } from "node:child_process";
|
|
|
5
5
|
import {
|
|
6
6
|
cpSync,
|
|
7
7
|
existsSync,
|
|
8
|
-
mkdirSync,
|
|
9
8
|
readdirSync,
|
|
10
9
|
readFileSync,
|
|
11
10
|
rmSync,
|
|
@@ -97,44 +96,24 @@ const validateProjectName = (value) => {
|
|
|
97
96
|
};
|
|
98
97
|
|
|
99
98
|
// Resolve the latest release tag (v-prefixed semver) so scaffolds pin to a
|
|
100
|
-
// deliberate release instead of whatever HEAD happens to be.
|
|
101
|
-
//
|
|
102
|
-
// tags resolve to the commit, not the tag object). Returns null when the repo
|
|
103
|
-
// has no tags (falls back to the default branch).
|
|
99
|
+
// deliberate release instead of whatever HEAD happens to be. Returns null when
|
|
100
|
+
// the repo has no tags (falls back to the default branch).
|
|
104
101
|
const resolveLatestTag = () => {
|
|
105
102
|
try {
|
|
106
103
|
const output = execSync(
|
|
107
104
|
`git ls-remote --tags --sort=-v:refname ${REPO} "v*"`,
|
|
108
105
|
{ stdio: "pipe" },
|
|
109
106
|
).toString();
|
|
110
|
-
let tag = null;
|
|
111
|
-
let commit = null;
|
|
112
107
|
for (const line of output.split("\n")) {
|
|
113
|
-
const match = line.match(
|
|
114
|
-
if (
|
|
115
|
-
if (!tag) {
|
|
116
|
-
tag = match[2];
|
|
117
|
-
commit = match[1];
|
|
118
|
-
}
|
|
119
|
-
if (match[2] === tag && match[3]) commit = match[1];
|
|
108
|
+
const match = line.match(/refs\/tags\/(v[0-9][^^\s]*)$/);
|
|
109
|
+
if (match) return match[1];
|
|
120
110
|
}
|
|
121
|
-
if (tag) return { tag, commit };
|
|
122
111
|
} catch {
|
|
123
112
|
// Network/git hiccup — fall back to default branch
|
|
124
113
|
}
|
|
125
114
|
return null;
|
|
126
115
|
};
|
|
127
116
|
|
|
128
|
-
// GitHub serves any tag as a single gzipped tarball — one HTTP request instead of
|
|
129
|
-
// git protocol negotiation, and no .git dir to delete afterwards. Only applicable
|
|
130
|
-
// for github.com remotes (KIDE_TEMPLATE_REPO may point anywhere, incl. file://).
|
|
131
|
-
const githubTarballUrl = (tag) => {
|
|
132
|
-
const match = REPO.match(/^https:\/\/github\.com\/([^/]+)\/([^/]+?)(?:\.git)?$/);
|
|
133
|
-
return match && tag
|
|
134
|
-
? `https://codeload.github.com/${match[1]}/${match[2]}/tar.gz/refs/tags/${tag}`
|
|
135
|
-
: null;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
117
|
// --- CLI flags (non-interactive use: CI, agents, testing) ---
|
|
139
118
|
// Any prompt whose answer is supplied by a flag is skipped. Example:
|
|
140
119
|
// create-kide-app my-app --starter=marketing --seed --mode=embedded --target=local --no-github --no-dev
|
|
@@ -216,58 +195,36 @@ async function main() {
|
|
|
216
195
|
|
|
217
196
|
s.start("Downloading template");
|
|
218
197
|
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
let templateCommit = resolved?.commit ?? null;
|
|
198
|
+
const templateRef = resolveLatestTag();
|
|
199
|
+
let templateCommit = null;
|
|
222
200
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
235
|
-
});
|
|
236
|
-
downloaded = true;
|
|
237
|
-
} catch {
|
|
238
|
-
rmSync(projectDir, { recursive: true, force: true });
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if (!downloaded) {
|
|
201
|
+
try {
|
|
202
|
+
const branchArgs = templateRef ? ["--branch", templateRef] : [];
|
|
203
|
+
// execFileSync, not execSync: no shell, so projectDir is passed as one argv entry
|
|
204
|
+
// and can never be reinterpreted as a command regardless of what it contains.
|
|
205
|
+
execFileSync(
|
|
206
|
+
"git",
|
|
207
|
+
["clone", "--depth", "1", ...branchArgs, REPO, projectDir],
|
|
208
|
+
{
|
|
209
|
+
stdio: "pipe",
|
|
210
|
+
},
|
|
211
|
+
);
|
|
243
212
|
try {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
{
|
|
251
|
-
stdio: "pipe",
|
|
252
|
-
},
|
|
253
|
-
);
|
|
254
|
-
try {
|
|
255
|
-
templateCommit = execSync("git rev-parse HEAD", {
|
|
256
|
-
cwd: projectDir,
|
|
257
|
-
stdio: "pipe",
|
|
258
|
-
})
|
|
259
|
-
.toString()
|
|
260
|
-
.trim();
|
|
261
|
-
} catch {
|
|
262
|
-
// best-effort — stamp without a commit hash
|
|
263
|
-
}
|
|
264
|
-
rmSync(path.join(projectDir, ".git"), { recursive: true, force: true });
|
|
213
|
+
templateCommit = execSync("git rev-parse HEAD", {
|
|
214
|
+
cwd: projectDir,
|
|
215
|
+
stdio: "pipe",
|
|
216
|
+
})
|
|
217
|
+
.toString()
|
|
218
|
+
.trim();
|
|
265
219
|
} catch {
|
|
266
|
-
|
|
267
|
-
s.stop("Failed to download template.");
|
|
268
|
-
p.cancel("Check your network connection.");
|
|
269
|
-
process.exit(1);
|
|
220
|
+
// best-effort — stamp without a commit hash
|
|
270
221
|
}
|
|
222
|
+
rmSync(path.join(projectDir, ".git"), { recursive: true, force: true });
|
|
223
|
+
} catch {
|
|
224
|
+
rmSync(projectDir, { recursive: true, force: true });
|
|
225
|
+
s.stop("Failed to download template.");
|
|
226
|
+
p.cancel("Check your network connection.");
|
|
227
|
+
process.exit(1);
|
|
271
228
|
}
|
|
272
229
|
|
|
273
230
|
// Remove files that shouldn't be in the scaffold
|