create-astrale-domain 0.1.3 → 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 +82 -15
  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,7 +820,12 @@ 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);
825
+ await writeFile(
826
+ join(opts.dir, ".env.dev"),
827
+ "# Dev secrets \u2014 the ENTIRE file is injected into the local runtime by `pnpm dev`.\n# Gitignored. See .env.example.\n"
828
+ );
822
829
  if (opts.template === "blank") await blankOut(opts.dir, opts.origin);
823
830
  }
824
831
  function assertSafeToDelete(dir) {
@@ -836,6 +843,33 @@ async function stampOrigin(dir, origin) {
836
843
  const config = join(dir, "astrale.config.ts");
837
844
  await replaceInFile(config, ORIGIN_PLACEHOLDER, origin);
838
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
+ }
839
873
  async function rewritePackageJson(dir, name, link) {
840
874
  const path = join(dir, "package.json");
841
875
  const pkg = JSON.parse(await readFile(path, "utf-8"));
@@ -922,15 +956,15 @@ var DLX = {
922
956
  };
923
957
  var ADAPTERS = [
924
958
  {
925
- value: "astrale-host",
926
- label: "Astrale Worker",
927
- hint: "deployed under /service on an Astrale host (soon)",
928
- 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
929
963
  },
930
964
  {
931
965
  value: "cloudflare",
932
966
  label: "Cloudflare Worker",
933
- hint: "standalone worker (*.workers.dev / custom domain)",
967
+ hint: "your own CF account (*.workers.dev / custom domain)",
934
968
  enabled: true
935
969
  },
936
970
  { value: "custom", label: "Custom", hint: "bring your own adapter (soon)", enabled: false }
@@ -964,11 +998,11 @@ async function main() {
964
998
  }
965
999
  let adapter = flags.adapter;
966
1000
  if (!adapter) {
967
- if (headless) adapter = "cloudflare";
1001
+ if (headless) adapter = "astrale";
968
1002
  else {
969
1003
  const answer = await ve({
970
1004
  message: "Where will it run? (deployment adapter)",
971
- initialValue: "cloudflare",
1005
+ initialValue: "astrale",
972
1006
  options: ADAPTERS.map((a) => ({
973
1007
  value: a.value,
974
1008
  label: a.enabled ? a.label : `${a.label} (soon)`,
@@ -979,10 +1013,24 @@ async function main() {
979
1013
  adapter = answer;
980
1014
  }
981
1015
  }
982
- if (adapter !== "cloudflare") {
983
- 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.`);
984
1023
  return 1;
985
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
+ }
986
1034
  let template = flags.template;
987
1035
  if (!template) {
988
1036
  if (headless) template = "template";
@@ -1006,7 +1054,7 @@ async function main() {
1006
1054
  let pm = flags.pm;
1007
1055
  if (!pm) {
1008
1056
  const detected = detectPm();
1009
- if (headless) pm = detected ?? "pnpm";
1057
+ if (headless) pm = "pnpm";
1010
1058
  else {
1011
1059
  const answer = await ve({
1012
1060
  message: "Package manager",
@@ -1039,8 +1087,9 @@ async function main() {
1039
1087
  dir,
1040
1088
  name: slug,
1041
1089
  origin,
1042
- adapter: "cloudflare",
1090
+ adapter,
1043
1091
  template,
1092
+ instance,
1044
1093
  link
1045
1094
  });
1046
1095
  s.stop(`Created ${dir}`);
@@ -1055,17 +1104,33 @@ async function main() {
1055
1104
  const rel = relative2(process.cwd(), dir);
1056
1105
  const cdTarget = rel && !rel.startsWith("..") ? rel : dir;
1057
1106
  Me(
1058
- [`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"),
1059
1114
  "Next"
1060
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
+ }
1061
1121
  M2.info(
1062
- "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`
1063
1124
  );
1064
1125
  Se(`\u2713 ${slug} ready`);
1065
1126
  return 0;
1066
1127
  }
1067
1128
  var devStep = (pm) => `${pm === "npm" ? "npm run dev" : `${pm} dev`} # wrangler dev \u2192 prints a local URL`;
1068
- 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
+ };
1069
1134
  function installStep(pm) {
1070
1135
  if (astraleOnPath()) return "astrale instance install <url> # mount it on an instance";
1071
1136
  return [
@@ -1098,6 +1163,7 @@ function parseFlags(argv) {
1098
1163
  else if (a === "--pm") flags.pm = argv[++i];
1099
1164
  else if (a === "--dir") flags.dir = argv[++i];
1100
1165
  else if (a === "--origin") flags.origin = argv[++i];
1166
+ else if (a === "--instance") flags.instance = argv[++i];
1101
1167
  else if (!a.startsWith("-")) flags.positional.push(a);
1102
1168
  }
1103
1169
  return flags;
@@ -1115,7 +1181,8 @@ Arguments:
1115
1181
  <slug> domain name (lowercase letters, digits, dots, dashes)
1116
1182
 
1117
1183
  Options:
1118
- --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)
1119
1186
  --template <kind> template | blank (default: template)
1120
1187
  --pm <pm> pnpm | npm | yarn | bun (default: detected, else pnpm)
1121
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.3",
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.6"
22
+ "@astrale-os/adapter-cloudflare": "^0.1.8"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@astrale-os/ox": ">=0.1.0 <1.0.0",