@zhqi9277/marina-db 0.1.0 → 0.1.1
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/README.md +4 -0
- package/package.json +7 -1
- package/src/cli.js +19 -6
- package/src/install/download.js +23 -1
- package/src/install/installer.js +3 -3
- package/src/runtime/autostart.js +7 -2
- package/src/runtime/lifecycle.js +2 -1
- package/src/ui/console.js +14 -7
package/README.md
CHANGED
|
@@ -211,6 +211,10 @@ Changes to Milvus packaging on `main` check for missing Linux x64 and macOS ARM6
|
|
|
211
211
|
|
|
212
212
|
Report bugs and feature requests in [GitHub Issues](https://github.com/zhqi9277/marina-db/issues).
|
|
213
213
|
|
|
214
|
+
### Release the CLI
|
|
215
|
+
|
|
216
|
+
Every push to `main` that changes `bin/`, `src/`, `assets/`, `package.json`, or a README runs the tests, bumps the patch version, tags the commit, publishes to npm with provenance, and creates a GitHub Release with generated notes. Add `#minor` or `#major` to the commit message for a larger bump, or `[skip release]` to skip publishing. To choose the bump yourself, open **Actions → Release → Run workflow**. The workflow needs an `NPM_TOKEN` repository secret. Engine releases (`engines-*`) are separate and unaffected.
|
|
217
|
+
|
|
214
218
|
## License
|
|
215
219
|
|
|
216
220
|
Marina is released under the [MIT License](./LICENSE).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhqi9277/marina-db",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"homepage": "https://github.com/zhqi9277/marina-db",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,6 +17,12 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"marina": "node bin/marina.js",
|
|
19
19
|
"test": "node --test test/*.mjs",
|
|
20
|
+
"desktop:ui:install": "pnpm --dir desktop/ui install",
|
|
21
|
+
"desktop:ui:dev": "pnpm --dir desktop/ui dev",
|
|
22
|
+
"desktop:ui:build": "pnpm --dir desktop/ui build",
|
|
23
|
+
"desktop:ui:test": "pnpm --dir desktop/ui test",
|
|
24
|
+
"desktop:shell:install": "pnpm --dir desktop install",
|
|
25
|
+
"desktop:shell:start": "pnpm --dir desktop start",
|
|
20
26
|
"smoke:e2e": "node test/e2e/smoke.mjs"
|
|
21
27
|
},
|
|
22
28
|
"keywords": [
|
package/src/cli.js
CHANGED
|
@@ -446,17 +446,28 @@ async function cmdStatus(flags, args) {
|
|
|
446
446
|
}
|
|
447
447
|
|
|
448
448
|
async function cmdLogs(flags, args) {
|
|
449
|
-
const
|
|
449
|
+
const ref = requireRef(args, flags);
|
|
450
|
+
const { ctx } = resolveRef(ref);
|
|
450
451
|
const lines = Number(flags.lines || 60);
|
|
451
452
|
const file = ctx.logFile;
|
|
452
|
-
if (!fs.existsSync(file))
|
|
453
|
+
if (!fs.existsSync(file)) {
|
|
454
|
+
if (flags.json) return jsonOut({ ref, lines, text: '' });
|
|
455
|
+
return warn(`no log yet at ${file}`);
|
|
456
|
+
}
|
|
453
457
|
const content = fs.readFileSync(file, 'utf8').trimEnd().split('\n');
|
|
454
|
-
|
|
458
|
+
const text = content.slice(-lines).join('\n');
|
|
459
|
+
if (flags.json) return jsonOut({ ref, lines, text });
|
|
460
|
+
out(text);
|
|
455
461
|
}
|
|
456
462
|
|
|
457
463
|
async function cmdConfig(flags, args) {
|
|
458
|
-
const
|
|
459
|
-
|
|
464
|
+
const ref = requireRef(args, flags);
|
|
465
|
+
const { ctx } = resolveRef(ref);
|
|
466
|
+
if (!ctx.confFile) {
|
|
467
|
+
if (flags.json) return jsonOut({ ref, path: null });
|
|
468
|
+
return info('this engine has no marina-managed config file');
|
|
469
|
+
}
|
|
470
|
+
if (flags.json) return jsonOut({ ref, path: ctx.confFile, exists: fs.existsSync(ctx.confFile) });
|
|
460
471
|
out(ctx.confFile);
|
|
461
472
|
if (!fs.existsSync(ctx.confFile)) warn('file does not exist yet — marina install --force');
|
|
462
473
|
}
|
|
@@ -472,7 +483,9 @@ async function cmdPort(flags, args) {
|
|
|
472
483
|
if (!result.restarted) hint(`start with: marina start ${ctx.key}@${ctx.major}`);
|
|
473
484
|
return;
|
|
474
485
|
}
|
|
475
|
-
|
|
486
|
+
const port = state.portOf(engine.key, ctx.major, engine.defaultPort);
|
|
487
|
+
if (flags.json) return jsonOut({ ref, port });
|
|
488
|
+
out(String(port));
|
|
476
489
|
}
|
|
477
490
|
|
|
478
491
|
async function cmdAuth(flags, args) {
|
package/src/install/download.js
CHANGED
|
@@ -79,13 +79,26 @@ export async function sha256File(file) {
|
|
|
79
79
|
* Download `url` to `dest`, verifying sha256 (when provided).
|
|
80
80
|
* Resumes a previous `.part` file when the server supports ranges.
|
|
81
81
|
*/
|
|
82
|
-
export async function downloadFile(url, dest, { sha256, size, label = path.basename(dest), retries = 2 } = {}) {
|
|
82
|
+
export async function downloadFile(url, dest, { sha256, size, label = path.basename(dest), retries = 2, onProgress } = {}) {
|
|
83
83
|
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
84
84
|
|
|
85
|
+
const emitProgress = (phase, received, total = 0, speed = 0) => {
|
|
86
|
+
if (!onProgress) return;
|
|
87
|
+
onProgress({
|
|
88
|
+
phase,
|
|
89
|
+
label,
|
|
90
|
+
received,
|
|
91
|
+
total,
|
|
92
|
+
percent: total ? Math.min(100, Math.floor((received / total) * 100)) : 0,
|
|
93
|
+
speed,
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
|
|
85
97
|
if (fs.existsSync(dest) && sha256) {
|
|
86
98
|
const got = await sha256File(dest);
|
|
87
99
|
if (got === sha256 && (size == null || fs.statSync(dest).size === size)) {
|
|
88
100
|
info(`${label} already in cache (sha256 ok)`);
|
|
101
|
+
emitProgress('done', size ?? 0, size ?? 0);
|
|
89
102
|
return dest;
|
|
90
103
|
}
|
|
91
104
|
fs.rmSync(dest, { force: true });
|
|
@@ -114,11 +127,18 @@ export async function downloadFile(url, dest, { sha256, size, label = path.basen
|
|
|
114
127
|
const totalBytes = size ?? (Number(range?.[2]) || (bytes ? start + bytes : 0));
|
|
115
128
|
const bar = progress(label, totalBytes);
|
|
116
129
|
let received = start;
|
|
130
|
+
const started = Date.now();
|
|
131
|
+
const speed = () => {
|
|
132
|
+
const secs = (Date.now() - started) / 1000;
|
|
133
|
+
return secs > 0.5 ? received / 1048576 / secs : 0;
|
|
134
|
+
};
|
|
135
|
+
emitProgress('start', received, totalBytes);
|
|
117
136
|
try {
|
|
118
137
|
await pipeline(res, new Transform({
|
|
119
138
|
transform(chunk, _encoding, callback) {
|
|
120
139
|
received += chunk.length;
|
|
121
140
|
bar.update(received);
|
|
141
|
+
emitProgress('download', received, totalBytes, speed());
|
|
122
142
|
callback(null, chunk);
|
|
123
143
|
},
|
|
124
144
|
}), fs.createWriteStream(part, { flags: resumed ? 'a' : 'w' }));
|
|
@@ -131,6 +151,7 @@ export async function downloadFile(url, dest, { sha256, size, label = path.basen
|
|
|
131
151
|
throw new Error(`incomplete download for ${label}: received ${received} of ${totalBytes} bytes`);
|
|
132
152
|
}
|
|
133
153
|
|
|
154
|
+
emitProgress('verify', received, totalBytes, speed());
|
|
134
155
|
if (sha256) {
|
|
135
156
|
const got = await sha256File(part);
|
|
136
157
|
if (got !== sha256) {
|
|
@@ -139,6 +160,7 @@ export async function downloadFile(url, dest, { sha256, size, label = path.basen
|
|
|
139
160
|
}
|
|
140
161
|
}
|
|
141
162
|
fs.renameSync(part, dest);
|
|
163
|
+
emitProgress('done', received, totalBytes, speed());
|
|
142
164
|
return dest;
|
|
143
165
|
} catch (e) {
|
|
144
166
|
lastErr = e;
|
package/src/install/installer.js
CHANGED
|
@@ -61,7 +61,7 @@ export async function resolveTarget(ref, { file = null, version = null } = {}) {
|
|
|
61
61
|
return { ...entry, engine, channel: 'catalog' };
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
export async function fetchPackage(target) {
|
|
64
|
+
export async function fetchPackage(target, { onProgress } = {}) {
|
|
65
65
|
if (target.file) {
|
|
66
66
|
mkdirp(cacheDir(target.engine.key, target.version));
|
|
67
67
|
const dest = path.join(cacheDir(target.engine.key, target.version), path.basename(target.file));
|
|
@@ -80,7 +80,7 @@ export async function fetchPackage(target) {
|
|
|
80
80
|
throw new Error('invalid artifact file name: ' + name);
|
|
81
81
|
}
|
|
82
82
|
const dest = path.join(cacheDir(target.engine.key, target.version), name);
|
|
83
|
-
await downloadFile(url, dest, { sha256: target.sha256, size: target.size, label: name });
|
|
83
|
+
await downloadFile(url, dest, { sha256: target.sha256, size: target.size, label: name, onProgress });
|
|
84
84
|
return { tarball: dest, sha256: target.sha256 };
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -158,7 +158,7 @@ async function installTarget(target, opts, port) {
|
|
|
158
158
|
: `${target.indexSource} · ${target.urls[0]}`;
|
|
159
159
|
info(`${engine.label} ${version} ${color.gray(`(${origin})`)}`);
|
|
160
160
|
|
|
161
|
-
const { tarball, sha256 } = await fetchPackage(target);
|
|
161
|
+
const { tarball, sha256 } = await fetchPackage(target, { onProgress: opts.onProgress });
|
|
162
162
|
const pending = pendingInstallFile(engine, major, version);
|
|
163
163
|
const interrupted = fs.existsSync(pending);
|
|
164
164
|
const wasInstalled = isInstalled(engine, major, version);
|
package/src/runtime/autostart.js
CHANGED
|
@@ -19,6 +19,11 @@ export { systemdEscape, xmlEscape };
|
|
|
19
19
|
export const CLI = fileURLToPath(new URL('../bin/marina.js', import.meta.url));
|
|
20
20
|
export const NODE = process.execPath;
|
|
21
21
|
|
|
22
|
+
let command = { node: NODE, cli: CLI };
|
|
23
|
+
export function configureAutostart({ node = command.node, cli = command.cli } = {}) {
|
|
24
|
+
command = { node, cli };
|
|
25
|
+
}
|
|
26
|
+
|
|
22
27
|
export const idOf = (ctx) => `${ctx.key}:${ctx.major}`;
|
|
23
28
|
|
|
24
29
|
export function isEnabled(ctx) {
|
|
@@ -35,11 +40,11 @@ function requireUnitTarget() {
|
|
|
35
40
|
return target;
|
|
36
41
|
}
|
|
37
42
|
|
|
38
|
-
export function renderUnit(ids, target = unitTarget()) {
|
|
43
|
+
export function renderUnit(ids, target = unitTarget(), { node = command.node, cli = command.cli } = {}) {
|
|
39
44
|
const backend = backendFor(target);
|
|
40
45
|
if (!backend) throw new Error('autostart is not available on this host');
|
|
41
46
|
const log = path.join(dirs.root, 'logs', 'autostart.log');
|
|
42
|
-
return backend.renderUnit(ids, target, { node
|
|
47
|
+
return backend.renderUnit(ids, target, { node, cli, log, home: path.resolve(dirs.root) });
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
function run(cmd, args) {
|
package/src/runtime/lifecycle.js
CHANGED
|
@@ -164,7 +164,8 @@ export function tailLog(ctx, lines = 12) {
|
|
|
164
164
|
const file = ctx.engine.logFile?.(ctx) || ctx.logFile;
|
|
165
165
|
try {
|
|
166
166
|
const content = fs.readFileSync(file, 'utf8').trimEnd().split('\n');
|
|
167
|
-
|
|
167
|
+
const take = Number.isSafeInteger(lines) && lines > 0 ? content.slice(-lines) : content;
|
|
168
|
+
return take.join('\n');
|
|
168
169
|
} catch {
|
|
169
170
|
return '';
|
|
170
171
|
}
|
package/src/ui/console.js
CHANGED
|
@@ -19,17 +19,24 @@ export const sym = {
|
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
let quietMode = false;
|
|
22
|
+
let outputChannel = null;
|
|
22
23
|
export function setQuiet(v) { quietMode = !!v; }
|
|
23
24
|
export function isQuiet() { return quietMode; }
|
|
25
|
+
export function setOutputChannel(channel) { outputChannel = channel; }
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
function emit(level, stream, rendered, message = rendered) {
|
|
28
|
+
if (outputChannel) return outputChannel({ level, stream, message });
|
|
29
|
+
(stream === 'stderr' ? process.stderr : process.stdout).write(rendered + '\n');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const out = (...a) => emit('out', 'stdout', a.join(' '));
|
|
33
|
+
export const err = (...a) => emit('err', 'stderr', a.join(' '));
|
|
27
34
|
|
|
28
|
-
export function info(msg) { if (!quietMode)
|
|
29
|
-
export function ok(msg) { if (!quietMode)
|
|
30
|
-
export function warn(msg) { if (!quietMode)
|
|
31
|
-
export function fail(msg) {
|
|
32
|
-
export function hint(msg) { if (!quietMode)
|
|
35
|
+
export function info(msg) { if (!quietMode) emit('info', 'stdout', `${sym.dot} ${msg}`, msg); }
|
|
36
|
+
export function ok(msg) { if (!quietMode) emit('ok', 'stdout', `${sym.ok} ${msg}`, msg); }
|
|
37
|
+
export function warn(msg) { if (!quietMode) emit('warn', 'stderr', `${sym.warn} ${color.yellow(msg)}`, msg); }
|
|
38
|
+
export function fail(msg) { emit('fail', 'stderr', `${sym.fail} ${color.red(msg)}`, msg); }
|
|
39
|
+
export function hint(msg) { if (!quietMode) emit('hint', 'stdout', color.gray(` ${msg}`), msg); }
|
|
33
40
|
|
|
34
41
|
// ---- tables ----------------------------------------------------------------
|
|
35
42
|
export function table(headers, rows, { align = [] } = {}) {
|