create-astro 4.10.0 → 4.11.0-beta.0

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/README.md CHANGED
@@ -45,19 +45,19 @@ npm create astro@latest my-astro-project -- --template cassidoo/shopify-react-as
45
45
 
46
46
  May be provided in place of prompts
47
47
 
48
- | Name | Description |
49
- | :--------------------------- | :----------------------------------------------------- |
50
- | `--help` (`-h`) | Display available flags. |
51
- | `--template <name>` | Specify your template. |
52
- | `--install` / `--no-install` | Install dependencies (or not). |
53
- | `--git` / `--no-git` | Initialize git repo (or not). |
54
- | `--yes` (`-y`) | Skip all prompts by accepting defaults. |
55
- | `--no` (`-n`) | Skip all prompts by declining defaults. |
56
- | `--dry-run` | Walk through steps without executing. |
57
- | `--skip-houston` | Skip Houston animation. |
58
- | `--ref` | Specify an Astro branch (default: latest). |
59
- | `--fancy` | Enable full Unicode support for Windows. |
60
- | `--typescript <option>` | TypeScript option: `strict` / `strictest` / `relaxed`. |
48
+ | Name | Description |
49
+ | :--------------------------- | :----------------------------------------- |
50
+ | `--help` (`-h`) | Display available flags. |
51
+ | `--template <name>` | Specify your template. |
52
+ | `--install` / `--no-install` | Install dependencies (or not). |
53
+ | `--add <integrations>` | Add integrations. |
54
+ | `--git` / `--no-git` | Initialize git repo (or not). |
55
+ | `--yes` (`-y`) | Skip all prompts by accepting defaults. |
56
+ | `--no` (`-n`) | Skip all prompts by declining defaults. |
57
+ | `--dry-run` | Walk through steps without executing. |
58
+ | `--skip-houston` | Skip Houston animation. |
59
+ | `--ref` | Specify an Astro branch (default: latest). |
60
+ | `--fancy` | Enable full Unicode support for Windows. |
61
61
 
62
62
  [examples]: https://github.com/withastro/astro/tree/main/examples
63
63
  [typescript]: https://github.com/withastro/astro/tree/main/packages/astro/tsconfigs
@@ -8,6 +8,7 @@ export interface Context {
8
8
  version: Promise<string>;
9
9
  skipHouston: boolean;
10
10
  fancy?: boolean;
11
+ add?: string[];
11
12
  dryRun?: boolean;
12
13
  yes?: boolean;
13
14
  projectName?: string;
@@ -1,2 +1,2 @@
1
1
  import type { Context } from './context.js';
2
- export declare function dependencies(ctx: Pick<Context, 'install' | 'yes' | 'prompt' | 'packageManager' | 'cwd' | 'dryRun' | 'tasks'>): Promise<void>;
2
+ export declare function dependencies(ctx: Pick<Context, 'install' | 'yes' | 'prompt' | 'packageManager' | 'cwd' | 'dryRun' | 'tasks' | 'add'>): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -5,8 +5,7 @@ import { intro } from './actions/intro.js';
5
5
  import { next } from './actions/next-steps.js';
6
6
  import { projectName } from './actions/project-name.js';
7
7
  import { template } from './actions/template.js';
8
- import { setupTypeScript, typescript } from './actions/typescript.js';
9
8
  import { verify } from './actions/verify.js';
10
9
  import { setStdout } from './messages.js';
11
10
  export declare function main(): Promise<void>;
12
- export { dependencies, getContext, git, intro, next, projectName, setStdout, setupTypeScript, template, typescript, verify, };
11
+ export { dependencies, getContext, git, intro, next, projectName, setStdout, template, verify };
package/dist/index.js CHANGED
@@ -228,6 +228,7 @@ function getSeasonalHouston({ fancy }) {
228
228
  `Your creativity is the gift that keeps on giving!`
229
229
  ]
230
230
  };
231
+ case void 0:
231
232
  default:
