create-astro 0.9.0 → 0.10.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 +120 -70
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ import { FRAMEWORKS, COUNTER_COMPONENTS } from "./frameworks.js";
|
|
|
26
26
|
import { TEMPLATES } from "./templates.js";
|
|
27
27
|
import { createConfig } from "./config.js";
|
|
28
28
|
import { logger, defaultLogLevel } from "./logger.js";
|
|
29
|
+
import { execa } from "execa";
|
|
29
30
|
const cleanArgv = process.argv.filter((arg) => arg !== "--");
|
|
30
31
|
const args = yargs(cleanArgv);
|
|
31
32
|
prompts.override(args);
|
|
@@ -42,8 +43,10 @@ function isEmpty(dirPath) {
|
|
|
42
43
|
return !fs.existsSync(dirPath) || fs.readdirSync(dirPath).length === 0;
|
|
43
44
|
}
|
|
44
45
|
const { version } = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf-8"));
|
|
46
|
+
const FILES_TO_REMOVE = [".stackblitzrc", "sandbox.config.json"];
|
|
45
47
|
const POSTPROCESS_FILES = ["package.json", "astro.config.mjs", "CHANGELOG.md"];
|
|
46
48
|
async function main() {
|
|
49
|
+
const pkgManager = pkgManagerFromUserAgent(process.env.npm_config_user_agent);
|
|
47
50
|
logger.debug("Verbose logging turned on");
|
|
48
51
|
console.log(`
|
|
49
52
|
${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
|
|
@@ -119,97 +122,144 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
|
|
|
119
122
|
integrations = result.integrations;
|
|
120
123
|
}
|
|
121
124
|
spinner = ora({ color: "green", text: "Copying project files..." }).start();
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (err.code === "MISSING_REF") {
|
|
135
|
-
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)."));
|
|
136
|
-
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"));
|
|
137
|
-
}
|
|
138
|
-
spinner.fail();
|
|
139
|
-
process.exit(1);
|
|
140
|
-
}
|
|
141
|
-
await Promise.all(POSTPROCESS_FILES.map(async (file) => {
|
|
142
|
-
const fileLoc = path.resolve(path.join(cwd, file));
|
|
143
|
-
switch (file) {
|
|
144
|
-
case "CHANGELOG.md": {
|
|
145
|
-
if (fs.existsSync(fileLoc)) {
|
|
146
|
-
await fs.promises.unlink(fileLoc);
|
|
147
|
-
}
|
|
148
|
-
break;
|
|
125
|
+
if (!args.dryrun) {
|
|
126
|
+
try {
|
|
127
|
+
emitter.on("info", (info) => {
|
|
128
|
+
logger.debug(info.message);
|
|
129
|
+
});
|
|
130
|
+
await emitter.clone(cwd);
|
|
131
|
+
} catch (err) {
|
|
132
|
+
logger.debug(err);
|
|
133
|
+
console.error(red(err.message));
|
|
134
|
+
if (err.message === "zlib: unexpected end of file") {
|
|
135
|
+
console.log(yellow("This seems to be a cache related problem. Remove the folder '~/.degit/github/withastro' to fix this error."));
|
|
136
|
+
console.log(yellow("For more information check out this issue: https://github.com/withastro/astro/issues/655"));
|
|
149
137
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
await fs.promises.writeFile(fileLoc, createConfig({ integrations }));
|
|
155
|
-
break;
|
|
138
|
+
if (err.code === "MISSING_REF") {
|
|
139
|
+
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)."));
|
|
140
|
+
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"));
|
|
156
141
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
142
|
+
spinner.fail();
|
|
143
|
+
process.exit(1);
|
|
144
|
+
}
|
|
145
|
+
await Promise.all([
|
|
146
|
+
...FILES_TO_REMOVE.map(async (file) => {
|
|
147
|
+
const fileLoc = path.resolve(path.join(cwd, file));
|
|
148
|
+
return fs.promises.rm(fileLoc);
|
|
149
|
+
}),
|
|
150
|
+
...POSTPROCESS_FILES.map(async (file) => {
|
|
151
|
+
const fileLoc = path.resolve(path.join(cwd, file));
|
|
152
|
+
switch (file) {
|
|
153
|
+
case "CHANGELOG.md": {
|
|
154
|
+
if (fs.existsSync(fileLoc)) {
|
|
155
|
+
await fs.promises.unlink(fileLoc);
|
|
165
156
|
}
|
|
157
|
+
break;
|
|
166
158
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
159
|
+
case "astro.config.mjs": {
|
|
160
|
+
if ((selectedTemplate == null ? void 0 : selectedTemplate.integrations) !== true) {
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
await fs.promises.writeFile(fileLoc, createConfig({ integrations }));
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
case "package.json": {
|
|
167
|
+
const packageJSON = JSON.parse(await fs.promises.readFile(fileLoc, "utf8"));
|
|
168
|
+
delete packageJSON.snowpack;
|
|
169
|
+
const integrationEntries = (await Promise.all(integrations.map((integration) => fetch(`https://registry.npmjs.org/${integration.packageName}/latest`).then((res) => res.json()).then((res) => {
|
|
170
|
+
let dependencies = [[res["name"], `^${res["version"]}`]];
|
|
171
|
+
if (res["peerDependencies"]) {
|
|
172
|
+
for (const peer in res["peerDependencies"]) {
|
|
173
|
+
dependencies.push([peer, res["peerDependencies"][peer]]);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return dependencies;
|
|
177
|
+
})))).flat(1);
|
|
178
|
+
packageJSON.devDependencies = __spreadValues(__spreadValues({}, packageJSON.devDependencies ?? {}), Object.fromEntries(integrationEntries));
|
|
179
|
+
packageJSON.devDependencies = Object.fromEntries(Object.entries(packageJSON.devDependencies).sort((a, b) => a[0].localeCompare(b[0])));
|
|
180
|
+
await fs.promises.writeFile(fileLoc, JSON.stringify(packageJSON, void 0, 2));
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
})
|
|
185
|
+
]);
|
|
186
|
+
if ((selectedTemplate == null ? void 0 : selectedTemplate.value) === "starter") {
|
|
187
|
+
let importStatements = [];
|
|
188
|
+
let components = [];
|
|
189
|
+
await Promise.all(integrations.map(async (integration) => {
|
|
190
|
+
const component = COUNTER_COMPONENTS[integration.id];
|
|
191
|
+
const componentName = path.basename(component.filename, path.extname(component.filename));
|
|
192
|
+
const absFileLoc = path.resolve(cwd, component.filename);
|
|
193
|
+
importStatements.push(`import ${componentName} from '${component.filename.replace(/^src/, "..")}';`);
|
|
194
|
+
components.push(`<${componentName} client:visible />`);
|
|
195
|
+
await fs.promises.writeFile(absFileLoc, component.content);
|
|
196
|
+
}));
|
|
197
|
+
const pageFileLoc = path.resolve(path.join(cwd, "src", "pages", "index.astro"));
|
|
198
|
+
const content = (await fs.promises.readFile(pageFileLoc)).toString();
|
|
199
|
+
const newContent = content.replace(/^(\s*)\/\* ASTRO\:COMPONENT_IMPORTS \*\//gm, (_, indent) => {
|
|
200
|
+
return indent + importStatements.join("\n");
|
|
201
|
+
}).replace(/^(\s*)<!-- ASTRO:COMPONENT_MARKUP -->/gm, (_, indent) => {
|
|
202
|
+
return components.map((ln) => indent + ln).join("\n");
|
|
203
|
+
});
|
|
204
|
+
await fs.promises.writeFile(pageFileLoc, newContent);
|
|
174
205
|
}
|
|
175
|
-
}));
|
|
176
|
-
if ((selectedTemplate == null ? void 0 : selectedTemplate.value) === "starter") {
|
|
177
|
-
let importStatements = [];
|
|
178
|
-
let components = [];
|
|
179
|
-
await Promise.all(integrations.map(async (integration) => {
|
|
180
|
-
const component = COUNTER_COMPONENTS[integration.id];
|
|
181
|
-
const componentName = path.basename(component.filename, path.extname(component.filename));
|
|
182
|
-
const absFileLoc = path.resolve(cwd, component.filename);
|
|
183
|
-
importStatements.push(`import ${componentName} from '${component.filename.replace(/^src/, "..")}';`);
|
|
184
|
-
components.push(`<${componentName} client:visible />`);
|
|
185
|
-
await fs.promises.writeFile(absFileLoc, component.content);
|
|
186
|
-
}));
|
|
187
|
-
const pageFileLoc = path.resolve(path.join(cwd, "src", "pages", "index.astro"));
|
|
188
|
-
const content = (await fs.promises.readFile(pageFileLoc)).toString();
|
|
189
|
-
const newContent = content.replace(/^(\s*)\/\* ASTRO\:COMPONENT_IMPORTS \*\//gm, (_, indent) => {
|
|
190
|
-
return indent + importStatements.join("\n");
|
|
191
|
-
}).replace(/^(\s*)<!-- ASTRO:COMPONENT_MARKUP -->/gm, (_, indent) => {
|
|
192
|
-
return components.map((ln) => indent + ln).join("\n");
|
|
193
|
-
});
|
|
194
|
-
await fs.promises.writeFile(pageFileLoc, newContent);
|
|
195
206
|
}
|
|
196
207
|
spinner.succeed();
|
|
197
208
|
console.log(bold(green("\u2714") + " Done!"));
|
|
209
|
+
const installResponse = await prompts({
|
|
210
|
+
type: "confirm",
|
|
211
|
+
name: "install",
|
|
212
|
+
message: `Would you like us to run "${pkgManager} install?"`,
|
|
213
|
+
initial: true
|
|
214
|
+
});
|
|
215
|
+
if (!installResponse) {
|
|
216
|
+
process.exit(0);
|
|
217
|
+
}
|
|
218
|
+
if (installResponse.install) {
|
|
219
|
+
const installExec = execa(pkgManager, ["install"], { cwd });
|
|
220
|
+
const installingPackagesMsg = `Installing packages${emojiWithFallback(" \u{1F4E6}", "...")}`;
|
|
221
|
+
spinner = ora({ color: "green", text: installingPackagesMsg }).start();
|
|
222
|
+
if (!args.dryrun) {
|
|
223
|
+
await new Promise((resolve, reject) => {
|
|
224
|
+
var _a;
|
|
225
|
+
(_a = installExec.stdout) == null ? void 0 : _a.on("data", function(data) {
|
|
226
|
+
spinner.text = `${installingPackagesMsg}
|
|
227
|
+
${bold(`[${pkgManager}]`)} ${data}`;
|
|
228
|
+
});
|
|
229
|
+
installExec.on("error", (error) => reject(error));
|
|
230
|
+
installExec.on("close", () => resolve());
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
spinner.succeed();
|
|
234
|
+
}
|
|
198
235
|
console.log("\nNext steps:");
|
|
199
236
|
let i = 1;
|
|
200
237
|
const relative = path.relative(process.cwd(), cwd);
|
|
201
238
|
if (relative !== "") {
|
|
202
239
|
console.log(` ${i++}: ${bold(cyan(`cd ${relative}`))}`);
|
|
203
240
|
}
|
|
204
|
-
|
|
241
|
+
if (!installResponse.install) {
|
|
242
|
+
console.log(` ${i++}: ${bold(cyan(`${pkgManager} install`))}`);
|
|
243
|
+
}
|
|
205
244
|
console.log(` ${i++}: ${bold(cyan('git init && git add -A && git commit -m "Initial commit"'))} (optional step)`);
|
|
206
|
-
|
|
245
|
+
const runCommand = pkgManager === "npm" ? "npm run dev" : `${pkgManager} dev`;
|
|
246
|
+
console.log(` ${i++}: ${bold(cyan(runCommand))}`);
|
|
207
247
|
console.log(`
|
|
208
248
|
To close the dev server, hit ${bold(cyan("Ctrl-C"))}`);
|
|
209
249
|
console.log(`
|
|
210
250
|
Stuck? Visit us at ${cyan("https://astro.build/chat")}
|
|
211
251
|
`);
|
|
212
252
|
}
|
|
253
|
+
function emojiWithFallback(char, fallback) {
|
|
254
|
+
return process.platform !== "win32" ? char : fallback;
|
|
255
|
+
}
|
|
256
|
+
function pkgManagerFromUserAgent(userAgent) {
|
|
257
|
+
if (!userAgent)
|
|
258
|
+
return "npm";
|
|
259
|
+
const pkgSpec = userAgent.split(" ")[0];
|
|
260
|
+
const pkgSpecArr = pkgSpec.split("/");
|
|
261
|
+
return pkgSpecArr[0];
|
|
262
|
+
}
|
|
213
263
|
export {
|
|
214
264
|
main,
|
|
215
265
|
mkdirp
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-astro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"@types/degit": "^2.8.3",
|
|
32
32
|
"@types/prompts": "^2.0.14",
|
|
33
33
|
"degit": "^2.8.4",
|
|
34
|
+
"execa": "^6.1.0",
|
|
34
35
|
"kleur": "^4.1.4",
|
|
35
36
|
"node-fetch": "^3.2.3",
|
|
36
37
|
"ora": "^6.1.0",
|
|
@@ -39,7 +40,7 @@
|
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@types/chai": "^4.3.1",
|
|
42
|
-
"@types/mocha": "^9.1.
|
|
43
|
+
"@types/mocha": "^9.1.1",
|
|
43
44
|
"@types/yargs-parser": "^21.0.0",
|
|
44
45
|
"astro-scripts": "workspace:*",
|
|
45
46
|
"chai": "^4.3.6",
|