auklet 0.1.4 → 0.1.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 +116 -429
- package/dist/cli/build.d.ts +3 -5
- package/dist/cli/build.js +86 -23
- package/dist/cli/buildCss.d.ts +10 -5
- package/dist/cli/buildCss.js +21 -17
- package/dist/cli/buildWorkspace.d.ts +24 -0
- package/dist/cli/buildWorkspace.js +43 -0
- package/dist/cli/dev.d.ts +2 -1
- package/dist/cli/dev.js +130 -23
- package/dist/cli/main.js +167 -26
- package/dist/cli/parse/build.d.ts +63 -0
- package/dist/cli/{buildArgs.js → parse/build.js} +47 -22
- package/dist/cli/parse/core.d.ts +14 -0
- package/dist/cli/parse/core.js +68 -0
- package/dist/cli/parse/dev.d.ts +18 -0
- package/dist/cli/parse/dev.js +4 -0
- package/dist/cli/parse/owner.d.ts +11 -0
- package/dist/cli/parse/owner.js +25 -0
- package/dist/cli/parse/publish.d.ts +19 -0
- package/dist/cli/parse/publish.js +60 -0
- package/dist/cli/parse/workspace.d.ts +14 -0
- package/dist/cli/parse/workspace.js +60 -0
- package/dist/css/inspect.js +4 -3
- package/dist/publish/api/pnpmApi.d.ts +0 -4
- package/dist/publish/api/pnpmApi.js +0 -34
- package/dist/publish/cli.d.ts +0 -16
- package/dist/publish/cli.js +5 -122
- package/dist/publish/inspect.js +2 -2
- package/dist/publish/targetResolver.js +28 -72
- package/dist/publish/types.d.ts +1 -7
- package/dist/workspace/targets.d.ts +31 -0
- package/dist/workspace/targets.js +144 -0
- package/package.json +1 -1
- package/dist/cli/buildArgs.d.ts +0 -9
- package/dist/cli/publish.d.ts +0 -2
- package/dist/cli/publish.js +0 -9
- /package/dist/cli/{values.d.ts → parse/values.d.ts} +0 -0
- /package/dist/cli/{values.js → parse/values.js} +0 -0
package/dist/cli/main.js
CHANGED
|
@@ -2,12 +2,15 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import { cac } from 'cac';
|
|
5
|
+
import { AukletEnvContext } from '#auklet/env';
|
|
5
6
|
import { createAukletLogger } from '#auklet/logger';
|
|
7
|
+
import { runOwnerCli, runPublishCli } from '#auklet/publish/cli';
|
|
6
8
|
import { runDev } from '#auklet/cli/dev';
|
|
9
|
+
import { runInspect } from '#auklet/cli/inspect';
|
|
7
10
|
import { runBuildCss } from '#auklet/cli/buildCss';
|
|
11
|
+
import { parseDevCommand } from '#auklet/cli/parse/dev';
|
|
8
12
|
import { runBuild, runBuildJs } from '#auklet/cli/build';
|
|
9
|
-
import {
|
|
10
|
-
import { runInspect } from '#auklet/cli/inspect';
|
|
13
|
+
import { parseBuildCommand, parseBuildCssCommand, parseBuildJsCommand, } from '#auklet/cli/parse/build';
|
|
11
14
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
12
15
|
const getPackageVersion = () => {
|
|
13
16
|
const packageJson = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../package.json'), 'utf8'));
|
|
@@ -17,61 +20,199 @@ const runVersion = async () => {
|
|
|
17
20
|
console.log(getPackageVersion());
|
|
18
21
|
return 0;
|
|
19
22
|
};
|
|
20
|
-
|
|
23
|
+
// Raw argv slicing is intentionally kept in this entry module. Command runners
|
|
24
|
+
// only receive parsed options or command-specific raw subcommand args.
|
|
25
|
+
const getRawCommandArgs = (argv, command) => {
|
|
21
26
|
const rawArgs = argv.slice(2);
|
|
22
27
|
const commandIndex = rawArgs.indexOf(command);
|
|
23
28
|
return commandIndex >= 0 ? rawArgs.slice(commandIndex + 1) : [];
|
|
24
29
|
};
|
|
25
|
-
const runCliCommand = (runner
|
|
26
|
-
return runner(
|
|
30
|
+
const runCliCommand = (runner) => {
|
|
31
|
+
return runner().then((exitCode) => {
|
|
27
32
|
process.exit(exitCode ?? 0);
|
|
28
33
|
});
|
|
29
34
|
};
|
|
35
|
+
const createCommandContext = () => {
|
|
36
|
+
const cwd = process.cwd();
|
|
37
|
+
return {
|
|
38
|
+
cwd,
|
|
39
|
+
envContext: new AukletEnvContext(cwd),
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
const addBuildOverrideOptions = (command) => {
|
|
43
|
+
return command
|
|
44
|
+
.option('--source <dir>', 'Source directory')
|
|
45
|
+
.option('--output <dir>', 'Output directory')
|
|
46
|
+
.option('--modules [value]', 'Enable unbundled module output')
|
|
47
|
+
.option('--no-modules', 'Disable unbundled module output')
|
|
48
|
+
.option('--build.formats <formats>', 'Comma-separated cjs, esm, and/or iife formats')
|
|
49
|
+
.option('--build.target <target>', 'JavaScript target passed to tsdown')
|
|
50
|
+
.option('--build.platform <platform>', 'node, neutral, or browser')
|
|
51
|
+
.option('--build.tsconfig <file>', 'TypeScript config file');
|
|
52
|
+
};
|
|
53
|
+
const addWorkspaceOptions = (command) => {
|
|
54
|
+
return command
|
|
55
|
+
.option('--filter <pattern>', 'Select workspace packages by package name')
|
|
56
|
+
.option('--workspace', "Alias for --filter '*'")
|
|
57
|
+
.option('--private [value]', 'Include private workspace packages')
|
|
58
|
+
.option('--deps [value]', "Include selected packages' workspace dependencies");
|
|
59
|
+
};
|
|
60
|
+
const addPublishOptions = (command) => {
|
|
61
|
+
return command
|
|
62
|
+
.option('--filter <pattern>', 'Select workspace packages by package name')
|
|
63
|
+
.option('--workspace', "Alias for --filter '*'")
|
|
64
|
+
.option('--version <value>', 'Publish version or version bump')
|
|
65
|
+
.option('--dry-run [value]', 'Validate without writing git or registry state')
|
|
66
|
+
.option('--format [value]', 'Enable publish output formatter')
|
|
67
|
+
.option('--no-format', 'Disable publish output formatter')
|
|
68
|
+
.option('--git [value]', 'Create release commit and tag')
|
|
69
|
+
.option('--no-git', 'Skip release commit and tag')
|
|
70
|
+
.option('--allow-dirty [value]', 'Allow publishing from a dirty worktree')
|
|
71
|
+
.option('--ignore-scripts [value]', 'Skip publish lifecycle hooks')
|
|
72
|
+
.option('--otp <code>', 'Forward an npm 2FA one-time password')
|
|
73
|
+
.option('--token <value>', 'Set NODE_AUTH_TOKEN and NPM_TOKEN for subprocesses');
|
|
74
|
+
};
|
|
75
|
+
const createHelpFormatter = (cli) => {
|
|
76
|
+
return (sections) => {
|
|
77
|
+
const command = cli.matchedCommand?.name;
|
|
78
|
+
return sections.map((section) => {
|
|
79
|
+
if (section.title !== 'Options')
|
|
80
|
+
return section;
|
|
81
|
+
let body = section.body.replace(/\s+\(default: true\)/g, '');
|
|
82
|
+
if (!command) {
|
|
83
|
+
body = addHelpOptionLine(body, ' -v, --version Print auklet version');
|
|
84
|
+
}
|
|
85
|
+
if (command === 'publish') {
|
|
86
|
+
body = addHelpOptionLine(body, ' --version <value> Publish version or version bump');
|
|
87
|
+
}
|
|
88
|
+
if (command === 'inspect') {
|
|
89
|
+
body = addHelpOptionLine(body, ' --version <value> Publish version or version bump');
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
...section,
|
|
93
|
+
body,
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
const addHelpOptionLine = (body, line) => {
|
|
99
|
+
if (body.includes(line.trimStart().split(/\s+/)[0]))
|
|
100
|
+
return body;
|
|
101
|
+
const helpLinePattern = /^ -h, --help/m;
|
|
102
|
+
if (!helpLinePattern.test(body))
|
|
103
|
+
return `${body}\n${line}`;
|
|
104
|
+
return body.replace(helpLinePattern, `${line}\n -h, --help`);
|
|
105
|
+
};
|
|
30
106
|
async function runCli(argv) {
|
|
31
107
|
const cli = cac('auk');
|
|
32
|
-
cli
|
|
33
|
-
.
|
|
108
|
+
addWorkspaceOptions(addBuildOverrideOptions(cli.command('build [...args]', 'Build package JavaScript and CSS output')))
|
|
109
|
+
.ignoreOptionDefaultValue()
|
|
34
110
|
.allowUnknownOptions()
|
|
35
|
-
.action(() => runCliCommand(
|
|
36
|
-
|
|
37
|
-
|
|
111
|
+
.action(() => runCliCommand(() => {
|
|
112
|
+
const context = createCommandContext();
|
|
113
|
+
return runBuild(parseBuildCommand(getRawCommandArgs(argv, 'build'), context));
|
|
114
|
+
}));
|
|
115
|
+
addBuildOverrideOptions(cli.command('build-js [...args]', 'Build package JavaScript output with tsdown'))
|
|
116
|
+
.ignoreOptionDefaultValue()
|
|
38
117
|
.allowUnknownOptions()
|
|
39
|
-
.action(() => runCliCommand(
|
|
40
|
-
|
|
118
|
+
.action(() => runCliCommand(() => {
|
|
119
|
+
const context = createCommandContext();
|
|
120
|
+
return runBuildJs(parseBuildJsCommand(getRawCommandArgs(argv, 'build-js'), context));
|
|
121
|
+
}));
|
|
122
|
+
addBuildOverrideOptions(cli
|
|
41
123
|
.command('build-css [...args]', 'Build package module CSS output')
|
|
42
|
-
.option('-w, --watch', 'Watch module CSS output')
|
|
124
|
+
.option('-w, --watch', 'Watch module CSS output'))
|
|
125
|
+
.ignoreOptionDefaultValue()
|
|
43
126
|
.allowUnknownOptions()
|
|
44
|
-
.action(() => runCliCommand(
|
|
45
|
-
|
|
46
|
-
|
|
127
|
+
.action(() => runCliCommand(() => {
|
|
128
|
+
const context = createCommandContext();
|
|
129
|
+
return runBuildCss(parseBuildCssCommand(getRawCommandArgs(argv, 'build-css'), context));
|
|
130
|
+
}));
|
|
131
|
+
addWorkspaceOptions(addBuildOverrideOptions(cli.command('dev [...args]', 'Watch package JavaScript and CSS output')))
|
|
132
|
+
.ignoreOptionDefaultValue()
|
|
133
|
+
.allowUnknownOptions()
|
|
134
|
+
.action(() => runCliCommand(() => {
|
|
135
|
+
const context = createCommandContext();
|
|
136
|
+
return runDev(parseDevCommand(getRawCommandArgs(argv, 'dev'), context));
|
|
137
|
+
}));
|
|
138
|
+
addPublishOptions(cli.command('publish [...args]', 'Build and publish package output with pnpm'))
|
|
139
|
+
.ignoreOptionDefaultValue()
|
|
47
140
|
.allowUnknownOptions()
|
|
48
|
-
.action(() => runCliCommand(
|
|
141
|
+
.action(() => runCliCommand(() => runPublishCli(getRawCommandArgs(argv, 'publish'))));
|
|
49
142
|
cli
|
|
50
|
-
.command('
|
|
143
|
+
.command('owner add <user...>', 'Add npm owners to the current package or selected packages')
|
|
144
|
+
.option('--filter <pattern>', 'Add owners to matching workspace packages')
|
|
145
|
+
.option('--package <name>', 'Add owners to explicit npm packages')
|
|
146
|
+
.option('--otp <code>', 'Forward an npm owner-management 2FA code')
|
|
147
|
+
.ignoreOptionDefaultValue()
|
|
51
148
|
.allowUnknownOptions()
|
|
52
|
-
.action(() => runCliCommand(
|
|
149
|
+
.action(() => runCliCommand(() => runOwnerCli(getRawCommandArgs(argv, 'owner'))));
|
|
53
150
|
cli
|
|
54
151
|
.command('owner [...args]', 'Manage npm package owners with pnpm')
|
|
152
|
+
.usage('add <user...> [options]')
|
|
153
|
+
.option('--filter <pattern>', 'Add owners to matching workspace packages')
|
|
154
|
+
.option('--package <name>', 'Add owners to explicit npm packages')
|
|
155
|
+
.option('--otp <code>', 'Forward an npm owner-management 2FA code')
|
|
156
|
+
.ignoreOptionDefaultValue()
|
|
157
|
+
.allowUnknownOptions()
|
|
158
|
+
.action(() => runCliCommand(() => runOwnerCli(getRawCommandArgs(argv, 'owner'))));
|
|
159
|
+
cli
|
|
160
|
+
.command('inspect publish [...args]', 'Check publish readiness')
|
|
161
|
+
.option('--filter <pattern>', 'Select workspace packages by package name')
|
|
162
|
+
.option('--workspace', "Alias for --filter '*'")
|
|
163
|
+
.option('--version <value>', 'Publish version or version bump')
|
|
164
|
+
.option('--dry-run [value]', 'Preview dry-run publish behavior')
|
|
165
|
+
.option('--otp <code>', 'Forward an npm 2FA one-time password')
|
|
166
|
+
.option('--token <value>', 'Set NODE_AUTH_TOKEN and NPM_TOKEN for subprocesses')
|
|
167
|
+
.ignoreOptionDefaultValue()
|
|
55
168
|
.allowUnknownOptions()
|
|
56
|
-
.action(() => runCliCommand(
|
|
169
|
+
.action(() => runCliCommand(() => runInspect(getRawCommandArgs(argv, 'inspect'))));
|
|
170
|
+
cli
|
|
171
|
+
.command('inspect pack [...args]', 'Check package entry and export files')
|
|
172
|
+
.option('--filter <pattern>', 'Select workspace packages by package name')
|
|
173
|
+
.ignoreOptionDefaultValue()
|
|
174
|
+
.allowUnknownOptions()
|
|
175
|
+
.action(() => runCliCommand(() => runInspect(getRawCommandArgs(argv, 'inspect'))));
|
|
176
|
+
addBuildOverrideOptions(cli.command('inspect css [...args]', 'Explain CSS output plans'))
|
|
177
|
+
.ignoreOptionDefaultValue()
|
|
178
|
+
.allowUnknownOptions()
|
|
179
|
+
.action(() => runCliCommand(() => runInspect(getRawCommandArgs(argv, 'inspect'))));
|
|
57
180
|
cli
|
|
58
181
|
.command('inspect [...args]', 'Inspect auklet plans without side effects')
|
|
182
|
+
.usage('<publish|pack|css> [...args]')
|
|
183
|
+
.option('--filter <pattern>', 'Select workspace packages by package name')
|
|
184
|
+
.option('--workspace', "Alias for --filter '*'")
|
|
185
|
+
.option('--version <value>', 'Publish version or version bump')
|
|
186
|
+
.option('--dry-run [value]', 'Preview dry-run publish behavior')
|
|
187
|
+
.option('--otp <code>', 'Forward an npm 2FA one-time password')
|
|
188
|
+
.option('--token <value>', 'Set publish auth token')
|
|
189
|
+
.option('--source <dir>', 'CSS inspect source directory')
|
|
190
|
+
.option('--output <dir>', 'CSS inspect output directory')
|
|
191
|
+
.option('--modules [value]', 'Enable CSS inspect module output')
|
|
192
|
+
.option('--no-modules', 'Disable CSS inspect module output')
|
|
193
|
+
.ignoreOptionDefaultValue()
|
|
59
194
|
.allowUnknownOptions()
|
|
60
|
-
.action(() => runCliCommand(runInspect
|
|
195
|
+
.action(() => runCliCommand(() => runInspect(getRawCommandArgs(argv, 'inspect'))));
|
|
61
196
|
cli
|
|
62
197
|
.command('version', 'Print auklet version')
|
|
63
|
-
.action(() => runCliCommand(runVersion
|
|
64
|
-
cli.
|
|
65
|
-
|
|
198
|
+
.action(() => runCliCommand(runVersion));
|
|
199
|
+
cli.command('help', 'Print auklet help').action(() => runCliCommand(async () => {
|
|
200
|
+
cli.unsetMatchedCommand();
|
|
201
|
+
cli.outputHelp();
|
|
202
|
+
return 0;
|
|
203
|
+
}));
|
|
204
|
+
cli.help(createHelpFormatter(cli));
|
|
66
205
|
if (argv.length <= 2) {
|
|
67
206
|
cli.outputHelp();
|
|
68
207
|
process.exit(1);
|
|
69
208
|
}
|
|
70
|
-
|
|
71
|
-
if (
|
|
209
|
+
const rawArgs = argv.slice(2);
|
|
210
|
+
if (rawArgs.length === 1 &&
|
|
211
|
+
(rawArgs[0] === '-v' || rawArgs[0] === '--version')) {
|
|
72
212
|
console.log(getPackageVersion());
|
|
73
213
|
process.exit(0);
|
|
74
214
|
}
|
|
215
|
+
cli.parse(argv, { run: false });
|
|
75
216
|
if (cli.options.help) {
|
|
76
217
|
process.exit(0);
|
|
77
218
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { AukletEnvContext } from '#auklet/env';
|
|
2
|
+
import type { AukletConfig } from '#auklet/types';
|
|
3
|
+
import type { WorkspaceSelection } from '#auklet/cli/parse/workspace';
|
|
4
|
+
export type BuildCommandOptions = {
|
|
5
|
+
cwd: string;
|
|
6
|
+
envContext: AukletEnvContext;
|
|
7
|
+
workspace: WorkspaceSelection;
|
|
8
|
+
overrides: AukletConfig;
|
|
9
|
+
passthroughArgs: Array<string>;
|
|
10
|
+
workspaceScriptArgs: Array<string>;
|
|
11
|
+
};
|
|
12
|
+
export type BuildJsCommandOptions = {
|
|
13
|
+
cwd: string;
|
|
14
|
+
envContext: AukletEnvContext;
|
|
15
|
+
overrides: AukletConfig;
|
|
16
|
+
passthroughArgs: Array<string>;
|
|
17
|
+
};
|
|
18
|
+
export type BuildCssCommandOptions = {
|
|
19
|
+
cwd: string;
|
|
20
|
+
envContext: AukletEnvContext;
|
|
21
|
+
overrides: AukletConfig;
|
|
22
|
+
watch: boolean;
|
|
23
|
+
};
|
|
24
|
+
export declare function parseBuildCommand(args: Array<string>, options: {
|
|
25
|
+
cwd: string;
|
|
26
|
+
envContext: AukletEnvContext;
|
|
27
|
+
}): {
|
|
28
|
+
cwd: string;
|
|
29
|
+
envContext: AukletEnvContext;
|
|
30
|
+
workspace: {
|
|
31
|
+
filters: string[];
|
|
32
|
+
includeDependencies: boolean;
|
|
33
|
+
includePrivate: boolean;
|
|
34
|
+
};
|
|
35
|
+
overrides: AukletConfig;
|
|
36
|
+
passthroughArgs: string[];
|
|
37
|
+
workspaceScriptArgs: string[];
|
|
38
|
+
};
|
|
39
|
+
export declare function parseBuildJsCommand(args: Array<string>, options: {
|
|
40
|
+
cwd: string;
|
|
41
|
+
envContext: AukletEnvContext;
|
|
42
|
+
}): {
|
|
43
|
+
cwd: string;
|
|
44
|
+
envContext: AukletEnvContext;
|
|
45
|
+
overrides: AukletConfig;
|
|
46
|
+
passthroughArgs: string[];
|
|
47
|
+
};
|
|
48
|
+
export declare function parseBuildCssCommand(args: Array<string>, options: {
|
|
49
|
+
cwd: string;
|
|
50
|
+
envContext: AukletEnvContext;
|
|
51
|
+
}): {
|
|
52
|
+
cwd: string;
|
|
53
|
+
envContext: AukletEnvContext;
|
|
54
|
+
overrides: AukletConfig;
|
|
55
|
+
watch: boolean;
|
|
56
|
+
};
|
|
57
|
+
export declare function parseBuildOverrideArgs(args: Array<string>, envContext: AukletEnvContext): {
|
|
58
|
+
args: string[];
|
|
59
|
+
config: AukletConfig;
|
|
60
|
+
};
|
|
61
|
+
export declare function createBuildEnv(config: AukletConfig): {
|
|
62
|
+
AUKLET_CONFIG_OVERRIDES: string;
|
|
63
|
+
} | undefined;
|
|
@@ -1,13 +1,48 @@
|
|
|
1
1
|
import { hasTsdownConfigArg } from '#auklet/build/runTsdown';
|
|
2
2
|
import { aukletCliConfigOverridesEnv, encodeAukletCliConfigOverrides, } from '#auklet/build/cliOverrides';
|
|
3
|
-
import { resolveCliBoolean, resolveCliValue } from '#auklet/cli/values';
|
|
4
|
-
import {
|
|
3
|
+
import { resolveCliBoolean, resolveCliValue } from '#auklet/cli/parse/values';
|
|
4
|
+
import { readFlagValue, readOptionalFlagValue } from '#auklet/cli/parse/core';
|
|
5
|
+
import { parseWorkspaceSelectionArgs } from '#auklet/cli/parse/workspace';
|
|
5
6
|
const buildFormats = new Set(['cjs', 'esm', 'iife']);
|
|
6
7
|
const buildPlatforms = new Set(['node', 'neutral', 'browser']);
|
|
7
8
|
const hasAukletConfig = (config) => {
|
|
8
9
|
return Object.keys(config).length > 0;
|
|
9
10
|
};
|
|
10
|
-
export function
|
|
11
|
+
export function parseBuildCommand(args, options) {
|
|
12
|
+
const workspaceArgs = parseWorkspaceSelectionArgs(args, options.envContext);
|
|
13
|
+
const buildArgs = parseBuildOverrideArgs(workspaceArgs.remainingArgs, options.envContext);
|
|
14
|
+
return {
|
|
15
|
+
cwd: options.cwd,
|
|
16
|
+
envContext: options.envContext,
|
|
17
|
+
workspace: workspaceArgs.workspace,
|
|
18
|
+
overrides: buildArgs.config,
|
|
19
|
+
passthroughArgs: buildArgs.args,
|
|
20
|
+
workspaceScriptArgs: workspaceArgs.remainingArgs,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function parseBuildJsCommand(args, options) {
|
|
24
|
+
const buildArgs = parseBuildOverrideArgs(args, options.envContext);
|
|
25
|
+
return {
|
|
26
|
+
cwd: options.cwd,
|
|
27
|
+
envContext: options.envContext,
|
|
28
|
+
overrides: buildArgs.config,
|
|
29
|
+
passthroughArgs: buildArgs.args,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export function parseBuildCssCommand(args, options) {
|
|
33
|
+
const buildArgs = parseBuildOverrideArgs(args, options.envContext);
|
|
34
|
+
const remainingArgs = buildArgs.args.filter((arg) => arg !== '--watch' && arg !== '-w');
|
|
35
|
+
if (remainingArgs.length) {
|
|
36
|
+
throw new Error(`[build-css] unknown build-css argument: ${remainingArgs[0]}`);
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
cwd: options.cwd,
|
|
40
|
+
envContext: options.envContext,
|
|
41
|
+
overrides: buildArgs.config,
|
|
42
|
+
watch: buildArgs.args.includes('--watch') || buildArgs.args.includes('-w'),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export function parseBuildOverrideArgs(args, envContext) {
|
|
11
46
|
const remainingArgs = [];
|
|
12
47
|
const config = {};
|
|
13
48
|
for (let index = 0; index < args.length; index += 1) {
|
|
@@ -26,7 +61,7 @@ export function resolveBuildCliArgs(args, envContext = new AukletEnvContext(proc
|
|
|
26
61
|
continue;
|
|
27
62
|
}
|
|
28
63
|
if (name === '--modules') {
|
|
29
|
-
const value =
|
|
64
|
+
const value = readOptionalFlagValue(args, index, inlineValue);
|
|
30
65
|
config.modules =
|
|
31
66
|
value === undefined
|
|
32
67
|
? true
|
|
@@ -42,7 +77,12 @@ export function resolveBuildCliArgs(args, envContext = new AukletEnvContext(proc
|
|
|
42
77
|
if (name === '--build.formats') {
|
|
43
78
|
config.build = {
|
|
44
79
|
...config.build,
|
|
45
|
-
formats: parseBuildFormats(
|
|
80
|
+
formats: parseBuildFormats(inlineValue === undefined
|
|
81
|
+
? getResolvedFlagValue(args, index, inlineValue, name, envContext)
|
|
82
|
+
: (resolveCliValue(inlineValue, {
|
|
83
|
+
label: name,
|
|
84
|
+
context: envContext,
|
|
85
|
+
}) ?? inlineValue)),
|
|
46
86
|
};
|
|
47
87
|
if (inlineValue === undefined)
|
|
48
88
|
index += 1;
|
|
@@ -92,23 +132,8 @@ export function createBuildEnv(config) {
|
|
|
92
132
|
[aukletCliConfigOverridesEnv]: encodeAukletCliConfigOverrides(config),
|
|
93
133
|
};
|
|
94
134
|
}
|
|
95
|
-
const getFlagValue = (args, index, inlineValue, flag) => {
|
|
96
|
-
const value = inlineValue ?? args[index + 1];
|
|
97
|
-
if (!value || value.startsWith('--')) {
|
|
98
|
-
throw new Error(`${flag} requires a value.`);
|
|
99
|
-
}
|
|
100
|
-
return value;
|
|
101
|
-
};
|
|
102
|
-
const getOptionalFlagValue = (args, index, inlineValue) => {
|
|
103
|
-
if (inlineValue !== undefined)
|
|
104
|
-
return inlineValue;
|
|
105
|
-
const value = args[index + 1];
|
|
106
|
-
if (!value || value.startsWith('--'))
|
|
107
|
-
return undefined;
|
|
108
|
-
return value;
|
|
109
|
-
};
|
|
110
135
|
const getResolvedFlagValue = (args, index, inlineValue, flag, envContext) => {
|
|
111
|
-
return resolveCliValue(
|
|
136
|
+
return resolveCliValue(readFlagValue(args, index, inlineValue, flag), {
|
|
112
137
|
label: flag,
|
|
113
138
|
context: envContext,
|
|
114
139
|
});
|
|
@@ -116,7 +141,7 @@ const getResolvedFlagValue = (args, index, inlineValue, flag, envContext) => {
|
|
|
116
141
|
const parseBuildFormats = (value) => {
|
|
117
142
|
const formats = value
|
|
118
143
|
.split(',')
|
|
119
|
-
.map((
|
|
144
|
+
.map((item) => item.trim())
|
|
120
145
|
.filter(Boolean);
|
|
121
146
|
if (!formats.length) {
|
|
122
147
|
throw new Error('--build.formats requires at least one format.');
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AukletEnvContext } from '#auklet/env';
|
|
2
|
+
export declare function stripArgsSeparator(args: Array<string>): string[];
|
|
3
|
+
export declare function readFlagValue(args: Array<string>, index: number, inlineValue: string | undefined, flag: string): string;
|
|
4
|
+
export declare function readOptionalFlagValue(args: Array<string>, index: number, inlineValue: string | undefined): string | undefined;
|
|
5
|
+
export declare function dedupe<T>(items: Array<T>): T[];
|
|
6
|
+
export declare function stringOption(value: unknown, label: string, envContext: AukletEnvContext): string | undefined;
|
|
7
|
+
export declare function deferredStringOption(value: unknown, label: string): {
|
|
8
|
+
raw: string;
|
|
9
|
+
resolve(context: AukletEnvContext): string | undefined;
|
|
10
|
+
} | undefined;
|
|
11
|
+
export declare function booleanOption(value: unknown, label: string, envContext: AukletEnvContext, defaultValue?: boolean): boolean;
|
|
12
|
+
export declare function stringArrayOption(value: unknown, label: string, envContext: AukletEnvContext): string[];
|
|
13
|
+
export declare function validateUnknownFlags(argv: Record<string, unknown>, allowedFlags: Set<string>, scope: string): void;
|
|
14
|
+
export declare function validateNoPrefixedFlags(args: Array<string>, allowedFlags: Set<string>, scope: string): void;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { isArray } from 'aidly';
|
|
2
|
+
import { createDeferredCliValue, resolveCliBoolean, resolveCliValue, } from '#auklet/cli/parse/values';
|
|
3
|
+
export function stripArgsSeparator(args) {
|
|
4
|
+
return args.filter((arg) => arg !== '--');
|
|
5
|
+
}
|
|
6
|
+
export function readFlagValue(args, index, inlineValue, flag) {
|
|
7
|
+
const value = inlineValue ?? args[index + 1];
|
|
8
|
+
if (!value || value.startsWith('--')) {
|
|
9
|
+
throw new Error(`${flag} requires a value.`);
|
|
10
|
+
}
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
export function readOptionalFlagValue(args, index, inlineValue) {
|
|
14
|
+
if (inlineValue !== undefined)
|
|
15
|
+
return inlineValue;
|
|
16
|
+
const value = args[index + 1];
|
|
17
|
+
if (!value || value.startsWith('--'))
|
|
18
|
+
return undefined;
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
export function dedupe(items) {
|
|
22
|
+
return [...new Set(items)];
|
|
23
|
+
}
|
|
24
|
+
export function stringOption(value, label, envContext) {
|
|
25
|
+
if (value === undefined)
|
|
26
|
+
return undefined;
|
|
27
|
+
if (isArray(value))
|
|
28
|
+
return stringOption(value.at(-1), label, envContext);
|
|
29
|
+
return resolveCliValue(String(value), { label, context: envContext });
|
|
30
|
+
}
|
|
31
|
+
export function deferredStringOption(value, label) {
|
|
32
|
+
if (value === undefined)
|
|
33
|
+
return undefined;
|
|
34
|
+
if (isArray(value))
|
|
35
|
+
return deferredStringOption(value.at(-1), label);
|
|
36
|
+
return createDeferredCliValue(String(value), { label });
|
|
37
|
+
}
|
|
38
|
+
export function booleanOption(value, label, envContext, defaultValue = false) {
|
|
39
|
+
if (value === undefined)
|
|
40
|
+
return defaultValue;
|
|
41
|
+
if (isArray(value)) {
|
|
42
|
+
return booleanOption(value.at(-1), label, envContext, defaultValue);
|
|
43
|
+
}
|
|
44
|
+
if (typeof value === 'boolean')
|
|
45
|
+
return value;
|
|
46
|
+
return resolveCliBoolean(String(value), { label, context: envContext });
|
|
47
|
+
}
|
|
48
|
+
export function stringArrayOption(value, label, envContext) {
|
|
49
|
+
if (value === undefined)
|
|
50
|
+
return [];
|
|
51
|
+
const values = isArray(value)
|
|
52
|
+
? value.map((item) => stringOption(item, label, envContext)).filter(Boolean)
|
|
53
|
+
: [stringOption(value, label, envContext)].filter(Boolean);
|
|
54
|
+
return values.filter((item) => Boolean(item));
|
|
55
|
+
}
|
|
56
|
+
export function validateUnknownFlags(argv, allowedFlags, scope) {
|
|
57
|
+
for (const flag of Object.keys(argv)) {
|
|
58
|
+
if (!allowedFlags.has(flag)) {
|
|
59
|
+
throw new Error(`[${scope}] unknown option: --${flag}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export function validateNoPrefixedFlags(args, allowedFlags, scope) {
|
|
64
|
+
const flag = args.find((arg) => arg.startsWith('--no-') && !allowedFlags.has(arg));
|
|
65
|
+
if (flag) {
|
|
66
|
+
throw new Error(`[${scope}] unknown option: ${flag}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AukletEnvContext } from '#auklet/env';
|
|
2
|
+
import type { BuildCommandOptions } from '#auklet/cli/parse/build';
|
|
3
|
+
export type DevCommandOptions = BuildCommandOptions;
|
|
4
|
+
export declare function parseDevCommand(args: Array<string>, options: {
|
|
5
|
+
cwd: string;
|
|
6
|
+
envContext: AukletEnvContext;
|
|
7
|
+
}): {
|
|
8
|
+
cwd: string;
|
|
9
|
+
envContext: AukletEnvContext;
|
|
10
|
+
workspace: {
|
|
11
|
+
filters: string[];
|
|
12
|
+
includeDependencies: boolean;
|
|
13
|
+
includePrivate: boolean;
|
|
14
|
+
};
|
|
15
|
+
overrides: import("../..").AukletConfig;
|
|
16
|
+
passthroughArgs: string[];
|
|
17
|
+
workspaceScriptArgs: string[];
|
|
18
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AukletEnvContext } from '#auklet/env';
|
|
2
|
+
export declare function parseOwnerCommand(args: Array<string>, options: {
|
|
3
|
+
cwd: string;
|
|
4
|
+
envContext: AukletEnvContext;
|
|
5
|
+
}): {
|
|
6
|
+
cwd: string;
|
|
7
|
+
users: string[];
|
|
8
|
+
filters: string[];
|
|
9
|
+
packages: string[];
|
|
10
|
+
otp: string | undefined;
|
|
11
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import minimist from 'minimist';
|
|
2
|
+
import { stringArrayOption, stringOption, stripArgsSeparator, validateNoPrefixedFlags, validateUnknownFlags, } from '#auklet/cli/parse/core';
|
|
3
|
+
const ownerFlags = new Set(['_', 'filter', 'package', 'otp']);
|
|
4
|
+
export function parseOwnerCommand(args, options) {
|
|
5
|
+
const cliArgs = stripArgsSeparator(args);
|
|
6
|
+
validateNoPrefixedFlags(cliArgs, new Set(), 'publish');
|
|
7
|
+
const argv = minimist(cliArgs, {
|
|
8
|
+
string: ['filter', 'package', 'otp'],
|
|
9
|
+
});
|
|
10
|
+
validateUnknownFlags(argv, ownerFlags, 'publish');
|
|
11
|
+
const [subcommand, ...users] = argv._;
|
|
12
|
+
if (subcommand !== 'add') {
|
|
13
|
+
throw new Error('[publish] expected owner command: auk owner add <user...>');
|
|
14
|
+
}
|
|
15
|
+
if (!users.length) {
|
|
16
|
+
throw new Error('[publish] owner add requires at least one user.');
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
cwd: options.cwd,
|
|
20
|
+
users,
|
|
21
|
+
filters: stringArrayOption(argv.filter, '--filter', options.envContext),
|
|
22
|
+
packages: stringArrayOption(argv.package, '--package', options.envContext),
|
|
23
|
+
otp: stringOption(argv.otp, '--otp', options.envContext),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AukletEnvContext } from '#auklet/env';
|
|
2
|
+
export declare function parsePublishCommand(args: Array<string>, options: {
|
|
3
|
+
cwd: string;
|
|
4
|
+
envContext: AukletEnvContext;
|
|
5
|
+
}): {
|
|
6
|
+
cwd: string;
|
|
7
|
+
otp: string | undefined;
|
|
8
|
+
filters: string[];
|
|
9
|
+
version: string | undefined;
|
|
10
|
+
git: boolean;
|
|
11
|
+
format: boolean;
|
|
12
|
+
dryRun: boolean;
|
|
13
|
+
allowDirty: boolean;
|
|
14
|
+
ignoreScripts: boolean;
|
|
15
|
+
token: {
|
|
16
|
+
raw: string;
|
|
17
|
+
resolve(context: AukletEnvContext): string | undefined;
|
|
18
|
+
} | undefined;
|
|
19
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import minimist from 'minimist';
|
|
2
|
+
import { booleanOption, deferredStringOption, dedupe, stringArrayOption, stringOption, stripArgsSeparator, validateNoPrefixedFlags, validateUnknownFlags, } from '#auklet/cli/parse/core';
|
|
3
|
+
const publishFlags = new Set([
|
|
4
|
+
'_',
|
|
5
|
+
'filter',
|
|
6
|
+
'workspace',
|
|
7
|
+
'version',
|
|
8
|
+
'dry-run',
|
|
9
|
+
'format',
|
|
10
|
+
'git',
|
|
11
|
+
'otp',
|
|
12
|
+
'token',
|
|
13
|
+
'ignore-scripts',
|
|
14
|
+
'allow-dirty',
|
|
15
|
+
]);
|
|
16
|
+
export function parsePublishCommand(args, options) {
|
|
17
|
+
const argv = parsePublishArgs(args);
|
|
18
|
+
if (argv._.length) {
|
|
19
|
+
throw new Error(`[publish] unknown publish argument: ${argv._.join(' ')}`);
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
cwd: options.cwd,
|
|
23
|
+
otp: stringOption(argv.otp, '--otp', options.envContext),
|
|
24
|
+
filters: resolvePublishFilters(argv, options.envContext),
|
|
25
|
+
version: stringOption(argv.version, '--version', options.envContext),
|
|
26
|
+
git: booleanOption(argv.git, '--git', options.envContext, true),
|
|
27
|
+
format: booleanOption(argv.format, '--format', options.envContext, true),
|
|
28
|
+
dryRun: booleanOption(argv['dry-run'], '--dry-run', options.envContext),
|
|
29
|
+
allowDirty: booleanOption(argv['allow-dirty'], '--allow-dirty', options.envContext),
|
|
30
|
+
ignoreScripts: booleanOption(argv['ignore-scripts'], '--ignore-scripts', options.envContext),
|
|
31
|
+
token: deferredStringOption(argv.token, '--token'),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const parsePublishArgs = (args) => {
|
|
35
|
+
const cliArgs = stripArgsSeparator(args);
|
|
36
|
+
validateNoPrefixedFlags(cliArgs, new Set(['--no-format', '--no-git']), 'publish');
|
|
37
|
+
const argv = minimist(cliArgs, {
|
|
38
|
+
string: [
|
|
39
|
+
'filter',
|
|
40
|
+
'version',
|
|
41
|
+
'otp',
|
|
42
|
+
'token',
|
|
43
|
+
'dry-run',
|
|
44
|
+
'format',
|
|
45
|
+
'git',
|
|
46
|
+
'ignore-scripts',
|
|
47
|
+
'allow-dirty',
|
|
48
|
+
],
|
|
49
|
+
boolean: ['workspace'],
|
|
50
|
+
});
|
|
51
|
+
validateUnknownFlags(argv, publishFlags, 'publish');
|
|
52
|
+
return argv;
|
|
53
|
+
};
|
|
54
|
+
const resolvePublishFilters = (argv, envContext) => {
|
|
55
|
+
const filters = stringArrayOption(argv.filter, '--filter', envContext);
|
|
56
|
+
if (booleanOption(argv.workspace, '--workspace', envContext)) {
|
|
57
|
+
filters.push('*');
|
|
58
|
+
}
|
|
59
|
+
return dedupe(filters);
|
|
60
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AukletEnvContext } from '#auklet/env';
|
|
2
|
+
export type WorkspaceSelection = {
|
|
3
|
+
filters: Array<string>;
|
|
4
|
+
includePrivate: boolean;
|
|
5
|
+
includeDependencies: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function parseWorkspaceSelectionArgs(args: Array<string>, envContext: AukletEnvContext): {
|
|
8
|
+
remainingArgs: string[];
|
|
9
|
+
workspace: {
|
|
10
|
+
filters: string[];
|
|
11
|
+
includeDependencies: boolean;
|
|
12
|
+
includePrivate: boolean;
|
|
13
|
+
};
|
|
14
|
+
};
|