create-astro 0.12.0 → 0.12.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/LICENSE ADDED
@@ -0,0 +1,61 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Fred K. Schott
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+
24
+ """
25
+ This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/sveltejs/kit repository:
26
+
27
+ Copyright (c) 2020 [these people](https://github.com/sveltejs/kit/graphs/contributors)
28
+
29
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
30
+
31
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
32
+
33
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34
+ """
35
+
36
+
37
+ """
38
+ This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/vitejs/vite repository:
39
+
40
+ MIT License
41
+
42
+ Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
43
+
44
+ Permission is hereby granted, free of charge, to any person obtaining a copy
45
+ of this software and associated documentation files (the "Software"), to deal
46
+ in the Software without restriction, including without limitation the rights
47
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
48
+ copies of the Software, and to permit persons to whom the Software is
49
+ furnished to do so, subject to the following conditions:
50
+
51
+ The above copyright notice and this permission notice shall be included in all
52
+ copies or substantial portions of the Software.
53
+
54
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
55
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
56
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
57
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
58
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
59
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
60
+ SOFTWARE.
61
+ """
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!`);
@@ -0,0 +1,65 @@
1
+ import chalk from "chalk";
2
+ import ora from "ora";
3
+ const gradientColors = [
4
+ `#ff5e00`,
5
+ `#ff4c29`,
6
+ `#ff383f`,
7
+ `#ff2453`,
8
+ `#ff0565`,
9
+ `#ff007b`,
10
+ `#f5008b`,
11
+ `#e6149c`,
12
+ `#d629ae`,
13
+ `#c238bd`
14
+ ];
15
+ const rocketAscii = "\u25A0\u25A0\u25B6";
16
+ const referenceGradient = [
17
+ ...gradientColors,
18
+ ...[...gradientColors].reverse(),
19
+ ...gradientColors
20
+ ];
21
+ const sleep = (time) => new Promise((resolve) => {
22
+ setTimeout(resolve, time);
23
+ });
24
+ function getGradientAnimFrames() {
25
+ const frames = [];
26
+ for (let start = 0; start < gradientColors.length * 2; start++) {
27
+ const end = start + gradientColors.length - 1;
28
+ frames.push(referenceGradient.slice(start, end).map((g) => chalk.bgHex(g)(" ")).join(""));
29
+ }
30
+ return frames;
31
+ }
32
+ function getIntroAnimFrames() {
33
+ const frames = [];
34
+ for (let end = 1; end <= gradientColors.length; end++) {
35
+ const leadingSpacesArr = Array.from(new Array(Math.abs(gradientColors.length - end - 1)), () => " ");
36
+ const gradientArr = gradientColors.slice(0, end).map((g) => chalk.bgHex(g)(" "));
37
+ frames.push([...leadingSpacesArr, ...gradientArr].join(""));
38
+ }
39
+ return frames;
40
+ }
41
+ async function loadWithRocketGradient(text) {
42
+ const frames = getIntroAnimFrames();
43
+ const intro = ora({
44
+ spinner: {
45
+ interval: 30,
46
+ frames
47
+ },
48
+ text: `${rocketAscii} ${text}`
49
+ });
50
+ intro.start();
51
+ await sleep((frames.length - 1) * intro.interval);
52
+ intro.stop();
53
+ const spinner = ora({
54
+ spinner: {
55
+ interval: 80,
56
+ frames: getGradientAnimFrames()
57
+ },
58
+ text: `${rocketAscii} ${text}`
59
+ }).start();
60
+ return spinner;
61
+ }
62
+ export {
63
+ loadWithRocketGradient,
64
+ rocketAscii
65
+ };
package/dist/index.js CHANGED
@@ -1,13 +1,21 @@
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, 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";
6
8
  import yargs from "yargs-parser";
7
- import ora from "ora";
9
+ import { loadWithRocketGradient, rocketAscii } from "./gradient.js";
10
+ import { defaultLogLevel, logger } from "./logger.js";
8
11
  import { TEMPLATES } from "./templates.js";
9
- import { logger, defaultLogLevel } from "./logger.js";
10
- import { execa, execaCommand } from "execa";
12
+ function wait(ms) {
13
+ return new Promise((resolve) => setTimeout(resolve, ms));
14
+ }
15
+ function logAndWait(message, ms = 100) {
16
+ console.log(message);
17
+ return wait(ms);
18
+ }
11
19
  const cleanArgv = process.argv.filter((arg) => arg !== "--");
12
20
  const args = yargs(cleanArgv);
13
21
  prompts.override(args);
