create-astrale-domain 0.2.11 → 0.2.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 +49 -13
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -781,7 +781,7 @@ import { delimiter, join as join2, relative as relative2, resolve as resolve2 }
|
|
|
781
781
|
|
|
782
782
|
// src/scaffold.ts
|
|
783
783
|
import { existsSync, readFileSync } from "node:fs";
|
|
784
|
-
import { cp, readFile, rm, writeFile } from "node:fs/promises";
|
|
784
|
+
import { cp, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
785
785
|
import { createRequire } from "node:module";
|
|
786
786
|
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
787
787
|
import { fileURLToPath } from "node:url";
|
|
@@ -857,6 +857,20 @@ function packageRoot(pkg) {
|
|
|
857
857
|
entry.error === void 0 ? void 0 : { cause: entry.error }
|
|
858
858
|
);
|
|
859
859
|
}
|
|
860
|
+
function installedPackageRange(pkg) {
|
|
861
|
+
const manifestPath = join(packageRoot(pkg), "package.json");
|
|
862
|
+
const manifest = JSON.parse(readFileSync(manifestPath, "utf-8"));
|
|
863
|
+
if (typeof manifest.version !== "string") {
|
|
864
|
+
throw new Error(`Could not determine ${pkg}'s version from ${manifestPath}.`);
|
|
865
|
+
}
|
|
866
|
+
const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.exec(
|
|
867
|
+
manifest.version
|
|
868
|
+
);
|
|
869
|
+
if (!match) {
|
|
870
|
+
throw new Error(`Could not derive a compatibility range for ${pkg}@${manifest.version}.`);
|
|
871
|
+
}
|
|
872
|
+
return `>=${manifest.version} <${Number(match[1]) + 1}.0.0`;
|
|
873
|
+
}
|
|
860
874
|
function templateDir(pkg) {
|
|
861
875
|
return join(packageRoot(pkg), "template");
|
|
862
876
|
}
|
|
@@ -886,16 +900,28 @@ async function writeProject(opts) {
|
|
|
886
900
|
`/${relative(src, s)}`
|
|
887
901
|
)
|
|
888
902
|
});
|
|
903
|
+
await materializeGitignores(opts.dir);
|
|
889
904
|
await materializeAdapter(opts);
|
|
890
905
|
await stampOrigin(opts.dir, opts.origin);
|
|
891
906
|
await rewritePackageJson(opts.dir, opts.name, opts.link);
|
|
892
907
|
await rewriteWorkspaceMember(join(opts.dir, "client", "package.json"), opts.link);
|
|
893
|
-
if (
|
|
908
|
+
if (opts.link) await writeLinkedZodOverride(opts.dir);
|
|
909
|
+
else await writeReleaseAgePolicy(opts.dir);
|
|
894
910
|
await writeFile(
|
|
895
911
|
join(opts.dir, ".env.dev"),
|
|
896
912
|
"# Dev secrets \u2014 the ENTIRE file is injected into the local runtime by `pnpm dev`.\n# Gitignored. See .env.example.\n"
|
|
897
913
|
);
|
|
898
914
|
}
|
|
915
|
+
async function materializeGitignores(dir) {
|
|
916
|
+
for (const path of [join(dir, ".gitignore"), join(dir, "client", ".gitignore")]) {
|
|
917
|
+
const packagedPath = `${path}.template`;
|
|
918
|
+
if (existsSync(packagedPath)) {
|
|
919
|
+
await rename(packagedPath, path);
|
|
920
|
+
} else if (!existsSync(path)) {
|
|
921
|
+
throw new Error(`Template is missing packaged Git ignore file ${packagedPath}.`);
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
}
|
|
899
925
|
function assertSafeToDelete(dir) {
|
|
900
926
|
const target = resolve(dir);
|
|
901
927
|
const rel = relative(target, resolve(process.cwd()));
|
|
@@ -921,8 +947,12 @@ async function materializeAdapter(opts) {
|
|
|
921
947
|
async function setAdapterDep(dir, from, to) {
|
|
922
948
|
const path = join(dir, "package.json");
|
|
923
949
|
const pkg = JSON.parse(await readFile(path, "utf-8"));
|
|
924
|
-
if (!pkg.dependencies || !(from in pkg.dependencies))
|
|
925
|
-
|
|
950
|
+
if (!pkg.dependencies || !(from in pkg.dependencies)) {
|
|
951
|
+
throw new Error(
|
|
952
|
+
`Could not materialize ${to}: the scaffold body does not declare its ${from} dependency.`
|
|
953
|
+
);
|
|
954
|
+
}
|
|
955
|
+
const range = installedPackageRange(to);
|
|
926
956
|
delete pkg.dependencies[from];
|
|
927
957
|
pkg.dependencies[to] = range;
|
|
928
958
|
pkg.dependencies = Object.fromEntries(
|
|
@@ -941,15 +971,6 @@ async function rewritePackageJson(dir, name, link) {
|
|
|
941
971
|
const pkg = JSON.parse(await readFile(path, "utf-8"));
|
|
942
972
|
pkg.name = name;
|
|
943
973
|
rewriteAstraleDeps(pkg, link);
|
|
944
|
-
if (link) {
|
|
945
|
-
pkg.pnpm = {
|
|
946
|
-
...pkg.pnpm,
|
|
947
|
-
overrides: {
|
|
948
|
-
...pkg.pnpm?.overrides,
|
|
949
|
-
zod: sdkZodVersion()
|
|
950
|
-
}
|
|
951
|
-
};
|
|
952
|
-
}
|
|
953
974
|
await writeFile(path, JSON.stringify(pkg, null, 2) + "\n");
|
|
954
975
|
}
|
|
955
976
|
function rewriteAstraleDeps(pkg, link) {
|
|
@@ -969,6 +990,21 @@ function rewriteAstraleDeps(pkg, link) {
|
|
|
969
990
|
return changed;
|
|
970
991
|
}
|
|
971
992
|
var FIRST_PARTY_SCOPES = ["@astrale-domains/*", "@astrale-os/*"];
|
|
993
|
+
async function writeLinkedZodOverride(dir) {
|
|
994
|
+
const workspace = join(dir, "pnpm-workspace.yaml");
|
|
995
|
+
if (!existsSync(workspace)) return;
|
|
996
|
+
const start = "# create-astrale-domain: linked overrides";
|
|
997
|
+
const end = "# /create-astrale-domain";
|
|
998
|
+
const block = `
|
|
999
|
+
${start}
|
|
1000
|
+
overrides:
|
|
1001
|
+
zod: ${sdkZodVersion()}
|
|
1002
|
+
${end}
|
|
1003
|
+
`;
|
|
1004
|
+
const text = await readFile(workspace, "utf-8");
|
|
1005
|
+
const pattern = new RegExp(`\\n?${escapeRegExp(start)}[\\s\\S]*?${escapeRegExp(end)}\\n?`);
|
|
1006
|
+
await writeFile(workspace, text.replace(pattern, "\n").trimEnd() + block);
|
|
1007
|
+
}
|
|
972
1008
|
async function writeReleaseAgePolicy(dir) {
|
|
973
1009
|
const workspace = join(dir, "pnpm-workspace.yaml");
|
|
974
1010
|
if (!existsSync(workspace)) return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-astrale-domain",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.13",
|
|
4
4
|
"description": "Scaffold a standalone Astrale domain — npm create astrale-domain",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astrale",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@clack/prompts": "^0.11.0",
|
|
22
22
|
"@astrale-os/adapter-astrale": "^0.4.1",
|
|
23
|
-
"@astrale-os/adapter-cloudflare": "^0.4.
|
|
23
|
+
"@astrale-os/adapter-cloudflare": "^0.4.10"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@astrale-os/ox": ">=0.1.0 <1.0.0",
|