create-astro 4.3.0 → 4.4.1
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/actions/typescript.d.ts +4 -4
- package/dist/index.js +60 -26
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Context } from './context.js';
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
4
|
-
|
|
5
|
-
}
|
|
2
|
+
type PickedTypeScriptContext = Pick<Context, 'typescript' | 'yes' | 'prompt' | 'dryRun' | 'cwd' | 'exit' | 'packageManager' | 'install'>;
|
|
3
|
+
export declare function typescript(ctx: PickedTypeScriptContext): Promise<void>;
|
|
4
|
+
export declare function setupTypeScript(value: string, ctx: PickedTypeScriptContext): Promise<void>;
|
|
5
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -391,7 +391,7 @@ function printHelp({
|
|
|
391
391
|
if (headline) {
|
|
392
392
|
message.push(
|
|
393
393
|
linebreak(),
|
|
394
|
-
`${title(commandName)} ${color.green(`v${"4.
|
|
394
|
+
`${title(commandName)} ${color.green(`v${"4.4.1"}`)} ${headline}`
|
|
395
395
|
);
|
|
396
396
|
}
|
|
397
397
|
if (usage) {
|
|
@@ -863,7 +863,12 @@ async function copyTemplate(tmpl, ctx) {
|
|
|
863
863
|
dir: "."
|
|
864
864
|
});
|
|
865
865
|
} catch (err) {
|
|
866
|
-
|
|
866
|
+
if (ctx.cwd !== "." && ctx.cwd !== "./" && !ctx.cwd.startsWith("../")) {
|
|
867
|
+
try {
|
|
868
|
+
fs4.rmdirSync(ctx.cwd);
|
|
869
|
+
} catch (_) {
|
|
870
|
+
}
|
|
871
|
+
}
|
|
867
872
|
if (err.message.includes("404")) {
|
|
868
873
|
throw new Error(`Template ${color6.reset(tmpl)} ${color6.dim("does not exist!")}`);
|
|
869
874
|
} else {
|
|
@@ -891,8 +896,7 @@ async function copyTemplate(tmpl, ctx) {
|
|
|
891
896
|
|
|
892
897
|
// src/actions/typescript.ts
|
|
893
898
|
import { color as color7 } from "@astrojs/cli-kit";
|
|
894
|
-
import
|
|
895
|
-
import { readFile } from "node:fs/promises";
|
|
899
|
+
import { readFile, rm, writeFile } from "node:fs/promises";
|
|
896
900
|
import path6 from "node:path";
|
|
897
901
|
|
|
898
902
|
// ../../node_modules/.pnpm/strip-json-comments@5.0.1/node_modules/strip-json-comments/index.js
|
|
@@ -1013,7 +1017,7 @@ async function typescript(ctx) {
|
|
|
1013
1017
|
} else {
|
|
1014
1018
|
if (!["strict", "strictest", "relaxed", "default", "base"].includes(ts)) {
|
|
1015
1019
|
if (!ctx.dryRun) {
|
|
1016
|
-
|
|
1020
|
+
await rm(ctx.cwd, { recursive: true, force: true });
|
|
1017
1021
|
}
|
|
1018
1022
|
error(
|
|
1019
1023
|
"Error",
|
|
@@ -1034,7 +1038,7 @@ async function typescript(ctx) {
|
|
|
1034
1038
|
await spinner({
|
|
1035
1039
|
start: "TypeScript customizing...",
|
|
1036
1040
|
end: "TypeScript customized",
|
|
1037
|
-
while: () => setupTypeScript(ts,
|
|
1041
|
+
while: () => setupTypeScript(ts, ctx).catch((e) => {
|
|
1038
1042
|
error("error", e);
|
|
1039
1043
|
process.exit(1);
|
|
1040
1044
|
})
|
|
@@ -1042,29 +1046,59 @@ async function typescript(ctx) {
|
|
|
1042
1046
|
} else {
|
|
1043
1047
|
}
|
|
1044
1048
|
}
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
});
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1049
|
+
var FILES_TO_UPDATE2 = {
|
|
1050
|
+
"package.json": async (file, options) => {
|
|
1051
|
+
try {
|
|
1052
|
+
if (options.ctx.install)
|
|
1053
|
+
await shell(options.ctx.packageManager, ["install", "@astrojs/check", "typescript"], {
|
|
1054
|
+
cwd: path6.dirname(file),
|
|
1055
|
+
stdio: "ignore"
|
|
1056
|
+
});
|
|
1057
|
+
const data = await readFile(file, { encoding: "utf-8" });
|
|
1058
|
+
const indent = /(^\s+)/m.exec(data)?.[1] ?? " ";
|
|
1059
|
+
const parsedPackageJson = JSON.parse(data);
|
|
1060
|
+
const buildScript = parsedPackageJson.scripts?.build;
|
|
1061
|
+
if (typeof buildScript === "string" && !buildScript.includes("astro check")) {
|
|
1062
|
+
parsedPackageJson.scripts.build = `astro check && ${buildScript}`;
|
|
1063
|
+
await writeFile(file, JSON.stringify(parsedPackageJson, null, indent), "utf-8");
|
|
1064
|
+
}
|
|
1065
|
+
} catch (err) {
|
|
1066
|
+
if (err && err.code === "ENOENT")
|
|
1067
|
+
return;
|
|
1068
|
+
if (err instanceof Error)
|
|
1069
|
+
throw new Error(err.message);
|
|
1059
1070
|
}
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
)
|
|
1071
|
+
},
|
|
1072
|
+
"tsconfig.json": async (file, options) => {
|
|
1073
|
+
try {
|
|
1074
|
+
const data = await readFile(file, { encoding: "utf-8" });
|
|
1075
|
+
const templateTSConfig = JSON.parse(stripJsonComments(data));
|
|
1076
|
+
if (templateTSConfig && typeof templateTSConfig === "object") {
|
|
1077
|
+
const result = Object.assign(templateTSConfig, {
|
|
1078
|
+
extends: `astro/tsconfigs/${options.value}`
|
|
1079
|
+
});
|
|
1080
|
+
await writeFile(file, JSON.stringify(result, null, 2));
|
|
1081
|
+
} else {
|
|
1082
|
+
throw new Error(
|
|
1083
|
+
"There was an error applying the requested TypeScript settings. This could be because the template's tsconfig.json is malformed"
|
|
1084
|
+
);
|
|
1085
|
+
}
|
|
1086
|
+
} catch (err) {
|
|
1087
|
+
if (err && err.code === "ENOENT") {
|
|
1088
|
+
await writeFile(
|
|
1089
|
+
file,
|
|
1090
|
+
JSON.stringify({ extends: `astro/tsconfigs/${options.value}` }, null, 2)
|
|
1091
|
+
);
|
|
1092
|
+
}
|
|
1066
1093
|
}
|
|
1067
1094
|
}
|
|
1095
|
+
};
|
|
1096
|
+
async function setupTypeScript(value, ctx) {
|
|
1097
|
+
await Promise.all(
|
|
1098
|
+
Object.entries(FILES_TO_UPDATE2).map(
|
|
1099
|
+
async ([file, update]) => update(path6.resolve(path6.join(ctx.cwd, file)), { value, ctx })
|
|
1100
|
+
)
|
|
1101
|
+
);
|
|
1068
1102
|
}
|
|
1069
1103
|
|
|
1070
1104
|
// src/actions/verify.ts
|