create-astro 0.14.0 → 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.
package/dist/gradient.js CHANGED
@@ -25,14 +25,19 @@ function getGradientAnimFrames() {
25
25
  const frames = [];
26
26
  for (let start = 0; start < gradientColors.length * 2; start++) {
27
27
  const end = start + gradientColors.length - 1;
28
- frames.push(referenceGradient.slice(start, end).map((g) => chalk.bgHex(g)(" ")).join(""));
28
+ frames.push(
29
+ referenceGradient.slice(start, end).map((g) => chalk.bgHex(g)(" ")).join("")
30
+ );
29
31
  }
30
32
  return frames;
31
33
  }
32
34
  function getIntroAnimFrames() {
33
35
  const frames = [];
34
36
  for (let end = 1; end <= gradientColors.length; end++) {
35
- const leadingSpacesArr = Array.from(new Array(Math.abs(gradientColors.length - end - 1)), () => " ");
37
+ const leadingSpacesArr = Array.from(
38
+ new Array(Math.abs(gradientColors.length - end - 1)),
39
+ () => " "
40
+ );
36
41
  const gradientArr = gradientColors.slice(0, end).map((g) => chalk.bgHex(g)(" "));
37
42
  frames.push([...leadingSpacesArr, ...gradientArr].join(""));
38
43
  }
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";
@@ -32,7 +33,9 @@ function mkdirp(dir) {
32
33
  function isEmpty(dirPath) {
33
34
  return !fs.existsSync(dirPath) || fs.readdirSync(dirPath).length === 0;
34
35
  }
35
- const { version } = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf-8"));
36
+ const { version } = JSON.parse(
37
+ fs.readFileSync(new URL("../package.json", import.meta.url), "utf-8")
38
+ );
36
39
  const FILES_TO_REMOVE = [".stackblitzrc", "sandbox.config.json", "CHANGELOG.md"];
37
40
  async function main() {
38
41
  var _a;
@@ -56,37 +59,43 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
56
59
  let rejectProjectDir = ora({ color: "red", text: notEmptyMsg(cwd) });
57
60
  rejectProjectDir.fail();
58
61
  }
59
- const dirResponse = await prompts({
60
- type: "text",
61
- name: "directory",
62
- message: "Where would you like to create your new project?",
63
- initial: "./my-astro-site",
64
- validate(value) {
65
- if (!isEmpty(value)) {
66
- 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;
67
73
  }
68
- return true;
69
- }
70
- });
74
+ },
75
+ { onCancel: () => ora().info(dim("Operation cancelled. See you later, astronaut!")) }
76
+ );
71
77
  cwd = dirResponse.directory;
72
78
  }
73
79
  if (!cwd) {
74
80
  process.exit(1);
75
81
  }
76
- const options = await prompts([
77
- {
78
- type: "select",
79
- name: "template",
80
- message: "Which template would you like to use?",
81
- choices: TEMPLATES
82
- }
83
- ]);
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
+ );
84
93
  if (!options.template) {
85
94
  process.exit(1);
86
95
  }
87
- const templateSpinner = await loadWithRocketGradient("Copying project files...");
96
+ let templateSpinner = await loadWithRocketGradient("Copying project files...");
88
97
  const hash = args.commit ? `#${args.commit}` : "";
89
- const templateTarget = `withastro/astro/examples/${options.template}#latest`;
98
+ const templateTarget = options.template.includes("/") ? options.template : `withastro/astro/examples/${options.template}#latest`;
90
99
  const emitter = degit(`${templateTarget}${hash}`, {
91
100
  cache: false,
92
101
  force: true,
@@ -103,35 +112,88 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
103
112
  logger.debug(info.message);
104
113
  });
