create-astro 4.7.0 โ†’ 4.7.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.
@@ -19,7 +19,9 @@ export interface Context {
19
19
  stdin?: typeof process.stdin;
20
20
  stdout?: typeof process.stdout;
21
21
  exit(code: number): never;
22
+ welcome?: string;
22
23
  hat?: string;
24
+ tie?: string;
23
25
  tasks: Task[];
24
26
  }
25
27
  export declare function getContext(argv: string[]): Promise<Context>;
@@ -1,2 +1,2 @@
1
1
  import type { Context } from './context.js';
2
- export declare function intro(ctx: Pick<Context, 'hat' | 'skipHouston' | 'version' | 'username' | 'fancy'>): Promise<void>;
2
+ export declare function intro(ctx: Pick<Context, 'skipHouston' | 'welcome' | 'hat' | 'tie' | 'version' | 'username' | 'fancy'>): Promise<void>;
@@ -1,2 +1,2 @@
1
1
  import type { Context } from './context.js';
2
- export declare function next(ctx: Pick<Context, 'hat' | 'cwd' | 'packageManager' | 'skipHouston'>): Promise<void>;
2
+ export declare function next(ctx: Pick<Context, 'hat' | 'tie' | 'cwd' | 'packageManager' | 'skipHouston'>): Promise<void>;
@@ -0,0 +1,9 @@
1
+ interface SeasonalHouston {
2
+ hats?: string[];
3
+ ties?: string[];
4
+ messages: string[];
5
+ }
6
+ export default function getSeasonalHouston({ fancy }: {
7
+ fancy?: boolean;
8
+ }): SeasonalHouston;
9
+ export {};
package/dist/index.js CHANGED
@@ -162,7 +162,7 @@ var require_arg = __commonJS({
162
162
  fn[flagSymbol] = true;
163
163
  return fn;
164
164
  };
165
- arg2.COUNT = arg2.flag((v2, name, existingCount) => (existingCount || 0) + 1);
165
+ arg2.COUNT = arg2.flag((v, name, existingCount) => (existingCount || 0) + 1);
166
166
  arg2.ArgError = ArgError;
167
167
  module.exports = arg2;
168
168
  }
@@ -229,48 +229,26 @@ async function shell(command, flags, opts = {}) {
229
229
  }
230
230
 
231
231
  // src/messages.ts
232
+ var _registry;
232
233
  async function getRegistry(packageManager) {
234
+ if (_registry)
235
+ return _registry;
233
236
  try {
234
237
  const { stdout: stdout2 } = await shell(packageManager, ["config", "get", "registry"]);
235
- return stdout2?.trim()?.replace(/\/$/, "") || "https://registry.npmjs.org";
238
+ _registry = stdout2?.trim()?.replace(/\/$/, "") || "https://registry.npmjs.org";
236
239
  } catch (e) {
237
- return "https://registry.npmjs.org";
240
+ _registry = "https://registry.npmjs.org";
238
241
  }
242
+ return _registry;
239
243
  }
240
244
  var stdout = process.stdout;
241
245
  function setStdout(writable) {
242
246
  stdout = writable;
243
247
  }
