create-astro 3.1.11 → 3.1.13
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 +43 -31
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -355,7 +355,7 @@ function printHelp({
|
|
|
355
355
|
if (headline) {
|
|
356
356
|
message.push(
|
|
357
357
|
linebreak(),
|
|
358
|
-
`${title(commandName)} ${color.green(`v${"3.1.
|
|
358
|
+
`${title(commandName)} ${color.green(`v${"3.1.13"}`)} ${headline}`
|
|
359
359
|
);
|
|
360
360
|
}
|
|
361
361
|
if (usage) {
|
|
@@ -457,6 +457,8 @@ async function getContext(argv) {
|
|
|
457
457
|
// src/actions/dependencies.ts
|
|
458
458
|
import { color as color2 } from "@astrojs/cli-kit";
|
|
459
459
|
import { execa as execa2 } from "execa";
|
|
460
|
+
import fs from "node:fs";
|
|
461
|
+
import path from "node:path";
|
|
460
462
|
async function dependencies(ctx) {
|
|
461
463
|
let deps = ctx.install ?? ctx.yes;
|
|
462
464
|
if (deps === void 0) {
|
|
@@ -496,21 +498,29 @@ async function dependencies(ctx) {
|
|
|
496
498
|
}
|
|
497
499
|
}
|
|
498
500
|
async function install({ pkgManager, cwd }) {
|
|
501
|
+
if (pkgManager === "yarn")
|
|
502
|
+
await ensureYarnLock({ cwd });
|
|
499
503
|
const installExec = execa2(pkgManager, ["install"], { cwd });
|
|
500
504
|
return new Promise((resolve, reject) => {
|
|
501
|
-
setTimeout(() => reject(`Request timed out after
|
|
505
|
+
setTimeout(() => reject(`Request timed out after 1m 30s`), 9e4);
|
|
502
506
|
installExec.on("error", (e) => reject(e));
|
|
503
507
|
installExec.on("close", () => resolve());
|
|
504
508
|
});
|
|
505
509
|
}
|
|
510
|
+
async function ensureYarnLock({ cwd }) {
|
|
511
|
+
const yarnLock = path.join(cwd, "yarn.lock");
|
|
512
|
+
if (fs.existsSync(yarnLock))
|
|
513
|
+
return;
|
|
514
|
+
return fs.promises.writeFile(yarnLock, "", { encoding: "utf-8" });
|
|
515
|
+
}
|
|
506
516
|
|
|
507
517
|
// src/actions/git.ts
|
|
508
|
-
import
|
|
509
|
-
import
|
|
518
|
+
import fs2 from "node:fs";
|
|
519
|
+
import path2 from "node:path";
|
|
510
520
|
import { color as color3 } from "@astrojs/cli-kit";
|
|
511
521
|
import { execa as execa3 } from "execa";
|
|
512
522
|
async function git(ctx) {
|
|
513
|
-
if (
|
|
523
|
+
if (fs2.existsSync(path2.join(ctx.cwd, ".git"))) {
|
|
514
524
|
await info("Nice!", `Git has already been initialized`);
|
|
515
525
|
return;
|
|
516
526
|
}
|
|
@@ -607,9 +617,9 @@ async function intro(ctx) {
|
|
|
607
617
|
}
|
|
608
618
|
|
|
609
619
|
// src/actions/next-steps.ts
|
|
610
|
-
import
|
|
620
|
+
import path3 from "node:path";
|
|
611
621
|
async function next(ctx) {
|
|
612
|
-
let projectDir =
|
|
622
|
+
let projectDir = path3.relative(process.cwd(), ctx.cwd);
|
|
613
623
|
const devCmd = ctx.pkgManager === "npm" ? "npm run dev" : `${ctx.pkgManager} dev`;
|
|
614
624
|
await nextSteps({ projectDir, devCmd });
|
|
615
625
|
if (!ctx.skipHouston) {
|
|
@@ -620,10 +630,10 @@ async function next(ctx) {
|
|
|
620
630
|
|
|
621
631
|
// src/actions/project-name.ts
|
|
622
632
|
import { color as color5, generateProjectName } from "@astrojs/cli-kit";
|
|
623
|
-
import
|
|
633
|
+
import path4 from "node:path";
|
|
624
634
|
|
|
625
635
|
// src/actions/shared.ts
|
|
626
|
-
import
|
|
636
|
+
import fs3 from "node:fs";
|
|
627
637
|
var VALID_PROJECT_DIRECTORY_SAFE_LIST = [
|
|
628
638
|
".DS_Store",
|
|
629
639
|
".git",
|
|
@@ -649,10 +659,10 @@ var VALID_PROJECT_DIRECTORY_SAFE_LIST = [
|
|
|
649
659
|
/^yarn-error\.log/
|
|
650
660
|
];
|
|
651
661
|
function isEmpty(dirPath) {
|
|
652
|
-
if (!
|
|
662
|
+
if (!fs3.existsSync(dirPath)) {
|
|
653
663
|
return true;
|
|
654
664
|
}
|
|
655
|
-
const conflicts =
|
|
665
|
+
const conflicts = fs3.readdirSync(dirPath).filter((content) => {
|
|
656
666
|
return !VALID_PROJECT_DIRECTORY_SAFE_LIST.some((safeContent) => {
|
|
657
667
|
return typeof safeContent === "string" ? content === safeContent : safeContent.test(content);
|
|
658
668
|
});
|
|
@@ -695,7 +705,7 @@ async function projectName(ctx) {
|
|
|
695
705
|
} else {
|
|
696
706
|
let name = ctx.cwd;
|
|
697
707
|
if (name === "." || name === "./") {
|
|
698
|
-
const parts = process.cwd().split(
|
|
708
|
+
const parts = process.cwd().split(path4.sep);
|
|
699
709
|
name = parts[parts.length - 1];
|
|
700
710
|
} else if (name.startsWith("./") || name.startsWith("../")) {
|
|
701
711
|
const parts = name.split("/");
|
|
@@ -719,8 +729,8 @@ async function checkCwd(cwd) {
|
|
|
719
729
|
// src/actions/template.ts
|
|
720
730
|
import { color as color6 } from "@astrojs/cli-kit";
|
|
721
731
|
import { downloadTemplate } from "giget";
|
|
722
|
-
import
|
|
723
|
-
import
|
|
732
|
+
import fs4 from "node:fs";
|
|
733
|
+
import path5 from "node:path";
|
|
724
734
|
async function template(ctx) {
|
|
725
735
|
if (!ctx.template) {
|
|
726
736
|
const { template: tmpl } = await ctx.prompt({
|
|
@@ -761,10 +771,10 @@ async function template(ctx) {
|
|
|
761
771
|
}
|
|
762
772
|
var FILES_TO_REMOVE = ["sandbox.config.json", "CHANGELOG.md"];
|
|
763
773
|
var FILES_TO_UPDATE = {
|
|
764
|
-
"package.json": (file, overrides) =>
|
|
774
|
+
"package.json": (file, overrides) => fs4.promises.readFile(file, "utf-8").then((value) => {
|
|
765
775
|
var _a;
|
|
766
776
|
const indent = ((_a = /(^\s+)/m.exec(value)) == null ? void 0 : _a[1]) ?? " ";
|
|
767
|
-
|
|
777
|
+
fs4.promises.writeFile(
|
|
768
778
|
file,
|
|
769
779
|
JSON.stringify(
|
|
770
780
|
Object.assign(JSON.parse(value), Object.assign(overrides, { private: void 0 })),
|
|
@@ -776,11 +786,13 @@ var FILES_TO_UPDATE = {
|
|
|
776
786
|
})
|
|
777
787
|
};
|
|
778
788
|
function getTemplateTarget(tmpl, ref = "latest") {
|
|
789
|
+
if (tmpl.startsWith("starlight")) {
|
|
790
|
+
const [, starter = "basics"] = tmpl.split("/");
|
|
791
|
+
return `withastro/starlight/examples/${starter}`;
|
|
792
|
+
}
|
|
779
793
|
const isThirdParty = tmpl.includes("/");
|
|
780
794
|
if (isThirdParty)
|
|
781
795
|
return tmpl;
|
|
782
|
-
if (tmpl === "starlight")
|
|
783
|
-
return `withastro/starlight/examples/basics`;
|
|
784
796
|
return `github:withastro/astro/examples/${tmpl}#${ref}`;
|
|
785
797
|
}
|
|
786
798
|
async function copyTemplate(tmpl, ctx) {
|
|
@@ -794,25 +806,25 @@ async function copyTemplate(tmpl, ctx) {
|
|
|
794
806
|
dir: "."
|
|
795
807
|
});
|
|
796
808
|
} catch (err) {
|
|
797
|
-
|
|
809
|
+
fs4.rmdirSync(ctx.cwd);
|
|
798
810
|
if (err.message.includes("404")) {
|
|
799
811
|
throw new Error(`Template ${color6.reset(tmpl)} ${color6.dim("does not exist!")}`);
|
|
800
812
|
} else {
|
|
801
813
|
throw new Error(err.message);
|
|
802
814
|
}
|
|
803
815
|
}
|
|
804
|
-
if (
|
|
816
|
+
if (fs4.readdirSync(ctx.cwd).length === 0) {
|
|
805
817
|
throw new Error(`Template ${color6.reset(tmpl)} ${color6.dim("is empty!")}`);
|
|
806
818
|
}
|
|
807
819
|
const removeFiles = FILES_TO_REMOVE.map(async (file) => {
|
|
808
|
-
const fileLoc =
|
|
809
|
-
if (
|
|
810
|
-
return
|
|
820
|
+
const fileLoc = path5.resolve(path5.join(ctx.cwd, file));
|
|
821
|
+
if (fs4.existsSync(fileLoc)) {
|
|
822
|
+
return fs4.promises.rm(fileLoc, { recursive: true });
|
|
811
823
|
}
|
|
812
824
|
});
|
|
813
825
|
const updateFiles = Object.entries(FILES_TO_UPDATE).map(async ([file, update]) => {
|
|
814
|
-
const fileLoc =
|
|
815
|
-
if (
|
|
826
|
+
const fileLoc = path5.resolve(path5.join(ctx.cwd, file));
|
|
827
|
+
if (fs4.existsSync(fileLoc)) {
|
|
816
828
|
return update(fileLoc, { name: ctx.projectName });
|
|
817
829
|
}
|
|
818
830
|
});
|
|
@@ -822,9 +834,9 @@ async function copyTemplate(tmpl, ctx) {
|
|
|
822
834
|
|
|
823
835
|
// src/actions/typescript.ts
|
|
824
836
|
import { color as color7 } from "@astrojs/cli-kit";
|
|
825
|
-
import
|
|
837
|
+
import fs5 from "node:fs";
|
|
826
838
|
import { readFile } from "node:fs/promises";
|
|
827
|
-
import
|
|
839
|
+
import path6 from "node:path";
|
|
828
840
|
|
|
829
841
|
// ../../node_modules/.pnpm/strip-json-comments@5.0.0/node_modules/strip-json-comments/index.js
|
|
830
842
|
var singleComment = Symbol("singleComment");
|
|
@@ -944,7 +956,7 @@ async function typescript(ctx) {
|
|
|
944
956
|
} else {
|
|
945
957
|
if (!["strict", "strictest", "relaxed", "default", "base"].includes(ts)) {
|
|
946
958
|
if (!ctx.dryRun) {
|
|
947
|
-
|
|
959
|
+
fs5.rmSync(ctx.cwd, { recursive: true, force: true });
|
|
948
960
|
}
|
|
949
961
|
error(
|
|
950
962
|
"Error",
|
|
@@ -974,7 +986,7 @@ async function typescript(ctx) {
|
|
|
974
986
|
}
|
|
975
987
|
}
|
|
976
988
|
async function setupTypeScript(value, { cwd }) {
|
|
977
|
-
const templateTSConfigPath =
|
|
989
|
+
const templateTSConfigPath = path6.join(cwd, "tsconfig.json");
|
|
978
990
|
try {
|
|
979
991
|
const data = await readFile(templateTSConfigPath, { encoding: "utf-8" });
|
|
980
992
|
const templateTSConfig = JSON.parse(stripJsonComments(data));
|
|
@@ -982,7 +994,7 @@ async function setupTypeScript(value, { cwd }) {
|
|
|
982
994
|
const result = Object.assign(templateTSConfig, {
|
|
983
995
|
extends: `astro/tsconfigs/${value}`
|
|
984
996
|
});
|
|
985
|
-
|
|
997
|
+
fs5.writeFileSync(templateTSConfigPath, JSON.stringify(result, null, 2));
|
|
986
998
|
} else {
|
|
987
999
|
throw new Error(
|
|
988
1000
|
"There was an error applying the requested TypeScript settings. This could be because the template's tsconfig.json is malformed"
|
|
@@ -990,7 +1002,7 @@ async function setupTypeScript(value, { cwd }) {
|
|
|
990
1002
|
}
|
|
991
1003
|
} catch (err) {
|
|
992
1004
|
if (err && err.code === "ENOENT") {
|
|
993
|
-
|
|
1005
|
+
fs5.writeFileSync(
|
|
994
1006
|
templateTSConfigPath,
|
|
995
1007
|
JSON.stringify({ extends: `astro/tsconfigs/${value}` }, null, 2)
|
|
996
1008
|
);
|