create-astrale-domain 0.1.4 → 0.1.5

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.
Files changed (2) hide show
  1. package/dist/index.js +77 -14
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -789,6 +789,7 @@ var require2 = createRequire(import.meta.url);
789
789
  var HERE = dirname(fileURLToPath(import.meta.url));
790
790
  var WORKSPACE_ROOT = join(HERE, "..", "..", "..");
791
791
  var ORIGIN_PLACEHOLDER = "astrale-domain.example.dev";
792
+ var INSTANCE_PLACEHOLDER = "my-instance-slug";
792
793
  var LINK_TARGETS = {
793
794
  "@astrale-os/sdk": "sdk",
794
795
  "@astrale-os/devkit": "sdk/devkit",
@@ -797,6 +798,7 @@ var LINK_TARGETS = {
797
798
  "@astrale-os/kernel-dsl": "kernel/dsl"
798
799
  };
799
800
  var ADAPTER_PACKAGES = {
801
+ astrale: "@astrale-os/adapter-cloudflare",
800
802
  cloudflare: "@astrale-os/adapter-cloudflare"
801
803
  };
802
804
  function templateDir(adapter) {
@@ -818,6 +820,7 @@ async function scaffold(opts) {
818
820
  filter: (s) => !/\/(node_modules|\.astrale|dist-client|\.wrangler)(\/|$)/.test(`/${relative(src, s)}`)
819
821
  });
820
822
  await stampOrigin(opts.dir, opts.origin);
823
+ await stampAdapter(opts);
821
824
  await rewritePackageJson(opts.dir, opts.name, opts.link);
822
825
  await writeFile(
823
826
  join(opts.dir, ".env.dev"),
@@ -840,6 +843,33 @@ async function stampOrigin(dir, origin) {
840
843
  const config = join(dir, "astrale.config.ts");
841
844
  await replaceInFile(config, ORIGIN_PLACEHOLDER, origin);
842
845
  }
846
+ async function stampAdapter(opts) {
847
+ const config = join(opts.dir, "astrale.config.ts");
848
+ if (opts.adapter === "astrale") {
849
+ if (opts.instance)
850
+ await replaceInFile(config, `'${INSTANCE_PLACEHOLDER}'`, `'${opts.instance}'`);
851
+ return;
852
+ }
853
+ await replaceInFile(
854
+ config,
855
+ "import { astrale } from '@astrale-os/adapter-cloudflare'",
856
+ "import { cloudflare } from '@astrale-os/adapter-cloudflare'"
857
+ );
858
+ await replaceInFile(config, "adapter: astrale({", "adapter: cloudflare({");
859
+ await replaceInFile(
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"
871
+ );
872
+ }
843
873
  async function rewritePackageJson(dir, name, link) {
844
874
  const path = join(dir, "package.json");
845
875
  const pkg = JSON.parse(await readFile(path, "utf-8"));
@@ -926,15 +956,15 @@ var DLX = {
926
956
  };
927
957
  var ADAPTERS = [
928
958
  {
929
- value: "astrale-host",
930
- label: "Astrale Worker",
931
- hint: "deployed under /service on an Astrale host (soon)",
932
- enabled: false
959
+ value: "astrale",
960
+ label: "Astrale managed",
961
+ hint: "publishes through the platform onto your instance \u2014 no Cloudflare account",
962
+ enabled: true
933
963
  },
934
964
  {
935
965
  value: "cloudflare",
936
966
  label: "Cloudflare Worker",
937
- hint: "standalone worker (*.workers.dev / custom domain)",
967
+ hint: "your own CF account (*.workers.dev / custom domain)",
938
968
  enabled: true
939
969
  },
940
970
  { value: "custom", label: "Custom", hint: "bring your own adapter (soon)", enabled: false }
@@ -968,11 +998,11 @@ async function main() {
968
998
  }
969
999
  let adapter = flags.adapter;
970
1000
  if (!adapter) {
971
- if (headless) adapter = "cloudflare";
1001
+ if (headless) adapter = "astrale";
972
1002
  else {
973
1003
  const answer = await ve({
974
1004
  message: "Where will it run? (deployment adapter)",
975
- initialValue: "cloudflare",
1005
+ initialValue: "astrale",
976
1006
  options: ADAPTERS.map((a) => ({
977
1007
  value: a.value,
978
1008
  label: a.enabled ? a.label : `${a.label} (soon)`,
@@ -983,10 +1013,24 @@ async function main() {
983
1013
  adapter = answer;
984
1014
  }
985
1015
  }
986
- if (adapter !== "cloudflare") {
987
- xe(`The "${adapter}" adapter is not available yet \u2014 only "cloudflare" is wired today.`);
1016
+ if (adapter !== "astrale" && adapter !== "cloudflare") {
1017
+ xe(`The "${adapter}" adapter is not available yet \u2014 use "astrale" or "cloudflare".`);
1018
+ return 1;
1019
+ }
1020
+ let instance = flags.instance;
1021
+ if (instance !== void 0 && !isValidSlug(instance)) {
1022
+ xe(`Invalid --instance "${instance}". Use lowercase letters, digits, dots and dashes.`);
988
1023
  return 1;
989
1024
  }
1025
+ if (adapter === "astrale" && !instance && !headless) {
1026
+ const answer = await he({
1027
+ message: "Target instance slug (`astrale instance create <slug>` \u2014 empty to set it later)",
1028
+ placeholder: "my-app",
1029
+ validate: (v2) => !v2 || isValidSlug(v2) ? void 0 : "Use lowercase letters, digits, dots and dashes."
1030
+ });
1031
+ if (pD(answer)) return bail();
1032
+ if (answer) instance = answer;
1033
+ }
990
1034
  let template = flags.template;
991
1035
  if (!template) {
992
1036
  if (headless) template = "template";
@@ -1043,8 +1087,9 @@ async function main() {
1043
1087
  dir,
1044
1088
  name: slug,
1045
1089
  origin,
1046
- adapter: "cloudflare",
1090
+ adapter,
1047
1091
  template,
1092
+ instance,
1048
1093
  link
1049
1094
  });
1050
1095
  s.stop(`Created ${dir}`);
@@ -1059,17 +1104,33 @@ async function main() {
1059
1104
  const rel = relative2(process.cwd(), dir);
1060
1105
  const cdTarget = rel && !rel.startsWith("..") ? rel : dir;
1061
1106
  Me(
1062
- [`cd ${cdTarget}`, `${pm} install`, devStep(pm), installStep(pm), prodStep(pm)].join("\n"),
1107
+ [
1108
+ `cd ${cdTarget}`,
1109
+ `${pm} install`,
1110
+ devStep(pm),
1111
+ installStep(pm),
1112
+ prodStep(pm, adapter, instance)
1113
+ ].join("\n"),
1063
1114
  "Next"
1064
1115
  );
1116
+ if (adapter === "astrale" && !instance) {
1117
+ M2.warn(
1118
+ `No target instance set \u2014 put your slug in astrale.config.ts (prod.instance) before \`${pm === "npm" ? "npm run prod" : `${pm} prod`}\`. Create one: astrale instance create <slug>`
1119
+ );
1120
+ }
1065
1121
  M2.info(
1066
- "AI agent on this project? The full authoring guide ships at .agents/skills/astrale-domain/SKILL.md"
1122
+ `AI agent on this project? The full authoring guide ships at .agents/skills/astrale-domain/SKILL.md
1123
+ Agent rooted at a parent workspace? Register the skills there: npx skills add ${cdTarget === dir ? dir : `./${cdTarget}`}/.agents/skills -y`
1067
1124
  );
1068
1125
  Se(`\u2713 ${slug} ready`);
1069
1126
  return 0;
1070
1127
  }
1071
1128
  var devStep = (pm) => `${pm === "npm" ? "npm run dev" : `${pm} dev`} # wrangler dev \u2192 prints a local URL`;
1072
- var prodStep = (pm) => `${pm === "npm" ? "npm run prod" : `${pm} prod`} # deploy prod \u2192 prints a URL`;
1129
+ var prodStep = (pm, adapter, instance) => {
1130
+ const cmd = pm === "npm" ? "npm run prod" : `${pm} prod`;
1131
+ const hint = adapter === "astrale" ? `# managed deploy \u2192 installs on ${instance ? `"${instance}"` : "your instance"}` : "# deploy prod \u2192 prints a URL";
1132
+ return `${cmd} ${hint}`;
1133
+ };
1073
1134
  function installStep(pm) {
1074
1135
  if (astraleOnPath()) return "astrale instance install <url> # mount it on an instance";
1075
1136
  return [
@@ -1102,6 +1163,7 @@ function parseFlags(argv) {
1102
1163
  else if (a === "--pm") flags.pm = argv[++i];
1103
1164
  else if (a === "--dir") flags.dir = argv[++i];
1104
1165
  else if (a === "--origin") flags.origin = argv[++i];
1166
+ else if (a === "--instance") flags.instance = argv[++i];
1105
1167
  else if (!a.startsWith("-")) flags.positional.push(a);
1106
1168
  }
1107
1169
  return flags;
@@ -1119,7 +1181,8 @@ Arguments:
1119
1181
  <slug> domain name (lowercase letters, digits, dots, dashes)
1120
1182
 
1121
1183
  Options:
1122
- --adapter <id> deployment adapter \u2014 cloudflare (default; others soon)
1184
+ --adapter <id> deployment adapter \u2014 astrale (managed, default) | cloudflare
1185
+ --instance <slug> target instance for managed deploys (astrale adapter)
1123
1186
  --template <kind> template | blank (default: template)
1124
1187
  --pm <pm> pnpm | npm | yarn | bun (default: detected, else pnpm)
1125
1188
  --dir <path> target directory (default: ./<slug>)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-astrale-domain",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Scaffold a standalone Astrale domain — npm create astrale-domain",
5
5
  "keywords": [
6
6
  "astrale",
@@ -19,7 +19,7 @@
19
19
  "type": "module",
20
20
  "dependencies": {
21
21
  "@clack/prompts": "^0.11.0",
22
- "@astrale-os/adapter-cloudflare": "^0.1.7"
22
+ "@astrale-os/adapter-cloudflare": "^0.1.8"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@astrale-os/ox": ">=0.1.0 <1.0.0",