create-astro 0.14.2 → 0.14.3

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 +98 -44
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import { execa, execaCommand } from "execa";
3
3
  import fs from "fs";
4
4
  import { bgCyan, black, bold, cyan, dim, gray, green, red, reset, yellow } from "kleur/colors";
5
5
  import ora from "ora";
6
+ import os from "os";
6
7
  import path from "path";
7
8
  import prompts from "prompts";
8
9
  import detectPackageManager from "which-pm-runs";
@@ -58,35 +59,41 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
58
59
  let rejectProjectDir = ora({ color: "red", text: notEmptyMsg(cwd) });
59
60
  rejectProjectDir.fail();
60
61
  }
61
- const dirResponse = await prompts({
62
- type: "text",
63
- name: "directory",
64
- message: "Where would you like to create your new project?",
65
- initial: "./my-astro-site",
66
- validate(value) {
67
- if (!isEmpty(value)) {
68
- return notEmptyMsg(value);
62
+ const dirResponse = await prompts(
63
+ {
64
+ type: "text",
65
+ name: "directory",
66
+ message: "Where would you like to create your new project?",
67
+ initial: "./my-astro-site",
68
+ validate(value) {
69
+ if (!isEmpty(value)) {
70
+ return notEmptyMsg(value);
71
+ }
72
+ return true;
69
73
  }
70
- return true;
71
- }
72
- });
74
+ },
75
+ { onCancel: () => ora().info(dim("Operation cancelled. See you later, astronaut!")) }
76
+ );
73
77
  cwd = dirResponse.directory;
74
78
  }
75
79
  if (!cwd) {
76
80
  process.exit(1);
77
81
  }
78
- const options = await prompts([
79
- {
80
- type: "select",
81
- name: "template",
82
- message: "Which template would you like to use?",
83
- choices: TEMPLATES
84
- }
85
- ]);
82
+ const options = await prompts(
83
+ [
84
+ {
85
+ type: "select",
86
+ name: "template",
87
+ message: "Which template would you like to use?",
88
+ choices: TEMPLATES
89
+ }
90
+ ],
91
+ { onCancel: () => ora().info(dim("Operation cancelled. See you later, astronaut!")) }
92
+ );
86
93
  if (!options.template) {
87
94
  process.exit(1);
88
95
  }
89
- const templateSpinner = await loadWithRocketGradient("Copying project files...");
96
+ let templateSpinner = await loadWithRocketGradient("Copying project files...");
90
97
  const hash = args.commit ? `#${args.commit}` : "";
91
98
  const templateTarget = options.template.includes("/") ? options.template : `withastro/astro/examples/${options.template}#latest`;
92
99
  const emitter = degit(`${templateTarget}${hash}`, {
@@ -105,20 +112,42 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
105
112
  logger.debug(info.message);
106
113
  });
107
114
  await emitter.clone(cwd);
115
+ if (isEmpty(cwd)) {
116
+ fs.rmdirSync(cwd);
117
+ throw new Error(`Error: The provided template (${cyan(options.template)}) does not exist`);
118
+ }
108
119
  } catch (err) {
120
+ templateSpinner.fail();
109
121
  logger.debug(err);
110
122
  console.error(red(err.message));
111
- if (err.message === "zlib: unexpected end of file") {
123
+ if (err.message === "zlib: unexpected end of file" || err.message === "TAR_BAD_ARCHIVE: Unrecognized archive format") {
112
124
  console.log(
113
125
  yellow(
114
- "This seems to be a cache related problem. Remove the folder '~/.degit/github/withastro' to fix this error."
115
- )
116
- );
117
- console.log(
118
- yellow(
119
- "For more information check out this issue: https://github.com/withastro/astro/issues/655"
126
+ "Local degit cache seems to be corrupted. For more information check out this issue: https://github.com/withastro/astro/issues/655. "
120
127
  )
121
128
  );
129
+ const cacheIssueResponse = await prompts({
130
+ type: "confirm",
131
+ name: "cache",
132
+ message: "Would you like us to clear the cache and try again?",
133
+ initial: true
134
+ });
135
+ if (cacheIssueResponse.cache) {
136
+ const homeDirectory = os.homedir();
137
+ const cacheDir = path.join(homeDirectory, ".degit", "github", "withastro");
138
+ fs.rmSync(cacheDir, { recursive: true, force: true, maxRetries: 3 });
139
+ templateSpinner = await loadWithRocketGradient("Copying project files...");
140
+ try {
141
+ await emitter.clone(cwd);
142
+ } catch (e) {
143
+ logger.debug(e);
144
+ console.error(red(e.message));
145
+ }
146
+ } else {
147
+ console.log(
148
+ "Okay, no worries! To fix this manually, remove the folder '~/.degit/github/withastro' and rerun the command."
149
+ );
150
+ }
122
151
  }
123
152
  if (err.code === "MISSING_REF") {
124
153
  console.log(
@@ -132,7 +161,6 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
132
161
  )
133
162
  );
134
163
  }
135
- templateSpinner.fail();
136
164
  process.exit(1);
137
165
  }
