incur 0.3.4 → 0.3.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/README.md +62 -1
- package/dist/Cli.d.ts +17 -7
- package/dist/Cli.d.ts.map +1 -1
- package/dist/Cli.js +435 -365
- package/dist/Cli.js.map +1 -1
- package/dist/Completions.d.ts +1 -2
- package/dist/Completions.d.ts.map +1 -1
- package/dist/Completions.js.map +1 -1
- package/dist/Filter.js +0 -18
- package/dist/Filter.js.map +1 -1
- package/dist/Help.d.ts +6 -0
- package/dist/Help.d.ts.map +1 -1
- package/dist/Help.js +35 -22
- package/dist/Help.js.map +1 -1
- package/dist/Mcp.d.ts +25 -5
- package/dist/Mcp.d.ts.map +1 -1
- package/dist/Mcp.js +61 -69
- package/dist/Mcp.js.map +1 -1
- package/dist/Parser.d.ts +2 -0
- package/dist/Parser.d.ts.map +1 -1
- package/dist/Parser.js +69 -37
- package/dist/Parser.js.map +1 -1
- package/dist/Skill.d.ts.map +1 -1
- package/dist/Skill.js +5 -1
- package/dist/Skill.js.map +1 -1
- package/dist/SyncSkills.d.ts.map +1 -1
- package/dist/SyncSkills.js +10 -1
- package/dist/SyncSkills.js.map +1 -1
- package/dist/bin.d.ts +1 -0
- package/dist/bin.d.ts.map +1 -1
- package/dist/bin.js +17 -2
- package/dist/bin.js.map +1 -1
- package/dist/internal/command.d.ts +118 -0
- package/dist/internal/command.d.ts.map +1 -0
- package/dist/internal/command.js +276 -0
- package/dist/internal/command.js.map +1 -0
- package/dist/internal/configSchema.d.ts +8 -0
- package/dist/internal/configSchema.d.ts.map +1 -0
- package/dist/internal/configSchema.js +57 -0
- package/dist/internal/configSchema.js.map +1 -0
- package/dist/internal/helpers.d.ts +5 -0
- package/dist/internal/helpers.d.ts.map +1 -0
- package/dist/internal/helpers.js +9 -0
- package/dist/internal/helpers.js.map +1 -0
- package/examples/npm/.npmrc.json +21 -0
- package/examples/npm/config.schema.json +137 -0
- package/package.json +1 -1
- package/src/Cli.test-d.ts +39 -0
- package/src/Cli.test.ts +704 -6
- package/src/Cli.ts +551 -448
- package/src/Completions.test.ts +35 -9
- package/src/Completions.ts +1 -2
- package/src/Filter.ts +0 -17
- package/src/Help.test.ts +77 -0
- package/src/Help.ts +39 -21
- package/src/Mcp.test.ts +143 -0
- package/src/Mcp.ts +92 -84
- package/src/Parser.test-d.ts +22 -0
- package/src/Parser.test.ts +89 -0
- package/src/Parser.ts +86 -35
- package/src/Skill.ts +5 -1
- package/src/SyncSkills.ts +11 -1
- package/src/bin.ts +21 -2
- package/src/e2e.test.ts +30 -17
- package/src/internal/command.ts +428 -0
- package/src/internal/configSchema.test.ts +193 -0
- package/src/internal/configSchema.ts +66 -0
- package/src/internal/helpers.ts +9 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import * as Cli from '../Cli.js';
|
|
3
|
+
import * as Schema from '../Schema.js';
|
|
4
|
+
import { importCli } from './utils.js';
|
|
5
|
+
/** Returns `true` if the CLI has `config` enabled on `Cli.create()`. */
|
|
6
|
+
export function hasConfig(cli) {
|
|
7
|
+
return Cli.toConfigEnabled.get(cli) === true;
|
|
8
|
+
}
|
|
9
|
+
/** Imports a CLI from `input` (must `export default` a `Cli`), generates the JSON Schema, and writes it to `output`. */
|
|
10
|
+
export async function generate(input, output) {
|
|
11
|
+
const cli = await importCli(input);
|
|
12
|
+
await fs.writeFile(output, JSON.stringify(fromCli(cli), null, 2) + '\n');
|
|
13
|
+
}
|
|
14
|
+
/** Generates a JSON Schema describing the config file structure for a CLI. */
|
|
15
|
+
export function fromCli(cli) {
|
|
16
|
+
const commands = Cli.toCommands.get(cli);
|
|
17
|
+
if (!commands)
|
|
18
|
+
return { type: 'object' };
|
|
19
|
+
const rootOptions = Cli.toRootOptions.get(cli);
|
|
20
|
+
const node = buildNode(commands, rootOptions);
|
|
21
|
+
const properties = (node.properties ?? {});
|
|
22
|
+
properties.$schema = { type: 'string' };
|
|
23
|
+
node.properties = properties;
|
|
24
|
+
return node;
|
|
25
|
+
}
|
|
26
|
+
/** Builds a JSON Schema node for a command level. */
|
|
27
|
+
function buildNode(commands, options) {
|
|
28
|
+
const properties = {};
|
|
29
|
+
// Add `options` property from the options schema
|
|
30
|
+
if (options) {
|
|
31
|
+
const optSchema = Schema.toJsonSchema(options);
|
|
32
|
+
const props = optSchema.properties;
|
|
33
|
+
if (props && Object.keys(props).length > 0)
|
|
34
|
+
properties.options = { type: 'object', additionalProperties: false, properties: props };
|
|
35
|
+
}
|
|
36
|
+
// Add `commands` property with subcommand namespaces
|
|
37
|
+
const commandProps = {};
|
|
38
|
+
for (const [name, entry] of commands) {
|
|
39
|
+
if ('_group' in entry && entry._group) {
|
|
40
|
+
commandProps[name] = buildNode(entry.commands, undefined);
|
|
41
|
+
}
|
|
42
|
+
else if (!('_fetch' in entry)) {
|
|
43
|
+
const cmd = entry;
|
|
44
|
+
commandProps[name] = buildNode(new Map(), cmd.options);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (Object.keys(commandProps).length > 0)
|
|
48
|
+
properties.commands = { type: 'object', additionalProperties: false, properties: commandProps };
|
|
49
|
+
const node = {
|
|
50
|
+
type: 'object',
|
|
51
|
+
additionalProperties: false,
|
|
52
|
+
};
|
|
53
|
+
if (Object.keys(properties).length > 0)
|
|
54
|
+
node.properties = properties;
|
|
55
|
+
return node;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=configSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configSchema.js","sourceRoot":"","sources":["../../src/internal/configSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAGjC,OAAO,KAAK,GAAG,MAAM,WAAW,CAAA;AAChC,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtC,wEAAwE;AACxE,MAAM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a plain object record. */
|
|
2
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
3
|
+
/** Converts a camelCase string to kebab-case. */
|
|
4
|
+
export declare function toKebab(value: string): string;
|
|
5
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/internal/helpers.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE;AAED,iDAAiD;AACjD,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Checks whether a value is a plain object record. */
|
|
2
|
+
export function isRecord(value) {
|
|
3
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
/** Converts a camelCase string to kebab-case. */
|
|
6
|
+
export function toKebab(value) {
|
|
7
|
+
return value.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/internal/helpers.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC7E,CAAC;AAED,iDAAiD;AACjD,MAAM,UAAU,OAAO,CAAC,KAAa;IACnC,OAAO,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;AAC9D,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./config.schema.json",
|
|
3
|
+
"commands": {
|
|
4
|
+
"install": {
|
|
5
|
+
"options": {
|
|
6
|
+
"saveExact": true
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"publish": {
|
|
10
|
+
"options": {
|
|
11
|
+
"access": "public",
|
|
12
|
+
"tag": "latest"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"outdated": {
|
|
16
|
+
"options": {
|
|
17
|
+
"long": true
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "object",
|
|
3
|
+
"additionalProperties": false,
|
|
4
|
+
"properties": {
|
|
5
|
+
"$schema": {
|
|
6
|
+
"type": "string"
|
|
7
|
+
},
|
|
8
|
+
"commands": {
|
|
9
|
+
"type": "object",
|
|
10
|
+
"additionalProperties": false,
|
|
11
|
+
"properties": {
|
|
12
|
+
"install": {
|
|
13
|
+
"type": "object",
|
|
14
|
+
"additionalProperties": false,
|
|
15
|
+
"properties": {
|
|
16
|
+
"options": {
|
|
17
|
+
"type": "object",
|
|
18
|
+
"additionalProperties": false,
|
|
19
|
+
"properties": {
|
|
20
|
+
"saveDev": {
|
|
21
|
+
"description": "Save as dev dependency",
|
|
22
|
+
"type": "boolean"
|
|
23
|
+
},
|
|
24
|
+
"saveExact": {
|
|
25
|
+
"description": "Save exact version",
|
|
26
|
+
"type": "boolean"
|
|
27
|
+
},
|
|
28
|
+
"global": {
|
|
29
|
+
"description": "Install globally",
|
|
30
|
+
"type": "boolean"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"info": {
|
|
37
|
+
"type": "object",
|
|
38
|
+
"additionalProperties": false
|
|
39
|
+
},
|
|
40
|
+
"init": {
|
|
41
|
+
"type": "object",
|
|
42
|
+
"additionalProperties": false,
|
|
43
|
+
"properties": {
|
|
44
|
+
"options": {
|
|
45
|
+
"type": "object",
|
|
46
|
+
"additionalProperties": false,
|
|
47
|
+
"properties": {
|
|
48
|
+
"yes": {
|
|
49
|
+
"type": "boolean",
|
|
50
|
+
"description": "Skip prompts and use defaults"
|
|
51
|
+
},
|
|
52
|
+
"scope": {
|
|
53
|
+
"description": "Package scope",
|
|
54
|
+
"type": "string"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"publish": {
|
|
61
|
+
"type": "object",
|
|
62
|
+
"additionalProperties": false,
|
|
63
|
+
"properties": {
|
|
64
|
+
"options": {
|
|
65
|
+
"type": "object",
|
|
66
|
+
"additionalProperties": false,
|
|
67
|
+
"properties": {
|
|
68
|
+
"tag": {
|
|
69
|
+
"default": "latest",
|
|
70
|
+
"description": "Distribution tag",
|
|
71
|
+
"type": "string"
|
|
72
|
+
},
|
|
73
|
+
"access": {
|
|
74
|
+
"default": "public",
|
|
75
|
+
"description": "Package access level",
|
|
76
|
+
"type": "string",
|
|
77
|
+
"enum": [
|
|
78
|
+
"public",
|
|
79
|
+
"restricted"
|
|
80
|
+
]
|
|
81
|
+
},
|
|
82
|
+
"dryRun": {
|
|
83
|
+
"type": "boolean",
|
|
84
|
+
"description": "Report what would be published"
|
|
85
|
+
},
|
|
86
|
+
"otp": {
|
|
87
|
+
"description": "One-time password for 2FA",
|
|
88
|
+
"type": "string"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
"run": {
|
|
95
|
+
"type": "object",
|
|
96
|
+
"additionalProperties": false
|
|
97
|
+
},
|
|
98
|
+
"uninstall": {
|
|
99
|
+
"type": "object",
|
|
100
|
+
"additionalProperties": false,
|
|
101
|
+
"properties": {
|
|
102
|
+
"options": {
|
|
103
|
+
"type": "object",
|
|
104
|
+
"additionalProperties": false,
|
|
105
|
+
"properties": {
|
|
106
|
+
"global": {
|
|
107
|
+
"type": "boolean",
|
|
108
|
+
"description": "Remove global package"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
"outdated": {
|
|
115
|
+
"type": "object",
|
|
116
|
+
"additionalProperties": false,
|
|
117
|
+
"properties": {
|
|
118
|
+
"options": {
|
|
119
|
+
"type": "object",
|
|
120
|
+
"additionalProperties": false,
|
|
121
|
+
"properties": {
|
|
122
|
+
"global": {
|
|
123
|
+
"type": "boolean",
|
|
124
|
+
"description": "Check global packages"
|
|
125
|
+
},
|
|
126
|
+
"long": {
|
|
127
|
+
"type": "boolean",
|
|
128
|
+
"description": "Show extended information"
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
package/package.json
CHANGED
package/src/Cli.test-d.ts
CHANGED
|
@@ -289,3 +289,42 @@ test('run() context exposes format metadata', () => {
|
|
|
289
289
|
},
|
|
290
290
|
})
|
|
291
291
|
})
|
|
292
|
+
|
|
293
|
+
test('create() accepts config-file defaults options', () => {
|
|
294
|
+
Cli.create('test', {
|
|
295
|
+
config: {},
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
Cli.create('test', {
|
|
299
|
+
config: { flag: 'config' },
|
|
300
|
+
})
|
|
301
|
+
|
|
302
|
+
Cli.create('test', {
|
|
303
|
+
config: { files: ['.myrc.json', '~/.config/my/config.json'] },
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
Cli.create('test', {
|
|
307
|
+
config: {
|
|
308
|
+
flag: 'config',
|
|
309
|
+
files: ['config.toml'],
|
|
310
|
+
loader: async (path) => {
|
|
311
|
+
if (!path) return undefined
|
|
312
|
+
return { key: 'value' }
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
Cli.create('test', {
|
|
318
|
+
config: { loader: async () => ({ key: 'value' }) },
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
Cli.create('test', {
|
|
322
|
+
// @ts-expect-error — flag must be a string
|
|
323
|
+
config: { flag: true },
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
Cli.create('test', {
|
|
327
|
+
// @ts-expect-error — files must be string[]
|
|
328
|
+
config: { files: [42] },
|
|
329
|
+
})
|
|
330
|
+
})
|