create-astro 1.0.1 → 1.1.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/README.md +6 -6
- package/dist/index.js +68 -34
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
**With NPM:**
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm
|
|
8
|
+
npm create astro@latest
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
**With Yarn:**
|
|
@@ -18,10 +18,10 @@ yarn create astro
|
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
20
|
# npm 6.x
|
|
21
|
-
npm
|
|
21
|
+
npm create astro@latest my-astro-project --template starter
|
|
22
22
|
|
|
23
23
|
# npm 7+, extra double-dash is needed:
|
|
24
|
-
npm
|
|
24
|
+
npm create astro@latest my-astro-project -- --template starter
|
|
25
25
|
|
|
26
26
|
# yarn
|
|
27
27
|
yarn create astro my-astro-project --template starter
|
|
@@ -31,7 +31,7 @@ yarn create astro my-astro-project --template starter
|
|
|
31
31
|
You can also use any GitHub repo as a template:
|
|
32
32
|
|
|
33
33
|
```bash
|
|
34
|
-
npm
|
|
34
|
+
npm create astro@latest my-astro-project -- --template cassidoo/shopify-react-astro
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
### CLI Flags
|
|
@@ -49,10 +49,10 @@ To debug `create-astro`, you can use the `--verbose` flag which will log the out
|
|
|
49
49
|
|
|
50
50
|
```bash
|
|
51
51
|
# npm 6.x
|
|
52
|
-
npm
|
|
52
|
+
npm create astro@latest my-astro-project --verbose
|
|
53
53
|
|
|
54
54
|
# npm 7+, extra double-dash is needed:
|
|
55
|
-
npm
|
|
55
|
+
npm create astro@latest my-astro-project -- --verbose
|
|
56
56
|
|
|
57
57
|
# yarn
|
|
58
58
|
yarn create astro my-astro-project --verbose
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,40 @@ function mkdirp(dir) {
|
|
|
34
34
|
function isEmpty(dirPath) {
|
|
35
35
|
return !fs.existsSync(dirPath) || fs.readdirSync(dirPath).length === 0;
|
|
36
36
|
}
|
|
37
|
+
const VALID_PROJECT_DIRECTORY_SAFE_LIST = [
|
|
38
|
+
".DS_Store",
|
|
39
|
+
".git",
|
|
40
|
+
".gitattributes",
|
|
41
|
+
".gitignore",
|
|
42
|
+
".gitlab-ci.yml",
|
|
43
|
+
".hg",
|
|
44
|
+
".hgcheck",
|
|
45
|
+
".hgignore",
|
|
46
|
+
".idea",
|
|
47
|
+
".npmignore",
|
|
48
|
+
".travis.yml",
|
|
49
|
+
".yarn",
|
|
50
|
+
".yarnrc.yml",
|
|
51
|
+
"docs",
|
|
52
|
+
"LICENSE",
|
|
53
|
+
"mkdocs.yml",
|
|
54
|
+
"Thumbs.db",
|
|
55
|
+
/\.iml$/,
|
|
56
|
+
/^npm-debug\.log/,
|
|
57
|
+
/^yarn-debug\.log/,
|
|
58
|
+
/^yarn-error\.log/
|
|
59
|
+
];
|
|
60
|
+
function isValidProjectDirectory(dirPath) {
|
|
61
|
+
if (!fs.existsSync(dirPath)) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
const conflicts = fs.readdirSync(dirPath).filter((content) => {
|
|
65
|
+
return !VALID_PROJECT_DIRECTORY_SAFE_LIST.some((safeContent) => {
|
|
66
|
+
return typeof safeContent === "string" ? content === safeContent : safeContent.test(content);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
return conflicts.length === 0;
|
|
70
|
+
}
|
|
37
71
|
const { version } = JSON.parse(
|
|
38
72
|
fs.readFileSync(new URL("../package.json", import.meta.url), "utf-8")
|
|
39
73
|
);
|
|
@@ -47,16 +81,16 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
|
|
|
47
81
|
console.log(`Lets walk through setting up your new Astro project.
|
|
48
82
|
`);
|
|
49
83
|
let cwd = args["_"][2];
|
|
50
|
-
if (cwd &&
|
|
84
|
+
if (cwd && isValidProjectDirectory(cwd)) {
|
|
51
85
|
let acknowledgeProjectDir = ora({
|
|
52
86
|
color: "green",
|
|
53
87
|
text: `Using ${bold(cwd)} as project directory.`
|
|
54
88
|
});
|
|
55
89
|
acknowledgeProjectDir.succeed();
|
|
56
90
|
}
|
|
57
|
-
if (!cwd || !
|
|
91
|
+
if (!cwd || !isValidProjectDirectory(cwd)) {
|
|
58
92
|
const notEmptyMsg = (dirPath) => `"${bold(dirPath)}" is not empty!`;
|
|
59
|
-
if (!
|
|
93
|
+
if (!isValidProjectDirectory(cwd)) {
|
|
60
94
|
let rejectProjectDir = ora({ color: "red", text: notEmptyMsg(cwd) });
|
|
61
95
|
rejectProjectDir.fail();
|
|
62
96
|
}
|
|
@@ -67,7 +101,7 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
|
|
|
67
101
|
message: "Where would you like to create your new project?",
|
|
68
102
|
initial: "./my-astro-site",
|
|
69
103
|
validate(value) {
|
|
70
|
-
if (!
|
|
104
|
+
if (!isValidProjectDirectory(value)) {
|
|
71
105
|
return notEmptyMsg(value);
|
|
72
106
|
}
|
|
73
107
|
return true;
|
|
@@ -97,7 +131,7 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
|
|
|
97
131
|
let templateSpinner = await loadWithRocketGradient("Copying project files...");
|
|
98
132
|
const hash = args.commit ? `#${args.commit}` : "";
|
|
99
133
|
const isThirdParty = options.template.includes("/");
|
|
100
|
-
const templateTarget =
|
|
134
|
+
const templateTarget = isThirdParty ? options.template : `withastro/astro/examples/${options.template}#latest`;
|
|
101
135
|
const emitter = degit(`${templateTarget}${hash}`, {
|
|
102
136
|
cache: false,
|
|
103
137
|
force: true,
|
|
@@ -114,8 +148,10 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
|
|
|
114
148
|
logger.debug(info.message);
|
|
115
149
|
});
|
|
116
150
|
await emitter.clone(cwd);
|
|
117
|
-
if (
|
|
118
|
-
|
|
151
|
+
if (isValidProjectDirectory(cwd)) {
|
|
152
|
+
if (isEmpty(cwd)) {
|
|
153
|
+
fs.rmdirSync(cwd);
|
|
154
|
+
}
|
|
119
155
|
throw new Error(`Error: The provided template (${cyan(options.template)}) does not exist`);
|
|
120
156
|
}
|
|
121
157
|
} catch (err) {
|
|
@@ -250,7 +286,7 @@ ${bold(
|
|
|
250
286
|
choices: [
|
|
251
287
|
{
|
|
252
288
|
title: "Relaxed",
|
|
253
|
-
value: "
|
|
289
|
+
value: "base"
|
|
254
290
|
},
|
|
255
291
|
{
|
|
256
292
|
title: "Strict (recommended)",
|
|
@@ -288,37 +324,35 @@ ${bold(
|
|
|
288
324
|
console.log(` You can safely ignore these files, but don't delete them!`);
|
|
289
325
|
console.log(dim(" (ex: tsconfig.json, src/env.d.ts)"));
|
|
290
326
|
console.log(``);
|
|
291
|
-
tsResponse.typescript = "
|
|
327
|
+
tsResponse.typescript = "base";
|
|
292
328
|
await wait(300);
|
|
293
329
|
}
|
|
294
330
|
if (args.dryRun) {
|
|
295
331
|
ora().info(dim(`--dry-run enabled, skipping.`));
|
|
296
332
|
} else if (tsResponse.typescript) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
});
|
|
321
|
-
}
|
|
333
|
+
const templateTSConfigPath = path.join(cwd, "tsconfig.json");
|
|
334
|
+
fs.readFile(templateTSConfigPath, (err, data) => {
|
|
335
|
+
if (err && err.code === "ENOENT") {
|
|
336
|
+
fs.writeFileSync(
|
|
337
|
+
templateTSConfigPath,
|
|
338
|
+
stringify({ extends: `astro/tsconfigs/${tsResponse.typescript}` }, null, 2)
|
|
339
|
+
);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
const templateTSConfig = parse(data.toString());
|
|
343
|
+
if (templateTSConfig && typeof templateTSConfig === "object") {
|
|
344
|
+
const result = assign(templateTSConfig, {
|
|
345
|
+
extends: `astro/tsconfigs/${tsResponse.typescript}`
|
|
346
|
+
});
|
|
347
|
+
fs.writeFileSync(templateTSConfigPath, stringify(result, null, 2));
|
|
348
|
+
} else {
|
|
349
|
+
console.log(
|
|
350
|
+
yellow(
|
|
351
|
+
"There was an error applying the requested TypeScript settings. This could be because the template's tsconfig.json is malformed"
|
|
352
|
+
)
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
});
|
|
322
356
|
ora().succeed("TypeScript settings applied!");
|
|
323
357
|
}
|
|
324
358
|
ora().succeed("Setup complete.");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-astro",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"kleur": "^4.1.4",
|
|
31
31
|
"ora": "^6.1.0",
|
|
32
32
|
"prompts": "^2.4.2",
|
|
33
|
+
"strip-ansi": "^7.0.1",
|
|
33
34
|
"which-pm-runs": "^1.1.0",
|
|
34
35
|
"yargs-parser": "^21.0.1"
|
|
35
36
|
},
|
|
@@ -40,7 +41,7 @@
|
|
|
40
41
|
"@types/prompts": "^2.0.14",
|
|
41
42
|
"@types/which-pm-runs": "^1.0.0",
|
|
42
43
|
"@types/yargs-parser": "^21.0.0",
|
|
43
|
-
"astro-scripts": "0.0.
|
|
44
|
+
"astro-scripts": "0.0.8",
|
|
44
45
|
"chai": "^4.3.6",
|
|
45
46
|
"mocha": "^9.2.2",
|
|
46
47
|
"uvu": "^0.5.3"
|