create-astro 4.9.1 → 4.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/create-astro.mjs +1 -1
- package/dist/index.js +15 -38
- package/package.json +2 -2
package/create-astro.mjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -446,7 +446,7 @@ function printHelp({
|
|
|
446
446
|
if (headline) {
|
|
447
447
|
message.push(
|
|
448
448
|
linebreak(),
|
|
449
|
-
`${title(commandName)} ${color.green(`v${"4.
|
|
449
|
+
`${title(commandName)} ${color.green(`v${"4.10.0"}`)} ${headline}`
|
|
450
450
|
);
|
|
451
451
|
}
|
|
452
452
|
if (usage) {
|
|
@@ -523,7 +523,7 @@ async function getContext(argv) {
|
|
|
523
523
|
prompt,
|
|
524
524
|
packageManager,
|
|
525
525
|
username: getName(),
|
|
526
|
-
version: getVersion(packageManager, "astro", "4.
|
|
526
|
+
version: getVersion(packageManager, "astro", "4.16.1"),
|
|
527
527
|
skipHouston,
|
|
528
528
|
fancy,
|
|
529
529
|
dryRun,
|
|
@@ -841,7 +841,7 @@ async function checkCwd(cwd) {
|
|
|
841
841
|
import fs4 from "node:fs";
|
|
842
842
|
import path5 from "node:path";
|
|
843
843
|
import { color as color6 } from "@astrojs/cli-kit";
|
|
844
|
-
import { downloadTemplate } from "giget";
|
|
844
|
+
import { downloadTemplate } from "@bluwy/giget-core";
|
|
845
845
|
async function template(ctx) {
|
|
846
846
|
if (!ctx.template && ctx.yes) ctx.template = "basics";
|
|
847
847
|
if (ctx.template) {
|
|
@@ -900,11 +900,15 @@ var FILES_TO_UPDATE = {
|
|
|
900
900
|
function getTemplateTarget(tmpl, ref = "latest") {
|
|
901
901
|
if (tmpl.startsWith("starlight")) {
|
|
902
902
|
const [, starter = "basics"] = tmpl.split("/");
|
|
903
|
-
return `withastro/starlight/examples/${starter}`;
|
|
903
|
+
return `github:withastro/starlight/examples/${starter}`;
|
|
904
904
|
}
|
|
905
905
|
const isThirdParty = tmpl.includes("/");
|
|
906
906
|
if (isThirdParty) return tmpl;
|
|
907
|
-
|
|
907
|
+
if (ref === "latest") {
|
|
908
|
+
return `github:withastro/astro#examples/${tmpl}`;
|
|
909
|
+
} else {
|
|
910
|
+
return `github:withastro/astro/examples/${tmpl}#${ref}`;
|
|
911
|
+
}
|
|
908
912
|
}
|
|
909
913
|
async function copyTemplate(tmpl, ctx) {
|
|
910
914
|
const templateTarget = getTemplateTarget(tmpl, ctx.ref);
|
|
@@ -912,7 +916,6 @@ async function copyTemplate(tmpl, ctx) {
|
|
|
912
916
|
try {
|
|
913
917
|
await downloadTemplate(templateTarget, {
|
|
914
918
|
force: true,
|
|
915
|
-
provider: "github",
|
|
916
919
|
cwd: ctx.cwd,
|
|
917
920
|
dir: "."
|
|
918
921
|
});
|
|
@@ -940,9 +943,6 @@ async function copyTemplate(tmpl, ctx) {
|
|
|
940
943
|
}
|
|
941
944
|
throw new Error(`Unable to download template ${color6.reset(tmpl)}`);
|
|
942
945
|
}
|
|
943
|
-
if (fs4.readdirSync(ctx.cwd).length === 0) {
|
|
944
|
-
throw new Error(`Template ${color6.reset(tmpl)} ${color6.dim("is empty!")}`);
|
|
945
|
-
}
|
|
946
946
|
const removeFiles = FILES_TO_REMOVE.map(async (file) => {
|
|
947
947
|
const fileLoc = path5.resolve(path5.join(ctx.cwd, file));
|
|
948
948
|
if (fs4.existsSync(fileLoc)) {
|
|
@@ -1129,7 +1129,7 @@ var FILES_TO_UPDATE2 = {
|
|
|
1129
1129
|
parsedPackageJson.dependencies ??= {};
|
|
1130
1130
|
parsedPackageJson.dependencies["@astrojs/check"] = `^${astroCheckVersion}`;
|
|
1131
1131
|
parsedPackageJson.dependencies.typescript = `^${typescriptVersion}`;
|
|
1132
|
-
await writeFile(file, JSON.stringify(parsedPackageJson, null, indent), "utf-8");
|
|
1132
|
+
await writeFile(file, JSON.stringify(parsedPackageJson, null, indent) + "\n", "utf-8");
|
|
1133
1133
|
} catch (err) {
|
|
1134
1134
|
if (err && err.code === "ENOENT") return;
|
|
1135
1135
|
if (err instanceof Error) throw new Error(err.message);
|
|
@@ -1143,7 +1143,7 @@ var FILES_TO_UPDATE2 = {
|
|
|
1143
1143
|
const result = Object.assign(templateTSConfig, {
|
|
1144
1144
|
extends: `astro/tsconfigs/${options.value}`
|
|
1145
1145
|
});
|
|
1146
|
-
await writeFile(file, JSON.stringify(result, null, 2));
|
|
1146
|
+
await writeFile(file, JSON.stringify(result, null, 2) + "\n");
|
|
1147
1147
|
} else {
|
|
1148
1148
|
throw new Error(
|
|
1149
1149
|
"There was an error applying the requested TypeScript settings. This could be because the template's tsconfig.json is malformed"
|
|
@@ -1153,7 +1153,7 @@ var FILES_TO_UPDATE2 = {
|
|
|
1153
1153
|
if (err && err.code === "ENOENT") {
|
|
1154
1154
|
await writeFile(
|
|
1155
1155
|
file,
|
|
1156
|
-
JSON.stringify({ extends: `astro/tsconfigs/${options.value}` }, null, 2)
|
|
1156
|
+
JSON.stringify({ extends: `astro/tsconfigs/${options.value}` }, null, 2) + "\n"
|
|
1157
1157
|
);
|
|
1158
1158
|
}
|
|
1159
1159
|
}
|
|
@@ -1184,6 +1184,7 @@ async function setupTypeScript(value, ctx) {
|
|
|
1184
1184
|
// src/actions/verify.ts
|
|
1185
1185
|
import dns from "node:dns/promises";
|
|
1186
1186
|
import { color as color8 } from "@astrojs/cli-kit";
|
|
1187
|
+
import { verifyTemplate } from "@bluwy/giget-core";
|
|
1187
1188
|
async function verify(ctx) {
|
|
1188
1189
|
if (!ctx.dryRun) {
|
|
1189
1190
|
const online = await isOnline();
|
|
@@ -1195,7 +1196,8 @@ async function verify(ctx) {
|
|
|
1195
1196
|
}
|
|
1196
1197
|
}
|
|
1197
1198
|
if (ctx.template) {
|
|
1198
|
-
const
|
|
1199
|
+
const target = getTemplateTarget(ctx.template, ctx.ref);
|
|
1200
|
+
const ok = await verifyTemplate(target);
|
|
1199
1201
|
if (!ok) {
|
|
1200
1202
|
bannerAbort();
|
|
1201
1203
|
log("");
|
|
@@ -1211,31 +1213,6 @@ function isOnline() {
|
|
|
1211
1213
|
() => false
|
|
1212
1214
|
);
|
|
1213
1215
|
}
|
|
1214
|
-
async function verifyTemplate(tmpl, ref) {
|
|
1215
|
-
const target = getTemplateTarget(tmpl, ref);
|
|
1216
|
-
const { repo, subdir, ref: branch } = parseGitURI(target.replace("github:", ""));
|
|
1217
|
-
const url = new URL(`/repos/${repo}/contents${subdir}?ref=${branch}`, "https://api.github.com/");
|
|
1218
|
-
let res = await fetch(url.toString(), {
|
|
1219
|
-
headers: {
|
|
1220
|
-
Accept: "application/vnd.github+json",
|
|
1221
|
-
"X-GitHub-Api-Version": "2022-11-28"
|
|
1222
|
-
}
|
|
1223
|
-
});
|
|
1224
|
-
if (res.status === 403) {
|
|
1225
|
-
res = await fetch(`https://github.com/${repo}/tree/${branch}${subdir}`);
|
|
1226
|
-
}
|
|
1227
|
-
return res.status === 200;
|
|
1228
|
-
}
|
|
1229
|
-
var GIT_RE = /^(?<repo>[\w.-]+\/[\w.-]+)(?<subdir>[^#]+)?(?<ref>#[\w.-]+)?/;
|
|
1230
|
-
function parseGitURI(input) {
|
|
1231
|
-
const m = GIT_RE.exec(input)?.groups;
|
|
1232
|
-
if (!m) throw new Error(`Unable to parse "${input}"`);
|
|
1233
|
-
return {
|
|
1234
|
-
repo: m.repo,
|
|
1235
|
-
subdir: m.subdir || "/",
|
|
1236
|
-
ref: m.ref ? m.ref.slice(1) : "main"
|
|
1237
|
-
};
|
|
1238
|
-
}
|
|
1239
1216
|
|
|
1240
1217
|
// src/index.ts
|
|
1241
1218
|
var exit = () => process.exit(0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-astro",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.10.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"//b": "DEPENDENCIES IS FOR UNBUNDLED PACKAGES",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@astrojs/cli-kit": "^0.4.1",
|
|
29
|
-
"giget": "1.
|
|
29
|
+
"@bluwy/giget-core": "^0.1.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"arg": "^5.0.2",
|