@@ -30,8 +38,8 @@ async function main() {
30
38
  logger.debug("Verbose logging turned on");
31
39
  console.log(`
32
40
  ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
33
- let spinner = ora({ color: "green", text: "Prepare for liftoff." });
34
- spinner.succeed();
41
+ console.log(`Lets walk through setting up your new Astro project.
42
+ `);
35
43
  let cwd = args["_"][2];
36
44
  if (cwd && isEmpty(cwd)) {
37
45
  let acknowledgeProjectDir = ora({
@@ -49,7 +57,7 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
49
57
  const dirResponse = await prompts({
50
58
  type: "text",
51
59
  name: "directory",
52
- message: "Where would you like to create your app?",
60
+ message: "Where would you like to create your new project?",
53
61
  initial: "./my-astro-site",
54
62
  validate(value) {
55
63
  if (!isEmpty(value)) {
@@ -67,13 +75,14 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
67
75
  {
68
76
  type: "select",
69
77
  name: "template",
70
- message: "Which app template would you like to use?",
78
+ message: "Which template would you like to use?",
71
79
  choices: TEMPLATES
72
80
  }
73
81
  ]);
74
82
  if (!options.template) {
75
83
  process.exit(1);
76
84
  }
85
+ const templateSpinner = await loadWithRocketGradient("Copying project files...");
77
86
  const hash = args.commit ? `#${args.commit}` : "";
78
87
  const templateTarget = `withastro/astro/examples/${options.template}#latest`;
79
88
  const emitter = degit(`${templateTarget}${hash}`, {
@@ -86,8 +95,7 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
86
95
  force: true,
87
96
  verbose: defaultLogLevel === "debug" ? true : false
88
97
  });
89
- spinner = ora({ color: "green", text: "Copying project files..." }).start();
90
- if (!args.dryrun) {
98
+ if (!args.dryRun) {
91
99
  try {
92
100
  emitter.on("info", (info) => {
93
101
  logger.debug(info.message);
@@ -104,7 +112,7 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
104
112
  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)."));
105
113
  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"));
106
114
  }
107
- spinner.fail();
115
+ templateSpinner.fail();
108
116
  process.exit(1);
109
117
  }
110
118
  await Promise.all(FILES_TO_REMOVE.map(async (file) => {
@@ -114,77 +122,62 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
114
122
  }
115
123
  }));
116
124
  }
117
- spinner.succeed();
118
- console.log(bold(green("\u2714") + " Done!"));
125
+ templateSpinner.text = green("Template copied!");
126
+ templateSpinner.succeed();
119
127
  const installResponse = await prompts({
120
128
  type: "confirm",
121
129
  name: "install",
122
130
  message: `Would you like us to run "${pkgManager} install?"`,
123
131
  initial: true
124
132
  });
125
- if (!installResponse) {
126
- process.exit(0);
127
- }
128
- if (installResponse.install && !args.dryrun) {
133
+ if (args.dryRun) {
134
+ ora().info(dim(`--dry-run enabled, skipping.`));
135
+ } else if (installResponse.install) {
129
136
  const installExec = execa(pkgManager, ["install"], { cwd });
130
137
  const installingPackagesMsg = `Installing packages${emojiWithFallback(" \u{1F4E6}", "...")}`;
131
- spinner = ora({ color: "green", text: installingPackagesMsg }).start();
138
+ const installSpinner = await loadWithRocketGradient(installingPackagesMsg);
132
139
  await new Promise((resolve, reject) => {
133
140
  var _a;
134
141
  (_a = installExec.stdout) == null ? void 0 : _a.on("data", function(data) {
135
- spinner.text = `${installingPackagesMsg}
142
+ installSpinner.text = `${rocketAscii} ${installingPackagesMsg}
136
143
  ${bold(`[${pkgManager}]`)} ${data}`;
137
144
  });
138
145
  installExec.on("error", (error) => reject(error));
139
146
  installExec.on("close", () => resolve());
140
147
  });
141
- spinner.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" });
148
+ installSpinner.text = green("Packages installed!");
149
+ installSpinner.succeed();
150
+ } else {
151
+ ora().info(dim(`No problem! You can install dependencies yourself after setup.`));
158
152
  }
159
153
  const gitResponse = await prompts({
160
154
  type: "confirm",
161
155
  name: "git",
162
- message: "Initialize a git repository?",
156
+ message: `Initialize a new git repository? ${dim("This can be useful to track changes.")}`,
163
157
  initial: true
164
158
  });
165
- if (!gitResponse) {
166
- process.exit(0);
167
- }
168
- if (gitResponse.git && !args.dryrun) {
159
+ if (args.dryRun) {
160
+ ora().info(dim(`--dry-run enabled, skipping.`));
161
+ } else if (gitResponse.git) {
169
162
  await execaCommand("git init", { cwd });
163
+ } else {
164
+ ora().info(dim(`Sounds good! You can come back and run ${cyan(`git init`)} later.`));
170
165
  }
166
+ ora().succeed("Setup complete.");
167
+ ora({ text: green("Ready for liftoff!") }).succeed();
168
+ await wait(300);
171
169
  console.log(`
172
170
  ${bgCyan(black(" Next steps "))}
173
171
  `);
174
- const relative = path.relative(process.cwd(), cwd);
175
- const startCommand = [];
176
- if (relative !== "") {
177
- startCommand.push(bold(cyan(`cd ${relative}`)));
178
- }
179
- if (!installResponse.install) {
180
- startCommand.push(bold(cyan(`${pkgManager} install`)));
181
- }
182
- startCommand.push(bold(cyan(pkgManager === "npm" ? "npm run dev" : `${pkgManager} dev`)));
183
- console.log(startCommand.join(" && "));
184
- console.log(`
185
- To close the dev server, hit ${bold(cyan("Ctrl-C"))}`);
186
- console.log(`Stuck? Visit us at ${cyan("https://astro.build/chat")}
187
- `);
172
+ let projectDir = path.relative(process.cwd(), cwd);
173
+ const devCmd = pkgManager === "npm" ? "npm run dev" : `${pkgManager} dev`;
174
+ await logAndWait(`You can now ${bold(cyan("cd"))} into the ${bold(cyan(projectDir))} project directory.`);
175
+ await logAndWait(`Run ${bold(cyan(devCmd))} to start the Astro dev server. ${bold(cyan("CTRL-C"))} to close.`);
176
+ await logAndWait(`Add frameworks like ${bold(cyan("react"))} and ${bold(cyan("tailwind"))} to your project using ${bold(cyan("astro add"))}`);
177
+ await logAndWait("");
178
+ await logAndWait(`Stuck? Come join us at ${bold(cyan("https://astro.build/chat"))}`, 1e3);
179
+ await logAndWait(dim("Good luck out there, astronaut."));
180
+ await logAndWait("", 300);
188
181
  }
189
182
  function emojiWithFallback(char, fallback) {
190
183
  return process.platform !== "win32" ? char : fallback;
package/dist/logger.js CHANGED
@@ -1,20 +1,10 @@
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
- function getLoggerLocale() {
5
- const defaultLocale = "en-US";
6
- if (process.env.LANG) {
7
- const extractedLocale = process.env.LANG.split(".")[0].replace(/_/g, "-");
8
- if (extractedLocale.length < 2)
9
- return defaultLocale;
10
- else
11
- return extractedLocale;
12
- } else
13
- return defaultLocale;
14
- }
15
- const dt = new Intl.DateTimeFormat(getLoggerLocale(), {
4
+ const dt = new Intl.DateTimeFormat([], {
16
5
  hour: "2-digit",
17
- minute: "2-digit"
6
+ minute: "2-digit",
7
+ second: "2-digit"
18
8
  });
19
9
  const defaultLogDestination = new Writable({
20
10
  objectMode: true,
@@ -0,0 +1,8 @@
1
+ import type { Ora } from 'ora';
2
+ export declare const rocketAscii = "\u25A0\u25A0\u25B6";
3
+ /**
4
+ * Generate loading spinner with rocket flames!
5
+ * @param text display text next to rocket
6
+ * @returns Ora spinner for running .stop()
7
+ */
8
+ export declare function loadWithRocketGradient(text: string): Promise<Ora>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-astro",
3
- "version": "0.12.0",
3
+ "version": "0.12.3",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -17,12 +17,6 @@
17
17
  "bin": {
18
18
  "create-astro": "./create-astro.mjs"
19
19
  },
20
- "scripts": {
21
- "build": "astro-scripts build \"src/**/*.ts\" && tsc",
22
- "build:ci": "astro-scripts build \"src/**/*.ts\"",
23
- "dev": "astro-scripts dev \"src/**/*.ts\"",
24
- "test": "mocha --exit --timeout 20000"
25
- },
26
20
  "files": [
27
21
  "dist",
28
22
  "create-astro.js"
@@ -30,6 +24,7 @@
30
24
  "dependencies": {
31
25
  "@types/degit": "^2.8.3",
32
26
  "@types/prompts": "^2.0.14",
27
+ "chalk": "^5.0.1",
33
28
  "degit": "^2.8.4",
34
29
  "execa": "^6.1.0",
35
30
  "kleur": "^4.1.4",
@@ -41,12 +36,18 @@
41
36
  "@types/chai": "^4.3.1",
42
37
  "@types/mocha": "^9.1.1",
43
38
  "@types/yargs-parser": "^21.0.0",
44
- "astro-scripts": "workspace:*",
39
+ "astro-scripts": "0.0.5",
45
40
  "chai": "^4.3.6",
46
41
  "mocha": "^9.2.2",
47
42
  "uvu": "^0.5.3"
48
43
  },
49
44
  "engines": {
50
45
  "node": "^14.15.0 || >=16.0.0"
46
+ },
47
+ "scripts": {
48
+ "build": "astro-scripts build \"src/**/*.ts\" && tsc",
49
+ "build:ci": "astro-scripts build \"src/**/*.ts\"",
50
+ "dev": "astro-scripts dev \"src/**/*.ts\"",
51
+ "test": "mocha --exit --timeout 20000"
51
52
  }
52
- }
53
+ }