105
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
+ }
106
119
  } catch (err) {
120
+ templateSpinner.fail();
107
121
  logger.debug(err);
108
122
  console.error(red(err.message));
109
- if (err.message === "zlib: unexpected end of file") {
110
- console.log(yellow("This seems to be a cache related problem. Remove the folder '~/.degit/github/withastro' to fix this error."));
111
- console.log(yellow("For more information check out this issue: https://github.com/withastro/astro/issues/655"));
123
+ if (err.message === "zlib: unexpected end of file" || err.message === "TAR_BAD_ARCHIVE: Unrecognized archive format") {
124
+ console.log(
125
+ yellow(
126
+ "Local degit cache seems to be corrupted. For more information check out this issue: https://github.com/withastro/astro/issues/655. "
127
+ )
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
+ }
112
151
  }
113
152
  if (err.code === "MISSING_REF") {
114
- console.log(yellow("This seems to be an issue with degit. Please check if you have 'git' installed on your system, and install it if you don't have (https://git-scm.com)."));
115
- console.log(yellow("If you do have 'git' installed, please run this command with the --verbose flag and file a new issue with the command output here: https://github.com/withastro/astro/issues"));
153
+ console.log(
154
+ yellow(
155
+ "This seems to be an issue with degit. Please check if you have 'git' installed on your system, and install it if you don't have (https://git-scm.com)."
156
+ )
157
+ );
158
+ console.log(
159
+ yellow(
160
+ "If you do have 'git' installed, please run this command with the --verbose flag and file a new issue with the command output here: https://github.com/withastro/astro/issues"
161
+ )
162
+ );
116
163
  }
117
- templateSpinner.fail();
118
164
  process.exit(1);
119
165
  }
120
- await Promise.all(FILES_TO_REMOVE.map(async (file) => {
121
- const fileLoc = path.resolve(path.join(cwd, file));
122
- if (fs.existsSync(fileLoc)) {
123
- return fs.promises.rm(fileLoc, {});
124
- }
125
- }));
166
+ await Promise.all(
167
+ FILES_TO_REMOVE.map(async (file) => {
168
+ const fileLoc = path.resolve(path.join(cwd, file));
169
+ if (fs.existsSync(fileLoc)) {
170
+ return fs.promises.rm(fileLoc, {});
171
+ }
172
+ })
173
+ );
126
174
  }
127
175
  templateSpinner.text = green("Template copied!");
128
176
  templateSpinner.succeed();
129
- const installResponse = await prompts({
130
- type: "confirm",
131
- name: "install",
132
- message: `Would you like to install ${pkgManager} dependencies? ${reset(dim("(recommended)"))}`,
133
- initial: true
134
- });
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
+ );
135
197
  if (args.dryRun) {
136
198
  ora().info(dim(`--dry-run enabled, skipping.`));
137
199
  } else if (installResponse.install) {
@@ -142,7 +204,9 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
142
204
  var _a2;
143
205
  (_a2 = installExec.stdout) == null ? void 0 : _a2.on("data", function(data) {
144
206
  installSpinner.text = `${rocketAscii} ${installingPackagesMsg}
145
- ${bold(`[${pkgManager}]`)} ${data}`;
207
+ ${bold(
208
+ `[${pkgManager}]`
209
+ )} ${data}`;
146
210
  });
147
211
  installExec.on("error", (error) => reject(error));
148
212
  installExec.on("close", () => resolve());
@@ -152,12 +216,22 @@ ${bold(`[${pkgManager}]`)} ${data}`;
152
216
  } else {
153
217
  ora().info(dim(`No problem! Remember to install dependencies after setup.`));
154
218
  }
155
- const gitResponse = await prompts({
156
- type: "confirm",
157
- name: "git",
158
- message: `Would you like to initialize a new git repository? ${reset(dim("(optional)"))}`,
159
- initial: true
160
- });
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
+ );
161
235
  if (args.dryRun) {
162
236
  ora().info(dim(`--dry-run enabled, skipping.`));
163
237
  } else if (gitResponse.git) {
@@ -173,11 +247,21 @@ ${bgCyan(black(" Next steps "))}
173
247
  `);
174
248
  let projectDir = path.relative(process.cwd(), cwd);
175
249
  const devCmd = pkgManager === "npm" ? "npm run dev" : `${pkgManager} dev`;
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"))}`);
250
+ if (projectDir !== "/") {
251
+ await logAndWait(
252
+ `You can now ${bold(cyan("cd"))} into the ${bold(cyan(projectDir))} project directory.`
253
+ );
254
+ }
255
+ await logAndWait(
256
+ `Run ${bold(cyan(devCmd))} to start the Astro dev server. ${bold(cyan("CTRL-C"))} to close.`
257
+ );
258
+ await logAndWait(
259
+ `Add frameworks like ${bold(cyan("react"))} and ${bold(
260
+ cyan("tailwind")
261
+ )} to your project using ${bold(cyan("astro add"))}`
262
+ );
179
263
  await logAndWait("");
180
- 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);
181
265
  await logAndWait(dim("Good luck out there, astronaut."));
182
266
  await logAndWait("", 300);
183
267
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-astro",
3
- "version": "0.14.0",
3
+ "version": "0.14.3",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -44,7 +44,7 @@
44
44
  "uvu": "^0.5.3"
45
45
  },
46
46
  "engines": {
47
- "node": "^14.20.0 || >=16.14.0"
47
+ "node": "^14.18.0 || >=16.12.0"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "astro-scripts build \"src/**/*.ts\" && tsc",