primo-cli 0.1.4 → 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.
package/dist/commands/login.js
CHANGED
|
@@ -21,7 +21,7 @@ export async function login(options) {
|
|
|
21
21
|
if (!server_url) {
|
|
22
22
|
console.log('');
|
|
23
23
|
console.log(chalk.red('Server URL required.'));
|
|
24
|
-
console.log(chalk.dim(' Pass -s <url>, or run from a workspace whose server.yaml has a `server:` field.'));
|
|
24
|
+
console.log(chalk.dim(' Pass it as the first argument, use -s <url>, or run from a workspace whose server.yaml has a `server:` field.'));
|
|
25
25
|
console.log('');
|
|
26
26
|
process.exit(1);
|
|
27
27
|
}
|
|
@@ -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`, {
|
package/dist/commands/pull.d.ts
CHANGED
package/dist/commands/pull.js
CHANGED
|
@@ -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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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:
|
|
60
|
-
//
|
|
61
|
-
const root_dir = options.output
|
|
62
|
-
? path.resolve(
|
|
63
|
-
:
|
|
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...';
|
|
@@ -75,7 +98,7 @@ export async function pull_site(options) {
|
|
|
75
98
|
const sites = sites_data.items || [];
|
|
76
99
|
if (sites.length === 0) {
|
|
77
100
|
if (!token) {
|
|
78
|
-
spinner.fail(`Not authenticated. Run \`primo login
|
|
101
|
+
spinner.fail(`Not authenticated. Run \`primo login ${server}\` first.`);
|
|
79
102
|
}
|
|
80
103
|
else {
|
|
81
104
|
spinner.fail('No sites visible — your token may be expired. Try `primo login` again.');
|
|
@@ -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
|
-
//
|
|
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
|
-
|
|
110
|
-
|
|
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({
|
|
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({
|
|
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')
|
|
@@ -115,11 +121,11 @@ library
|
|
|
115
121
|
.option('-t, --token <token>', 'Auth token')
|
|
116
122
|
.action((server, options) => push_library({ ...options, server: server || options.server }));
|
|
117
123
|
program
|
|
118
|
-
.command('login')
|
|
124
|
+
.command('login [server]')
|
|
119
125
|
.description('Login to hosted CMS')
|
|
120
126
|
.option('-s, --server <url>', 'Server URL (defaults to `server:` in server.yaml)')
|
|
121
127
|
.option('-e, --email <email>', 'Email')
|
|
122
|
-
.action(login);
|
|
128
|
+
.action((server, options) => login({ ...options, server: server || options.server }));
|
|
123
129
|
program
|
|
124
130
|
.command('validate')
|
|
125
131
|
.description('Validate site structure')
|