138
166
  await Promise.all(
@@ -146,12 +174,26 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
146
174
  }
147
175
  templateSpinner.text = green("Template copied!");
148
176
  templateSpinner.succeed();
149
- const installResponse = await prompts({
150
- type: "confirm",
151
- name: "install",
152
- message: `Would you like to install ${pkgManager} dependencies? ${reset(dim("(recommended)"))}`,
153
- initial: true
154
- });
177
+ const installResponse = await prompts(
178
+ {
179
+ type: "confirm",
180
+ name: "install",
181
+ message: `Would you like to install ${pkgManager} dependencies? ${reset(
182
+ dim("(recommended)")
183
+ )}`,
184
+ initial: true
185
+ },
186
+ {
187
+ onCancel: () => {
188
+ ora().info(
189
+ dim(
190
+ "Operation cancelled. Your project folder has already been created, however no dependencies have been installed"
191
+ )
192
+ );
193
+ process.exit(1);
194
+ }
195
+ }
196
+ );
155
197
  if (args.dryRun) {
156
198
  ora().info(dim(`--dry-run enabled, skipping.`));
157
199
  } else if (installResponse.install) {
@@ -174,12 +216,22 @@ ${bold(
174
216
  } else {
175
217
  ora().info(dim(`No problem! Remember to install dependencies after setup.`));
176
218
  }
177
- const gitResponse = await prompts({
178
- type: "confirm",
179
- name: "git",
180
- message: `Would you like to initialize a new git repository? ${reset(dim("(optional)"))}`,
181
- initial: true
182
- });
219
+ const gitResponse = await prompts(
220
+ {
221
+ type: "confirm",
222
+ name: "git",
223
+ message: `Would you like to initialize a new git repository? ${reset(dim("(optional)"))}`,
224
+ initial: true
225
+ },
226
+ {
227
+ onCancel: () => {
228
+ ora().info(
229
+ dim("Operation cancelled. No worries, your project folder has already been created")
230
+ );
231
+ process.exit(1);
232
+ }
233
+ }
234
+ );
183
235
  if (args.dryRun) {
184
236
  ora().info(dim(`--dry-run enabled, skipping.`));
185
237
  } else if (gitResponse.git) {
@@ -195,9 +247,11 @@ ${bgCyan(black(" Next steps "))}
195
247
  `);
196
248
  let projectDir = path.relative(process.cwd(), cwd);
197
249
  const devCmd = pkgManager === "npm" ? "npm run dev" : `${pkgManager} dev`;
198
- await logAndWait(
199
- `You can now ${bold(cyan("cd"))} into the ${bold(cyan(projectDir))} project directory.`
200
- );
250
+ if (projectDir !== "/") {
251
+ await logAndWait(
252
+ `You can now ${bold(cyan("cd"))} into the ${bold(cyan(projectDir))} project directory.`
253
+ );
254
+ }
201
255
  await logAndWait(
202
256
  `Run ${bold(cyan(devCmd))} to start the Astro dev server. ${bold(cyan("CTRL-C"))} to close.`
203
257
  );
@@ -207,7 +261,7 @@ ${bgCyan(black(" Next steps "))}
207
261
  )} to your project using ${bold(cyan("astro add"))}`
208
262
  );
209
263
  await logAndWait("");
210
- await logAndWait(`Stuck? Come join us at ${bold(cyan("https://astro.build/chat"))}`, 1e3);
264
+ await logAndWait(`Stuck? Come join us at ${bold(cyan("https://astro.build/chat"))}`, 750);
211
265
  await logAndWait(dim("Good luck out there, astronaut."));
212
266
  await logAndWait("", 300);
213
267
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-astro",
3
- "version": "0.14.2",
3
+ "version": "0.14.3",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",