create-astrale-domain 0.1.5 → 0.1.6
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 +66 -40
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -792,22 +792,22 @@ var ORIGIN_PLACEHOLDER = "astrale-domain.example.dev";
|
|
|
792
792
|
var INSTANCE_PLACEHOLDER = "my-instance-slug";
|
|
793
793
|
var LINK_TARGETS = {
|
|
794
794
|
"@astrale-os/sdk": "sdk",
|
|
795
|
-
"@astrale-os/devkit": "sdk/devkit",
|
|
796
795
|
"@astrale-os/adapter-cloudflare": "sdk/adapter-cloudflare",
|
|
796
|
+
"@astrale-os/adapter-astrale": "sdk/adapter-astrale",
|
|
797
797
|
"@astrale-os/kernel-core": "kernel/core",
|
|
798
798
|
"@astrale-os/kernel-dsl": "kernel/dsl"
|
|
799
799
|
};
|
|
800
|
+
var BODY_PACKAGE = "@astrale-os/adapter-cloudflare";
|
|
800
801
|
var ADAPTER_PACKAGES = {
|
|
801
|
-
astrale: "@astrale-os/adapter-
|
|
802
|
+
astrale: "@astrale-os/adapter-astrale",
|
|
802
803
|
cloudflare: "@astrale-os/adapter-cloudflare"
|
|
803
804
|
};
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
if (!pkg) throw new Error(`No template package registered for adapter "${adapter}".`);
|
|
805
|
+
var ADAPTER_DEP_RANGE = ">=0.1.0 <1.0.0";
|
|
806
|
+
function templateDir(pkg) {
|
|
807
807
|
return join(dirname(require2.resolve(`${pkg}/package.json`)), "template");
|
|
808
808
|
}
|
|
809
809
|
async function scaffold(opts) {
|
|
810
|
-
const src = templateDir(
|
|
810
|
+
const src = templateDir(BODY_PACKAGE);
|
|
811
811
|
if (!existsSync(src)) {
|
|
812
812
|
throw new Error(`Template not found at ${src}.`);
|
|
813
813
|
}
|
|
@@ -819,8 +819,8 @@ async function scaffold(opts) {
|
|
|
819
819
|
recursive: true,
|
|
820
820
|
filter: (s) => !/\/(node_modules|\.astrale|dist-client|\.wrangler)(\/|$)/.test(`/${relative(src, s)}`)
|
|
821
821
|
});
|
|
822
|
+
await materializeAdapter(opts);
|
|
822
823
|
await stampOrigin(opts.dir, opts.origin);
|
|
823
|
-
await stampAdapter(opts);
|
|
824
824
|
await rewritePackageJson(opts.dir, opts.name, opts.link);
|
|
825
825
|
await writeFile(
|
|
826
826
|
join(opts.dir, ".env.dev"),
|
|
@@ -843,32 +843,23 @@ async function stampOrigin(dir, origin) {
|
|
|
843
843
|
const config = join(dir, "astrale.config.ts");
|
|
844
844
|
await replaceInFile(config, ORIGIN_PLACEHOLDER, origin);
|
|
845
845
|
}
|
|
846
|
-
async function
|
|
846
|
+
async function materializeAdapter(opts) {
|
|
847
|
+
if (opts.adapter !== "astrale") return;
|
|
847
848
|
const config = join(opts.dir, "astrale.config.ts");
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
config,
|
|
861
|
-
/\n \/\/ Managed deploy:[\s\S]*?prod: \{ instance: '[^']*' \},\n \/\/ Author secrets[\s\S]*?omit = keep, `\{\}` = clear\)\.\n/,
|
|
862
|
-
`
|
|
863
|
-
// Custom-domain prod. Drop \`route\` to ship to *.workers.dev instead.
|
|
864
|
-
prod: { route: '${opts.origin}', secrets: '.env.prod' },
|
|
865
|
-
`
|
|
866
|
-
);
|
|
867
|
-
await replaceInFile(
|
|
868
|
-
config,
|
|
869
|
-
/\/\/ Have your own Cloudflare account[\s\S]*?\/\/ \}\),\n/,
|
|
870
|
-
"// No Cloudflare account? Swap the adapter for the Astrale-managed one \u2014 it\n// publishes the same bundle THROUGH the platform and installs it on your\n// instance as a managed service (auth = your `astrale auth login` session):\n//\n// import { astrale } from '@astrale-os/adapter-cloudflare'\n// adapter: astrale({\n// dev: { secrets: '.env.dev' }, // local wrangler dev, unchanged\n// prod: { instance: '<your-instance-slug>' } // pnpm prod \u2192 managed deploy\n// }),\n"
|
|
849
|
+
await cp(join(templateDir(ADAPTER_PACKAGES.astrale), "astrale.config.ts"), config);
|
|
850
|
+
await setAdapterDep(opts.dir, "@astrale-os/adapter-cloudflare", "@astrale-os/adapter-astrale");
|
|
851
|
+
if (opts.instance) await replaceInFile(config, `'${INSTANCE_PLACEHOLDER}'`, `'${opts.instance}'`);
|
|
852
|
+
}
|
|
853
|
+
async function setAdapterDep(dir, from, to) {
|
|
854
|
+
const path = join(dir, "package.json");
|
|
855
|
+
const pkg = JSON.parse(await readFile(path, "utf-8"));
|
|
856
|
+
if (!pkg.dependencies || !(from in pkg.dependencies)) return;
|
|
857
|
+
delete pkg.dependencies[from];
|
|
858
|
+
pkg.dependencies[to] = ADAPTER_DEP_RANGE;
|
|
859
|
+
pkg.dependencies = Object.fromEntries(
|
|
860
|
+
Object.entries(pkg.dependencies).sort(([a], [b3]) => a.localeCompare(b3))
|
|
871
861
|
);
|
|
862
|
+
await writeFile(path, JSON.stringify(pkg, null, 2) + "\n");
|
|
872
863
|
}
|
|
873
864
|
async function rewritePackageJson(dir, name, link) {
|
|
874
865
|
const path = join(dir, "package.json");
|
|
@@ -907,18 +898,53 @@ export {}
|
|
|
907
898
|
`import { defineSchema, KernelSchema } from '@astrale-os/kernel-core'
|
|
908
899
|
|
|
909
900
|
export const schema = defineSchema('${origin}', {
|
|
901
|
+
interfaces: {},
|
|
902
|
+
classes: {},
|
|
910
903
|
imports: [KernelSchema],
|
|
911
904
|
})
|
|
912
905
|
`
|
|
913
906
|
);
|
|
914
907
|
await writeFile(
|
|
915
|
-
join(dir, "
|
|
908
|
+
join(dir, "env.ts"),
|
|
909
|
+
`/**
|
|
910
|
+
* Worker runtime env. The adapter injects \`WORKER_URL\` and the bindings; your
|
|
911
|
+
* handlers receive this (mapped by deps.ts) as \`ctx.deps\`. Secrets from
|
|
912
|
+
* \`.env.<env>\` arrive as extra string fields here. Add typed fields as you
|
|
913
|
+
* reference new secrets/vars.
|
|
914
|
+
*/
|
|
915
|
+
export interface Env {
|
|
916
|
+
WORKER_URL?: string
|
|
917
|
+
ASSETS?: { fetch(request: Request): Promise<Response> }
|
|
918
|
+
SELF?: { fetch(request: Request): Promise<Response> }
|
|
919
|
+
VIEW_DEV_URL?: string
|
|
920
|
+
[key: string]: unknown
|
|
921
|
+
}
|
|
922
|
+
`
|
|
923
|
+
);
|
|
924
|
+
await writeFile(
|
|
925
|
+
join(dir, "deps.ts"),
|
|
926
|
+
`/**
|
|
927
|
+
* env \u2192 handler dependency container (the seam \`defineDomain({ deps })\` mounts).
|
|
928
|
+
* Passthrough by default; transform here the moment a handler should depend on a
|
|
929
|
+
* PORT (built from \`integrations/\`) instead of raw env.
|
|
930
|
+
*/
|
|
931
|
+
import type { Env } from './env'
|
|
932
|
+
|
|
933
|
+
export interface Deps extends Env {}
|
|
934
|
+
|
|
935
|
+
export function deps(env: Env): Deps {
|
|
936
|
+
return env
|
|
937
|
+
}
|
|
938
|
+
`
|
|
939
|
+
);
|
|
940
|
+
await writeFile(
|
|
941
|
+
join(dir, "runtime", "index.ts"),
|
|
916
942
|
`import type { SchemaMethodsImpl } from '@astrale-os/sdk'
|
|
917
943
|
|
|
918
|
-
import type {
|
|
944
|
+
import type { Deps } from '../deps'
|
|
919
945
|
import { schema } from '../schema'
|
|
920
946
|
|
|
921
|
-
export const methods: SchemaMethodsImpl<typeof schema,
|
|
947
|
+
export const methods: SchemaMethodsImpl<typeof schema, Deps> = { class: {} }
|
|
922
948
|
`
|
|
923
949
|
);
|
|
924
950
|
await writeFile(join(dir, "functions", "index.ts"), `export const functions = {}
|
|
@@ -926,12 +952,12 @@ export const methods: SchemaMethodsImpl<typeof schema, Env> = {}
|
|
|
926
952
|
await writeFile(join(dir, "views", "index.ts"), `export const views = {}
|
|
927
953
|
`);
|
|
928
954
|
await rm(join(dir, "schema", "compiled.ts"), { force: true });
|
|
929
|
-
await rm(join(dir, "
|
|
930
|
-
await rm(join(dir, "
|
|
955
|
+
await rm(join(dir, "core"), { recursive: true, force: true });
|
|
956
|
+
await rm(join(dir, "integrations"), { recursive: true, force: true });
|
|
931
957
|
await rm(join(dir, "views", "welcome.ts"), { force: true });
|
|
932
958
|
await rm(join(dir, "views", "note.ts"), { force: true });
|
|
933
959
|
await replaceInFile(
|
|
934
|
-
join(dir, "
|
|
960
|
+
join(dir, "domain.ts"),
|
|
935
961
|
/\n\s*postInstall: `\/:\$\{schema\.domain\}:class\.Note:seed`,/,
|
|
936
962
|
""
|
|
937
963
|
);
|
|
@@ -943,7 +969,7 @@ async function replaceInFile(path, from, to) {
|
|
|
943
969
|
if (next !== text) await writeFile(path, next);
|
|
944
970
|
}
|
|
945
971
|
function workspaceAvailable() {
|
|
946
|
-
return existsSync(join(WORKSPACE_ROOT, "sdk", "
|
|
972
|
+
return existsSync(join(WORKSPACE_ROOT, "sdk", "package.json"));
|
|
947
973
|
}
|
|
948
974
|
|
|
949
975
|
// src/index.ts
|
|
@@ -1132,10 +1158,10 @@ var prodStep = (pm, adapter, instance) => {
|
|
|
1132
1158
|
return `${cmd} ${hint}`;
|
|
1133
1159
|
};
|
|
1134
1160
|
function installStep(pm) {
|
|
1135
|
-
if (astraleOnPath()) return "astrale
|
|
1161
|
+
if (astraleOnPath()) return "astrale domain install <url> --direct # mount it on an instance";
|
|
1136
1162
|
return [
|
|
1137
1163
|
"# astrale CLI not found on PATH \u2014 run it on demand (no install):",
|
|
1138
|
-
`${DLX[pm]} @astrale-os/astrale
|
|
1164
|
+
`${DLX[pm]} @astrale-os/astrale domain install <url> --direct`,
|
|
1139
1165
|
"# or install it globally: npm i -g @astrale-os/astrale"
|
|
1140
1166
|
].join("\n");
|
|
1141
1167
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-astrale-domain",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Scaffold a standalone Astrale domain — npm create astrale-domain",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astrale",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"type": "module",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@clack/prompts": "^0.11.0",
|
|
22
|
-
"@astrale-os/adapter-cloudflare": "^0.1.
|
|
22
|
+
"@astrale-os/adapter-cloudflare": "^0.1.9",
|
|
23
|
+
"@astrale-os/adapter-astrale": "^0.1.0"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"@astrale-os/ox": ">=0.1.0 <1.0.0",
|