create-astro 0.14.1 → 0.15.0
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 +7 -2
- package/dist/index.js +199 -51
- package/package.json +3 -2
- package/tsconfigs/tsconfig.strict.json +19 -0
- package/tsconfigs/tsconfig.stricter.json +33 -0
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(
|
|
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(
|
|
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,8 +3,10 @@ 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";
|
|
9
|
+
import url from "url";
|
|
8
10
|
import detectPackageManager from "which-pm-runs";
|
|
9
11
|
import yargs from "yargs-parser";
|
|
10
12
|
import { loadWithRocketGradient, rocketAscii } from "./gradient.js";
|
|
@@ -32,7 +34,9 @@ function mkdirp(dir) {
|
|
|
32
34
|
function isEmpty(dirPath) {
|
|
33
35
|
return !fs.existsSync(dirPath) || fs.readdirSync(dirPath).length === 0;
|
|
34
36
|
}
|
|
35
|
-
const { version } = JSON.parse(
|
|
37
|
+
const { version } = JSON.parse(
|
|
38
|
+
fs.readFileSync(new URL("../package.json", import.meta.url), "utf-8")
|
|
39
|
+
);
|
|
36
40
|
const FILES_TO_REMOVE = [".stackblitzrc", "sandbox.config.json", "CHANGELOG.md"];
|
|
37
41
|
async function main() {
|
|
38
42
|
var _a;
|
|
@@ -56,37 +60,43 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
|
|
|
56
60
|
let rejectProjectDir = ora({ color: "red", text: notEmptyMsg(cwd) });
|
|
57
61
|
rejectProjectDir.fail();
|
|
58
62
|
}
|
|
59
|
-
const dirResponse = await prompts(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
const dirResponse = await prompts(
|
|
64
|
+
{
|
|
65
|
+
type: "text",
|
|
66
|
+
name: "directory",
|
|
67
|
+
message: "Where would you like to create your new project?",
|
|
68
|
+
initial: "./my-astro-site",
|
|
69
|
+
validate(value) {
|
|
70
|
+
if (!isEmpty(value)) {
|
|
71
|
+
return notEmptyMsg(value);
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
67
74
|
}
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
75
|
+
},
|
|
76
|
+
{ onCancel: () => ora().info(dim("Operation cancelled. See you later, astronaut!")) }
|
|
77
|
+
);
|
|
71
78
|
cwd = dirResponse.directory;
|
|
72
79
|
}
|
|
73
80
|
if (!cwd) {
|
|
74
81
|
process.exit(1);
|
|
75
82
|
}
|
|
76
|
-
const options = await prompts(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
const options = await prompts(
|
|
84
|
+
[
|
|
85
|
+
{
|
|
86
|
+
type: "select",
|
|
87
|
+
name: "template",
|
|
88
|
+
message: "Which template would you like to use?",
|
|
89
|
+
choices: TEMPLATES
|
|
90
|
+
}
|
|
91
|
+
],
|
|
92
|
+
{ onCancel: () => ora().info(dim("Operation cancelled. See you later, astronaut!")) }
|
|
93
|
+
);
|
|
84
94
|
if (!options.template) {
|
|
85
95
|
process.exit(1);
|
|
86
96
|
}
|
|
87
|
-
|
|
97
|
+
let templateSpinner = await loadWithRocketGradient("Copying project files...");
|
|
88
98
|
const hash = args.commit ? `#${args.commit}` : "";
|
|
89
|
-
const templateTarget = `withastro/astro/examples/${options.template}#latest`;
|
|
99
|
+
const templateTarget = options.template.includes("/") ? options.template : `withastro/astro/examples/${options.template}#latest`;
|
|
90
100
|
const emitter = degit(`${templateTarget}${hash}`, {
|
|
91
101
|
cache: false,
|
|
92
102
|
force: true,
|
|
@@ -103,35 +113,88 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
|
|
|
103
113
|
logger.debug(info.message);
|
|
104
114
|
});
|
|
105
115
|
await emitter.clone(cwd);
|
|
116
|
+
if (isEmpty(cwd)) {
|
|
117
|
+
fs.rmdirSync(cwd);
|
|
118
|
+
throw new Error(`Error: The provided template (${cyan(options.template)}) does not exist`);
|
|
119
|
+
}
|
|
106
120
|
} catch (err) {
|
|
121
|
+
templateSpinner.fail();
|
|
107
122
|
logger.debug(err);
|
|
108
123
|
console.error(red(err.message));
|
|
109
|
-
if (err.message === "zlib: unexpected end of file") {
|
|
110
|
-
console.log(
|
|
111
|
-
|
|
124
|
+
if (err.message === "zlib: unexpected end of file" || err.message === "TAR_BAD_ARCHIVE: Unrecognized archive format") {
|
|
125
|
+
console.log(
|
|
126
|
+
yellow(
|
|
127
|
+
"Local degit cache seems to be corrupted. For more information check out this issue: https://github.com/withastro/astro/issues/655. "
|
|
128
|
+
)
|
|
129
|
+
);
|
|
130
|
+
const cacheIssueResponse = await prompts({
|
|
131
|
+
type: "confirm",
|
|
132
|
+
name: "cache",
|
|
133
|
+
message: "Would you like us to clear the cache and try again?",
|
|
134
|
+
initial: true
|
|
135
|
+
});
|
|
136
|
+
if (cacheIssueResponse.cache) {
|
|
137
|
+
const homeDirectory = os.homedir();
|
|
138
|
+
const cacheDir = path.join(homeDirectory, ".degit", "github", "withastro");
|
|
139
|
+
fs.rmSync(cacheDir, { recursive: true, force: true, maxRetries: 3 });
|
|
140
|
+
templateSpinner = await loadWithRocketGradient("Copying project files...");
|
|
141
|
+
try {
|
|
142
|
+
await emitter.clone(cwd);
|
|
143
|
+
} catch (e) {
|
|
144
|
+
logger.debug(e);
|
|
145
|
+
console.error(red(e.message));
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
console.log(
|
|
149
|
+
"Okay, no worries! To fix this manually, remove the folder '~/.degit/github/withastro' and rerun the command."
|
|
150
|
+
);
|
|
151
|
+
}
|
|
112
152
|
}
|
|
113
153
|
if (err.code === "MISSING_REF") {
|
|
114
|
-
console.log(
|
|
115
|
-
|
|
154
|
+
console.log(
|
|
155
|
+
yellow(
|
|
156
|
+
"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)."
|
|
157
|
+
)
|
|
158
|
+
);
|
|
159
|
+
console.log(
|
|
160
|
+
yellow(
|
|
161
|
+
"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"
|
|
162
|
+
)
|
|
163
|
+
);
|
|
116
164
|
}
|
|
117
|
-
templateSpinner.fail();
|
|
118
165
|
process.exit(1);
|
|
119
166
|
}
|
|
120
|
-
await Promise.all(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
167
|
+
await Promise.all(
|
|
168
|
+
FILES_TO_REMOVE.map(async (file) => {
|
|
169
|
+
const fileLoc = path.resolve(path.join(cwd, file));
|
|
170
|
+
if (fs.existsSync(fileLoc)) {
|
|
171
|
+
return fs.promises.rm(fileLoc, {});
|
|
172
|
+
}
|
|
173
|
+
})
|
|
174
|
+
);
|
|
126
175
|
}
|
|
127
176
|
templateSpinner.text = green("Template copied!");
|
|
128
177
|
templateSpinner.succeed();
|
|
129
|
-
const installResponse = await prompts(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
178
|
+
const installResponse = await prompts(
|
|
179
|
+
{
|
|
180
|
+
type: "confirm",
|
|
181
|
+
name: "install",
|
|
182
|
+
message: `Would you like to install ${pkgManager} dependencies? ${reset(
|
|
183
|
+
dim("(recommended)")
|
|
184
|
+
)}`,
|
|
185
|
+
initial: true
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
onCancel: () => {
|
|
189
|
+
ora().info(
|
|
190
|
+
dim(
|
|
191
|
+
"Operation cancelled. Your project folder has already been created, however no dependencies have been installed"
|
|
192
|
+
)
|
|
193
|
+
);
|
|
194
|
+
process.exit(1);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
);
|
|
135
198
|
if (args.dryRun) {
|
|
136
199
|
ora().info(dim(`--dry-run enabled, skipping.`));
|
|
137
200
|
} else if (installResponse.install) {
|
|
@@ -142,7 +205,9 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
|
|
|
142
205
|
var _a2;
|
|
143
206
|
(_a2 = installExec.stdout) == null ? void 0 : _a2.on("data", function(data) {
|
|
144
207
|
installSpinner.text = `${rocketAscii} ${installingPackagesMsg}
|
|
145
|
-
${bold(
|
|
208
|
+
${bold(
|
|
209
|
+
`[${pkgManager}]`
|
|
210
|
+
)} ${data}`;
|
|
146
211
|
});
|
|
147
212
|
installExec.on("error", (error) => reject(error));
|
|
148
213
|
installExec.on("close", () => resolve());
|
|
@@ -152,19 +217,92 @@ ${bold(`[${pkgManager}]`)} ${data}`;
|
|
|
152
217
|
} else {
|
|
153
218
|
ora().info(dim(`No problem! Remember to install dependencies after setup.`));
|
|
154
219
|
}
|
|
155
|
-
const gitResponse = await prompts(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
220
|
+
const gitResponse = await prompts(
|
|
221
|
+
{
|
|
222
|
+
type: "confirm",
|
|
223
|
+
name: "git",
|
|
224
|
+
message: `Would you like to initialize a new git repository? ${reset(dim("(optional)"))}`,
|
|
225
|
+
initial: true
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
onCancel: () => {
|
|
229
|
+
ora().info(
|
|
230
|
+
dim("Operation cancelled. No worries, your project folder has already been created")
|
|
231
|
+
);
|
|
232
|
+
process.exit(1);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
);
|
|
161
236
|
if (args.dryRun) {
|
|
162
237
|
ora().info(dim(`--dry-run enabled, skipping.`));
|
|
163
238
|
} else if (gitResponse.git) {
|
|
164
239
|
await execaCommand("git init", { cwd });
|
|
240
|
+
ora().succeed("Git repository created!");
|
|
165
241
|
} else {
|
|
166
242
|
ora().info(dim(`Sounds good! You can come back and run ${cyan(`git init`)} later.`));
|
|
167
243
|
}
|
|
244
|
+
const tsResponse = await prompts(
|
|
245
|
+
{
|
|
246
|
+
type: "select",
|
|
247
|
+
name: "typescript",
|
|
248
|
+
message: "How would you like to setup TypeScript?",
|
|
249
|
+
choices: [
|
|
250
|
+
{
|
|
251
|
+
title: "Relaxed",
|
|
252
|
+
value: "default"
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
title: "Strict (recommended)",
|
|
256
|
+
description: "Enable `strict` typechecking rules",
|
|
257
|
+
value: "strict"
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
title: "Strictest",
|
|
261
|
+
description: "Enable all typechecking rules",
|
|
262
|
+
value: "stricter"
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
title: "I prefer not to use TypeScript",
|
|
266
|
+
description: `That's cool too!`,
|
|
267
|
+
value: "optout"
|
|
268
|
+
}
|
|
269
|
+
]
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
onCancel: () => {
|
|
273
|
+
ora().info(
|
|
274
|
+
dim(
|
|
275
|
+
"Operation cancelled. Your project folder has been created but no TypeScript configuration file was created."
|
|
276
|
+
)
|
|
277
|
+
);
|
|
278
|
+
process.exit(1);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
);
|
|
282
|
+
if (tsResponse.typescript === "optout") {
|
|
283
|
+
console.log(``);
|
|
284
|
+
ora().warn(yellow(bold(`Astro \u2764\uFE0F TypeScript!`)));
|
|
285
|
+
console.log(` Astro supports TypeScript inside of ".astro" component scripts, so`);
|
|
286
|
+
console.log(` we still need to create some TypeScript-related files in your project.`);
|
|
287
|
+
console.log(` You can safely ignore these files, but don't delete them!`);
|
|
288
|
+
console.log(dim(" (ex: tsconfig.json, src/types.d.ts)"));
|
|
289
|
+
console.log(``);
|
|
290
|
+
tsResponse.typescript = "default";
|
|
291
|
+
await wait(300);
|
|
292
|
+
}
|
|
293
|
+
if (args.dryRun) {
|
|
294
|
+
ora().info(dim(`--dry-run enabled, skipping.`));
|
|
295
|
+
} else if (tsResponse.typescript) {
|
|
296
|
+
fs.copyFileSync(
|
|
297
|
+
path.join(
|
|
298
|
+
url.fileURLToPath(new URL("..", import.meta.url)),
|
|
299
|
+
"tsconfigs",
|
|
300
|
+
`tsconfig.${tsResponse.typescript}.json`
|
|
301
|
+
),
|
|
302
|
+
path.join(cwd, "tsconfig.json")
|
|
303
|
+
);
|
|
304
|
+
ora().succeed("TypeScript settings applied!");
|
|
305
|
+
}
|
|
168
306
|
ora().succeed("Setup complete.");
|
|
169
307
|
ora({ text: green("Ready for liftoff!") }).succeed();
|
|
170
308
|
await wait(300);
|
|
@@ -173,11 +311,21 @@ ${bgCyan(black(" Next steps "))}
|
|
|
173
311
|
`);
|
|
174
312
|
let projectDir = path.relative(process.cwd(), cwd);
|
|
175
313
|
const devCmd = pkgManager === "npm" ? "npm run dev" : `${pkgManager} dev`;
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
314
|
+
if (projectDir !== "/") {
|
|
315
|
+
await logAndWait(
|
|
316
|
+
`You can now ${bold(cyan("cd"))} into the ${bold(cyan(projectDir))} project directory.`
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
await logAndWait(
|
|
320
|
+
`Run ${bold(cyan(devCmd))} to start the Astro dev server. ${bold(cyan("CTRL-C"))} to close.`
|
|
321
|
+
);
|
|
322
|
+
await logAndWait(
|
|
323
|
+
`Add frameworks like ${bold(cyan("react"))} and ${bold(
|
|
324
|
+
cyan("tailwind")
|
|
325
|
+
)} to your project using ${bold(cyan("astro add"))}`
|
|
326
|
+
);
|
|
179
327
|
await logAndWait("");
|
|
180
|
-
await logAndWait(`Stuck? Come join us at ${bold(cyan("https://astro.build/chat"))}`,
|
|
328
|
+
await logAndWait(`Stuck? Come join us at ${bold(cyan("https://astro.build/chat"))}`, 750);
|
|
181
329
|
await logAndWait(dim("Good luck out there, astronaut."));
|
|
182
330
|
await logAndWait("", 300);
|
|
183
331
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-astro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
21
21
|
"dist",
|
|
22
|
-
"create-astro.js"
|
|
22
|
+
"create-astro.js",
|
|
23
|
+
"tsconfigs"
|
|
23
24
|
],
|
|
24
25
|
"dependencies": {
|
|
25
26
|
"chalk": "^5.0.1",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Enable top-level await, and other modern ESM features.
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
// Enable node-style module resolution, for things like npm package imports.
|
|
7
|
+
"moduleResolution": "node",
|
|
8
|
+
// Enable JSON imports.
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
// Enable stricter transpilation for better output.
|
|
11
|
+
"isolatedModules": true,
|
|
12
|
+
// Astro will directly run your TypeScript code, no transpilation needed.
|
|
13
|
+
"noEmit": true,
|
|
14
|
+
// Enable strict type checking.
|
|
15
|
+
"strict": true,
|
|
16
|
+
// Error when a value import is only used as a type.
|
|
17
|
+
"importsNotUsedAsValues": "error"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Enable top-level await, and other modern ESM features.
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
// Enable node-style module resolution, for things like npm package imports.
|
|
7
|
+
"moduleResolution": "node",
|
|
8
|
+
// Enable JSON imports.
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
// Enable stricter transpilation for better output.
|
|
11
|
+
"isolatedModules": true,
|
|
12
|
+
// Astro will directly run your TypeScript code, no transpilation needed.
|
|
13
|
+
"noEmit": true,
|
|
14
|
+
// Enable strict type checking.
|
|
15
|
+
"strict": true,
|
|
16
|
+
// Error when a value import is only used as a type.
|
|
17
|
+
"importsNotUsedAsValues": "error",
|
|
18
|
+
// Report errors for fallthrough cases in switch statements
|
|
19
|
+
"noFallthroughCasesInSwitch": true,
|
|
20
|
+
// Force functions designed to override their parent class to be specified as `override`.
|
|
21
|
+
"noImplicitOverride": true,
|
|
22
|
+
// Force functions to specify that they can return `undefined` if a possibe code path does not return a value.
|
|
23
|
+
"noImplicitReturns": true,
|
|
24
|
+
// Report an error when a variable is declared but never used.
|
|
25
|
+
"noUnusedLocals": true,
|
|
26
|
+
// Report an error when a parameter is declared but never used.
|
|
27
|
+
"noUnusedParameters": true,
|
|
28
|
+
// Force the usage of the indexed syntax to access fields declared using an index signature.
|
|
29
|
+
"noUncheckedIndexedAccess": true,
|
|
30
|
+
// Report an error when the value `undefined` is given to an optional property that doesn't specify `undefined` as a valid value.
|
|
31
|
+
"exactOptionalPropertyTypes": true
|
|
32
|
+
}
|
|
33
|
+
}
|