232
233
  return {
233
234
  hats: fancy ? ["\u{1F3A9}", "\u{1F3A9}", "\u{1F3A9}", "\u{1F3A9}", "\u{1F393}", "\u{1F451}", "\u{1F9E2}", "\u{1F366}"] : void 0,
@@ -380,11 +381,6 @@ var error = async (prefix, text2) => {
380
381
  log(`${" ".repeat(5)} ${color.red("\u25B2")} ${color.red(prefix)} ${color.dim(text2)}`);
381
382
  }
382
383
  };
383
- var typescriptByDefault = async () => {
384
- await info(`No worries!`, "TypeScript is supported in Astro by default,");
385
- log(`${" ".repeat(9)}${color.dim("but you are free to continue writing JavaScript instead.")}`);
386
- await sleep(1e3);
387
- };
388
384
  var nextSteps = async ({ projectDir, devCmd }) => {
389
385
  const max = stdout.columns;
390
386
  const prefix = max < 80 ? " " : " ".repeat(9);
@@ -446,7 +442,7 @@ function printHelp({
446
442
  if (headline) {
447
443
  message.push(
448
444
  linebreak(),
449
- `${title(commandName)} ${color.green(`v${"4.10.0"}`)} ${headline}`
445
+ `${title(commandName)} ${color.green(`v${"4.11.0-beta.0"}`)} ${headline}`
450
446
  );
451
447
  }
452
448
  if (usage) {
@@ -481,11 +477,11 @@ async function getContext(argv) {
481
477
  "--no-install": Boolean,
482
478
  "--git": Boolean,
483
479
  "--no-git": Boolean,
484
- "--typescript": String,
485
480
  "--skip-houston": Boolean,
486
481
  "--dry-run": Boolean,
487
482
  "--help": Boolean,
488
483
  "--fancy": Boolean,
484
+ "--add": [String],
489
485
  "-y": "--yes",
490
486
  "-n": "--no",
491
487
  "-h": "--help"
@@ -503,29 +499,29 @@ async function getContext(argv) {
503
499
  "--no-install": noInstall,
504
500
  "--git": git2,
505
501
  "--no-git": noGit,
506
- "--typescript": typescript2,
507
502
  "--fancy": fancy,
508
503
  "--skip-houston": skipHouston,
509
504
  "--dry-run": dryRun,
510
- "--ref": ref
505
+ "--ref": ref,
506
+ "--add": add
511
507
  } = flags;
512
508
  let projectName2 = cwd;
513
509
  if (no) {
514
510
  yes = false;
515
511
  if (install2 == void 0) install2 = false;
516
512
  if (git2 == void 0) git2 = false;
517
- if (typescript2 == void 0) typescript2 = "strict";
518
513
  }
519
- skipHouston = (os.platform() === "win32" && !fancy || skipHouston) ?? [yes, no, install2, git2, typescript2].some((v) => v !== void 0);
514
+ skipHouston = (os.platform() === "win32" && !fancy || skipHouston) ?? [yes, no, install2, git2].some((v) => v !== void 0);
520
515
  const { messages, hats, ties } = getSeasonalHouston({ fancy });
521
516
  const context = {
522
517
  help: help2,
523
518
  prompt,
524
519
  packageManager,
525
520
  username: getName(),
526
- version: getVersion(packageManager, "astro", "4.16.1"),
521
+ version: getVersion(packageManager, "astro", "5.0.0-beta.7"),
527
522
  skipHouston,
528
523
  fancy,
524
+ add,
529
525
  dryRun,
530
526
  projectName: projectName2,
531
527
  template: template2,
@@ -536,7 +532,6 @@ async function getContext(argv) {
536
532
  yes,
537
533
  install: install2 ?? (noInstall ? false : void 0),
538
534
  git: git2 ?? (noGit ? false : void 0),
539
- typescript: typescript2,
540
535
  cwd,
541
536
  exit(code) {
542
537
  process.exit(code);
@@ -572,8 +567,12 @@ async function dependencies(ctx) {
572
567
  }));
573
568
  ctx.install = deps;
574
569
  }
570
+ ctx.add = ctx.add?.reduce((acc, item) => acc.concat(item.split(",")), []);
575
571
  if (ctx.dryRun) {
576
- await info("--dry-run", `Skipping dependency installation`);
572
+ await info(
573
+ "--dry-run",
574
+ `Skipping dependency installation${ctx.add ? ` and adding ${ctx.add.join(", ")}` : ""}`
575
+ );
577
576
  } else if (deps) {
578
577
  ctx.tasks.push({
579
578
  pending: "Dependencies",
@@ -590,6 +589,24 @@ async function dependencies(ctx) {
590
589
  },
591
590
  while: () => install({ packageManager: ctx.packageManager, cwd: ctx.cwd })
592
591
  });
592
+ let add = ctx.add;
593
+ if (add) {
594
+ ctx.tasks.push({
595
+ pending: "Integrations",
596
+ start: `Adding integrations with astro add`,
597
+ end: "Integrations added",
598
+ onError: (e) => {
599
+ error("error", e);
600
+ error(
601
+ "error",
602
+ `Failed to add integrations, please run ${color2.bold(
603
+ `astro add ${add.join(" ")}`
604
+ )} to install them manually after setup.`
605
+ );
606
+ },
607
+ while: () => astroAdd({ integrations: add, packageManager: ctx.packageManager, cwd: ctx.cwd })
608
+ });
609
+ }
593
610
  } else {
594
611
  await info(
595
612
  ctx.yes === false ? "deps [skip]" : "No problem!",
@@ -597,6 +614,18 @@ async function dependencies(ctx) {
597
614
  );
598
615
  }
599
616
  }
617
+ async function astroAdd({
618
+ integrations,
619
+ packageManager,
620
+ cwd
621
+ }) {
622
+ if (packageManager === "yarn") await ensureYarnLock({ cwd });
623
+ return shell(
624
+ packageManager === "npm" ? "npx" : `${packageManager} dlx`,
625
+ ["astro add", integrations.join(" "), "-y"],
626
+ { cwd, timeout: 9e4, stdio: "ignore" }
627
+ );
628
+ }
600
629
  async function install({ packageManager, cwd }) {
601
630
  if (packageManager === "yarn") await ensureYarnLock({ cwd });
602
631
  return shell(packageManager, ["install"], { cwd, timeout: 9e4, stdio: "ignore" });
@@ -675,14 +704,14 @@ function help() {
675
704
  ["--help (-h)", "See all available flags."],
676
705
  ["--template <name>", "Specify your template."],
677
706
  ["--install / --no-install", "Install dependencies (or not)."],
707
+ ["--add <integrations>", "Add integrations."],
678
708
  ["--git / --no-git", "Initialize git repo (or not)."],
679
709
  ["--yes (-y)", "Skip all prompts by accepting defaults."],
680
710
  ["--no (-n)", "Skip all prompts by declining defaults."],
681
711
  ["--dry-run", "Walk through steps without executing."],
682
712
  ["--skip-houston", "Skip Houston animation."],
683
713
  ["--ref", "Choose astro branch (default: latest)."],
684
- ["--fancy", "Enable full Unicode support for Windows."],
685
- ["--typescript <option>", "TypeScript option: strict | strictest | relaxed."]
714
+ ["--fancy", "Enable full Unicode support for Windows."]
686
715
  ]
687
716
  }
688
717
  });
@@ -854,9 +883,9 @@ async function template(ctx) {
854
883
  message: "How would you like to start your new project?",
855
884
  initial: "basics",
856
885
  choices: [
857
- { value: "basics", label: "Include sample files", hint: "(recommended)" },
886
+ { value: "basics", label: "A basic, minimal starter", hint: "(recommended)" },
858
887
  { value: "blog", label: "Use blog template" },
859
- { value: "minimal", label: "Empty" }
888
+ { value: "starlight", label: "Use docs (Starlight) template" }
860
889
  ]
861
890
  });
862
891
  ctx.template = tmpl;
@@ -959,231 +988,9 @@ async function copyTemplate(tmpl, ctx) {
959
988
  }
960
989
  }
961
990
 
962
- // src/actions/typescript.ts
963
- import { readFile, rm, writeFile } from "node:fs/promises";
964
- import path6 from "node:path";
965
- import { color as color7 } from "@astrojs/cli-kit";
966
-
967
- // ../../node_modules/.pnpm/strip-json-comments@5.0.1/node_modules/strip-json-comments/index.js
968
- var singleComment = Symbol("singleComment");
969
- var multiComment = Symbol("multiComment");
970
- var stripWithoutWhitespace = () => "";
971
- var stripWithWhitespace = (string, start, end) => string.slice(start, end).replace(/\S/g, " ");
972
- var isEscaped = (jsonString, quotePosition) => {
973
- let index = quotePosition - 1;
974
- let backslashCount = 0;
975
- while (jsonString[index] === "\\") {
976
- index -= 1;
977
- backslashCount += 1;
978
- }
979
- return Boolean(backslashCount % 2);
980
- };
981
- function stripJsonComments(jsonString, { whitespace = true, trailingCommas = false } = {}) {
982
- if (typeof jsonString !== "string") {
983
- throw new TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof jsonString}\``);
984
- }
985
- const strip = whitespace ? stripWithWhitespace : stripWithoutWhitespace;
986
- let isInsideString = false;
987
- let isInsideComment = false;
988
- let offset = 0;
989
- let buffer = "";
990
- let result = "";
991
- let commaIndex = -1;
992
- for (let index = 0; index < jsonString.length; index++) {
993
- const currentCharacter = jsonString[index];
994
- const nextCharacter = jsonString[index + 1];
995
- if (!isInsideComment && currentCharacter === '"') {
996
- const escaped = isEscaped(jsonString, index);
997
- if (!escaped) {
998
- isInsideString = !isInsideString;
999
- }
1000
- }
1001
- if (isInsideString) {
1002
- continue;
1003
- }
1004
- if (!isInsideComment && currentCharacter + nextCharacter === "//") {
1005
- buffer += jsonString.slice(offset, index);
1006
- offset = index;
1007
- isInsideComment = singleComment;
1008
- index++;
1009
- } else if (isInsideComment === singleComment && currentCharacter + nextCharacter === "\r\n") {
1010
- index++;
1011
- isInsideComment = false;
1012
- buffer += strip(jsonString, offset, index);
1013
- offset = index;
1014
- continue;
1015
- } else if (isInsideComment === singleComment && currentCharacter === "\n") {
1016
- isInsideComment = false;
1017
- buffer += strip(jsonString, offset, index);
1018
- offset = index;
1019
- } else if (!isInsideComment && currentCharacter + nextCharacter === "/*") {
1020
- buffer += jsonString.slice(offset, index);
1021
- offset = index;
1022
- isInsideComment = multiComment;
1023
- index++;
1024
- continue;
1025
- } else if (isInsideComment === multiComment && currentCharacter + nextCharacter === "*/") {
1026
- index++;
1027
- isInsideComment = false;
1028
- buffer += strip(jsonString, offset, index + 1);
1029
- offset = index + 1;
1030
- continue;
1031
- } else if (trailingCommas && !isInsideComment) {
1032
- if (commaIndex !== -1) {
1033
- if (currentCharacter === "}" || currentCharacter === "]") {
1034
- buffer += jsonString.slice(offset, index);
1035
- result += strip(buffer, 0, 1) + buffer.slice(1);
1036
- buffer = "";
1037
- offset = index;
1038
- commaIndex = -1;
1039
- } else if (currentCharacter !== " " && currentCharacter !== " " && currentCharacter !== "\r" && currentCharacter !== "\n") {
1040
- buffer += jsonString.slice(offset, index);
1041
- offset = index;
1042
- commaIndex = -1;
1043
- }
1044
- } else if (currentCharacter === ",") {
1045
- result += buffer + jsonString.slice(offset, index);
1046
- buffer = "";
1047
- offset = index;
1048
- commaIndex = index;
1049
- }
1050
- }
1051
- }
1052
- return result + buffer + (isInsideComment ? strip(jsonString.slice(offset)) : jsonString.slice(offset));
1053
- }
1054
-
1055
- // src/actions/typescript.ts
1056
- async function typescript(ctx) {
1057
- let ts = ctx.typescript ?? (typeof ctx.yes !== "undefined" ? "strict" : void 0);
1058
- if (ts === void 0) {
1059
- const { useTs } = await ctx.prompt({
1060
- name: "useTs",
1061
- type: "confirm",
1062
- label: title("ts"),
1063
- message: `Do you plan to write TypeScript?`,
1064
- initial: true
1065
- });
1066
- if (!useTs) {
1067
- await typescriptByDefault();
1068
- return;
1069
- }
1070
- ({ ts } = await ctx.prompt({
1071
- name: "ts",
1072
- type: "select",
1073
- label: title("use"),
1074
- message: `How strict should TypeScript be?`,
1075
- initial: "strict",
1076
- choices: [
1077
- { value: "strict", label: "Strict", hint: `(recommended)` },
1078
- { value: "strictest", label: "Strictest" },
1079
- { value: "base", label: "Relaxed" }
1080
- ]
1081
- }));
1082
- } else {
1083
- if (!["strict", "strictest", "relaxed", "default", "base"].includes(ts)) {
1084
- if (!ctx.dryRun) {
1085
- await rm(ctx.cwd, { recursive: true, force: true });
1086
- }
1087
- error(
1088
- "Error",
1089
- `Unknown TypeScript option ${color7.reset(ts)}${color7.dim(
1090
- "! Expected strict | strictest | relaxed"
1091
- )}`
1092
- );
1093
- ctx.exit(1);
1094
- }
1095
- await info("ts", `Using ${color7.reset(ts)}${color7.dim(" TypeScript configuration")}`);
1096
- }
1097
- if (ctx.dryRun) {
1098
- await info("--dry-run", `Skipping TypeScript setup`);
1099
- } else if (ts && ts !== "unsure") {
1100
- if (ts === "relaxed" || ts === "default") {
1101
- ts = "base";
1102
- }
1103
- ctx.tasks.push({
1104
- pending: "TypeScript",
1105
- start: "TypeScript customizing...",
1106
- end: "TypeScript customized",
1107
- while: () => setupTypeScript(ts, ctx).catch((e) => {
1108
- error("error", e);
1109
- process.exit(1);
1110
- })
1111
- });
1112
- } else {
1113
- }
1114
- }
1115
- var FILES_TO_UPDATE2 = {
1116
- "package.json": async (file, options) => {
1117
- try {
1118
- const data = await readFile(file, { encoding: "utf-8" });
1119
- const indent = /(^\s+)/m.exec(data)?.[1] ?? " ";
1120
- const parsedPackageJson = JSON.parse(data);
1121
- const buildScript = parsedPackageJson.scripts?.build;
1122
- if (typeof buildScript === "string" && !buildScript.includes("astro check")) {
1123
- parsedPackageJson.scripts.build = `astro check && ${buildScript}`;
1124
- }
1125
- const [astroCheckVersion, typescriptVersion] = await Promise.all([
1126
- getVersion(options.ctx.packageManager, "@astrojs/check", "0.9.4"),
1127
- getVersion(options.ctx.packageManager, "typescript", "5.6.2")
1128
- ]);
1129
- parsedPackageJson.dependencies ??= {};
1130
- parsedPackageJson.dependencies["@astrojs/check"] = `^${astroCheckVersion}`;
1131
- parsedPackageJson.dependencies.typescript = `^${typescriptVersion}`;
1132
- await writeFile(file, JSON.stringify(parsedPackageJson, null, indent) + "\n", "utf-8");
1133
- } catch (err) {
1134
- if (err && err.code === "ENOENT") return;
1135
- if (err instanceof Error) throw new Error(err.message);
1136
- }
1137
- },
1138
- "tsconfig.json": async (file, options) => {
1139
- try {
1140
- const data = await readFile(file, { encoding: "utf-8" });
1141
- const templateTSConfig = JSON.parse(stripJsonComments(data));
1142
- if (templateTSConfig && typeof templateTSConfig === "object") {
1143
- const result = Object.assign(templateTSConfig, {
1144
- extends: `astro/tsconfigs/${options.value}`
1145
- });
1146
- await writeFile(file, JSON.stringify(result, null, 2) + "\n");
1147
- } else {
1148
- throw new Error(
1149
- "There was an error applying the requested TypeScript settings. This could be because the template's tsconfig.json is malformed"
1150
- );
1151
- }
1152
- } catch (err) {
1153
- if (err && err.code === "ENOENT") {
1154
- await writeFile(
1155
- file,
1156
- JSON.stringify({ extends: `astro/tsconfigs/${options.value}` }, null, 2) + "\n"
1157
- );
1158
- }
1159
- }
1160
- },
1161
- "astro.config.mjs": async (file, options) => {
1162
- if (!(options.value === "strict" || options.value === "strictest")) {
1163
- return;
1164
- }
1165
- try {
1166
- let data = await readFile(file, { encoding: "utf-8" });
1167
- data = `// @ts-check
1168
- ${data}`;
1169
- await writeFile(file, data, { encoding: "utf-8" });
1170
- } catch (err) {
1171
- if (err && err.code === "ENOENT") return;
1172
- if (err instanceof Error) throw new Error(err.message);
1173
- }
1174
- }
1175
- };
1176
- async function setupTypeScript(value, ctx) {
1177
- await Promise.all(
1178
- Object.entries(FILES_TO_UPDATE2).map(
1179
- async ([file, update]) => update(path6.resolve(path6.join(ctx.cwd, file)), { value, ctx })
1180
- )
1181
- );
1182
- }
1183
-
1184
991
  // src/actions/verify.ts
