@nuxtseo/cli 0.1.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 +218 -0
- package/dist/api.d.ts +14 -0
- package/dist/api.js +43 -0
- package/dist/browser.d.ts +7 -0
- package/dist/browser.js +24 -0
- package/dist/cli-entry.d.ts +2 -0
- package/dist/cli-entry.js +41 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +232 -0
- package/dist/command-contract.d.ts +33 -0
- package/dist/command-contract.js +131 -0
- package/dist/commands.d.ts +8 -0
- package/dist/commands.js +626 -0
- package/dist/failures.d.ts +36 -0
- package/dist/failures.js +132 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +3 -0
- package/dist/pairing.d.ts +13 -0
- package/dist/pairing.js +100 -0
- package/dist/parse.d.ts +23 -0
- package/dist/parse.js +126 -0
- package/dist/render.d.ts +17 -0
- package/dist/render.js +156 -0
- package/dist/runtime.d.ts +18 -0
- package/dist/runtime.js +12 -0
- package/dist/site.d.ts +5 -0
- package/dist/site.js +48 -0
- package/dist/state/auth.d.ts +45 -0
- package/dist/state/auth.js +232 -0
- package/dist/state/config.d.ts +39 -0
- package/dist/state/config.js +145 -0
- package/dist/state/files.d.ts +6 -0
- package/dist/state/files.js +125 -0
- package/dist/state/index.d.ts +4 -0
- package/dist/state/index.js +4 -0
- package/dist/state/paths.d.ts +10 -0
- package/dist/state/paths.js +16 -0
- package/dist/state/result.d.ts +67 -0
- package/dist/state/result.js +6 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +2 -0
- package/package.json +62 -0
- package/skills/nuxtseo-cli/SKILL.md +162 -0
- package/skills/nuxtseo-cli/references/protocol.md +64 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { EXIT_CODE, fail, ok } from './failures.js';
|
|
2
|
+
function staticValue(value) {
|
|
3
|
+
return typeof value === 'function' || value instanceof Promise ? undefined : value;
|
|
4
|
+
}
|
|
5
|
+
function commandArgs(command) {
|
|
6
|
+
return staticValue(command.args) ?? {};
|
|
7
|
+
}
|
|
8
|
+
function commandMeta(command) {
|
|
9
|
+
return staticValue(command.meta) ?? {};
|
|
10
|
+
}
|
|
11
|
+
function commandChildren(command) {
|
|
12
|
+
return staticValue(command.subCommands) ?? {};
|
|
13
|
+
}
|
|
14
|
+
function childCommand(value) {
|
|
15
|
+
return staticValue(value);
|
|
16
|
+
}
|
|
17
|
+
export function resolveCommand(root, rawArgs) {
|
|
18
|
+
let command = root;
|
|
19
|
+
const path = [commandMeta(root).name ?? 'nuxtseo'];
|
|
20
|
+
let index = 0;
|
|
21
|
+
while (index < rawArgs.length) {
|
|
22
|
+
const argument = rawArgs[index];
|
|
23
|
+
if (argument.startsWith('-'))
|
|
24
|
+
break;
|
|
25
|
+
const child = childCommand(commandChildren(command)[argument]);
|
|
26
|
+
if (!child)
|
|
27
|
+
break;
|
|
28
|
+
command = child;
|
|
29
|
+
path.push(argument);
|
|
30
|
+
index++;
|
|
31
|
+
}
|
|
32
|
+
return { command, path, remaining: rawArgs.slice(index) };
|
|
33
|
+
}
|
|
34
|
+
function argument(name, definition) {
|
|
35
|
+
const type = definition.type ?? 'string';
|
|
36
|
+
const alias = 'alias' in definition ? definition.alias : undefined;
|
|
37
|
+
const aliases = alias === undefined
|
|
38
|
+
? undefined
|
|
39
|
+
: Array.isArray(alias) ? alias : [alias];
|
|
40
|
+
const options = 'options' in definition ? definition.options : undefined;
|
|
41
|
+
return {
|
|
42
|
+
name,
|
|
43
|
+
type,
|
|
44
|
+
required: definition.required === true,
|
|
45
|
+
...(definition.description === undefined ? {} : { description: definition.description }),
|
|
46
|
+
...(definition.valueHint === undefined ? {} : { valueHint: definition.valueHint }),
|
|
47
|
+
...(aliases === undefined ? {} : { aliases }),
|
|
48
|
+
...(options === undefined ? {} : { options: [...options] }),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function argumentsFor(command) {
|
|
52
|
+
return Object.entries(commandArgs(command)).map(([name, definition]) => argument(name, definition));
|
|
53
|
+
}
|
|
54
|
+
export function describeCommand(root, rawArgs, cliVersion) {
|
|
55
|
+
const resolved = resolveCommand(root, rawArgs.filter(argument => argument !== '--help' && argument !== '-h'));
|
|
56
|
+
const meta = commandMeta(resolved.command);
|
|
57
|
+
return {
|
|
58
|
+
_tag: 'CliHelp',
|
|
59
|
+
schemaVersion: 1,
|
|
60
|
+
cliVersion,
|
|
61
|
+
command: resolved.path.join(' '),
|
|
62
|
+
...(meta.description === undefined ? {} : { description: meta.description }),
|
|
63
|
+
globalOptions: argumentsFor(root).filter(argument => argument.type !== 'positional'),
|
|
64
|
+
arguments: resolved.command === root ? [] : argumentsFor(resolved.command),
|
|
65
|
+
subcommands: Object.entries(commandChildren(resolved.command)).flatMap(([name, value]) => {
|
|
66
|
+
const child = childCommand(value);
|
|
67
|
+
if (!child)
|
|
68
|
+
return [];
|
|
69
|
+
const childMeta = commandMeta(child);
|
|
70
|
+
return [{ name, ...(childMeta.description === undefined ? {} : { description: childMeta.description }) }];
|
|
71
|
+
}),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function optionName(argument) {
|
|
75
|
+
const rawName = argument.slice(2).split('=', 1)[0];
|
|
76
|
+
return rawName.startsWith('no-')
|
|
77
|
+
? { name: rawName.slice(3), negated: true }
|
|
78
|
+
: { name: rawName, negated: false };
|
|
79
|
+
}
|
|
80
|
+
export function validateCommandOptions(root, rawArgs) {
|
|
81
|
+
const resolved = resolveCommand(root, rawArgs);
|
|
82
|
+
const definitions = commandArgs(resolved.command);
|
|
83
|
+
const aliases = new Map();
|
|
84
|
+
for (const definition of Object.values(definitions)) {
|
|
85
|
+
const alias = 'alias' in definition ? definition.alias : undefined;
|
|
86
|
+
const names = alias === undefined
|
|
87
|
+
? []
|
|
88
|
+
: Array.isArray(alias) ? alias : [alias];
|
|
89
|
+
for (const name of names)
|
|
90
|
+
aliases.set(name, definition);
|
|
91
|
+
}
|
|
92
|
+
for (let index = 0; index < resolved.remaining.length; index++) {
|
|
93
|
+
const token = resolved.remaining[index];
|
|
94
|
+
if (token === '--')
|
|
95
|
+
break;
|
|
96
|
+
if (token === '--help' || token === '-h')
|
|
97
|
+
continue;
|
|
98
|
+
if (token.startsWith('--')) {
|
|
99
|
+
const parsed = optionName(token);
|
|
100
|
+
const definition = definitions[parsed.name];
|
|
101
|
+
if (!definition || (parsed.negated && definition.type !== 'boolean')) {
|
|
102
|
+
return fail(EXIT_CODE.invalidInput, `invalid_cli_input: Unknown option ${JSON.stringify(token.split('=', 1)[0])}.`);
|
|
103
|
+
}
|
|
104
|
+
if (!token.includes('=')
|
|
105
|
+
&& definition.type !== 'boolean'
|
|
106
|
+
&& !resolved.remaining[index + 1]?.startsWith('-')) {
|
|
107
|
+
index++;
|
|
108
|
+
}
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (token.startsWith('-')) {
|
|
112
|
+
const definition = aliases.get(token.slice(1));
|
|
113
|
+
if (!definition)
|
|
114
|
+
return fail(EXIT_CODE.invalidInput, `invalid_cli_input: Unknown option ${JSON.stringify(token)}.`);
|
|
115
|
+
if (definition.type !== 'boolean' && !resolved.remaining[index + 1]?.startsWith('-'))
|
|
116
|
+
index++;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return ok(undefined);
|
|
120
|
+
}
|
|
121
|
+
export function commandWithGlobalOptions(root, command) {
|
|
122
|
+
if (command === root)
|
|
123
|
+
return command;
|
|
124
|
+
return {
|
|
125
|
+
...command,
|
|
126
|
+
args: {
|
|
127
|
+
...commandArgs(root),
|
|
128
|
+
...commandArgs(command),
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CommandDef } from 'citty';
|
|
2
|
+
import type { CliResult } from './failures.js';
|
|
3
|
+
import type { GlobalOptions } from './parse.js';
|
|
4
|
+
import type { CliRuntime } from './runtime.js';
|
|
5
|
+
export interface CommandExecution {
|
|
6
|
+
result: CliResult<void> | null;
|
|
7
|
+
}
|
|
8
|
+
export declare function createRootCommand(runtime: CliRuntime, globals: GlobalOptions, execution: CommandExecution): CommandDef<any>;
|