create-astro 0.10.1 → 0.11.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/index.js +32 -97
- package/dist/templates.js +3 -4
- package/dist/types/templates.d.ts +2 -7
- package/package.json +1 -2
- package/dist/config.js +0 -23
- package/dist/frameworks.js +0 -134
- package/dist/types/config.d.ts +0 -4
- package/dist/types/frameworks.d.ts +0 -30
package/dist/index.js
CHANGED
|
@@ -1,32 +1,13 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
};
|
|
17
1
|
import fs from "fs";
|
|
18
2
|
import path from "path";
|
|
19
3
|
import { bold, cyan, gray, green, red, yellow } from "kleur/colors";
|
|
20
|
-
import fetch from "node-fetch";
|
|
21
4
|
import prompts from "prompts";
|
|
22
5
|
import degit from "degit";
|
|
23
6
|
import yargs from "yargs-parser";
|
|
24
7
|
import ora from "ora";
|
|
25
|
-
import { FRAMEWORKS, COUNTER_COMPONENTS } from "./frameworks.js";
|
|
26
8
|
import { TEMPLATES } from "./templates.js";
|
|
27
|
-
import { createConfig } from "./config.js";
|
|
28
9
|
import { logger, defaultLogLevel } from "./logger.js";
|
|
29
|
-
import { execa } from "execa";
|
|
10
|
+
import { execa, execaCommand } from "execa";
|
|
30
11
|
const cleanArgv = process.argv.filter((arg) => arg !== "--");
|
|
31
12
|
const args = yargs(cleanArgv);
|
|
32
13
|
prompts.override(args);
|
|
@@ -43,8 +24,7 @@ function isEmpty(dirPath) {
|
|
|
43
24
|
return !fs.existsSync(dirPath) || fs.readdirSync(dirPath).length === 0;
|
|
44
25
|
}
|
|
45
26
|
const { version } = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf-8"));
|
|
46
|
-
const FILES_TO_REMOVE = [".stackblitzrc", "sandbox.config.json"];
|
|
47
|
-
const POSTPROCESS_FILES = ["package.json", "astro.config.mjs", "CHANGELOG.md"];
|
|
27
|
+
const FILES_TO_REMOVE = [".stackblitzrc", "sandbox.config.json", "CHANGELOG.md"];
|
|
48
28
|
async function main() {
|
|
49
29
|
const pkgManager = pkgManagerFromUserAgent(process.env.npm_config_user_agent);
|
|
50
30
|
logger.debug("Verbose logging turned on");
|
|
@@ -95,7 +75,7 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
|
|
|
95
75
|
process.exit(1);
|
|
96
76
|
}
|
|
97
77
|
const hash = args.commit ? `#${args.commit}` : "";
|
|
98
|
-
const templateTarget =
|
|
78
|
+
const templateTarget = `withastro/astro/examples/${options.template}#latest`;
|
|
99
79
|
const emitter = degit(`${templateTarget}${hash}`, {
|
|
100
80
|
cache: false,
|
|
101
81
|
force: true,
|
|
@@ -106,19 +86,6 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
|
|
|
106
86
|
force: true,
|
|
107
87
|
verbose: defaultLogLevel === "debug" ? true : false
|
|
108
88
|
});
|
|
109
|
-
const selectedTemplate = TEMPLATES.find((template) => template.value === options.template);
|
|
110
|
-
let integrations = [];
|
|
111
|
-
if ((selectedTemplate == null ? void 0 : selectedTemplate.integrations) === true) {
|
|
112
|
-
const result = await prompts([
|
|
113
|
-
{
|
|
114
|
-
type: "multiselect",
|
|
115
|
-
name: "integrations",
|
|
116
|
-
message: "Which frameworks would you like to use?",
|
|
117
|
-
choices: FRAMEWORKS
|
|
118
|
-
}
|
|
119
|
-
]);
|
|
120
|
-
integrations = result.integrations;
|
|
121
|
-
}
|
|
122
89
|
spinner = ora({ color: "green", text: "Copying project files..." }).start();
|
|
123
90
|
if (!args.dryrun) {
|
|
124
91
|
try {
|
|
@@ -140,67 +107,12 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
|
|
|
140
107
|
spinner.fail();
|
|
141
108
|
process.exit(1);
|
|
142
109
|
}
|
|
143
|
-
await Promise.all(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return fs.promises.rm(fileLoc);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const fileLoc = path.resolve(path.join(cwd, file));
|
|
150
|
-
switch (file) {
|
|
151
|
-
case "CHANGELOG.md": {
|
|
152
|
-
if (fs.existsSync(fileLoc)) {
|
|
153
|
-
await fs.promises.unlink(fileLoc);
|
|
154
|
-
}
|
|
155
|
-
break;
|
|
156
|
-
}
|
|
157
|
-
case "astro.config.mjs": {
|
|
158
|
-
if ((selectedTemplate == null ? void 0 : selectedTemplate.integrations) !== true) {
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
await fs.promises.writeFile(fileLoc, createConfig({ integrations }));
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
case "package.json": {
|
|
165
|
-
const packageJSON = JSON.parse(await fs.promises.readFile(fileLoc, "utf8"));
|
|
166
|
-
delete packageJSON.snowpack;
|
|
167
|
-
const integrationEntries = (await Promise.all(integrations.map((integration) => fetch(`https://registry.npmjs.org/${integration.packageName}/latest`).then((res) => res.json()).then((res) => {
|
|
168
|
-
let dependencies = [[res["name"], `^${res["version"]}`]];
|
|
169
|
-
if (res["peerDependencies"]) {
|
|
170
|
-
for (const peer in res["peerDependencies"]) {
|
|
171
|
-
dependencies.push([peer, res["peerDependencies"][peer]]);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return dependencies;
|
|
175
|
-
})))).flat(1);
|
|
176
|
-
packageJSON.devDependencies = __spreadValues(__spreadValues({}, packageJSON.devDependencies ?? {}), Object.fromEntries(integrationEntries));
|
|
177
|
-
packageJSON.devDependencies = Object.fromEntries(Object.entries(packageJSON.devDependencies).sort((a, b) => a[0].localeCompare(b[0])));
|
|
178
|
-
await fs.promises.writeFile(fileLoc, JSON.stringify(packageJSON, void 0, 2));
|
|
179
|
-
break;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
})
|
|
183
|
-
]);
|
|
184
|
-
if ((selectedTemplate == null ? void 0 : selectedTemplate.value) === "starter") {
|
|
185
|
-
let importStatements = [];
|
|
186
|
-
let components = [];
|
|
187
|
-
await Promise.all(integrations.map(async (integration) => {
|
|
188
|
-
const component = COUNTER_COMPONENTS[integration.id];
|
|
189
|
-
const componentName = path.basename(component.filename, path.extname(component.filename));
|
|
190
|
-
const absFileLoc = path.resolve(cwd, component.filename);
|
|
191
|
-
importStatements.push(`import ${componentName} from '${component.filename.replace(/^src/, "..")}';`);
|
|
192
|
-
components.push(`<${componentName} client:visible />`);
|
|
193
|
-
await fs.promises.writeFile(absFileLoc, component.content);
|
|
194
|
-
}));
|
|
195
|
-
const pageFileLoc = path.resolve(path.join(cwd, "src", "pages", "index.astro"));
|
|
196
|
-
const content = (await fs.promises.readFile(pageFileLoc)).toString();
|
|
197
|
-
const newContent = content.replace(/^(\s*)\/\* ASTRO\:COMPONENT_IMPORTS \*\//gm, (_, indent) => {
|
|
198
|
-
return indent + importStatements.join("\n");
|
|
199
|
-
}).replace(/^(\s*)<!-- ASTRO:COMPONENT_MARKUP -->/gm, (_, indent) => {
|
|
200
|
-
return components.map((ln) => indent + ln).join("\n");
|
|
201
|
-
});
|
|
202
|
-
await fs.promises.writeFile(pageFileLoc, newContent);
|
|
203
|
-
}
|
|
110
|
+
await Promise.all(FILES_TO_REMOVE.map(async (file) => {
|
|
111
|
+
const fileLoc = path.resolve(path.join(cwd, file));
|
|
112
|
+
if (fs.existsSync(fileLoc)) {
|
|
113
|
+
return fs.promises.rm(fileLoc, {});
|
|
114
|
+
}
|
|
115
|
+
}));
|
|
204
116
|
}
|
|
205
117
|
spinner.succeed();
|
|
206
118
|
console.log(bold(green("\u2714") + " Done!"));
|
|
@@ -230,6 +142,22 @@ ${bold(`[${pkgManager}]`)} ${data}`;
|
|
|
230
142
|
}
|
|
231
143
|
spinner.succeed();
|
|
232
144
|
}
|
|
145
|
+
const astroAddCommand = installResponse.install ? "astro add --yes" : `${pkgManagerExecCommand(pkgManager)} astro@latest add --yes`;
|
|
146
|
+
const astroAddResponse = await prompts({
|
|
147
|
+
type: "confirm",
|
|
148
|
+
name: "astroAdd",
|
|
149
|
+
message: `Run "${astroAddCommand}?" This lets you optionally add component frameworks (ex. React), CSS frameworks (ex. Tailwind), and more.`,
|
|
150
|
+
initial: true
|
|
151
|
+
});
|
|
152
|
+
if (!astroAddResponse) {
|
|
153
|
+
process.exit(0);
|
|
154
|
+
}
|
|
155
|
+
if (!astroAddResponse.astroAdd) {
|
|
156
|
+
ora().info(`No problem. You can always run "${pkgManagerExecCommand(pkgManager)} astro add" later!`);
|
|
157
|
+
}
|
|
158
|
+
if (astroAddResponse.astroAdd && !args.dryrun) {
|
|
159
|
+
await execaCommand(astroAddCommand, astroAddCommand === "astro add --yes" ? { cwd, stdio: "inherit", localDir: cwd, preferLocal: true } : { cwd, stdio: "inherit" });
|
|
160
|
+
}
|
|
233
161
|
console.log("\nNext steps:");
|
|
234
162
|
let i = 1;
|
|
235
163
|
const relative = path.relative(process.cwd(), cwd);
|
|
@@ -258,6 +186,13 @@ function pkgManagerFromUserAgent(userAgent) {
|
|
|
258
186
|
const pkgSpecArr = pkgSpec.split("/");
|
|
259
187
|
return pkgSpecArr[0];
|
|
260
188
|
}
|
|
189
|
+
function pkgManagerExecCommand(pkgManager) {
|
|
190
|
+
if (pkgManager === "pnpm") {
|
|
191
|
+
return "pnpx";
|
|
192
|
+
} else {
|
|
193
|
+
return "npx";
|
|
194
|
+
}
|
|
195
|
+
}
|
|
261
196
|
export {
|
|
262
197
|
main,
|
|
263
198
|
mkdirp
|
package/dist/templates.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
const TEMPLATES = [
|
|
2
2
|
{
|
|
3
|
-
title: "
|
|
4
|
-
value: "
|
|
5
|
-
integrations: true
|
|
3
|
+
title: "Just the basics",
|
|
4
|
+
value: "basics"
|
|
6
5
|
},
|
|
7
6
|
{
|
|
8
7
|
title: "Blog",
|
|
@@ -17,7 +16,7 @@ const TEMPLATES = [
|
|
|
17
16
|
value: "portfolio"
|
|
18
17
|
},
|
|
19
18
|
{
|
|
20
|
-
title: "
|
|
19
|
+
title: "Completely empty",
|
|
21
20
|
value: "minimal"
|
|
22
21
|
}
|
|
23
22
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-astro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
"degit": "^2.8.4",
|
|
34
34
|
"execa": "^6.1.0",
|
|
35
35
|
"kleur": "^4.1.4",
|
|
36
|
-
"node-fetch": "^3.2.3",
|
|
37
36
|
"ora": "^6.1.0",
|
|
38
37
|
"prompts": "^2.4.2",
|
|
39
38
|
"yargs-parser": "^21.0.1"
|
package/dist/config.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const createConfig = ({ integrations }) => {
|
|
2
|
-
if (integrations.length === 0) {
|
|
3
|
-
return `import { defineConfig } from 'astro/config';
|
|
4
|
-
// https://astro.build/config
|
|
5
|
-
export default defineConfig({});
|
|
6
|
-
`;
|
|
7
|
-
}
|
|
8
|
-
const rendererImports = integrations.map((r) => ` import ${r.id} from '${r.packageName}';`);
|
|
9
|
-
const rendererIntegrations = integrations.map((r) => ` ${r.id}(),`);
|
|
10
|
-
return [
|
|
11
|
-
`import { defineConfig } from 'astro/config';`,
|
|
12
|
-
...rendererImports,
|
|
13
|
-
`// https://astro.build/config`,
|
|
14
|
-
`export default defineConfig({`,
|
|
15
|
-
` integrations: [`,
|
|
16
|
-
...rendererIntegrations,
|
|
17
|
-
` ]`,
|
|
18
|
-
`});`
|
|
19
|
-
].join("\n");
|
|
20
|
-
};
|
|
21
|
-
export {
|
|
22
|
-
createConfig
|
|
23
|
-
};
|
package/dist/frameworks.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
const COUNTER_COMPONENTS = {
|
|
2
|
-
preact: {
|
|
3
|
-
filename: `src/components/PreactCounter.jsx`,
|
|
4
|
-
content: `import { useState } from 'preact/hooks';
|
|
5
|
-
|
|
6
|
-
export default function PreactCounter() {
|
|
7
|
-
const [count, setCount] = useState(0);
|
|
8
|
-
const add = () => setCount((i) => i + 1);
|
|
9
|
-
const subtract = () => setCount((i) => i - 1);
|
|
10
|
-
|
|
11
|
-
return (
|
|
12
|
-
<div id="preact" class="counter">
|
|
13
|
-
<button onClick={subtract}>-</button>
|
|
14
|
-
<pre>{count}</pre>
|
|
15
|
-
<button onClick={add}>+</button>
|
|
16
|
-
</div>
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
`
|
|
20
|
-
},
|
|
21
|
-
react: {
|
|
22
|
-
filename: `src/components/ReactCounter.jsx`,
|
|
23
|
-
content: `import { useState } from 'react';
|
|
24
|
-
|
|
25
|
-
export default function ReactCounter() {
|
|
26
|
-
const [count, setCount] = useState(0);
|
|
27
|
-
const add = () => setCount((i) => i + 1);
|
|
28
|
-
const subtract = () => setCount((i) => i - 1);
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<div id="react" className="counter">
|
|
32
|
-
<button onClick={subtract}>-</button>
|
|
33
|
-
<pre>{count}</pre>
|
|
34
|
-
<button onClick={add}>+</button>
|
|
35
|
-
</div>
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
`
|
|
39
|
-
},
|
|
40
|
-
solid: {
|
|
41
|
-
filename: `src/components/SolidCounter.jsx`,
|
|
42
|
-
content: `import { createSignal } from "solid-js";
|
|
43
|
-
|
|
44
|
-
export default function SolidCounter() {
|
|
45
|
-
const [count, setCount] = createSignal(0);
|
|
46
|
-
const add = () => setCount(count() + 1);
|
|
47
|
-
const subtract = () => setCount(count() - 1);
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<div id="solid" class="counter">
|
|
51
|
-
<button onClick={subtract}>-</button>
|
|
52
|
-
<pre>{count()}</pre>
|
|
53
|
-
<button onClick={add}>+</button>
|
|
54
|
-
</div>
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
`
|
|
58
|
-
},
|
|
59
|
-
svelte: {
|
|
60
|
-
filename: `src/components/SvelteCounter.svelte`,
|
|
61
|
-
content: `<script>
|
|
62
|
-
let count = 0;
|
|
63
|
-
|
|
64
|
-
function add() {
|
|
65
|
-
count += 1;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function subtract() {
|
|
69
|
-
count -= 1;
|
|
70
|
-
}
|
|
71
|
-
<\/script>
|
|
72
|
-
|
|
73
|
-
<div id="svelte" class="counter">
|
|
74
|
-
<button on:click={subtract}>-</button>
|
|
75
|
-
<pre>{ count }</pre>
|
|
76
|
-
<button on:click={add}>+</button>
|
|
77
|
-
</div>
|
|
78
|
-
`
|
|
79
|
-
},
|
|
80
|
-
vue: {
|
|
81
|
-
filename: `src/components/VueCounter.vue`,
|
|
82
|
-
content: `<template>
|
|
83
|
-
<div id="vue" class="counter">
|
|
84
|
-
<button @click="subtract()">-</button>
|
|
85
|
-
<pre>{{ count }}</pre>
|
|
86
|
-
<button @click="add()">+</button>
|
|
87
|
-
</div>
|
|
88
|
-
</template>
|
|
89
|
-
|
|
90
|
-
<script>
|
|
91
|
-
import { ref } from 'vue';
|
|
92
|
-
export default {
|
|
93
|
-
setup() {
|
|
94
|
-
const count = ref(0)
|
|
95
|
-
const add = () => count.value = count.value + 1;
|
|
96
|
-
const subtract = () => count.value = count.value - 1;
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
count,
|
|
100
|
-
add,
|
|
101
|
-
subtract
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
<\/script>
|
|
106
|
-
`
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
const FRAMEWORKS = [
|
|
110
|
-
{
|
|
111
|
-
title: "Preact",
|
|
112
|
-
value: { id: "preact", packageName: "@astrojs/preact" }
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
title: "React",
|
|
116
|
-
value: { id: "react", packageName: "@astrojs/react" }
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
title: "Solid.js",
|
|
120
|
-
value: { id: "solid", packageName: "@astrojs/solid-js" }
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
title: "Svelte",
|
|
124
|
-
value: { id: "svelte", packageName: "@astrojs/svelte" }
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
title: "Vue",
|
|
128
|
-
value: { id: "vue", packageName: "@astrojs/vue" }
|
|
129
|
-
}
|
|
130
|
-
];
|
|
131
|
-
export {
|
|
132
|
-
COUNTER_COMPONENTS,
|
|
133
|
-
FRAMEWORKS
|
|
134
|
-
};
|
package/dist/types/config.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export declare const COUNTER_COMPONENTS: {
|
|
2
|
-
preact: {
|
|
3
|
-
filename: string;
|
|
4
|
-
content: string;
|
|
5
|
-
};
|
|
6
|
-
react: {
|
|
7
|
-
filename: string;
|
|
8
|
-
content: string;
|
|
9
|
-
};
|
|
10
|
-
solid: {
|
|
11
|
-
filename: string;
|
|
12
|
-
content: string;
|
|
13
|
-
};
|
|
14
|
-
svelte: {
|
|
15
|
-
filename: string;
|
|
16
|
-
content: string;
|
|
17
|
-
};
|
|
18
|
-
vue: {
|
|
19
|
-
filename: string;
|
|
20
|
-
content: string;
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
export interface Integration {
|
|
24
|
-
id: string;
|
|
25
|
-
packageName: string;
|
|
26
|
-
}
|
|
27
|
-
export declare const FRAMEWORKS: {
|
|
28
|
-
title: string;
|
|
29
|
-
value: Integration;
|
|
30
|
-
}[];
|