create-astro 3.2.1 → 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.
Files changed (2) hide show
  1. package/dist/index.js +67 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -302,8 +302,10 @@ var getVersion = () => new Promise(async (resolve) => {
302
302
  var log = (message) => stdout.write(message + "\n");
303
303
  var banner = async (version) => log(
304
304
  `
305
- ${label("astro", color.bgGreen, color.black)} ${version ? color.green(color.bold(`v${version}`)) : ""} ${color.bold("Launch sequence initiated.")}`
305
+ ${label("astro", color.bgGreen, color.black)}${version ? " " + color.green(color.bold(`v${version}`)) : ""} ${color.bold("Launch sequence initiated.")}`
306
306
  );
307
+ var bannerAbort = () => log(`
308
+ ${label("astro", color.bgRed)} ${color.bold("Launch sequence aborted.")}`);
307
309
  var info = async (prefix, text2) => {
308
310
  await sleep(100);
309
311
  if (stdout.columns < 80) {
@@ -387,7 +389,7 @@ function printHelp({
387
389
  if (headline) {
388
390
  message.push(
389
391
  linebreak(),
390
- `${title(commandName)} ${color.green(`v${"3.2.1"}`)} ${headline}`
392
+ `${title(commandName)} ${color.green(`v${"3.2.2"}`)} ${headline}`
391
393
  );
392
394
  }
393
395
  if (usage) {
@@ -645,7 +647,7 @@ async function intro(ctx) {
645
647
  import path3 from "node:path";
646
648
  async function next(ctx) {
647
649
  let projectDir = path3.relative(process.cwd(), ctx.cwd);
648
- 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`;
649
651
  await nextSteps({ projectDir, devCmd });
650
652
  if (!ctx.skipHouston) {
651
653
  await say(["Good luck out there, astronaut! \u{1F680}"]);
@@ -1035,6 +1037,65 @@ async function setupTypeScript(value, { cwd }) {
1035
1037
  }
1036
1038
  }
1037
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
+
1038
1099
  // src/index.ts
1039
1100
  var exit = () => process.exit(0);
1040
1101
  process.on("SIGINT", exit);
@@ -1047,6 +1108,7 @@ async function main() {
1047
1108
  return;
1048
1109
  }
1049
1110
  const steps = [
1111
+ verify,
1050
1112
  intro,
1051
1113
  projectName,
1052
1114
  template,
@@ -1072,5 +1134,6 @@ export {
1072
1134
  setStdout,
1073
1135
  setupTypeScript,
1074
1136
  template,
1075
- typescript
1137
+ typescript,
1138
+ verify
1076
1139
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-astro",
3
- "version": "3.2.1",
3
+ "version": "3.2.2",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",