create-astro 4.12.0 → 4.13.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.
@@ -1,4 +1,4 @@
1
- import { type Task, prompt } from '@astrojs/cli-kit';
1
+ import { prompt, type Task } from '@astrojs/cli-kit';
2
2
  export interface Context {
3
3
  help: boolean;
4
4
  prompt: typeof prompt;
@@ -1,3 +1,17 @@
1
1
  import type { Context } from './context.js';
2
+ /**
3
+ * Removes sections from README content that are marked with HTML template markers.
4
+ *
5
+ * Template marker format:
6
+ * <!-- ASTRO:REMOVE:START -->
7
+ * Content to remove
8
+ * <!-- ASTRO:REMOVE:END -->
9
+ */
10
+ export declare function removeTemplateMarkerSections(content: string): string;
11
+ /**
12
+ * Processes a template README file by removing template marker sections and
13
+ * replacing package manager references.
14
+ */
15
+ export declare function processTemplateReadme(content: string, packageManager: string): string;
2
16
  export declare function template(ctx: Pick<Context, 'template' | 'prompt' | 'yes' | 'dryRun' | 'exit' | 'tasks'>): Promise<void>;
3
17
  export declare function getTemplateTarget(tmpl: string, ref?: string): string;
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ 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
8
  import { verify } from './actions/verify.js';
9
- import { setStdout } from './messages.js';
9
+ export { processTemplateReadme, removeTemplateMarkerSections } from './actions/template.js';
10
+ export { setStdout } from './messages.js';
10
11
  export declare function main(): Promise<void>;
11
- export { dependencies, getContext, git, intro, next, projectName, setStdout, template, verify };
12
+ export { dependencies, getContext, git, intro, next, projectName, template, verify };
package/dist/index.js CHANGED
@@ -168,6 +168,9 @@ var require_arg = __commonJS({
168
168
  }
169
169
  });
170
170
 
171
+ // src/index.ts
172
+ import { tasks } from "@astrojs/cli-kit";
173
+
171
174
  // src/actions/context.ts
172
175
  var import_arg = __toESM(require_arg(), 1);
173
176
  import os from "node:os";
@@ -349,9 +352,9 @@ var getName = () => new Promise((resolve) => {
349
352
  });
350
353
  });
351
354
  });
