create-astro 0.12.2 → 0.12.5

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/create-astro.mjs CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  const currentVersion = process.versions.node;
5
5
  const requiredMajorVersion = parseInt(currentVersion.split('.')[0], 10);
6
- const minimumMajorVersion = 12;
6
+ const minimumMajorVersion = 14;
7
7
 
8
8
  if (requiredMajorVersion < minimumMajorVersion) {
9
9
  console.error(`Node.js v${currentVersion} is out of date and unsupported!`);
package/dist/index.js CHANGED
@@ -1,14 +1,22 @@
1
+ import degit from "degit";
2
+ import { execa, execaCommand } from "execa";
1
3
  import fs from "fs";
4
+ import { bgCyan, black, bold, cyan, dim, gray, green, red, reset, yellow } from "kleur/colors";
5
+ import ora from "ora";
2
6
  import path from "path";
3
- import { bgCyan, black, bold, cyan, gray, green, red, yellow } from "kleur/colors";
4
7
  import prompts from "prompts";
5
- import degit from "degit";
8
+ import detectPackageManager from "which-pm-runs";
6
9
  import yargs from "yargs-parser";
7
- import ora from "ora";
8
- import { TEMPLATES } from "./templates.js";
9
- import { logger, defaultLogLevel } from "./logger.js";
10
- import { execa, execaCommand } from "execa";
11
10
  import { loadWithRocketGradient, rocketAscii } from "./gradient.js";
11
+ import { defaultLogLevel, logger } from "./logger.js";
12
+ import { TEMPLATES } from "./templates.js";
13
+ function wait(ms) {
14
+ return new Promise((resolve) => setTimeout(resolve, ms));
15
+ }
16
+ function logAndWait(message, ms = 100) {
17
+ console.log(message);
18
+ return wait(ms);
19
+ }
12
20
  const cleanArgv = process.argv.filter((arg) => arg !== "--");
13
21
  const args = yargs(cleanArgv);
14
22
  prompts.override(args);
@@ -27,10 +35,13 @@ function isEmpty(dirPath) {
27
35
  const { version } = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf-8"));
28
36
  const FILES_TO_REMOVE = [".stackblitzrc", "sandbox.config.json", "CHANGELOG.md"];
29
37
  async function main() {
30
- const pkgManager = pkgManagerFromUserAgent(process.env.npm_config_user_agent);
38
+ var _a;
39
+ const pkgManager = ((_a = detectPackageManager()) == null ? void 0 : _a.name) || "npm";
31
40
  logger.debug("Verbose logging turned on");
32
41
  console.log(`
33
42
  ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
43
+ console.log(`Lets walk through setting up your new Astro project.
44
+ `);
34
45
  let cwd = args["_"][2];
35
46
  if (cwd && isEmpty(cwd)) {
36
47
  let acknowledgeProjectDir = ora({
@@ -48,7 +59,7 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
48
59
  const dirResponse = await prompts({
49
60
  type: "text",
50
61
  name: "directory",
51
- message: "Where would you like to create your app?",
62
+ message: "Where would you like to create your new project?",
52
63
  initial: "./my-astro-site",
53
64
  validate(value) {
54
65
  if (!isEmpty(value)) {
@@ -66,7 +77,7 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
66
77
  {
67
78
  type: "select",
68
79
  name: "template",
69
- message: "Which app template would you like to use?",
80
+ message: "Which template would you like to use?",
70
81
  choices: TEMPLATES
71
82
  }
72
83
  ]);
@@ -86,7 +97,7 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
86
97
  force: true,
87
98
  verbose: defaultLogLevel === "debug" ? true : false
88
99
  });
89
- if (!args.dryrun) {
100
+ if (!args.dryRun) {
90
101
  try {
91
102
  emitter.on("info", (info) => {
92
103
  logger.debug(info.message);
@@ -118,19 +129,18 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
118
129
  const installResponse = await prompts({
119
130
  type: "confirm",
120
131
  name: "install",
121
- message: `Would you like us to run "${pkgManager} install?"`,
132
+ message: `Would you like to install ${pkgManager} dependencies? ${reset(dim("(recommended)"))}`,
122
133
  initial: true
123
134
  });
124
- if (!installResponse) {
125
- process.exit(0);
126
- }
127
- if (installResponse.install && !args.dryrun) {
135
+ if (args.dryRun) {
136
+ ora().info(dim(`--dry-run enabled, skipping.`));
137
+ } else if (installResponse.install) {
128
138
  const installExec = execa(pkgManager, ["install"], { cwd });
129
139
  const installingPackagesMsg = `Installing packages${emojiWithFallback(" \u{1F4E6}", "...")}`;
130
140
  const installSpinner = await loadWithRocketGradient(installingPackagesMsg);
131
141
  await new Promise((resolve, reject) => {
132
- var _a;
133
- (_a = installExec.stdout) == null ? void 0 : _a.on("data", function(data) {
142
+ var _a2;
143
+ (_a2 = installExec.stdout) == null ? void 0 : _a2.on("data", function(data) {
134
144
  installSpinner.text = `${rocketAscii} ${installingPackagesMsg}
135
145
  ${bold(`[${pkgManager}]`)} ${data}`;
136
146
  });
@@ -139,66 +149,41 @@ ${bold(`[${pkgManager}]`)} ${data}`;
139
149
  });
140
150
  installSpinner.text = green("Packages installed!");
141
151
  installSpinner.succeed();
142
- }
143
- const astroAddCommand = installResponse.install ? "astro add --yes" : `${pkgManagerExecCommand(pkgManager)} astro@latest add --yes`;
144
- const astroAddResponse = await prompts({
145
- type: "confirm",
146
- name: "astroAdd",
147
- message: `Run "${astroAddCommand}?" This lets you optionally add component frameworks (ex. React), CSS frameworks (ex. Tailwind), and more.`,
148
- initial: true
149
- });
150
- if (!astroAddResponse) {
151
- process.exit(0);
152
- }
153
- if (!astroAddResponse.astroAdd) {
154
- ora().info(`No problem. You can always run "${pkgManagerExecCommand(pkgManager)} astro add" later!`);
155
- }
156
- if (astroAddResponse.astroAdd && !args.dryrun) {
157
- await execaCommand(astroAddCommand, astroAddCommand === "astro add --yes" ? { cwd, stdio: "inherit", localDir: cwd, preferLocal: true } : { cwd, stdio: "inherit" });
152
+ } else {
153
+ ora().info(dim(`No problem! Remember to install dependencies after setup.`));
158
154
  }
159
155
  const gitResponse = await prompts({
160
156
  type: "confirm",
161
157
  name: "git",
162
- message: "Initialize a git repository?",
158
+ message: `Would you like to initialize a new git repository? ${reset(dim("(optional)"))}`,
163
159
  initial: true
164
160
  });
165
- if (!gitResponse) {
166
- process.exit(0);
167
- }
168
- if (gitResponse.git && !args.dryrun) {
161
+ if (args.dryRun) {
162
+ ora().info(dim(`--dry-run enabled, skipping.`));
163
+ } else if (gitResponse.git) {
169
164
  await execaCommand("git init", { cwd });
165
+ } else {
166
+ ora().info(dim(`Sounds good! You can come back and run ${cyan(`git init`)} later.`));
170
167
  }
171
- ora({ text: green("Done. Ready for liftoff!") }).succeed();
168
+ ora().succeed("Setup complete.");
169
+ ora({ text: green("Ready for liftoff!") }).succeed();
170
+ await wait(300);
172
171
  console.log(`
173
172
  ${bgCyan(black(" Next steps "))}
174
173
  `);
175
- const projectDir = path.relative(process.cwd(), cwd);
174
+ let projectDir = path.relative(process.cwd(), cwd);
176
175
  const devCmd = pkgManager === "npm" ? "npm run dev" : `${pkgManager} dev`;
177
- console.log(`You can now ${bold(cyan("cd"))} into the ${bold(cyan(projectDir))} project directory.`);
178
- console.log(`Run ${bold(cyan(devCmd))} to start the Astro dev server. ${bold(cyan("CTRL-C"))} to close.`);
179
- if (!installResponse.install) {
180
- console.log(yellow(`Remember to install dependencies first!`));
181
- }
182
- console.log(`
183
- Stuck? Come join us at ${bold(cyan("https://astro.build/chat"))}`);
176
+ await logAndWait(`You can now ${bold(cyan("cd"))} into the ${bold(cyan(projectDir))} project directory.`);
177
+ await logAndWait(`Run ${bold(cyan(devCmd))} to start the Astro dev server. ${bold(cyan("CTRL-C"))} to close.`);
178
+ await logAndWait(`Add frameworks like ${bold(cyan("react"))} and ${bold(cyan("tailwind"))} to your project using ${bold(cyan("astro add"))}`);
179
+ await logAndWait("");
180
+ await logAndWait(`Stuck? Come join us at ${bold(cyan("https://astro.build/chat"))}`, 1e3);
181
+ await logAndWait(dim("Good luck out there, astronaut."));
182
+ await logAndWait("", 300);
184
183
  }
185
184
  function emojiWithFallback(char, fallback) {
186
185
  return process.platform !== "win32" ? char : fallback;
187
186
  }
188
- function pkgManagerFromUserAgent(userAgent) {
189
- if (!userAgent)
190
- return "npm";
191
- const pkgSpec = userAgent.split(" ")[0];
192
- const pkgSpecArr = pkgSpec.split("/");
193
- return pkgSpecArr[0];
194
- }
195
- function pkgManagerExecCommand(pkgManager) {
196
- if (pkgManager === "pnpm") {
197
- return "pnpx";
198
- } else {
199
- return "npx";
200
- }
201
- }
202
187
  export {
203
188
  main,
204
189
  mkdirp
package/dist/logger.js CHANGED
@@ -1,4 +1,4 @@
1
- import { bold, blue, dim, red, yellow } from "kleur/colors";
1
+ import { blue, bold, dim, red, yellow } from "kleur/colors";
2
2
  import { Writable } from "stream";
3
3
  import { format as utilFormat } from "util";
4
4
  const dt = new Intl.DateTimeFormat([], {
package/dist/templates.js CHANGED
@@ -1,22 +1,22 @@
1
1
  const TEMPLATES = [
2
2
  {
3
- title: "Just the basics",
3
+ title: "Just the basics (recommended)",
4
4
  value: "basics"
5
5
  },
6
6
  {
7
7
  title: "Blog",
8
8
  value: "blog"
9
9
  },
10
- {
11
- title: "Documentation",
12
- value: "docs"
13
- },
14
10
  {
15
11
  title: "Portfolio",
16
12
  value: "portfolio"
17
13
  },
18
14
  {
19
- title: "Completely empty",
15
+ title: "Documentation Site",
16
+ value: "docs"
17
+ },
18
+ {
19
+ title: "Empty project",
20
20
  value: "minimal"
21
21
  }
22
22
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-astro",
3
- "version": "0.12.2",
3
+ "version": "0.12.5",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -22,21 +22,23 @@
22
22
  "create-astro.js"
23
23
  ],
24
24
  "dependencies": {
25
- "@types/degit": "^2.8.3",
26
- "@types/prompts": "^2.0.14",
27
25
  "chalk": "^5.0.1",
28
26
  "degit": "^2.8.4",
29
27
  "execa": "^6.1.0",
30
28
  "kleur": "^4.1.4",
31
29
  "ora": "^6.1.0",
32
30
  "prompts": "^2.4.2",
31
+ "which-pm-runs": "^1.1.0",
33
32
  "yargs-parser": "^21.0.1"
34
33
  },
35
34
  "devDependencies": {
36
35
  "@types/chai": "^4.3.1",
36
+ "@types/degit": "^2.8.3",
37
37
  "@types/mocha": "^9.1.1",
38
+ "@types/prompts": "^2.0.14",
39
+ "@types/which-pm-runs": "^1.0.0",
38
40
  "@types/yargs-parser": "^21.0.0",
39
- "astro-scripts": "0.0.3",
41
+ "astro-scripts": "0.0.6",
40
42
  "chai": "^4.3.6",
41
43
  "mocha": "^9.2.2",
42
44
  "uvu": "^0.5.3"