castle-web-cli 0.4.64 → 0.4.65

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 CHANGED
@@ -9,7 +9,16 @@ import { init } from './init.js';
9
9
  import { connectWS, savePreviewImage, savePreviewIfNeeded, takeScreenshot } from './preview.js';
10
10
  const args = process.argv.slice(2);
11
11
  const command = args[0];
12
- const FLAGS_WITH_VALUES = new Set(['--port', '--out', '--host', '--kit', '--deck-id']);
12
+ const FLAGS_WITH_VALUES = new Set([
13
+ '--port',
14
+ '--out',
15
+ '--host',
16
+ '--kit',
17
+ '--deck-id',
18
+ '--title',
19
+ '--caption',
20
+ '--visibility',
21
+ ]);
13
22
  function findPositionalDir() {
14
23
  for (let i = 1; i < args.length; i++) {
15
24
  if (args[i].startsWith('--')) {
@@ -53,7 +62,7 @@ function usage() {
53
62
  castle-web restart [--port PORT]
54
63
  castle-web screenshot [--out FILE] [--port PORT]
55
64
  castle-web save-preview-image [dir] [--port PORT] [--no-restart]
56
- castle-web save-deck [dir]
65
+ castle-web save-deck [dir] [--title TITLE] [--caption TEXT] [--visibility unlisted|private]
57
66
  castle-web get-deck <dir> [--deck-id ID]
58
67
  castle-web login
59
68
 
@@ -87,9 +96,15 @@ async function main() {
87
96
  }
88
97
  case 'save-deck': {
89
98
  const dir = findPositionalDir();
90
- await saveDeck(dir);
91
- const wsPort = getWsPort(dir);
92
- await savePreviewIfNeeded(dir, wsPort);
99
+ const title = getFlagValue('--title');
100
+ const caption = getFlagValue('--caption');
101
+ const visibility = getFlagValue('--visibility');
102
+ await saveDeck(dir, { title, caption, visibility });
103
+ // --no-preview: skip the WS canvas capture (no browser tab in headless/cloud saves).
104
+ if (!args.includes('--no-preview')) {
105
+ const wsPort = getWsPort(dir);
106
+ await savePreviewIfNeeded(dir, wsPort);
107
+ }
93
108
  break;
94
109
  }
95
110
  case 'get-deck': {
@@ -1,2 +1,8 @@
1
1
  export declare function archiveSource(projectDir: string): Promise<Buffer>;
2
- export declare function saveDeck(dir: string): Promise<void>;
2
+ export type SaveVisibility = 'unlisted' | 'private';
3
+ export interface SaveDeckOptions {
4
+ title?: string;
5
+ caption?: string;
6
+ visibility?: SaveVisibility;
7
+ }
8
+ export declare function saveDeck(dir: string, opts?: SaveDeckOptions): Promise<void>;
package/dist/save-deck.js CHANGED
@@ -85,11 +85,16 @@ function buildSceneData(bundle) {
85
85
  },
86
86
  };
87
87
  }
88
- export async function saveDeck(dir) {
88
+ export async function saveDeck(dir, opts = {}) {
89
89
  if (!config.getToken()) {
90
90
  console.error('Not logged in. Run `castle-web login` first.');
91
91
  process.exit(1);
92
92
  }
93
+ const visibility = opts.visibility ?? 'unlisted';
94
+ if (visibility !== 'unlisted' && visibility !== 'private') {
95
+ console.error(`Invalid visibility "${visibility}". Use unlisted or private.`);
96
+ process.exit(1);
97
+ }
93
98
  const projectDir = path.resolve(dir);
94
99
  if (!fs.existsSync(path.join(projectDir, 'index.html'))) {
95
100
  console.error(`No index.html found in ${projectDir}`);
@@ -128,17 +133,24 @@ export async function saveDeck(dir) {
128
133
  if (s3Res.status >= 300) {
129
134
  throw new Error(`Upload failed: HTTP ${s3Res.status}`);
130
135
  }
131
- // Create or update via updateCardAndDeckV2
132
- const title = path.basename(path.resolve(projectDir));
136
+ const title = opts.title ?? castleJson?.title ?? path.basename(path.resolve(projectDir));
137
+ const deckInput = { deckId, title, visibility };
138
+ if (opts.caption !== undefined)
139
+ deckInput.caption = opts.caption;
133
140
  try {
134
- const result = await api.updateCardAndDeckV2({ deckId, title, visibility: 'unlisted' }, { cardId, blocks: [], uploadId: uploadConfig.uploadId, makeInitialCard: true });
141
+ const result = await api.updateCardAndDeckV2(deckInput, {
142
+ cardId,
143
+ blocks: [],
144
+ uploadId: uploadConfig.uploadId,
145
+ makeInitialCard: true,
146
+ });
147
+ const newCastleJson = { deckId: result.deckId, cardId: result.cardId, title };
148
+ fs.writeFileSync(path.join(projectDir, 'castle.json'), JSON.stringify(newCastleJson, null, 2) + '\n', 'utf-8');
135
149
  if (isNew) {
136
- const newCastleJson = { deckId: result.deckId, cardId: result.cardId };
137
- fs.writeFileSync(path.join(projectDir, 'castle.json'), JSON.stringify(newCastleJson, null, 2) + '\n', 'utf-8');
138
150
  console.log(`Created deck "${title}" (${result.deckId}). Saved castle.json.`);
139
151
  }
140
152
  else {
141
- console.log('Saved to Castle.');
153
+ console.log(`Saved "${title}" to Castle.`);
142
154
  }
143
155
  console.log('Uploading source archive...');
144
156
  await uploadSource(projectDir, result.deckId);