primo-cli 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.
@@ -1,6 +1,6 @@
1
1
  interface PullLibraryOptions {
2
2
  server?: string;
3
- output: string;
3
+ output?: string;
4
4
  token?: string;
5
5
  }
6
6
  export declare function pull_library(options: PullLibraryOptions): Promise<void>;
@@ -40,7 +40,7 @@ export async function pull_library(options) {
40
40
  if (token) {
41
41
  headers.Authorization = `Bearer ${token}`;
42
42
  }
43
- const output_dir = path.resolve(options.output);
43
+ const output_dir = path.resolve(options.output || '.');
44
44
  await fs.mkdir(output_dir, { recursive: true });
45
45
  spinner.text = 'Exporting library...';
46
46
  const response = await fetch(`${server}/api/palacms/export-library`, {
@@ -1,6 +1,6 @@
1
1
  interface PullOptions {
2
2
  server?: string;
3
- output: string;
3
+ output?: string;
4
4
  token?: string;
5
5
  }
6
6
  export declare function pull_site(options: PullOptions): Promise<void>;
@@ -6,7 +6,7 @@ import extract from 'extract-zip';
6
6
  import { dump as dump_yaml, load as load_yaml } from 'js-yaml';
7
7
  import { get_auth_token } from '../utils/auth.js';
8
8
  import { write_site_config } from '../utils/site-config.js';
9
- import { write_server_config } from '../utils/server-config.js';
9
+ import { read_server_config, write_server_config } from '../utils/server-config.js';
10
10
  async function detect_server() {
11
11
  const ports = [3000, 8080, 5173];
12
12
  for (const port of ports) {
@@ -36,19 +36,40 @@ function server_folder_name(server) {
36
36
  return 'primo-server';
37
37
  }
38
38
  }
39
+ async function read_configured_server(dir) {
40
+ const config = await read_configured_server_config(dir);
41
+ return config?.server || null;
42
+ }
43
+ async function read_configured_server_config(dir) {
44
+ try {
45
+ return await read_server_config(dir);
46
+ }
47
+ catch {
48
+ return null;
49
+ }
50
+ }
39
51
  export async function pull_site(options) {
40
52
  const spinner = ora('Connecting...').start();
41
53
  try {
42
- // Resolve server (flag > local detect)
54
+ // Resolve server (flag > server.yaml in cwd > local detect)
43
55
  let server;
56
+ let used_configured = false;
44
57
  if (options.server) {
45
58
  server = options.server.replace(/\/+$/, '');
46
59
  }
47
60
  else {
48
- spinner.text = 'Looking for local server...';
49
- const detected = await detect_server();
50
- server = (detected || 'http://localhost:3000').replace(/\/+$/, '');
51
- spinner.text = `Using ${server}`;
61
+ const configured = await read_configured_server(process.cwd());
62
+ if (configured) {
63
+ server = configured;
64
+ used_configured = true;
65
+ spinner.text = `Using ${server}`;
66
+ }
67
+ else {
68
+ spinner.text = 'Looking for local server...';
69
+ const detected = await detect_server();
70
+ server = (detected || 'http://localhost:3000').replace(/\/+$/, '');
71
+ spinner.text = `Using ${server}`;
72
+ }
52
73
  }
53
74
  // Auth (optional for local)
54
75
  const token = options.token || await get_auth_token(server);
@@ -56,11 +77,13 @@ export async function pull_site(options) {
56
77
  if (token) {
57
78
  headers['Authorization'] = `Bearer ${token}`;
58
79
  }
59
- // Decide root dir: if --output is default ('.'), nest under server hostname.
60
- // Otherwise use --output verbatim.
61
- const root_dir = options.output === '.'
62
- ? path.resolve(server_folder_name(server))
63
- : path.resolve(options.output);
80
+ // Decide root dir: explicit --output wins; if cwd already has a configured
81
+ // server.yaml, pull in place; otherwise nest under server hostname.
82
+ const root_dir = options.output
83
+ ? path.resolve(options.output)
84
+ : used_configured
85
+ ? process.cwd()
86
+ : path.resolve(server_folder_name(server));
64
87
  await fs.mkdir(root_dir, { recursive: true });
65
88
  // List all sites
66
89
  spinner.text = 'Fetching sites...';
@@ -104,10 +127,13 @@ export async function pull_site(options) {
104
127
  }
105
128
  // Fetch site groups so server.yaml has them
106
129
  const site_groups = await fetch_site_groups(server, headers);
107
- // Write minimal server.yaml so MCP registration + dev work at the root
130
+ // Preserve any existing server.yaml (port, format, server URL) and just
131
+ // refresh site_groups from the source of truth.
132
+ const existing = await read_configured_server_config(root_dir);
108
133
  await write_server_config(root_dir, {
109
- port: 3000,
110
- site_groups: site_groups.length > 0 ? site_groups : undefined
134
+ ...existing,
135
+ port: existing?.port ?? 3000,
136
+ site_groups: site_groups.length > 0 ? site_groups : existing?.site_groups
111
137
  });
112
138
  spinner.succeed(`Server pulled to ${chalk.cyan(root_dir)}`);
113
139
  console.log('');
package/dist/index.js CHANGED
@@ -91,22 +91,28 @@ ${chalk.bold('See also')}
91
91
  `)
92
92
  .action((server, options) => push_site({ ...options, server: server || options.server }));
93
93
  program
94
- .command('pull [server]')
95
- .description('Pull entire server (all sites + library) to local files')
94
+ .command('pull [server] [dir]')
95
+ .description('Pull entire server (all sites + library) to local files (defaults to ./<server-hostname>)')
96
96
  .option('-s, --server <url>', 'Server URL (auto-detects local)')
97
- .option('-o, --output <dir>', 'Output directory (defaults to ./<server-hostname>)', '.')
98
97
  .option('-t, --token <token>', 'Auth token')
99
- .action((server, options) => pull_site({ ...options, server: server || options.server }));
98
+ .action((server, dir, options) => pull_site({
99
+ ...options,
100
+ server: server || options.server,
101
+ output: dir
102
+ }));
100
103
  const library = program
101
104
  .command('library')
102
105
  .description('Manage shared block library');
103
106
  library
104
- .command('pull [server]')
107
+ .command('pull [server] [dir]')
105
108
  .description('Pull shared library to local files')
106
109
  .option('-s, --server <url>', 'Server URL (auto-detects local)')
107
- .option('-o, --output <dir>', 'Output directory', '.')
108
110
  .option('-t, --token <token>', 'Auth token')
109
- .action((server, options) => pull_library({ ...options, server: server || options.server }));
111
+ .action((server, dir, options) => pull_library({
112
+ ...options,
113
+ server: server || options.server,
114
+ output: dir
115
+ }));
110
116
  library
111
117
  .command('push [server]')
112
118
  .description('Push local shared library to hosted CMS')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "primo-cli",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Local development CLI for Primo",
5
5
  "type": "module",
6
6
  "bin": {