@darkrymit/crunes-cli 0.5.10 → 0.7.0
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 +5 -5
- package/dist/chunks/add-OWYVF3IE.js +22 -0
- package/dist/chunks/apply-OMEVXCHC.js +183 -0
- package/dist/chunks/args-32BVYW77.js +42 -0
- package/dist/chunks/benchmark-CLUBISCR.js +164 -0
- package/dist/chunks/browse-COH6IJEX.js +34 -0
- package/dist/chunks/check-BS6TZGRR.js +144 -0
- package/dist/chunks/chunk-2Q24YPGL.js +369 -0
- package/dist/chunks/chunk-3TM6B4E5.js +70 -0
- package/dist/chunks/chunk-67I2J474.js +153 -0
- package/dist/chunks/chunk-6XLT25GS.js +50 -0
- package/dist/chunks/chunk-BVY5LN7X.js +25091 -0
- package/dist/chunks/chunk-CGZL5SSH.js +926 -0
- package/dist/chunks/chunk-DMMC4X27.js +1836 -0
- package/dist/chunks/chunk-G3U4V32O.js +46 -0
- package/dist/chunks/chunk-GHQOK4L7.js +59 -0
- package/dist/chunks/chunk-H3BVJCIL.js +105 -0
- package/dist/chunks/chunk-HMU2J25D.js +63 -0
- package/dist/chunks/chunk-HOH7WZX4.js +95 -0
- package/dist/chunks/chunk-L72BG6DS.js +225 -0
- package/dist/chunks/chunk-NXSDVVTW.js +181 -0
- package/dist/chunks/chunk-QLDB3FO2.js +73059 -0
- package/dist/chunks/chunk-QMWGQXEZ.js +26 -0
- package/dist/chunks/chunk-TPK5AGRA.js +54 -0
- package/dist/chunks/chunk-UGN3FFEF.js +8379 -0
- package/dist/chunks/chunk-WCODTMDN.js +508 -0
- package/dist/chunks/chunk-XIXND2M4.js +296 -0
- package/dist/chunks/chunk-XXUNHQIB.js +129 -0
- package/dist/chunks/chunk-ZXIP4Z5V.js +281 -0
- package/dist/chunks/clear-Y5POLIMF.js +32 -0
- package/dist/chunks/completions-2MSEWWTG.js +232 -0
- package/dist/chunks/create-5FXQYCGM.js +165 -0
- package/dist/chunks/create-I6BNYZ5Q.js +247 -0
- package/dist/chunks/create-O3HMODSL.js +130 -0
- package/dist/chunks/delete-7CQFYIXS.js +40 -0
- package/dist/chunks/delete-UB5SXO5I.js +40 -0
- package/dist/chunks/disable-FCBW7WVG.js +47 -0
- package/dist/chunks/doctor-DS57HDLJ.js +53 -0
- package/dist/chunks/enable-IXRVUXJM.js +47 -0
- package/dist/chunks/esm-7MEWZCHY.js +5162 -0
- package/dist/chunks/globals-YCJ2DGWC.js +60 -0
- package/dist/chunks/init-WGKQVAZE.js +59 -0
- package/dist/chunks/install-BCTBOPBS.js +57 -0
- package/dist/chunks/intro-2UDWF6D4.js +1482 -0
- package/dist/chunks/kill-LWRXZVM5.js +37 -0
- package/dist/chunks/list-5DVVP7HX.js +50 -0
- package/dist/chunks/list-6WL5LGIZ.js +80 -0
- package/dist/chunks/list-NGOCMJXE.js +104 -0
- package/dist/chunks/list-TTKLNJKI.js +28 -0
- package/dist/chunks/list-WUAOSO3M.js +110 -0
- package/dist/chunks/list-YPI7YDKK.js +80 -0
- package/dist/chunks/list-ZBYPMUID.js +23 -0
- package/dist/chunks/manifest-7RVNKBOH.js +9 -0
- package/dist/chunks/output-RJ6JSNY7.js +12 -0
- package/dist/chunks/promise-DUSIQMA2.js +19400 -0
- package/dist/chunks/query-NY4SCO77.js +41 -0
- package/dist/chunks/registry-W5XFI5T6.js +16 -0
- package/dist/chunks/remove-WEAZFZCO.js +22 -0
- package/dist/chunks/run-I6TZX347.js +23 -0
- package/dist/chunks/run-MVIZQVJ6.js +36 -0
- package/dist/chunks/rune-TAX26NH2.js +76 -0
- package/dist/chunks/search-XENXL3GC.js +25 -0
- package/dist/chunks/uninstall-MX5PLGDI.js +49 -0
- package/dist/chunks/unset-KQOZYVTE.js +28 -0
- package/dist/chunks/update-7XDTVFZ3.js +39 -0
- package/dist/chunks/update-IEE54GPY.js +79 -0
- package/dist/chunks/utils-PO3ZK53L.js +50 -0
- package/dist/chunks/version-DIEA5FVV.js +145 -0
- package/dist/cli.js +3360 -125840
- package/package.json +23 -15
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_require_shim
|
|
3
|
+
} from "./chunk-TPK5AGRA.js";
|
|
4
|
+
|
|
5
|
+
// src/plugin/manifest.js
|
|
6
|
+
init_require_shim();
|
|
7
|
+
import fs from "node:fs/promises";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
var PLUGIN_JSON_RELATIVE = ".crunes-plugin/plugin.json";
|
|
10
|
+
async function loadPluginJson(pluginDir) {
|
|
11
|
+
const jsonPath = path.join(pluginDir, PLUGIN_JSON_RELATIVE);
|
|
12
|
+
const raw = await fs.readFile(jsonPath, "utf8");
|
|
13
|
+
const json = JSON.parse(raw);
|
|
14
|
+
validatePluginJson(json);
|
|
15
|
+
return json;
|
|
16
|
+
}
|
|
17
|
+
function validatePluginJson(json) {
|
|
18
|
+
if (json.format !== "1") throw new Error(`plugin.json: unsupported format "${json.format}" (expected "1")`);
|
|
19
|
+
if (!json.runes || typeof json.runes !== "object") throw new Error('plugin.json: "runes" must be an object');
|
|
20
|
+
for (const [key, rune] of Object.entries(json.runes)) {
|
|
21
|
+
if (!rune.permissions || Object.keys(rune.permissions).length === 0) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const perms = rune.permissions;
|
|
25
|
+
if (Array.isArray(perms)) {
|
|
26
|
+
throw new Error(`plugin.json: rune "${key}" permissions must be lifecycle-scoped (e.g. permissions.run.allow)`);
|
|
27
|
+
}
|
|
28
|
+
if (perms.allow || perms.deny) {
|
|
29
|
+
throw new Error(`plugin.json: rune "${key}" permissions must be lifecycle-scoped (e.g. permissions.run.allow)`);
|
|
30
|
+
}
|
|
31
|
+
const hasLifecycleScoped = Object.values(perms).some((v) => v && Array.isArray(v.allow));
|
|
32
|
+
if (!hasLifecycleScoped) {
|
|
33
|
+
const hasEmptyRun = perms.run && typeof perms.run === "object" && Object.keys(perms.run).length === 0;
|
|
34
|
+
if (hasEmptyRun) {
|
|
35
|
+
console.warn(`[crunes:warn] plugin.json: rune "${key}" permissions.run is empty.`);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
throw new Error(`plugin.json: rune "${key}" must have lifecycle-scoped permissions (e.g. permissions.run.allow)`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
loadPluginJson,
|
|
45
|
+
validatePluginJson
|
|
46
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getPluginsJsonPath
|
|
3
|
+
} from "./chunk-HMU2J25D.js";
|
|
4
|
+
import {
|
|
5
|
+
init_require_shim
|
|
6
|
+
} from "./chunk-TPK5AGRA.js";
|
|
7
|
+
|
|
8
|
+
// src/plugin/registry.js
|
|
9
|
+
init_require_shim();
|
|
10
|
+
import fs from "node:fs/promises";
|
|
11
|
+
var EMPTY_REGISTRY = { format: "1", plugins: {} };
|
|
12
|
+
async function loadRegistry() {
|
|
13
|
+
try {
|
|
14
|
+
const raw = await fs.readFile(getPluginsJsonPath(), "utf8");
|
|
15
|
+
return JSON.parse(raw);
|
|
16
|
+
} catch (err) {
|
|
17
|
+
if (err.code === "ENOENT") return structuredClone(EMPTY_REGISTRY);
|
|
18
|
+
throw err;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async function saveRegistry(data) {
|
|
22
|
+
const jsonPath = getPluginsJsonPath();
|
|
23
|
+
const tmp = jsonPath + ".tmp";
|
|
24
|
+
await fs.writeFile(tmp, JSON.stringify(data, null, 2), "utf8");
|
|
25
|
+
await fs.rename(tmp, jsonPath);
|
|
26
|
+
}
|
|
27
|
+
async function registerPlugin(entry) {
|
|
28
|
+
const registry = await loadRegistry();
|
|
29
|
+
const key = `${entry.marketplaceName}@${entry.name}`;
|
|
30
|
+
registry.plugins[key] = {
|
|
31
|
+
version: entry.version,
|
|
32
|
+
path: entry.path,
|
|
33
|
+
cacheDir: entry.cacheDir ?? entry.path,
|
|
34
|
+
local: entry.local ?? false,
|
|
35
|
+
installedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
36
|
+
consentedPermissions: entry.consentedPermissions ?? {}
|
|
37
|
+
};
|
|
38
|
+
await saveRegistry(registry);
|
|
39
|
+
}
|
|
40
|
+
async function removePlugin(key) {
|
|
41
|
+
const registry = await loadRegistry();
|
|
42
|
+
delete registry.plugins[key];
|
|
43
|
+
await saveRegistry(registry);
|
|
44
|
+
}
|
|
45
|
+
function resolvePluginKey(nameOrKey, registry) {
|
|
46
|
+
if (nameOrKey.includes("@")) return nameOrKey;
|
|
47
|
+
const matches = Object.keys(registry.plugins ?? {}).filter((k) => k.slice(k.indexOf("@") + 1) === nameOrKey);
|
|
48
|
+
if (matches.length > 1)
|
|
49
|
+
throw new Error(`Ambiguous plugin "${nameOrKey}". Use the full key: ${matches.join(", ")}`);
|
|
50
|
+
return matches[0] ?? null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
loadRegistry,
|
|
55
|
+
saveRegistry,
|
|
56
|
+
registerPlugin,
|
|
57
|
+
removePlugin,
|
|
58
|
+
resolvePluginKey
|
|
59
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_require_shim
|
|
3
|
+
} from "./chunk-TPK5AGRA.js";
|
|
4
|
+
|
|
5
|
+
// src/core/config.js
|
|
6
|
+
init_require_shim();
|
|
7
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
function isObject(item) {
|
|
10
|
+
return item && typeof item === "object" && !Array.isArray(item);
|
|
11
|
+
}
|
|
12
|
+
function mergeConfigs(shared, local) {
|
|
13
|
+
const merged = { ...shared };
|
|
14
|
+
for (const [key, value] of Object.entries(local)) {
|
|
15
|
+
if (key !== "runes" && key !== "vars" && key !== "permissions" && key !== "plugins") {
|
|
16
|
+
merged[key] = value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (local.runes) {
|
|
20
|
+
merged.runes = { ...shared.runes };
|
|
21
|
+
for (const [key, localEntry] of Object.entries(local.runes)) {
|
|
22
|
+
const sharedEntry = shared.runes?.[key];
|
|
23
|
+
if (sharedEntry && isObject(sharedEntry) && isObject(localEntry)) {
|
|
24
|
+
merged.runes[key] = {
|
|
25
|
+
...sharedEntry,
|
|
26
|
+
...localEntry,
|
|
27
|
+
vars: { ...sharedEntry.vars, ...localEntry.vars }
|
|
28
|
+
};
|
|
29
|
+
} else {
|
|
30
|
+
merged.runes[key] = localEntry;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (local.vars) {
|
|
35
|
+
merged.vars = { ...shared.vars };
|
|
36
|
+
for (const [key, localVarsObj] of Object.entries(local.vars)) {
|
|
37
|
+
const sharedVarsObj = shared.vars?.[key];
|
|
38
|
+
if (sharedVarsObj && isObject(sharedVarsObj) && isObject(localVarsObj)) {
|
|
39
|
+
merged.vars[key] = { ...sharedVarsObj, ...localVarsObj };
|
|
40
|
+
} else {
|
|
41
|
+
merged.vars[key] = localVarsObj;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (local.permissions) {
|
|
46
|
+
merged.permissions = { ...shared.permissions, ...local.permissions };
|
|
47
|
+
}
|
|
48
|
+
if (local.plugins) {
|
|
49
|
+
const combined = [...shared.plugins ?? [], ...local.plugins ?? []];
|
|
50
|
+
merged.plugins = Array.from(new Set(combined));
|
|
51
|
+
}
|
|
52
|
+
return merged;
|
|
53
|
+
}
|
|
54
|
+
function validateConfig(config, fileName = "config.json") {
|
|
55
|
+
if (config.permissions && typeof config.permissions === "object") {
|
|
56
|
+
for (const [runeKey, perms] of Object.entries(config.permissions)) {
|
|
57
|
+
if (Array.isArray(perms)) {
|
|
58
|
+
throw new Error(`${fileName}: permissions for "${runeKey}" must be lifecycle-scoped (e.g. permissions["${runeKey}"].run.allow)`);
|
|
59
|
+
}
|
|
60
|
+
if (perms && typeof perms === "object") {
|
|
61
|
+
if (Array.isArray(perms.allow) || Array.isArray(perms.deny)) {
|
|
62
|
+
throw new Error(`${fileName}: permissions for "${runeKey}" must be lifecycle-scoped (e.g. permissions["${runeKey}"].run.allow)`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (config.runes && typeof config.runes === "object") {
|
|
68
|
+
for (const [runeKey, entry] of Object.entries(config.runes)) {
|
|
69
|
+
if (entry && typeof entry === "object" && entry.permissions) {
|
|
70
|
+
const perms = entry.permissions;
|
|
71
|
+
if (Array.isArray(perms)) {
|
|
72
|
+
throw new Error(`${fileName}: runes["${runeKey}"].permissions must be lifecycle-scoped (e.g. permissions.run.allow)`);
|
|
73
|
+
}
|
|
74
|
+
if (perms && typeof perms === "object") {
|
|
75
|
+
if (Array.isArray(perms.allow) || Array.isArray(perms.deny)) {
|
|
76
|
+
throw new Error(`${fileName}: runes["${runeKey}"].permissions must be lifecycle-scoped (e.g. permissions.run.allow)`);
|
|
77
|
+
}
|
|
78
|
+
if (perms.run && typeof perms.run === "object" && Object.keys(perms.run).length === 0) {
|
|
79
|
+
console.warn(`[crunes:warn] ${fileName}: runes["${runeKey}"].permissions.run is empty. No extra permissions will be granted.`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function loadConfig(dir) {
|
|
87
|
+
const configPath = join(dir, ".crunes", "config.json");
|
|
88
|
+
const localConfigPath = join(dir, ".crunes", "config.local.json");
|
|
89
|
+
const shared = JSON.parse(readFileSync(configPath, "utf8"));
|
|
90
|
+
validateConfig(shared, "config.json");
|
|
91
|
+
let local = {};
|
|
92
|
+
if (existsSync(localConfigPath)) {
|
|
93
|
+
try {
|
|
94
|
+
local = JSON.parse(readFileSync(localConfigPath, "utf8"));
|
|
95
|
+
} catch (err) {
|
|
96
|
+
throw new Error(`config.local.json is invalid JSON: ${err.message}`);
|
|
97
|
+
}
|
|
98
|
+
validateConfig(local, "config.local.json");
|
|
99
|
+
}
|
|
100
|
+
return mergeConfigs(shared, local);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export {
|
|
104
|
+
loadConfig
|
|
105
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_require_shim
|
|
3
|
+
} from "./chunk-TPK5AGRA.js";
|
|
4
|
+
|
|
5
|
+
// src/store/index.js
|
|
6
|
+
init_require_shim();
|
|
7
|
+
import fs from "node:fs/promises";
|
|
8
|
+
import os from "node:os";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
function getStorePath() {
|
|
11
|
+
return process.env.CRUNES_STORE ?? path.join(os.homedir(), ".crunes");
|
|
12
|
+
}
|
|
13
|
+
function getProjectsJsonPath() {
|
|
14
|
+
return path.join(getStorePath(), "projects.json");
|
|
15
|
+
}
|
|
16
|
+
function getPluginsJsonPath() {
|
|
17
|
+
return path.join(getStorePath(), "plugins.json");
|
|
18
|
+
}
|
|
19
|
+
function getPluginCacheDir(name, version, marketplace = "_local") {
|
|
20
|
+
return path.join(getStorePath(), "plugins", marketplace, name, version);
|
|
21
|
+
}
|
|
22
|
+
function getPnpmStorePath() {
|
|
23
|
+
return path.join(getStorePath(), "store");
|
|
24
|
+
}
|
|
25
|
+
function getMarketplacesJsonPath() {
|
|
26
|
+
return path.join(getStorePath(), "marketplaces.json");
|
|
27
|
+
}
|
|
28
|
+
function getMarketplaceCacheDir(name) {
|
|
29
|
+
return path.join(getStorePath(), "marketplaces", name);
|
|
30
|
+
}
|
|
31
|
+
function getCachesBasePath() {
|
|
32
|
+
return path.join(getStorePath(), "caches");
|
|
33
|
+
}
|
|
34
|
+
function getSqliteBasePath() {
|
|
35
|
+
return path.join(getStorePath(), "sqlite");
|
|
36
|
+
}
|
|
37
|
+
function getCacheJsonPath() {
|
|
38
|
+
return path.join(getStorePath(), "cache.json");
|
|
39
|
+
}
|
|
40
|
+
function getSqliteJsonPath() {
|
|
41
|
+
return path.join(getStorePath(), "sqlite.json");
|
|
42
|
+
}
|
|
43
|
+
async function ensureStoreDirs() {
|
|
44
|
+
const base = getStorePath();
|
|
45
|
+
await fs.mkdir(path.join(base, "plugins"), { recursive: true });
|
|
46
|
+
await fs.mkdir(path.join(base, "marketplaces"), { recursive: true });
|
|
47
|
+
await fs.mkdir(getPnpmStorePath(), { recursive: true });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export {
|
|
51
|
+
getStorePath,
|
|
52
|
+
getProjectsJsonPath,
|
|
53
|
+
getPluginsJsonPath,
|
|
54
|
+
getPluginCacheDir,
|
|
55
|
+
getPnpmStorePath,
|
|
56
|
+
getMarketplacesJsonPath,
|
|
57
|
+
getMarketplaceCacheDir,
|
|
58
|
+
getCachesBasePath,
|
|
59
|
+
getSqliteBasePath,
|
|
60
|
+
getCacheJsonPath,
|
|
61
|
+
getSqliteJsonPath,
|
|
62
|
+
ensureStoreDirs
|
|
63
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_require_shim
|
|
3
|
+
} from "./chunk-TPK5AGRA.js";
|
|
4
|
+
|
|
5
|
+
// src/docs/formatter.js
|
|
6
|
+
init_require_shim();
|
|
7
|
+
function formatCommands(commands, depth = 0) {
|
|
8
|
+
const lines = [];
|
|
9
|
+
const indent = " ".repeat(depth + 1);
|
|
10
|
+
const childIndent = " ".repeat(depth + 2);
|
|
11
|
+
const detailIndent = " ".repeat(depth + 3);
|
|
12
|
+
for (const cmd of commands) {
|
|
13
|
+
const posSpecs = (cmd.positionals ?? []).map((p) => p.spec).join(" ");
|
|
14
|
+
const cmdStr = `${cmd.name}${posSpecs ? " " + posSpecs : ""}`;
|
|
15
|
+
lines.push(`${indent}${cmdStr.padEnd(30 - depth * 2)} ${cmd.description ?? ""}`.trimEnd());
|
|
16
|
+
const cmdOpts = cmd.options ?? [];
|
|
17
|
+
if (cmdOpts.length > 0) {
|
|
18
|
+
lines.push(`${childIndent}Options:`);
|
|
19
|
+
for (const opt of cmdOpts) {
|
|
20
|
+
const defStr = opt.def !== void 0 ? ` [default: ${JSON.stringify(opt.def)}]` : "";
|
|
21
|
+
lines.push(`${detailIndent}${opt.flags.padEnd(26)} ${opt.description ?? ""}${defStr}`.trimEnd());
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const cmdExs = cmd.examples ?? [];
|
|
25
|
+
if (cmdExs.length > 0) {
|
|
26
|
+
lines.push(`${childIndent}Examples:`);
|
|
27
|
+
for (const ex of cmdExs) {
|
|
28
|
+
lines.push(`${detailIndent}${ex.usage}`);
|
|
29
|
+
if (ex.description) lines.push(`${detailIndent} ${ex.description}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const nestedCmds = cmd.commands ?? [];
|
|
33
|
+
if (nestedCmds.length > 0) {
|
|
34
|
+
lines.push(`${childIndent}Commands:`);
|
|
35
|
+
lines.push(...formatCommands(nestedCmds, depth + 2));
|
|
36
|
+
}
|
|
37
|
+
lines.push("");
|
|
38
|
+
}
|
|
39
|
+
return lines;
|
|
40
|
+
}
|
|
41
|
+
function formatHelp(schema, runeMeta) {
|
|
42
|
+
const lines = [];
|
|
43
|
+
const key = runeMeta?.key ?? "rune";
|
|
44
|
+
const desc = runeMeta?.description ?? runeMeta?.name;
|
|
45
|
+
if (runeMeta?.relativePath) {
|
|
46
|
+
lines.push(`File (project-relative): ${runeMeta.relativePath}`);
|
|
47
|
+
lines.push("");
|
|
48
|
+
}
|
|
49
|
+
const hasCommands = (schema?.commands ?? []).length > 0;
|
|
50
|
+
lines.push(`Usage: crunes run ${key} ${hasCommands ? "<command> " : ""}[options]`);
|
|
51
|
+
if (desc) {
|
|
52
|
+
lines.push("");
|
|
53
|
+
lines.push(` ${desc}`);
|
|
54
|
+
}
|
|
55
|
+
const positionals = schema?.positionals ?? [];
|
|
56
|
+
if (positionals.length > 0) {
|
|
57
|
+
lines.push("");
|
|
58
|
+
for (const p of positionals) {
|
|
59
|
+
lines.push(` ${(p.spec ?? "").padEnd(20)} ${p.description ?? ""}`.trimEnd());
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const options = schema?.options ?? [];
|
|
63
|
+
if (options.length > 0) {
|
|
64
|
+
lines.push("");
|
|
65
|
+
lines.push("Options:");
|
|
66
|
+
for (const opt of options) {
|
|
67
|
+
const defStr = opt.def !== void 0 ? ` [default: ${JSON.stringify(opt.def)}]` : "";
|
|
68
|
+
lines.push(` ${opt.flags.padEnd(30)} ${opt.description ?? ""}${defStr}`.trimEnd());
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const commands = schema?.commands ?? [];
|
|
72
|
+
if (commands.length > 0) {
|
|
73
|
+
lines.push("");
|
|
74
|
+
lines.push("Commands:");
|
|
75
|
+
const cmdLines = formatCommands(commands, 0);
|
|
76
|
+
lines.push(...cmdLines);
|
|
77
|
+
if (lines[lines.length - 1] === "") {
|
|
78
|
+
lines.pop();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const examples = schema?.examples ?? [];
|
|
82
|
+
if (examples.length > 0) {
|
|
83
|
+
lines.push("");
|
|
84
|
+
lines.push("Examples:");
|
|
85
|
+
for (const ex of examples) {
|
|
86
|
+
lines.push(` ${ex.usage}`);
|
|
87
|
+
if (ex.description) lines.push(` ${ex.description}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return lines.join("\n");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export {
|
|
94
|
+
formatHelp
|
|
95
|
+
};
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ensureStoreDirs,
|
|
3
|
+
getMarketplaceCacheDir,
|
|
4
|
+
getMarketplacesJsonPath
|
|
5
|
+
} from "./chunk-HMU2J25D.js";
|
|
6
|
+
import {
|
|
7
|
+
init_require_shim
|
|
8
|
+
} from "./chunk-TPK5AGRA.js";
|
|
9
|
+
|
|
10
|
+
// src/marketplace/marketplace.js
|
|
11
|
+
init_require_shim();
|
|
12
|
+
import fs from "node:fs/promises";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
import { execFile } from "node:child_process";
|
|
15
|
+
import { promisify } from "node:util";
|
|
16
|
+
import os from "node:os";
|
|
17
|
+
var execFileAsync = promisify(execFile);
|
|
18
|
+
var EMPTY_MARKETPLACES = { format: "1", marketplaces: {} };
|
|
19
|
+
async function loadMarketplaces() {
|
|
20
|
+
try {
|
|
21
|
+
const raw = await fs.readFile(getMarketplacesJsonPath(), "utf8");
|
|
22
|
+
return JSON.parse(raw);
|
|
23
|
+
} catch (err) {
|
|
24
|
+
if (err.code === "ENOENT") return structuredClone(EMPTY_MARKETPLACES);
|
|
25
|
+
throw err;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async function saveMarketplaces(data) {
|
|
29
|
+
const jsonPath = getMarketplacesJsonPath();
|
|
30
|
+
const tmp = jsonPath + ".tmp";
|
|
31
|
+
await fs.writeFile(tmp, JSON.stringify(data, null, 2), "utf8");
|
|
32
|
+
await fs.rename(tmp, jsonPath);
|
|
33
|
+
}
|
|
34
|
+
function classifyMarketplaceSource(source) {
|
|
35
|
+
if (source.startsWith("http://") || source.startsWith("https://")) {
|
|
36
|
+
return { type: "http", resolved: source };
|
|
37
|
+
}
|
|
38
|
+
if (source.startsWith("github:") || /^[\w-]+\/[\w.-]+$/.test(source)) {
|
|
39
|
+
return { type: "github", resolved: source.replace(/^github:/, "") };
|
|
40
|
+
}
|
|
41
|
+
if (source.startsWith("npm:")) {
|
|
42
|
+
return { type: "npm", resolved: source.replace(/^npm:/, "") };
|
|
43
|
+
}
|
|
44
|
+
if (isLocalPath(source)) {
|
|
45
|
+
return { type: "local", resolved: path.resolve(source) };
|
|
46
|
+
}
|
|
47
|
+
return { type: "npm", resolved: source };
|
|
48
|
+
}
|
|
49
|
+
function isLocalPath(source) {
|
|
50
|
+
return source.startsWith(".") || source.startsWith("/") || source.startsWith("~") || /^[A-Za-z]:[/\\]/.test(source);
|
|
51
|
+
}
|
|
52
|
+
async function downloadMarketplaceJson(classified) {
|
|
53
|
+
if (classified.type === "github") {
|
|
54
|
+
const url = `https://raw.githubusercontent.com/${classified.resolved}/HEAD/.crunes-plugin/marketplace.json`;
|
|
55
|
+
const res = await fetch(url, { headers: { "User-Agent": "crunes-cli" } });
|
|
56
|
+
if (!res.ok) throw new Error(`Failed to fetch marketplace from GitHub (${classified.resolved}): HTTP ${res.status}`);
|
|
57
|
+
return res.json();
|
|
58
|
+
}
|
|
59
|
+
if (classified.type === "http") {
|
|
60
|
+
const res = await fetch(classified.resolved, { headers: { "User-Agent": "crunes-cli" } });
|
|
61
|
+
if (!res.ok) throw new Error(`Failed to fetch marketplace: HTTP ${res.status}`);
|
|
62
|
+
return res.json();
|
|
63
|
+
}
|
|
64
|
+
if (classified.type === "npm") {
|
|
65
|
+
const tmp = path.join(os.tmpdir(), `crunes-marketplace-${Date.now()}`);
|
|
66
|
+
await fs.mkdir(tmp, { recursive: true });
|
|
67
|
+
try {
|
|
68
|
+
await execFileAsync("npm", ["pack", classified.resolved, "--pack-destination", tmp], { shell: process.platform === "win32" });
|
|
69
|
+
const files = await fs.readdir(tmp);
|
|
70
|
+
const tarball = files.find((f) => f.endsWith(".tgz"));
|
|
71
|
+
if (!tarball) throw new Error(`npm pack produced no tarball for ${classified.resolved}`);
|
|
72
|
+
const extractDir = path.join(tmp, "extracted");
|
|
73
|
+
await fs.mkdir(extractDir, { recursive: true });
|
|
74
|
+
await execFileAsync("tar", ["-xzf", path.join(tmp, tarball), "-C", extractDir, "--strip-components=1"], { shell: process.platform === "win32" });
|
|
75
|
+
const raw = await fs.readFile(path.join(extractDir, ".crunes-plugin", "marketplace.json"), "utf8");
|
|
76
|
+
return JSON.parse(raw);
|
|
77
|
+
} finally {
|
|
78
|
+
await fs.rm(tmp, { recursive: true, force: true }).catch(() => {
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
throw new Error(`Unsupported marketplace source type: ${classified.type}`);
|
|
83
|
+
}
|
|
84
|
+
async function readLocalMarketplace(resolvedPath) {
|
|
85
|
+
const stat = await fs.stat(resolvedPath);
|
|
86
|
+
const jsonPath = stat.isDirectory() ? path.join(resolvedPath, ".crunes-plugin", "marketplace.json") : resolvedPath;
|
|
87
|
+
const data = JSON.parse(await fs.readFile(jsonPath, "utf8"));
|
|
88
|
+
const resolvedDir = path.dirname(jsonPath);
|
|
89
|
+
const resolutionBase = path.basename(resolvedDir) === ".crunes-plugin" ? path.dirname(resolvedDir) : resolvedDir;
|
|
90
|
+
return { data, resolvedPath: resolutionBase };
|
|
91
|
+
}
|
|
92
|
+
async function fetchMarketplace(name, entry) {
|
|
93
|
+
const classified = classifyMarketplaceSource(entry.source);
|
|
94
|
+
if (classified.type === "local") {
|
|
95
|
+
return readLocalMarketplace(classified.resolved);
|
|
96
|
+
}
|
|
97
|
+
if (classified.type === "http") {
|
|
98
|
+
const res = await fetch(classified.resolved, { headers: { "User-Agent": "crunes-cli" } });
|
|
99
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
100
|
+
return { data: await res.json(), resolvedPath: classified.resolved };
|
|
101
|
+
}
|
|
102
|
+
const cacheDir = getMarketplaceCacheDir(name);
|
|
103
|
+
try {
|
|
104
|
+
const data = JSON.parse(await fs.readFile(path.join(cacheDir, "marketplace.json"), "utf8"));
|
|
105
|
+
return { data, resolvedPath: cacheDir };
|
|
106
|
+
} catch (err) {
|
|
107
|
+
if (err.code === "ENOENT") throw new Error(`Marketplace "${name}" not cached. Run: crunes marketplace update ${name}`);
|
|
108
|
+
throw err;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async function cacheMarketplace(source, classified) {
|
|
112
|
+
const json = await downloadMarketplaceJson(classified);
|
|
113
|
+
if (!json.name) throw new Error(`marketplace.json from "${source}" is missing a "name" field`);
|
|
114
|
+
const cacheDir = getMarketplaceCacheDir(json.name);
|
|
115
|
+
await fs.mkdir(cacheDir, { recursive: true });
|
|
116
|
+
await fs.writeFile(path.join(cacheDir, "marketplace.json"), JSON.stringify(json, null, 2), "utf8");
|
|
117
|
+
return json.name;
|
|
118
|
+
}
|
|
119
|
+
async function addMarketplace(source) {
|
|
120
|
+
await ensureStoreDirs();
|
|
121
|
+
const normalised = isLocalPath(source) ? path.resolve(source) : source;
|
|
122
|
+
const classified = classifyMarketplaceSource(normalised);
|
|
123
|
+
let name;
|
|
124
|
+
if (classified.type === "local") {
|
|
125
|
+
const { data: data2 } = await readLocalMarketplace(classified.resolved);
|
|
126
|
+
if (!data2.name) throw new Error(`marketplace.json at "${normalised}" is missing a "name" field`);
|
|
127
|
+
name = data2.name;
|
|
128
|
+
} else {
|
|
129
|
+
name = await cacheMarketplace(normalised, classified);
|
|
130
|
+
}
|
|
131
|
+
const data = await loadMarketplaces();
|
|
132
|
+
if (data.marketplaces[name]) throw new Error(`Marketplace "${name}" is already configured.`);
|
|
133
|
+
data.marketplaces[name] = { source: normalised };
|
|
134
|
+
await saveMarketplaces(data);
|
|
135
|
+
return name;
|
|
136
|
+
}
|
|
137
|
+
async function removeMarketplace(name) {
|
|
138
|
+
const data = await loadMarketplaces();
|
|
139
|
+
if (!data.marketplaces[name]) throw new Error(`Marketplace "${name}" is not configured.`);
|
|
140
|
+
delete data.marketplaces[name];
|
|
141
|
+
await saveMarketplaces(data);
|
|
142
|
+
await fs.rm(getMarketplaceCacheDir(name), { recursive: true, force: true }).catch(() => {
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
async function updateMarketplace(name) {
|
|
146
|
+
const data = await loadMarketplaces();
|
|
147
|
+
if (!data.marketplaces[name]) throw new Error(`Marketplace "${name}" is not configured.`);
|
|
148
|
+
const entry = data.marketplaces[name];
|
|
149
|
+
const classified = classifyMarketplaceSource(entry.source);
|
|
150
|
+
if (classified.type === "local" || classified.type === "http") return;
|
|
151
|
+
const newName = await cacheMarketplace(entry.source, classified);
|
|
152
|
+
if (newName !== name) {
|
|
153
|
+
await fs.rm(getMarketplaceCacheDir(name), { recursive: true, force: true }).catch(() => {
|
|
154
|
+
});
|
|
155
|
+
delete data.marketplaces[name];
|
|
156
|
+
data.marketplaces[newName] = { source: entry.source };
|
|
157
|
+
await saveMarketplaces(data);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async function listMarketplaces() {
|
|
161
|
+
const data = await loadMarketplaces();
|
|
162
|
+
return Object.entries(data.marketplaces).map(([name, entry]) => ({ name, ...entry }));
|
|
163
|
+
}
|
|
164
|
+
async function searchMarketplaces(query) {
|
|
165
|
+
const data = await loadMarketplaces();
|
|
166
|
+
const entries = Object.entries(data.marketplaces);
|
|
167
|
+
if (entries.length === 0) return [];
|
|
168
|
+
const results = [];
|
|
169
|
+
const lowerQuery = query.toLowerCase();
|
|
170
|
+
await Promise.allSettled(
|
|
171
|
+
entries.map(async ([name, entry]) => {
|
|
172
|
+
try {
|
|
173
|
+
const { data: marketplace } = await fetchMarketplace(name, entry);
|
|
174
|
+
for (const plugin of marketplace.plugins ?? []) {
|
|
175
|
+
const searchable = `${plugin.name} ${plugin.description ?? ""}`.toLowerCase();
|
|
176
|
+
if (searchable.includes(lowerQuery)) {
|
|
177
|
+
results.push({ ...plugin, _marketplace: name });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
} catch (err) {
|
|
181
|
+
console.error(`Warning: could not load marketplace "${name}": ${err.message}`);
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
);
|
|
185
|
+
return results;
|
|
186
|
+
}
|
|
187
|
+
async function resolveFromMarketplace(marketplaceName, pluginName) {
|
|
188
|
+
const data = await loadMarketplaces();
|
|
189
|
+
if (Object.keys(data.marketplaces).length === 0) {
|
|
190
|
+
throw new Error("No marketplaces configured. Run: crunes marketplace add <source>");
|
|
191
|
+
}
|
|
192
|
+
const entry = data.marketplaces[marketplaceName];
|
|
193
|
+
if (!entry) throw new Error(`Marketplace "${marketplaceName}" is not configured. Run: crunes marketplace list`);
|
|
194
|
+
const { data: marketplace, resolvedPath } = await fetchMarketplace(marketplaceName, entry);
|
|
195
|
+
const plugin = (marketplace.plugins ?? []).find((p) => p.name === pluginName);
|
|
196
|
+
if (!plugin) {
|
|
197
|
+
throw new Error(`Plugin "${pluginName}" not found in marketplace "${marketplaceName}". Run: crunes marketplace search <query>`);
|
|
198
|
+
}
|
|
199
|
+
const resolvedSource = resolvePluginSource(plugin.source, resolvedPath);
|
|
200
|
+
return {
|
|
201
|
+
resolvedSource,
|
|
202
|
+
marketplaceName,
|
|
203
|
+
pluginName,
|
|
204
|
+
version: plugin.version,
|
|
205
|
+
description: plugin.description,
|
|
206
|
+
author: plugin.author,
|
|
207
|
+
license: plugin.license
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function resolvePluginSource(source, marketplaceResolvedPath) {
|
|
211
|
+
if (!isLocalPath(source)) return source;
|
|
212
|
+
if (marketplaceResolvedPath.startsWith("http://") || marketplaceResolvedPath.startsWith("https://")) {
|
|
213
|
+
return new URL(source, marketplaceResolvedPath).href;
|
|
214
|
+
}
|
|
215
|
+
return path.resolve(marketplaceResolvedPath, source);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export {
|
|
219
|
+
addMarketplace,
|
|
220
|
+
removeMarketplace,
|
|
221
|
+
updateMarketplace,
|
|
222
|
+
listMarketplaces,
|
|
223
|
+
searchMarketplaces,
|
|
224
|
+
resolveFromMarketplace
|
|
225
|
+
};
|