@vlandoss/clibuddy 0.6.0 → 0.6.1-git-e775e2a.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/package.json +8 -3
- package/dist/index.d.mts +0 -98
- package/dist/index.mjs +0 -228
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vlandoss/clibuddy",
|
|
3
|
-
"version": "0.6.0",
|
|
3
|
+
"version": "0.6.1-git-e775e2a.0",
|
|
4
4
|
"description": "A helper library to create CLIs in Variable Land",
|
|
5
5
|
"homepage": "https://github.com/variableland/dx/tree/main/packages/clibuddy#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -12,7 +12,10 @@
|
|
|
12
12
|
"directory": "packages/clibuddy"
|
|
13
13
|
},
|
|
14
14
|
"license": "MIT",
|
|
15
|
-
"author":
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "rcrd",
|
|
17
|
+
"email": "rcrd@variable.land"
|
|
18
|
+
},
|
|
16
19
|
"type": "module",
|
|
17
20
|
"exports": {
|
|
18
21
|
".": {
|
|
@@ -45,8 +48,10 @@
|
|
|
45
48
|
"devDependencies": {
|
|
46
49
|
"@vlandoss/tsdown-config": "^0.0.1"
|
|
47
50
|
},
|
|
51
|
+
"readme": "ERROR: No README data found!",
|
|
52
|
+
"_id": "@vlandoss/clibuddy@0.6.0",
|
|
48
53
|
"scripts": {
|
|
49
54
|
"build": "tsdown",
|
|
50
55
|
"test:types": "rr tsc"
|
|
51
56
|
}
|
|
52
|
-
}
|
|
57
|
+
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import * as _$ansis from "ansis";
|
|
2
|
-
import { hasTTY, isCI } from "std-env";
|
|
3
|
-
import { PackageJson } from "pkg-types";
|
|
4
|
-
import { NonZeroExitError, Output } from "tinyexec";
|
|
5
|
-
import { Project } from "@pnpm/types";
|
|
6
|
-
|
|
7
|
-
//#region src/colors.d.ts
|
|
8
|
-
declare const colorize: (hex: string) => _$ansis.Ansis;
|
|
9
|
-
declare const palette: {
|
|
10
|
-
bold: _$ansis.Ansis;
|
|
11
|
-
italic: _$ansis.Ansis;
|
|
12
|
-
link: _$ansis.Ansis;
|
|
13
|
-
muted: _$ansis.Ansis;
|
|
14
|
-
primary: _$ansis.Ansis;
|
|
15
|
-
dim: _$ansis.Ansis;
|
|
16
|
-
highlight: _$ansis.Ansis;
|
|
17
|
-
success: _$ansis.Ansis;
|
|
18
|
-
label: (s: string) => string;
|
|
19
|
-
};
|
|
20
|
-
//#endregion
|
|
21
|
-
//#region src/meta.d.ts
|
|
22
|
-
declare function dirnameOf(meta: ImportMeta): string;
|
|
23
|
-
declare function filenameOf(meta: ImportMeta): string;
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region src/pkg.d.ts
|
|
26
|
-
declare class Pkg {
|
|
27
|
-
#private;
|
|
28
|
-
get dirPath(): string;
|
|
29
|
-
get pkgPath(): string;
|
|
30
|
-
get packageJson(): PackageJson;
|
|
31
|
-
get version(): string;
|
|
32
|
-
constructor(packageJson: PackageJson, pkgPath: string);
|
|
33
|
-
info(): {
|
|
34
|
-
packageJson: PackageJson;
|
|
35
|
-
dirPath: string;
|
|
36
|
-
};
|
|
37
|
-
hasFile(name: string, dir?: string): boolean;
|
|
38
|
-
isMonorepo(): boolean;
|
|
39
|
-
getWorkspaceProjects(): Promise<Project[]>;
|
|
40
|
-
write(packageJson: PackageJson): Promise<void>;
|
|
41
|
-
}
|
|
42
|
-
declare function createPkg(cwd: string): Promise<Pkg | null>;
|
|
43
|
-
//#endregion
|
|
44
|
-
//#region src/run.d.ts
|
|
45
|
-
declare function run(fn: () => Promise<void>, logger: {
|
|
46
|
-
error: (...args: unknown[]) => void;
|
|
47
|
-
}): Promise<void>;
|
|
48
|
-
//#endregion
|
|
49
|
-
//#region src/shell/types.d.ts
|
|
50
|
-
type ShellOptions = {
|
|
51
|
-
cwd?: string;
|
|
52
|
-
env?: NodeJS.ProcessEnv;
|
|
53
|
-
verbose?: boolean;
|
|
54
|
-
};
|
|
55
|
-
type RunOptions = ShellOptions & {
|
|
56
|
-
throwOnError?: boolean;
|
|
57
|
-
shell?: boolean;
|
|
58
|
-
stdin?: string;
|
|
59
|
-
display?: string;
|
|
60
|
-
};
|
|
61
|
-
//#endregion
|
|
62
|
-
//#region src/shell/shell.d.ts
|
|
63
|
-
declare class ShellService {
|
|
64
|
-
#private;
|
|
65
|
-
constructor(options?: ShellOptions);
|
|
66
|
-
get options(): ShellOptions;
|
|
67
|
-
at(cwd: string): ShellService;
|
|
68
|
-
child(options: ShellOptions): ShellService;
|
|
69
|
-
quiet(): ShellService;
|
|
70
|
-
run(cmd: string, args?: string[], opts?: RunOptions): Promise<Output>;
|
|
71
|
-
runCaptured(cmd: string, args?: string[], opts?: RunOptions): Promise<Output>;
|
|
72
|
-
}
|
|
73
|
-
//#endregion
|
|
74
|
-
//#region src/shell/create.d.ts
|
|
75
|
-
declare const cwd: string;
|
|
76
|
-
declare function createShellService(options?: ShellOptions): ShellService;
|
|
77
|
-
//#endregion
|
|
78
|
-
//#region src/shell/resolve-package-bin.d.ts
|
|
79
|
-
type Options = {
|
|
80
|
-
from: string;
|
|
81
|
-
binName?: string;
|
|
82
|
-
};
|
|
83
|
-
declare function _resolvePackageBin(pkg: string, {
|
|
84
|
-
from,
|
|
85
|
-
binName
|
|
86
|
-
}: Options): Promise<string>;
|
|
87
|
-
declare const resolvePackageBin: typeof _resolvePackageBin;
|
|
88
|
-
//#endregion
|
|
89
|
-
//#region src/shell/utils.d.ts
|
|
90
|
-
declare function isNonZeroExitError(value: unknown): value is NonZeroExitError;
|
|
91
|
-
//#endregion
|
|
92
|
-
//#region src/text.d.ts
|
|
93
|
-
declare const text: {
|
|
94
|
-
vland: string;
|
|
95
|
-
version: (version: string) => string;
|
|
96
|
-
};
|
|
97
|
-
//#endregion
|
|
98
|
-
export { NonZeroExitError, Pkg, type Project, RunOptions, ShellOptions, ShellService, colorize, createPkg, createShellService, cwd, dirnameOf, filenameOf, hasTTY, isCI, isNonZeroExitError, palette, resolvePackageBin, run, text };
|
package/dist/index.mjs
DELETED
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
import ansis, { bold, cyan, dim, green, italic, underline } from "ansis";
|
|
3
|
-
import { hasTTY, isCI } from "std-env";
|
|
4
|
-
import path, { dirname } from "node:path";
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
6
|
-
import fs, { existsSync } from "node:fs";
|
|
7
|
-
import { readFile } from "node:fs/promises";
|
|
8
|
-
import { findPackages } from "@pnpm/fs.find-packages";
|
|
9
|
-
import { readPackageJSON, resolvePackageJSON, writePackageJSON } from "pkg-types";
|
|
10
|
-
import { parse } from "yaml";
|
|
11
|
-
import { NonZeroExitError, x } from "tinyexec";
|
|
12
|
-
import memoize from "memoize";
|
|
13
|
-
//#region src/colors.ts
|
|
14
|
-
const colorize = (hex) => ansis.hex(hex);
|
|
15
|
-
const palette = {
|
|
16
|
-
bold,
|
|
17
|
-
italic,
|
|
18
|
-
link: underline,
|
|
19
|
-
muted: ansis.hex("#a8afb5"),
|
|
20
|
-
primary: ansis.hex("#36d399"),
|
|
21
|
-
dim,
|
|
22
|
-
highlight: cyan,
|
|
23
|
-
success: green,
|
|
24
|
-
label: (s) => ansis.bgMagenta.black(s)
|
|
25
|
-
};
|
|
26
|
-
//#endregion
|
|
27
|
-
//#region src/meta.ts
|
|
28
|
-
function dirnameOf(meta) {
|
|
29
|
-
return meta.dirname ?? dirname(fileURLToPath(meta.url));
|
|
30
|
-
}
|
|
31
|
-
function filenameOf(meta) {
|
|
32
|
-
return meta.filename ?? fileURLToPath(meta.url);
|
|
33
|
-
}
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region src/pkg.ts
|
|
36
|
-
var Pkg = class {
|
|
37
|
-
#packageJson;
|
|
38
|
-
#dirPath;
|
|
39
|
-
#pkgPath;
|
|
40
|
-
get dirPath() {
|
|
41
|
-
return this.#dirPath;
|
|
42
|
-
}
|
|
43
|
-
get pkgPath() {
|
|
44
|
-
return this.#pkgPath;
|
|
45
|
-
}
|
|
46
|
-
get packageJson() {
|
|
47
|
-
return this.#packageJson;
|
|
48
|
-
}
|
|
49
|
-
get version() {
|
|
50
|
-
return process.env.VERSION || this.#packageJson.version || "0.0.0";
|
|
51
|
-
}
|
|
52
|
-
constructor(packageJson, pkgPath) {
|
|
53
|
-
this.#packageJson = packageJson;
|
|
54
|
-
this.#pkgPath = pkgPath;
|
|
55
|
-
this.#dirPath = path.dirname(pkgPath);
|
|
56
|
-
}
|
|
57
|
-
info() {
|
|
58
|
-
return {
|
|
59
|
-
packageJson: this.#packageJson,
|
|
60
|
-
dirPath: this.#dirPath
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
hasFile(name, dir) {
|
|
64
|
-
return existsSync(dir ? path.join(dir, name) : this.#fromPkgDir(name));
|
|
65
|
-
}
|
|
66
|
-
isMonorepo() {
|
|
67
|
-
return !!this.#packageJson.workspaces || this.#hasPnpmWorkspace();
|
|
68
|
-
}
|
|
69
|
-
async getWorkspaceProjects() {
|
|
70
|
-
let patterns;
|
|
71
|
-
if (this.#hasPnpmWorkspace()) patterns = (await this.#readPnpmWorkspaceManifest()).packages;
|
|
72
|
-
else patterns = Array.isArray(this.#packageJson.workspaces) ? this.#packageJson.workspaces : this.#packageJson.workspaces?.packages ?? [];
|
|
73
|
-
if (!Array.isArray(patterns) || patterns.some((p) => typeof p !== "string")) throw new Error("Invalid workspace patterns");
|
|
74
|
-
const projects = await findPackages(this.#dirPath, { patterns });
|
|
75
|
-
const excludeRoot = (projects) => {
|
|
76
|
-
return projects.filter((project) => project.rootDir !== this.#dirPath);
|
|
77
|
-
};
|
|
78
|
-
return excludeRoot(projects);
|
|
79
|
-
}
|
|
80
|
-
async write(packageJson) {
|
|
81
|
-
await writePackageJSON(this.#pkgPath, packageJson);
|
|
82
|
-
}
|
|
83
|
-
#hasPnpmWorkspace() {
|
|
84
|
-
return this.hasFile("pnpm-workspace.yaml");
|
|
85
|
-
}
|
|
86
|
-
async #readPnpmWorkspaceManifest() {
|
|
87
|
-
const manifest = parse(await readFile(this.#fromPkgDir("pnpm-workspace.yaml"), "utf-8"));
|
|
88
|
-
if (!manifest) throw new Error("Can't read pnpm workspace manifest");
|
|
89
|
-
return manifest;
|
|
90
|
-
}
|
|
91
|
-
#fromPkgDir(...args) {
|
|
92
|
-
return path.join(this.#dirPath, ...args);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
async function createPkg(cwd) {
|
|
96
|
-
let pkgPath;
|
|
97
|
-
try {
|
|
98
|
-
pkgPath = await resolvePackageJSON(cwd);
|
|
99
|
-
} catch {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
return new Pkg(await readPackageJSON(pkgPath), pkgPath);
|
|
103
|
-
}
|
|
104
|
-
//#endregion
|
|
105
|
-
//#region src/shell/utils.ts
|
|
106
|
-
function isNonZeroExitError(value) {
|
|
107
|
-
return value instanceof NonZeroExitError;
|
|
108
|
-
}
|
|
109
|
-
//#endregion
|
|
110
|
-
//#region src/run.ts
|
|
111
|
-
function hasMessage(error) {
|
|
112
|
-
return typeof error === "object" && error !== null && "message" in error && typeof error.message === "string";
|
|
113
|
-
}
|
|
114
|
-
function formatError(error) {
|
|
115
|
-
if (hasMessage(error)) return error.message;
|
|
116
|
-
return String(error);
|
|
117
|
-
}
|
|
118
|
-
async function run(fn, logger) {
|
|
119
|
-
try {
|
|
120
|
-
await fn();
|
|
121
|
-
} catch (error) {
|
|
122
|
-
if (!isNonZeroExitError(error)) logger.error(formatError(error));
|
|
123
|
-
process.exit(1);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
//#endregion
|
|
127
|
-
//#region src/shell/shell.ts
|
|
128
|
-
var ShellService = class ShellService {
|
|
129
|
-
#options;
|
|
130
|
-
constructor(options = {}) {
|
|
131
|
-
this.#options = Object.freeze({
|
|
132
|
-
cwd: options.cwd ?? process.cwd(),
|
|
133
|
-
env: options.env,
|
|
134
|
-
verbose: options.verbose ?? true
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
get options() {
|
|
138
|
-
return this.#options;
|
|
139
|
-
}
|
|
140
|
-
at(cwd) {
|
|
141
|
-
return this.child({ cwd });
|
|
142
|
-
}
|
|
143
|
-
child(options) {
|
|
144
|
-
return new ShellService({
|
|
145
|
-
...this.#options,
|
|
146
|
-
...options,
|
|
147
|
-
env: options.env ? {
|
|
148
|
-
...this.#options.env,
|
|
149
|
-
...options.env
|
|
150
|
-
} : this.#options.env
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
quiet() {
|
|
154
|
-
return this.child({ verbose: false });
|
|
155
|
-
}
|
|
156
|
-
async run(cmd, args = [], opts = {}) {
|
|
157
|
-
const merged = this.#mergeRunOpts(opts);
|
|
158
|
-
if (merged.verbose) printCmdLine(opts.display ?? cmd, args);
|
|
159
|
-
return x(cmd, args, {
|
|
160
|
-
throwOnError: opts.throwOnError ?? true,
|
|
161
|
-
...opts.stdin !== void 0 && { stdin: opts.stdin },
|
|
162
|
-
nodeOptions: {
|
|
163
|
-
cwd: merged.cwd,
|
|
164
|
-
...merged.env && { env: merged.env },
|
|
165
|
-
stdio: "inherit",
|
|
166
|
-
...opts.shell && { shell: true }
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
async runCaptured(cmd, args = [], opts = {}) {
|
|
171
|
-
const merged = this.#mergeRunOpts(opts);
|
|
172
|
-
return x(cmd, args, {
|
|
173
|
-
throwOnError: opts.throwOnError ?? true,
|
|
174
|
-
...opts.stdin !== void 0 && { stdin: opts.stdin },
|
|
175
|
-
nodeOptions: {
|
|
176
|
-
cwd: merged.cwd,
|
|
177
|
-
...merged.env && { env: merged.env },
|
|
178
|
-
...opts.shell && { shell: true }
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
#mergeRunOpts(opts) {
|
|
183
|
-
return {
|
|
184
|
-
cwd: opts.cwd ?? this.#options.cwd ?? process.cwd(),
|
|
185
|
-
env: opts.env ? {
|
|
186
|
-
...this.#options.env,
|
|
187
|
-
...opts.env
|
|
188
|
-
} : this.#options.env,
|
|
189
|
-
verbose: opts.verbose ?? this.#options.verbose ?? true
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
function printCmdLine(cmd, args) {
|
|
194
|
-
const tail = args.length === 0 ? "" : ` ${args.join(" ")}`;
|
|
195
|
-
process.stderr.write(`${palette.muted("$")} ${palette.highlight(cmd)}${tail}\n`);
|
|
196
|
-
}
|
|
197
|
-
//#endregion
|
|
198
|
-
//#region src/shell/create.ts
|
|
199
|
-
const cwd = fs.realpathSync(process.cwd());
|
|
200
|
-
function createShellService(options = {}) {
|
|
201
|
-
return new ShellService({
|
|
202
|
-
cwd,
|
|
203
|
-
...options
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
//#endregion
|
|
207
|
-
//#region src/shell/resolve-package-bin.ts
|
|
208
|
-
async function _resolvePackageBin(pkg, { from, binName }) {
|
|
209
|
-
let pkgJsonPath;
|
|
210
|
-
try {
|
|
211
|
-
pkgJsonPath = await resolvePackageJSON(pkg, { from });
|
|
212
|
-
} catch {
|
|
213
|
-
pkgJsonPath = createRequire(from).resolve(`${pkg}/package.json`);
|
|
214
|
-
}
|
|
215
|
-
const { bin } = await readPackageJSON(pkgJsonPath);
|
|
216
|
-
const rel = typeof bin === "string" ? bin : bin?.[binName ?? pkg.replace(/^@[^/]+\//, "")];
|
|
217
|
-
if (!rel) throw new Error(`No bin "${binName ?? pkg}" in ${pkg}`);
|
|
218
|
-
return path.join(path.dirname(pkgJsonPath), rel);
|
|
219
|
-
}
|
|
220
|
-
const resolvePackageBin = memoize(_resolvePackageBin, { cacheKey: ([pkg, opts]) => `${pkg}|${opts.from}|${opts.binName ?? ""}` });
|
|
221
|
-
//#endregion
|
|
222
|
-
//#region src/text.ts
|
|
223
|
-
const text = {
|
|
224
|
-
vland: `${palette.link(palette.primary("https://variable.land"))} 👊`,
|
|
225
|
-
version: (version) => palette.muted(`v${version}`)
|
|
226
|
-
};
|
|
227
|
-
//#endregion
|
|
228
|
-
export { NonZeroExitError, Pkg, ShellService, colorize, createPkg, createShellService, cwd, dirnameOf, filenameOf, hasTTY, isCI, isNonZeroExitError, palette, resolvePackageBin, run, text };
|