create-astro 0.11.0 → 0.12.2

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
+ """
@@ -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,6 +1,6 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
- import { bold, cyan, gray, green, red, yellow } from "kleur/colors";
3
+ import { bgCyan, black, bold, cyan, gray, green, red, yellow } from "kleur/colors";
4
4
  import prompts from "prompts";
5
5
  import degit from "degit";
6
6
  import yargs from "yargs-parser";
@@ -8,6 +8,7 @@ import ora from "ora";
8
8
  import { TEMPLATES } from "./templates.js";
9
9
  import { logger, defaultLogLevel } from "./logger.js";
10
10
  import { execa, execaCommand } from "execa";
11
+ import { loadWithRocketGradient, rocketAscii } from "./gradient.js";
11
12
  const cleanArgv = process.argv.filter((arg) => arg !== "--");
12
13
  const args = yargs(cleanArgv);
13
14
  prompts.override(args);
@@ -30,8 +31,6 @@ async function main() {
30
31
  logger.debug("Verbose logging turned on");
31
32
  console.log(`
32
33
  ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
33
- let spinner = ora({ color: "green", text: "Prepare for liftoff." });
34
- spinner.succeed();
35
34
  let cwd = args["_"][2];
36
35
  if (cwd && isEmpty(cwd)) {
37
36
  let acknowledgeProjectDir = ora({
@@ -74,6 +73,7 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
74
73
  if (!options.template) {
75
74
  process.exit(1);
76
75
  }
76
+ const templateSpinner = await loadWithRocketGradient("Copying project files...");
77
77
  const hash = args.commit ? `#${args.commit}` : "";
78
78
  const templateTarget = `withastro/astro/examples/${options.template}#latest`;
79
79
  const emitter = degit(`${templateTarget}${hash}`, {
@@ -86,7 +86,6 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
86
86
  force: true,
87
87
  verbose: defaultLogLevel === "debug" ? true : false
88
88
  });
89
- spinner = ora({ color: "green", text: "Copying project files..." }).start();
90
89
  if (!args.dryrun) {
91
90
  try {
92
91
  emitter.on("info", (info) => {
@@ -104,7 +103,7 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
104
103
  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
104
  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
105
  }
107
- spinner.fail();
106
+ templateSpinner.fail();
108
107
  process.exit(1);
109
108
  }
110
109
  await Promise.all(FILES_TO_REMOVE.map(async (file) => {
@@ -114,8 +113,8 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
114
113
  }
115
114
  }));
116
115
  }
117
- spinner.succeed();
118
- console.log(bold(green("\u2714") + " Done!"));
116
+ templateSpinner.text = green("Template copied!");
117
+ templateSpinner.succeed();
119
118
  const installResponse = await prompts({
120
119
  type: "confirm",
121
120
  name: "install",
@@ -125,22 +124,21 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
125
124
  if (!installResponse) {
126
125
  process.exit(0);
127
126
  }
128
- if (installResponse.install) {
127
+ if (installResponse.install && !args.dryrun) {
129
128
  const installExec = execa(pkgManager, ["install"], { cwd });
130
129
  const installingPackagesMsg = `Installing packages${emojiWithFallback(" \u{1F4E6}", "...")}`;
131
- spinner = ora({ color: "green", text: installingPackagesMsg }).start();
132
- if (!args.dryrun) {
133
- await new Promise((resolve, reject) => {
134
- var _a;
135
- (_a = installExec.stdout) == null ? void 0 : _a.on("data", function(data) {
136
- spinner.text = `${installingPackagesMsg}
130
+ const installSpinner = await loadWithRocketGradient(installingPackagesMsg);
131
+ await new Promise((resolve, reject) => {
132
+ var _a;
133
+ (_a = installExec.stdout) == null ? void 0 : _a.on("data", function(data) {
134
+ installSpinner.text = `${rocketAscii} ${installingPackagesMsg}
137
135
  ${bold(`[${pkgManager}]`)} ${data}`;
138
- });
139
- installExec.on("error", (error) => reject(error));
140
- installExec.on("close", () => resolve());
141
136
  });
142
- }
143
- spinner.succeed();
137
+ installExec.on("error", (error) => reject(error));
138
+ installExec.on("close", () => resolve());
139
+ });
140
+ installSpinner.text = green("Packages installed!");
141
+ installSpinner.succeed();
144
142
  }
145
143
  const astroAddCommand = installResponse.install ? "astro add --yes" : `${pkgManagerExecCommand(pkgManager)} astro@latest add --yes`;
146
144
  const astroAddResponse = await prompts({
@@ -158,23 +156,31 @@ ${bold(`[${pkgManager}]`)} ${data}`;
158
156
  if (astroAddResponse.astroAdd && !args.dryrun) {
159
157
  await execaCommand(astroAddCommand, astroAddCommand === "astro add --yes" ? { cwd, stdio: "inherit", localDir: cwd, preferLocal: true } : { cwd, stdio: "inherit" });
160
158
  }
161
- console.log("\nNext steps:");
162
- let i = 1;
163
- const relative = path.relative(process.cwd(), cwd);
164
- if (relative !== "") {
165
- console.log(` ${i++}: ${bold(cyan(`cd ${relative}`))}`);
159
+ const gitResponse = await prompts({
160
+ type: "confirm",
161
+ name: "git",
162
+ message: "Initialize a git repository?",
163
+ initial: true
164
+ });
165
+ if (!gitResponse) {
166
+ process.exit(0);
166
167
  }
167
- if (!installResponse.install) {
168
- console.log(` ${i++}: ${bold(cyan(`${pkgManager} install`))}`);
168
+ if (gitResponse.git && !args.dryrun) {
169
+ await execaCommand("git init", { cwd });
169
170
  }
170
- console.log(` ${i++}: ${bold(cyan('git init && git add -A && git commit -m "Initial commit"'))} (optional step)`);
171
- const runCommand = pkgManager === "npm" ? "npm run dev" : `${pkgManager} dev`;
172
- console.log(` ${i++}: ${bold(cyan(runCommand))}`);
173
- console.log(`
174
- To close the dev server, hit ${bold(cyan("Ctrl-C"))}`);
171
+ ora({ text: green("Done. Ready for liftoff!") }).succeed();
175
172
  console.log(`
176
- Stuck? Visit us at ${cyan("https://astro.build/chat")}
173
+ ${bgCyan(black(" Next steps "))}
177
174
  `);
175
+ const projectDir = path.relative(process.cwd(), cwd);
176
+ 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"))}`);
178
184
  }
179
185
  function emojiWithFallback(char, fallback) {
180
186
  return process.platform !== "win32" ? char : fallback;
package/dist/logger.js CHANGED
@@ -1,20 +1,10 @@
1
1
  import { bold, blue, 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.11.0",
3
+ "version": "0.12.2",
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.3",
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
+ }