create-astro 3.2.0 → 3.2.2
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.js +93 -28
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -176,7 +176,7 @@ import detectPackageManager2 from "which-pm-runs";
|
|
|
176
176
|
|
|
177
177
|
// src/messages.ts
|
|
178
178
|
import { color, say as houston, label, spinner as load } from "@astrojs/cli-kit";
|
|
179
|
-
import { align, sleep
|
|
179
|
+
import { align, sleep } from "@astrojs/cli-kit/utils";
|
|
180
180
|
import fetch from "node-fetch-native";
|
|
181
181
|
import { exec } from "node:child_process";
|
|
182
182
|
|
|
@@ -204,28 +204,30 @@ import detectPackageManager from "which-pm-runs";
|
|
|
204
204
|
// src/shell.ts
|
|
205
205
|
import { spawn } from "node:child_process";
|
|
206
206
|
import { text as textFromStream } from "node:stream/consumers";
|
|
207
|
-
import { setTimeout as sleep } from "node:timers/promises";
|
|
208
207
|
var text = (stream) => stream ? textFromStream(stream).then((t) => t.trimEnd()) : "";
|
|
209
208
|
async function shell(command, flags, opts = {}) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if (opts.timeout) {
|
|
220
|
-
sleep(opts.timeout).then(() => {
|
|
221
|
-
controller.abort();
|
|
222
|
-
throw { stdout: stdout2, stderr, exitCode: 1 };
|
|
209
|
+
let child;
|
|
210
|
+
let stdout2 = "";
|
|
211
|
+
let stderr = "";
|
|
212
|
+
try {
|
|
213
|
+
child = spawn(command, flags, {
|
|
214
|
+
cwd: opts.cwd,
|
|
215
|
+
shell: true,
|
|
216
|
+
stdio: opts.stdio,
|
|
217
|
+
timeout: opts.timeout
|
|
223
218
|
});
|
|
219
|
+
const done = new Promise((resolve) => child.on("close", resolve));
|
|
220
|
+
[stdout2, stderr] = await Promise.all([text(child.stdout), text(child.stderr)]);
|
|
221
|
+
await done;
|
|
222
|
+
} catch (e) {
|
|
223
|
+
throw { stdout: stdout2, stderr, exitCode: 1 };
|
|
224
224
|
}
|
|
225
|
-
await new Promise((resolve) => child.on("exit", resolve));
|
|
226
225
|
const { exitCode } = child;
|
|
226
|
+
if (exitCode === null) {
|
|
227
|
+
throw new Error("Timeout");
|
|
228
|
+
}
|
|
227
229
|
if (exitCode !== 0) {
|
|
228
|
-
throw
|
|
230
|
+
throw new Error(stderr);
|
|
229
231
|
}
|
|
230
232
|
return { stdout: stdout2, stderr, exitCode };
|
|
231
233
|
}
|
|
@@ -300,10 +302,12 @@ var getVersion = () => new Promise(async (resolve) => {
|
|
|
300
302
|
var log = (message) => stdout.write(message + "\n");
|
|
301
303
|
var banner = async (version) => log(
|
|
302
304
|
`
|
|
303
|
-
${label("astro", color.bgGreen, color.black)}
|
|
305
|
+
${label("astro", color.bgGreen, color.black)}${version ? " " + color.green(color.bold(`v${version}`)) : ""} ${color.bold("Launch sequence initiated.")}`
|
|
304
306
|
);
|
|
307
|
+
var bannerAbort = () => log(`
|
|
308
|
+
${label("astro", color.bgRed)} ${color.bold("Launch sequence aborted.")}`);
|
|
305
309
|
var info = async (prefix, text2) => {
|
|
306
|
-
await
|
|
310
|
+
await sleep(100);
|
|
307
311
|
if (stdout.columns < 80) {
|
|
308
312
|
log(`${" ".repeat(5)} ${color.cyan("\u25FC")} ${color.cyan(prefix)}`);
|
|
309
313
|
log(`${" ".repeat(9)}${color.dim(text2)}`);
|
|
@@ -322,19 +326,19 @@ var error = async (prefix, text2) => {
|
|
|
322
326
|
var typescriptByDefault = async () => {
|
|
323
327
|
await info(`No worries!`, "TypeScript is supported in Astro by default,");
|
|
324
328
|
log(`${" ".repeat(9)}${color.dim("but you are free to continue writing JavaScript instead.")}`);
|
|
325
|
-
await
|
|
329
|
+
await sleep(1e3);
|
|
326
330
|
};
|
|
327
331
|
var nextSteps = async ({ projectDir, devCmd }) => {
|
|
328
332
|
const max = stdout.columns;
|
|
329
333
|
const prefix = max < 80 ? " " : " ".repeat(9);
|
|
330
|
-
await
|
|
334
|
+
await sleep(200);
|
|
331
335
|
log(
|
|
332
336
|
`
|
|
333
337
|
${color.bgCyan(` ${color.black("next")} `)} ${color.bold(
|
|
334
338
|
"Liftoff confirmed. Explore your project!"
|
|
335
339
|
)}`
|
|
336
340
|
);
|
|
337
|
-
await
|
|
341
|
+
await sleep(100);
|
|
338
342
|
if (projectDir !== "") {
|
|
339
343
|
projectDir = projectDir.includes(" ") ? `"./${projectDir}"` : `./${projectDir}`;
|
|
340
344
|
const enter = [
|
|
@@ -348,16 +352,16 @@ ${prefix}Enter your project directory using`,
|
|
|
348
352
|
log(
|
|
349
353
|
`${prefix}Run ${color.cyan(devCmd)} to start the dev server. ${color.cyan("CTRL+C")} to stop.`
|
|
350
354
|
);
|
|
351
|
-
await
|
|
355
|
+
await sleep(100);
|
|
352
356
|
log(
|
|
353
357
|
`${prefix}Add frameworks like ${color.cyan(`react`)} or ${color.cyan(
|
|
354
358
|
"tailwind"
|
|
355
359
|
)} using ${color.cyan("astro add")}.`
|
|
356
360
|
);
|
|
357
|
-
await
|
|
361
|
+
await sleep(100);
|
|
358
362
|
log(`
|
|
359
363
|
${prefix}Stuck? Join us at ${color.cyan(`https://astro.build/chat`)}`);
|
|
360
|
-
await
|
|
364
|
+
await sleep(200);
|
|
361
365
|
};
|
|
362
366
|
function printHelp({
|
|
363
367
|
commandName,
|
|
@@ -385,7 +389,7 @@ function printHelp({
|
|
|
385
389
|
if (headline) {
|
|
386
390
|
message.push(
|
|
387
391
|
linebreak(),
|
|
388
|
-
`${title(commandName)} ${color.green(`v${"3.2.
|
|
392
|
+
`${title(commandName)} ${color.green(`v${"3.2.2"}`)} ${headline}`
|
|
389
393
|
);
|
|
390
394
|
}
|
|
391
395
|
if (usage) {
|
|
@@ -643,7 +647,7 @@ async function intro(ctx) {
|
|
|
643
647
|
import path3 from "node:path";
|
|
644
648
|
async function next(ctx) {
|
|
645
649
|
let projectDir = path3.relative(process.cwd(), ctx.cwd);
|
|
646
|
-
const devCmd = ctx.pkgManager === "npm" ? "npm run dev" : `${ctx.pkgManager} dev`;
|
|
650
|
+
const devCmd = ctx.pkgManager === "npm" ? "npm run dev" : ctx.pkgManager === "bun" ? "bun run dev" : `${ctx.pkgManager} dev`;
|
|
647
651
|
await nextSteps({ projectDir, devCmd });
|
|
648
652
|
if (!ctx.skipHouston) {
|
|
649
653
|
await say(["Good luck out there, astronaut! \u{1F680}"]);
|
|
@@ -1033,6 +1037,65 @@ async function setupTypeScript(value, { cwd }) {
|
|
|
1033
1037
|
}
|
|
1034
1038
|
}
|
|
1035
1039
|
|
|
1040
|
+
// src/actions/verify.ts
|
|
1041
|
+
import { color as color8 } from "@astrojs/cli-kit";
|
|
1042
|
+
import fetch2 from "node-fetch-native";
|
|
1043
|
+
import dns from "node:dns/promises";
|
|
1044
|
+
async function verify(ctx) {
|
|
1045
|
+
if (!ctx.dryRun) {
|
|
1046
|
+
const online = await isOnline();
|
|
1047
|
+
if (!online) {
|
|
1048
|
+
bannerAbort();
|
|
1049
|
+
log("");
|
|
1050
|
+
error("error", `Unable to connect to the internet.`);
|
|
1051
|
+
ctx.exit(1);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
if (ctx.template) {
|
|
1055
|
+
const ok = await verifyTemplate(ctx.template, ctx.ref);
|
|
1056
|
+
if (!ok) {
|
|
1057
|
+
bannerAbort();
|
|
1058
|
+
log("");
|
|
1059
|
+
error("error", `Template ${color8.reset(ctx.template)} ${color8.dim("could not be found!")}`);
|
|
1060
|
+
await info("check", "https://astro.build/examples");
|
|
1061
|
+
ctx.exit(1);
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
function isOnline() {
|
|
1066
|
+
return dns.lookup("github.com").then(
|
|
1067
|
+
() => true,
|
|
1068
|
+
() => false
|
|
1069
|
+
);
|
|
1070
|
+
}
|
|
1071
|
+
async function verifyTemplate(tmpl, ref) {
|
|
1072
|
+
const target = getTemplateTarget(tmpl, ref);
|
|
1073
|
+
const { repo, subdir, ref: branch } = parseGitURI(target.replace("github:", ""));
|
|
1074
|
+
const url = new URL(`/repos/${repo}/contents${subdir}?ref=${branch}`, "https://api.github.com/");
|
|
1075
|
+
let res = await fetch2(url.toString(), {
|
|
1076
|
+
headers: {
|
|
1077
|
+
Accept: "application/vnd.github+json",
|
|
1078
|
+
"X-GitHub-Api-Version": "2022-11-28"
|
|
1079
|
+
}
|
|
1080
|
+
});
|
|
1081
|
+
if (res.status === 403) {
|
|
1082
|
+
res = await fetch2(`https://github.com/${repo}/tree/${branch}${subdir}`);
|
|
1083
|
+
}
|
|
1084
|
+
return res.status === 200;
|
|
1085
|
+
}
|
|
1086
|
+
var GIT_RE = /^(?<repo>[\w.-]+\/[\w.-]+)(?<subdir>[^#]+)?(?<ref>#[\w.-]+)?/;
|
|
1087
|
+
function parseGitURI(input) {
|
|
1088
|
+
var _a;
|
|
1089
|
+
const m = (_a = input.match(GIT_RE)) == null ? void 0 : _a.groups;
|
|
1090
|
+
if (!m)
|
|
1091
|
+
throw new Error(`Unable to parse "${input}"`);
|
|
1092
|
+
return {
|
|
1093
|
+
repo: m.repo,
|
|
1094
|
+
subdir: m.subdir || "/",
|
|
1095
|
+
ref: m.ref ? m.ref.slice(1) : "main"
|
|
1096
|
+
};
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1036
1099
|
// src/index.ts
|
|
1037
1100
|
var exit = () => process.exit(0);
|
|
1038
1101
|
process.on("SIGINT", exit);
|
|
@@ -1045,6 +1108,7 @@ async function main() {
|
|
|
1045
1108
|
return;
|
|
1046
1109
|
}
|
|
1047
1110
|
const steps = [
|
|
1111
|
+
verify,
|
|
1048
1112
|
intro,
|
|
1049
1113
|
projectName,
|
|
1050
1114
|
template,
|
|
@@ -1070,5 +1134,6 @@ export {
|
|
|
1070
1134
|
setStdout,
|
|
1071
1135
|
setupTypeScript,
|
|
1072
1136
|
template,
|
|
1073
|
-
typescript
|
|
1137
|
+
typescript,
|
|
1138
|
+
verify
|
|
1074
1139
|
};
|