1185
992
  import dns from "node:dns/promises";
1186
- import { color as color8 } from "@astrojs/cli-kit";
993
+ import { color as color7 } from "@astrojs/cli-kit";
1187
994
  import { verifyTemplate } from "@bluwy/giget-core";
1188
995
  async function verify(ctx) {
1189
996
  if (!ctx.dryRun) {
@@ -1201,7 +1008,7 @@ async function verify(ctx) {
1201
1008
  if (!ok) {
1202
1009
  bannerAbort();
1203
1010
  log("");
1204
- error("error", `Template ${color8.reset(ctx.template)} ${color8.dim("could not be found!")}`);
1011
+ error("error", `Template ${color7.reset(ctx.template)} ${color7.dim("could not be found!")}`);
1205
1012
  await info("check", "https://astro.build/examples");
1206
1013
  ctx.exit(1);
1207
1014
  }
@@ -1231,7 +1038,6 @@ async function main() {
1231
1038
  intro,
1232
1039
  projectName,
1233
1040
  template,
1234
- typescript,
1235
1041
  dependencies,
1236
1042
  // Steps which write to files need to go above git
1237
1043
  git
@@ -1257,8 +1063,6 @@ export {
1257
1063
  next,
1258
1064
  projectName,
1259
1065
  setStdout,
1260
- setupTypeScript,
1261
1066
  template,
1262
- typescript,
1263
1067
  verify
1264
1068
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-astro",
3
- "version": "4.10.0",
3
+ "version": "4.11.0-beta.0",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -26,7 +26,7 @@
26
26
  "//b": "DEPENDENCIES IS FOR UNBUNDLED PACKAGES",
27
27
  "dependencies": {
28
28
  "@astrojs/cli-kit": "^0.4.1",
29
- "@bluwy/giget-core": "^0.1.0"
29
+ "@bluwy/giget-core": "^0.1.1"
30
30
  },
31
31
  "devDependencies": {
32
32
  "arg": "^5.0.2",
@@ -1,5 +0,0 @@
1
- import type { Context } from './context.js';
2
- type PickedTypeScriptContext = Pick<Context, 'typescript' | 'yes' | 'prompt' | 'dryRun' | 'cwd' | 'exit' | 'packageManager' | 'install' | 'tasks'>;
3
- export declare function typescript(ctx: PickedTypeScriptContext): Promise<void>;
4
- export declare function setupTypeScript(value: string, ctx: PickedTypeScriptContext): Promise<void>;
5
- export {};