@jskit-ai/jskit-cli 0.2.11 → 0.2.12
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 +3 -2
- package/src/server/argParser.js +187 -0
- package/src/server/cliEntrypoint.js +1 -14
- package/src/server/cliError.js +1 -8
- package/src/server/cliRuntime.js +4359 -0
- package/src/server/index.js +1 -4604
- package/src/server/optionInterpolation.js +19 -7
- package/src/server/runCli.js +103 -0
- package/src/server/runtimeDeps.js +55 -0
|
@@ -116,14 +116,27 @@ function wordsToKebab(words) {
|
|
|
116
116
|
.join("-");
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
function
|
|
119
|
+
function resolveLastWordMutationInput(value) {
|
|
120
120
|
const words = splitTextIntoWords(value);
|
|
121
121
|
if (words.length < 1) {
|
|
122
|
-
return
|
|
122
|
+
return null;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
const lastIndex = words.length - 1;
|
|
126
|
-
|
|
126
|
+
return {
|
|
127
|
+
words,
|
|
128
|
+
lastIndex,
|
|
129
|
+
last: words[lastIndex]
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function toSingularForm(value) {
|
|
134
|
+
const input = resolveLastWordMutationInput(value);
|
|
135
|
+
if (!input) {
|
|
136
|
+
return "";
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const { words, lastIndex, last } = input;
|
|
127
140
|
if (!last) {
|
|
128
141
|
return wordsToKebab(words);
|
|
129
142
|
}
|
|
@@ -145,13 +158,12 @@ function toSingularForm(value) {
|
|
|
145
158
|
}
|
|
146
159
|
|
|
147
160
|
function toPluralForm(value) {
|
|
148
|
-
const
|
|
149
|
-
if (
|
|
161
|
+
const input = resolveLastWordMutationInput(value);
|
|
162
|
+
if (!input) {
|
|
150
163
|
return "";
|
|
151
164
|
}
|
|
152
165
|
|
|
153
|
-
const lastIndex
|
|
154
|
-
const last = words[lastIndex];
|
|
166
|
+
const { words, lastIndex, last } = input;
|
|
155
167
|
if (!last) {
|
|
156
168
|
return wordsToKebab(words);
|
|
157
169
|
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
function createRunCli({
|
|
2
|
+
parseArgs,
|
|
3
|
+
printUsage,
|
|
4
|
+
commandHandlers,
|
|
5
|
+
cleanupMaterializedPackageRoots,
|
|
6
|
+
createCliError
|
|
7
|
+
} = {}) {
|
|
8
|
+
if (typeof parseArgs !== "function") {
|
|
9
|
+
throw new TypeError("createRunCli requires parseArgs.");
|
|
10
|
+
}
|
|
11
|
+
if (typeof printUsage !== "function") {
|
|
12
|
+
throw new TypeError("createRunCli requires printUsage.");
|
|
13
|
+
}
|
|
14
|
+
if (!commandHandlers || typeof commandHandlers !== "object") {
|
|
15
|
+
throw new TypeError("createRunCli requires commandHandlers.");
|
|
16
|
+
}
|
|
17
|
+
if (typeof cleanupMaterializedPackageRoots !== "function") {
|
|
18
|
+
throw new TypeError("createRunCli requires cleanupMaterializedPackageRoots.");
|
|
19
|
+
}
|
|
20
|
+
if (typeof createCliError !== "function") {
|
|
21
|
+
throw new TypeError("createRunCli requires createCliError.");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return async function runCli(argv = process.argv.slice(2), io = {}) {
|
|
25
|
+
const cwd = io.cwd || process.cwd();
|
|
26
|
+
const stdin = io.stdin || process.stdin;
|
|
27
|
+
const stdout = io.stdout || process.stdout;
|
|
28
|
+
const stderr = io.stderr || process.stderr;
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const { command, options, positional } = parseArgs(argv, { createCliError });
|
|
32
|
+
if (options.help || command === "help") {
|
|
33
|
+
printUsage(stdout);
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (command === "create") {
|
|
38
|
+
return await commandHandlers.commandCreate({
|
|
39
|
+
positional,
|
|
40
|
+
options,
|
|
41
|
+
cwd,
|
|
42
|
+
io: { stdin, stdout, stderr }
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (command === "list") {
|
|
46
|
+
return await commandHandlers.commandList({ positional, options, cwd, stdout });
|
|
47
|
+
}
|
|
48
|
+
if (command === "show") {
|
|
49
|
+
return await commandHandlers.commandShow({ positional, options, stdout });
|
|
50
|
+
}
|
|
51
|
+
if (command === "add") {
|
|
52
|
+
return await commandHandlers.commandAdd({
|
|
53
|
+
positional,
|
|
54
|
+
options,
|
|
55
|
+
cwd,
|
|
56
|
+
io: { stdin, stdout, stderr }
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (command === "position") {
|
|
60
|
+
return await commandHandlers.commandPosition({
|
|
61
|
+
positional,
|
|
62
|
+
options,
|
|
63
|
+
cwd,
|
|
64
|
+
io: { stdin, stdout, stderr }
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (command === "update") {
|
|
68
|
+
return await commandHandlers.commandUpdate({
|
|
69
|
+
positional,
|
|
70
|
+
options,
|
|
71
|
+
cwd,
|
|
72
|
+
io: { stdin, stdout, stderr }
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (command === "remove") {
|
|
76
|
+
return await commandHandlers.commandRemove({
|
|
77
|
+
positional,
|
|
78
|
+
options,
|
|
79
|
+
cwd,
|
|
80
|
+
io: { stdin, stdout, stderr }
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (command === "doctor") {
|
|
84
|
+
return await commandHandlers.commandDoctor({ cwd, options, stdout });
|
|
85
|
+
}
|
|
86
|
+
if (command === "lint-descriptors") {
|
|
87
|
+
return await commandHandlers.commandLintDescriptors({ options, stdout });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
throw createCliError(`Unhandled command: ${command}`, { showUsage: true });
|
|
91
|
+
} catch (error) {
|
|
92
|
+
stderr.write(`jskit: ${error?.message || String(error)}\n`);
|
|
93
|
+
if (error?.showUsage) {
|
|
94
|
+
printUsage(stderr);
|
|
95
|
+
}
|
|
96
|
+
return 1;
|
|
97
|
+
} finally {
|
|
98
|
+
await cleanupMaterializedPackageRoots();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { createRunCli };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
function createCommandHandlerDeps(deps = {}) {
|
|
2
|
+
return {
|
|
3
|
+
createCliError: deps.createCliError,
|
|
4
|
+
createColorFormatter: deps.createColorFormatter,
|
|
5
|
+
resolveWrapWidth: deps.resolveWrapWidth,
|
|
6
|
+
writeWrappedItems: deps.writeWrappedItems,
|
|
7
|
+
normalizeRelativePath: deps.normalizeRelativePath,
|
|
8
|
+
normalizeRelativePosixPath: deps.normalizeRelativePosixPath,
|
|
9
|
+
resolveAppRootFromCwd: deps.resolveAppRootFromCwd,
|
|
10
|
+
loadLockFile: deps.loadLockFile,
|
|
11
|
+
loadPackageRegistry: deps.loadPackageRegistry,
|
|
12
|
+
loadBundleRegistry: deps.loadBundleRegistry,
|
|
13
|
+
loadAppLocalPackageRegistry: deps.loadAppLocalPackageRegistry,
|
|
14
|
+
mergePackageRegistries: deps.mergePackageRegistries,
|
|
15
|
+
resolvePackageIdInput: deps.resolvePackageIdInput,
|
|
16
|
+
resolveInstalledPackageIdInput: deps.resolveInstalledPackageIdInput,
|
|
17
|
+
resolveInstalledNodeModulePackageEntry: deps.resolveInstalledNodeModulePackageEntry,
|
|
18
|
+
hydratePackageRegistryFromInstalledNodeModules: deps.hydratePackageRegistryFromInstalledNodeModules,
|
|
19
|
+
validateInlineOptionsForPackage: deps.validateInlineOptionsForPackage,
|
|
20
|
+
resolveLocalDependencyOrder: deps.resolveLocalDependencyOrder,
|
|
21
|
+
validatePlannedCapabilityClosure: deps.validatePlannedCapabilityClosure,
|
|
22
|
+
resolvePackageOptions: deps.resolvePackageOptions,
|
|
23
|
+
applyPackageInstall: deps.applyPackageInstall,
|
|
24
|
+
applyPackagePositioning: deps.applyPackagePositioning,
|
|
25
|
+
adoptAppLocalPackageDependencies: deps.adoptAppLocalPackageDependencies,
|
|
26
|
+
loadAppPackageJson: deps.loadAppPackageJson,
|
|
27
|
+
resolveLocalPackageId: deps.resolveLocalPackageId,
|
|
28
|
+
createLocalPackageScaffoldFiles: deps.createLocalPackageScaffoldFiles,
|
|
29
|
+
fileExists: deps.fileExists,
|
|
30
|
+
applyPackageJsonField: deps.applyPackageJsonField,
|
|
31
|
+
toFileDependencySpecifier: deps.toFileDependencySpecifier,
|
|
32
|
+
writeJsonFile: deps.writeJsonFile,
|
|
33
|
+
writeFile: deps.writeFile,
|
|
34
|
+
mkdir: deps.mkdir,
|
|
35
|
+
path: deps.path,
|
|
36
|
+
inspectPackageOfferings: deps.inspectPackageOfferings,
|
|
37
|
+
buildFileWriteGroups: deps.buildFileWriteGroups,
|
|
38
|
+
listDeclaredCapabilities: deps.listDeclaredCapabilities,
|
|
39
|
+
buildCapabilityDetailsForPackage: deps.buildCapabilityDetailsForPackage,
|
|
40
|
+
formatPackageSubpathImport: deps.formatPackageSubpathImport,
|
|
41
|
+
normalizePlacementOutlets: deps.normalizePlacementOutlets,
|
|
42
|
+
normalizePlacementContributions: deps.normalizePlacementContributions,
|
|
43
|
+
shouldShowPackageExportTarget: deps.shouldShowPackageExportTarget,
|
|
44
|
+
classifyExportedSymbols: deps.classifyExportedSymbols,
|
|
45
|
+
deriveProviderDisplayName: deps.deriveProviderDisplayName,
|
|
46
|
+
restorePackageJsonField: deps.restorePackageJsonField,
|
|
47
|
+
readFileBufferIfExists: deps.readFileBufferIfExists,
|
|
48
|
+
removeEnvValue: deps.removeEnvValue,
|
|
49
|
+
removeManagedViteProxyEntries: deps.removeManagedViteProxyEntries,
|
|
50
|
+
hashBuffer: deps.hashBuffer,
|
|
51
|
+
rm: deps.rm
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { createCommandHandlerDeps };
|