244
- async function say(messages, { clear = false, hat = "" } = {}) {
245
- return houston(messages, { clear, hat, stdout });
248
+ async function say(messages, { clear = false, hat = "", tie = "" } = {}) {
249
+ return houston(messages, { clear, hat, tie, stdout });
246
250
  }
247
251
  var title = (text2) => align(label(text2), "end", 7) + " ";
248
- var welcome = [
249
- // `Let's claim your corner of the internet.`,
250
- // `I'll be your assistant today.`,
251
- // `Let's build something awesome!`,
252
- // `Let's build something great!`,
253
- // `Let's build something fast!`,
254
- // `Let's build the web we want.`,
255
- // `Let's make the web weird!`,
256
- // `Let's make the web a better place!`,
257
- // `Let's create a new project!`,
258
- // `Let's create something unique!`,
259
- // `Time to build a new website.`,
260
- // `Time to build a faster website.`,
261
- // `Time to build a sweet new website.`,
262
- // `We're glad to have you on board.`,
263
- // `Keeping the internet weird since 2021.`,
264
- // `Initiating launch sequence...`,
265
- // `Initiating launch sequence... right... now!`,
266
- // `Awaiting further instructions.`,
267
- `Ho, ho, ho! 'Tis the season to code and create.`,
268
- `Jingle all the way through your web creation journey!`,
269
- `Let's unwrap the magic of the web together!`,
270
- `Bells are ringing, and so are your creative ideas!`,
271
- `It's starting to look a lot like Christmas on the internet.`,
272
- `It's time to decorate the web with your festive ideas!`
273
- ];
274
252
  var getName = () => new Promise((resolve) => {
275
253
  exec("git config user.name", { encoding: "utf-8" }, (_1, gitName) => {
276
254
  if (gitName.trim()) {
@@ -284,17 +262,15 @@ var getName = () => new Promise((resolve) => {
284
262
  });
285
263
  });
286
264
  });
287
- var v;
288
- var getVersion = (packageManager) => new Promise(async (resolve) => {
289
- if (v)
290
- return resolve(v);
265
+ var getVersion = (packageManager, packageName, fallback = "") => new Promise(async (resolve) => {
291
266
  let registry = await getRegistry(packageManager);
292
- const { version } = await fetch(`${registry}/astro/latest`, { redirect: "follow" }).then(
267
+ const { version } = await fetch(`${registry}/${packageName}/latest`, {
268
+ redirect: "follow"
269
+ }).then(
293
270
  (res) => res.json(),
294
- () => ({ version: "" })
271
+ () => ({ version: fallback })
295
272
  );
296
- v = version;
297
- resolve(version);
273
+ return resolve(version);
298
274
  });
299
275
  var log = (message) => stdout.write(message + "\n");
300
276
  var banner = () => {
@@ -387,7 +363,7 @@ function printHelp({
387
363
  if (headline) {
388
364
  message.push(
389
365
  linebreak(),
390
- `${title(commandName)} ${color.green(`v${"4.7.0"}`)} ${headline}`
366
+ `${title(commandName)} ${color.green(`v${"4.7.2"}`)} ${headline}`
391
367
  );
392
368
  }
393
369
  if (usage) {
@@ -410,6 +386,110 @@ function printHelp({
410
386
  log(message.join("\n") + "\n");
411
387
  }
412
388
 
389
+ // src/data/seasonal.ts
390
+ function getSeasonalHouston({ fancy }) {
391
+ const season = getSeason();
392
+ switch (season) {
393
+ case "new-year": {
394
+ const year = (/* @__PURE__ */ new Date()).getFullYear();
395
+ return {
396
+ hats: rarity(0.5, ["\u{1F3A9}"]),
397
+ ties: rarity(0.25, ["\u{1F38A}", "\u{1F380}", "\u{1F389}"]),
398
+ messages: [
399
+ `New year, new Astro site!`,
400
+ `Kicking ${year} off with Astro?! What an honor!`,
401
+ `Happy ${year}! Let's make something cool.`,
402
+ `${year} is your year! Let's build something awesome.`,
403
+ `${year} is the year of Astro!`,
404
+ `${year} is clearly off to a great start!`,
405
+ `Thanks for starting ${year} with Astro!`
406
+ ]
407
+ };
408
+ }
409
+ case "spooky":
410
+ return {
411
+ hats: rarity(0.5, ["\u{1F383}", "\u{1F47B}", "\u2620\uFE0F", "\u{1F480}", "\u{1F577}\uFE0F", "\u{1F52E}"]),
412
+ ties: rarity(0.25, ["\u{1F9B4}", "\u{1F36C}", "\u{1F36B}"]),
413
+ messages: [
414
+ `I'm afraid I can't help you... Just kidding!`,
415
+ `Boo! Just kidding. Let's make a website!`,
416
+ `Let's haunt the internet. OooOooOOoo!`,
417
+ `No tricks here. Seeing you is always treat!`,
418
+ `Spiders aren't the only ones building the web!`,
419
+ `Let's conjure up some web magic!`,
420
+ `Let's harness the power of Astro to build a frightful new site!`,
421
+ `We're conjuring up a spooktacular website!`,
422
+ `Prepare for a web of spooky wonders to be woven.`,
423
+ `Chills and thrills await you on your new project!`
424
+ ]
425
+ };
426
+ case "holiday":
427
+ return {
428
+ hats: rarity(0.75, ["\u{1F381}", "\u{1F384}", "\u{1F332}"]),
429
+ ties: rarity(0.75, ["\u{1F9E3}"]),
430
+ messages: [
431
+ `'Tis the season to code and create.`,
432
+ `Jingle all the way through your web creation journey!`,
433
+ `Bells are ringing, and so are your creative ideas!`,
434
+ `Let's make the internet our own winter wonderland!`,
435
+ `It's time to decorate a brand new website!`,
436
+ `Let's unwrap the magic of the web together!`,
437
+ `Hope you're enjoying the holiday season!`,
438
+ `I'm dreaming of a brand new website!`,
439
+ `No better holiday gift than a new site!`,
440
+ `Your creativity is the gift that keeps on giving!`
441
+ ]
442
+ };
443
+ default:
444
+ return {
445
+ hats: fancy ? ["\u{1F3A9}", "\u{1F3A9}", "\u{1F3A9}", "\u{1F3A9}", "\u{1F393}", "\u{1F451}", "\u{1F9E2}", "\u{1F366}"] : void 0,
446
+ ties: fancy ? rarity(0.33, ["\u{1F380}", "\u{1F9E3}"]) : void 0,
447
+ messages: [
448
+ `Let's claim your corner of the internet.`,
449
+ `I'll be your assistant today.`,
450
+ `Let's build something awesome!`,
451
+ `Let's build something great!`,
452
+ `Let's build something fast!`,
453
+ `Let's build the web we want.`,
454
+ `Let's make the web weird!`,
455
+ `Let's make the web a better place!`,
456
+ `Let's create a new project!`,
457
+ `Let's create something unique!`,
458
+ `Time to build a new website.`,
459
+ `Time to build a faster website.`,
460
+ `Time to build a sweet new website.`,
461
+ `We're glad to have you on board.`,
462
+ `Keeping the internet weird since 2021.`,
463
+ `Initiating launch sequence...`,
464
+ `Initiating launch sequence... right... now!`,
465
+ `Awaiting further instructions.`
466
+ ]
467
+ };
468
+ }
469
+ }
470
+ function getSeason() {
471
+ const date = /* @__PURE__ */ new Date();
472
+ const month = date.getMonth() + 1;
473
+ const day = date.getDate() + 1;
474
+ if (month === 1 && day <= 7) {
475
+ return "new-year";
476
+ }
477
+ if (month === 10 && day > 7) {
478
+ return "spooky";
479
+ }
480
+ if (month === 12 && day > 7 && day < 25) {
481
+ return "holiday";
482
+ }
483
+ }
484
+ function rarity(frequency, emoji) {
485
+ if (frequency === 1)
486
+ return emoji;
487
+ if (frequency === 0)
488
+ return [""];
489
+ const empty = Array.from({ length: Math.round(emoji.length * frequency) }, () => "");
490
+ return [...emoji, ...empty];
491
+ }
492
+
413
493
  // src/actions/context.ts
414
494
  async function getContext(argv) {
415
495
  const flags = (0, import_arg.default)(
@@ -460,21 +540,23 @@ async function getContext(argv) {
460
540
  if (typescript2 == void 0)
461
541
  typescript2 = "strict";
462
542
  }
463
- skipHouston = (os.platform() === "win32" && !fancy || skipHouston) ?? [yes, no, install2, git2, typescript2].some((v2) => v2 !== void 0);
543
+ skipHouston = (os.platform() === "win32" && !fancy || skipHouston) ?? [yes, no, install2, git2, typescript2].some((v) => v !== void 0);
544
+ const { messages, hats, ties } = getSeasonalHouston({ fancy });
464
545
  const context = {
465
546
  help: help2,
466
547
  prompt,
467
548
  packageManager,
468
549
  username: getName(),
469
- version: getVersion(packageManager),
550
+ version: getVersion(packageManager, "astro"),
470
551
  skipHouston,
471
552
  fancy,
472
553
  dryRun,
473
554
  projectName: projectName2,
474
555
  template: template2,
475
556
  ref: ref ?? "latest",
476
- hat: random(["\u2744\uFE0F", "\u{1F384}", "\u{1F381}"]),
477
- // fancy ? random(['๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽ“', '๐Ÿ‘‘', '๐Ÿงข', '๐Ÿฆ']) : undefined,
557
+ welcome: random(messages),
558
+ hat: hats ? random(hats) : void 0,
559
+ tie: ties ? random(ties) : void 0,
478
560
  yes,
479
561
  install: install2 ?? (noInstall ? false : void 0),
480
562
  git: git2 ?? (noGit ? false : void 0),
@@ -632,10 +714,10 @@ function help() {
632
714
 
633
715
  // src/actions/intro.ts
634
716
  import { color as color4, label as label2 } from "@astrojs/cli-kit";
635
- import { random as random2 } from "@astrojs/cli-kit/utils";
636
717
  async function intro(ctx) {
637
718
  banner();
638
719
  if (!ctx.skipHouston) {
720
+ const { welcome, hat, tie } = ctx;
639
721
  await say(
640
722
  [
641
723
  [
@@ -647,9 +729,9 @@ async function intro(ctx) {
647
729
  ),
648
730
  Promise.resolve(ctx.username).then((username) => `${username}!`)
649
731
  ],
650
- random2(welcome)
732
+ welcome ?? "Let's build something awesome!"
651
733
  ],
652
- { clear: true, hat: ctx.hat }
734
+ { clear: true, hat, tie }
653
735
  );
654
736
  }
655
737
  }
@@ -667,7 +749,7 @@ async function next(ctx) {
667
749
  const devCmd = commandMap[ctx.packageManager] || "npm run dev";
668
750
  await nextSteps({ projectDir, devCmd });
669
751
  if (!ctx.skipHouston) {
670
- await say(["Good luck out there, astronaut! \u{1F680}"], { hat: ctx.hat });
752
+ await say(["Good luck out there, astronaut! \u{1F680}"], { hat: ctx.hat, tie: ctx.tie });
671
753
  }
672
754
  return;
673
755
  }
@@ -1049,19 +1131,21 @@ async function typescript(ctx) {
1049
1131
  var FILES_TO_UPDATE2 = {
1050
1132
  "package.json": async (file, options) => {
1051
1133
  try {
1052
- if (options.ctx.install)
1053
- await shell(options.ctx.packageManager, ["add", "@astrojs/check", "typescript"], {
1054
- cwd: path6.dirname(file),
1055
- stdio: "ignore"
1056
- });
1057
1134
  const data = await readFile(file, { encoding: "utf-8" });
1058
1135
  const indent = /(^\s+)/m.exec(data)?.[1] ?? " ";
1059
1136
  const parsedPackageJson = JSON.parse(data);
1060
1137
  const buildScript = parsedPackageJson.scripts?.build;
1061
1138
  if (typeof buildScript === "string" && !buildScript.includes("astro check")) {
1062
1139
  parsedPackageJson.scripts.build = `astro check && ${buildScript}`;
1063
- await writeFile(file, JSON.stringify(parsedPackageJson, null, indent), "utf-8");
1064
1140
  }
1141
+ const [astroCheckVersion, typescriptVersion] = await Promise.all([
1142
+ getVersion(options.ctx.packageManager, "@astrojs/check"),
1143
+ getVersion(options.ctx.packageManager, "typescript")
1144
+ ]);
1145
+ parsedPackageJson.dependencies ??= {};
1146
+ parsedPackageJson.dependencies["@astrojs/check"] = `^${astroCheckVersion}`;
1147
+ parsedPackageJson.dependencies.typescript = `^${typescriptVersion}`;
1148
+ await writeFile(file, JSON.stringify(parsedPackageJson, null, indent), "utf-8");
1065
1149
  } catch (err) {
1066
1150
  if (err && err.code === "ENOENT")
1067
1151
  return;
@@ -1176,8 +1260,8 @@ async function main() {
1176
1260
  intro,
1177
1261
  projectName,
1178
1262
  template,
1179
- dependencies,
1180
1263
  typescript,
1264
+ dependencies,
1181
1265
  // Steps which write to files need to go above git
1182
1266
  git
1183
1267
  ];
@@ -1,6 +1,7 @@
1
- export declare function say(messages: string | string[], { clear, hat }?: {
1
+ export declare function say(messages: string | string[], { clear, hat, tie }?: {
2
2
  clear?: boolean | undefined;
3
3
  hat?: string | undefined;
4
+ tie?: string | undefined;
4
5
  }): Promise<void>;
5
6
  export declare function spinner(args: {
6
7
  start: string;
@@ -9,9 +10,8 @@ export declare function spinner(args: {
9
10
  while: (...args: any) => Promise<any>;
10
11
  }): Promise<void>;
11
12
  export declare const title: (text: string) => string;
12
- export declare const welcome: string[];
13
13
  export declare const getName: () => Promise<string>;
14
- export declare const getVersion: (packageManager: string) => Promise<string>;
14
+ export declare const getVersion: (packageManager: string, packageName: string, fallback?: string) => Promise<string>;
15
15
  export declare const log: (message: string) => boolean;
16
16
  export declare const banner: () => void;
17
17
  export declare const bannerAbort: () => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-astro",
3
- "version": "4.7.0",
3
+ "version": "4.7.2",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -25,7 +25,7 @@
25
25
  "//a": "MOST PACKAGES SHOULD GO IN DEV_DEPENDENCIES! THEY WILL BE BUNDLED.",
26
26
  "//b": "DEPENDENCIES IS FOR UNBUNDLED PACKAGES",
27
27
  "dependencies": {
28
- "@astrojs/cli-kit": "^0.4.0",
28
+ "@astrojs/cli-kit": "^0.4.1",
29
29
  "giget": "1.1.3"
30
30
  },
31
31
  "devDependencies": {