352
- var getVersion = (packageManager, packageName, fallback = "") => new Promise(async (resolve) => {
355
+ var getVersion = (packageManager, packageName, packageTag = "latest", fallback = "") => new Promise(async (resolve) => {
353
356
  let registry = await getRegistry(packageManager);
354
- const { version } = await fetch(`${registry}/${packageName}/latest`, {
357
+ const { version } = await fetch(`${registry}/${packageName}/${packageTag}`, {
355
358
  redirect: "follow"
356
359
  }).then((res) => res.json()).catch(() => ({ version: fallback }));
357
360
  return resolve(version);
@@ -442,7 +445,7 @@ function printHelp({
442
445
  if (headline) {
443
446
  message.push(
444
447
  linebreak(),
445
- `${title(commandName)} ${color.green(`v${"4.12.0"}`)} ${headline}`
448
+ `${title(commandName)} ${color.green(`v${"4.13.0"}`)} ${headline}`
446
449
  );
447
450
  }
448
451
  if (usage) {
@@ -466,7 +469,20 @@ function printHelp({
466
469
  }
467
470
 
468
471
  // src/actions/context.ts
472
+ function getPackageTag(packageSpecifier) {
473
+ switch (packageSpecifier) {
474
+ case "alpha":
475
+ case "beta":
476
+ case "rc":
477
+ return packageSpecifier;
478
+ // Will fallback to latest
479
+ case void 0:
480
+ default:
481
+ return void 0;
482
+ }
483
+ }
469
484
  async function getContext(argv) {
485
+ const packageSpecifier = argv.find((argItem) => /^(astro|create-astro)@/.exec(argItem))?.split("@")[1];
470
486
  const flags = (0, import_arg.default)(
471
487
  {
472
488
  "--template": String,
@@ -518,7 +534,12 @@ async function getContext(argv) {
518
534
  prompt,
519
535
  packageManager,
520
536
  username: getName(),
521
- version: getVersion(packageManager, "astro", "5.8.0"),
537
+ version: getVersion(
538
+ packageManager,
539
+ "astro",
540
+ getPackageTag(packageSpecifier),
541
+ "5.12.3"
542
+ ),
522
543
  skipHouston,
523
544
  fancy,
524
545
  add,
@@ -547,9 +568,6 @@ function detectPackageManager() {
547
568
  return name === "npminstall" ? "cnpm" : name;
548
569
  }
549
570
 
550
- // src/index.ts
551
- import { tasks } from "@astrojs/cli-kit";
552
-
553
571
  // src/actions/dependencies.ts
554
572
  import fs from "node:fs";
555
573
  import path from "node:path";
@@ -871,6 +889,19 @@ import fs4 from "node:fs";
871
889
  import path5 from "node:path";
872
890
  import { color as color6 } from "@astrojs/cli-kit";
873
891
  import { downloadTemplate } from "@bluwy/giget-core";
892
+ function removeTemplateMarkerSections(content) {
893
+ const pattern = /<!--\s*ASTRO:REMOVE:START\s*-->[\s\S]*?<!--\s*ASTRO:REMOVE:END\s*-->/gi;
894
+ let result = content.replace(pattern, "");
895
+ result = result.replace(/\n{3,}/g, "\n\n");
896
+ return result;
897
+ }
898
+ function processTemplateReadme(content, packageManager) {
899
+ let processed = removeTemplateMarkerSections(content);
900
+ if (packageManager !== "npm") {
901
+ processed = processed.replace(/\bnpm run\b/g, packageManager).replace(/\bnpm\b/g, packageManager);
902
+ }
903
+ return processed;
904
+ }
874
905
  async function template(ctx) {
875
906
  if (!ctx.template && ctx.yes) ctx.template = "basics";
876
907
  if (ctx.template) {
@@ -949,11 +980,11 @@ async function copyTemplate(tmpl, ctx) {
949
980
  cwd: ctx.cwd,
950
981
  dir: "."
951
982
  });
952
- if (ctx.packageManager !== "npm") {
953
- const readmePath = path5.resolve(ctx.cwd, "README.md");
983
+ const readmePath = path5.resolve(ctx.cwd, "README.md");
984
+ if (fs4.existsSync(readmePath)) {
954
985
  const readme = fs4.readFileSync(readmePath, "utf8");
955
- const updatedReadme = readme.replace(/\bnpm run\b/g, ctx.packageManager).replace(/\bnpm\b/g, ctx.packageManager);
956
- fs4.writeFileSync(readmePath, updatedReadme);
986
+ const processedReadme = processTemplateReadme(readme, ctx.packageManager);
987
+ fs4.writeFileSync(readmePath, processedReadme);
957
988
  }
958
989
  } catch (err) {
959
990
  if (ctx.cwd !== "." && ctx.cwd !== "./" && !ctx.cwd.startsWith("../")) {
@@ -1068,7 +1099,9 @@ export {
1068
1099
  intro,
1069
1100
  main,
1070
1101
  next,
1102
+ processTemplateReadme,
1071
1103
  projectName,
1104
+ removeTemplateMarkerSections,
1072
1105
  setStdout,
1073
1106
  template,
1074
1107
  verify
@@ -5,7 +5,7 @@ export declare function say(messages: string | string[], { clear, hat, tie }?: {
5
5
  }): Promise<void>;
6
6
  export declare const title: (text: string) => string;
7
7
  export declare const getName: () => Promise<string>;
8
- export declare const getVersion: (packageManager: string, packageName: string, fallback?: string) => Promise<string>;
8
+ export declare const getVersion: (packageManager: string, packageName: string, packageTag?: string, fallback?: string) => Promise<string>;
9
9
  export declare const log: (message: string) => boolean;
10
10
  export declare const banner: () => void;
11
11
  export declare const bannerAbort: () => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-astro",
3
- "version": "4.12.0",
3
+ "version": "4.13.0",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",