castle-web-cli 0.4.17 → 0.4.19

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/init.js +31 -20
  2. package/package.json +1 -1
package/dist/init.js CHANGED
@@ -39,8 +39,27 @@ const PUBLISHED_SDK_VERSION = '0.4.3';
39
39
  // Never copied into a fresh deck: build/dependency junk, and castle.json (a
40
40
  // fresh deck has no deckId until its first save-deck).
41
41
  const KIT_COPY_EXCLUDE = new Set(['node_modules', '.castle', 'dist', '.git', 'castle.json']);
42
- function relativeFromProject(projectDir, target) {
43
- return toPosixPath(path.relative(projectDir, target));
42
+ // Resolve how a scaffolded deck should reference the sdk + cli. Both the bare
43
+ // and kit scaffold paths go through here so they stay in sync.
44
+ // workspace mode (sdk/ sits next to cli/, i.e. running from a checkout):
45
+ // sdk -> file: absolute path to sdk/, scripts -> `node <abs cli dist>/index.js`
46
+ // published mode (globally-installed castle-web, no sibling sdk/):
47
+ // sdk -> registry `^${PUBLISHED_SDK_VERSION}`, scripts -> the `castle-web` binary
48
+ function resolveScaffoldRefs() {
49
+ const sdkPath = getSdkPackagePath();
50
+ // "Workspace mode" = the cli is running from a castle-experimental-web
51
+ // checkout (sdk/ exists next to cli/). Otherwise we're a globally-installed
52
+ // npm package and need the published refs + `castle-web` binary.
53
+ const workspaceMode = fs.existsSync(sdkPath);
54
+ const sdkPathPosix = workspaceMode ? toPosixPath(sdkPath) : null;
55
+ const cliDistAbs = workspaceMode ? toPosixPath(path.dirname(getCliEntryPath())) : null;
56
+ return {
57
+ workspaceMode,
58
+ sdkRef: workspaceMode ? `file:${sdkPathPosix}` : `^${PUBLISHED_SDK_VERSION}`,
59
+ cliCommand: workspaceMode ? `node ${toPosixPath(getCliEntryPath())}` : 'castle-web',
60
+ cliDistAbs,
61
+ sdkPathPosix,
62
+ };
44
63
  }
45
64
  function makeClaudeMd() {
46
65
  // Inline the upstream CLAUDE.md content. An @-import works inside the
@@ -72,19 +91,18 @@ function tryMakeAgentsSymlink(agentsPath) {
72
91
  }
73
92
  }
74
93
  function makePackageJson(projectDir) {
75
- const cliEntry = relativeFromProject(projectDir, getCliEntryPath());
76
- const sdkPackage = relativeFromProject(projectDir, getSdkPackagePath());
94
+ const { sdkRef, cliCommand } = resolveScaffoldRefs();
77
95
  return {
78
96
  name: path.basename(projectDir),
79
97
  private: true,
80
98
  type: 'module',
81
99
  scripts: {
82
- restart: `node ${cliEntry} restart .`,
83
- screenshot: `node ${cliEntry} screenshot .`,
84
- 'save-deck': `node ${cliEntry} save-deck .`,
100
+ restart: `${cliCommand} restart .`,
101
+ screenshot: `${cliCommand} screenshot .`,
102
+ 'save-deck': `${cliCommand} save-deck .`,
85
103
  },
86
104
  dependencies: {
87
- 'castle-web-sdk': `file:${sdkPackage}`,
105
+ 'castle-web-sdk': sdkRef,
88
106
  },
89
107
  };
90
108
  }
@@ -151,16 +169,9 @@ function scaffoldFromKit(kit, projectDir) {
151
169
  // Local-dev paths (`file:../../sdk` / `node ../../cli/dist/index.js`) only
152
170
  // work when the deck lives inside the castle-experimental-web workspace.
153
171
  // For a deck scaffolded from a globally-installed castle-web, rewrite to
154
- // the published packages instead.
155
- const sdkPath = getSdkPackagePath();
156
- // "Workspace mode" = the cli is running from a castle-experimental-web
157
- // checkout (sdk/ exists next to cli/). Otherwise we're a globally-
158
- // installed npm package and need to use the published refs + binary.
159
- const workspaceMode = fs.existsSync(sdkPath);
160
- const sdkRef = workspaceMode ? `file:${toPosixPath(sdkPath)}` : `^${PUBLISHED_SDK_VERSION}`;
161
- const cliDistAbs = workspaceMode
162
- ? toPosixPath(path.dirname(getCliEntryPath()))
163
- : null;
172
+ // the published packages instead. Same workspace-vs-published resolution
173
+ // the bare scaffold path uses.
174
+ const { workspaceMode, sdkRef, cliDistAbs, sdkPathPosix } = resolveScaffoldRefs();
164
175
  if (pkg.dependencies &&
165
176
  typeof pkg.dependencies['castle-web-sdk'] === 'string' &&
166
177
  pkg.dependencies['castle-web-sdk'].startsWith('file:')) {
@@ -170,10 +181,10 @@ function scaffoldFromKit(kit, projectDir) {
170
181
  for (const k of Object.keys(pkg.scripts)) {
171
182
  if (typeof pkg.scripts[k] !== 'string')
172
183
  continue;
173
- if (cliDistAbs) {
184
+ if (workspaceMode) {
174
185
  pkg.scripts[k] = pkg.scripts[k]
175
186
  .replace(/\.\.\/\.\.\/cli\/dist/g, cliDistAbs)
176
- .replace(/\.\.\/\.\.\/sdk/g, toPosixPath(sdkPath));
187
+ .replace(/\.\.\/\.\.\/sdk/g, sdkPathPosix);
177
188
  }
178
189
  else {
179
190
  // Globally-installed: route through the `castle-web` binary on PATH.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "castle-web-cli",
3
- "version": "0.4.17",
3
+ "version": "0.4.19",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "castle-web": "./dist/index.js"