Skip to content

Commit 47bea93

Browse files
committed
feat(core): Added the state built-in module
1 parent 8b41e3a commit 47bea93

66 files changed

Lines changed: 3079 additions & 1538 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

eslint.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,8 @@ export default defineConfig({
2525
name: "shell-shock",
2626
nx: {
2727
depsCheck: false
28+
},
29+
tsdoc: {
30+
configFile: "@powerlines/tsdoc/recommended.json"
2831
}
2932
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"@nx/workspace": "catalog:",
6565
"@powerlines/nx": "catalog:",
6666
"@powerlines/tsconfig": "catalog:",
67+
"@powerlines/tsdoc": "catalog:",
6768
"@storm-software/config": "catalog:",
6869
"@storm-software/config-tools": "catalog:",
6970
"@storm-software/cspell": "catalog:",

packages/core/package.json

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,34 @@
138138
"default": "./dist/components/options-parser-logic.mjs"
139139
}
140140
},
141+
"./components/spawn-builtin": {
142+
"require": {
143+
"types": "./dist/components/spawn-builtin.d.cts",
144+
"default": "./dist/components/spawn-builtin.cjs"
145+
},
146+
"import": {
147+
"types": "./dist/components/spawn-builtin.d.mts",
148+
"default": "./dist/components/spawn-builtin.mjs"
149+
},
150+
"default": {
151+
"types": "./dist/components/spawn-builtin.d.mts",
152+
"default": "./dist/components/spawn-builtin.mjs"
153+
}
154+
},
155+
"./components/state-builtin": {
156+
"require": {
157+
"types": "./dist/components/state-builtin.d.cts",
158+
"default": "./dist/components/state-builtin.cjs"
159+
},
160+
"import": {
161+
"types": "./dist/components/state-builtin.d.mts",
162+
"default": "./dist/components/state-builtin.mjs"
163+
},
164+
"default": {
165+
"types": "./dist/components/state-builtin.d.mts",
166+
"default": "./dist/components/state-builtin.mjs"
167+
}
168+
},
141169
"./components/usage": {
142170
"require": {
143171
"types": "./dist/components/usage.d.cts",
@@ -334,20 +362,6 @@
334362
"types": "./dist/types/options.d.mts",
335363
"default": "./dist/types/options.mjs"
336364
}
337-
},
338-
"./types/runtime": {
339-
"require": {
340-
"types": "./dist/types/runtime.d.cts",
341-
"default": "./dist/types/runtime.cjs"
342-
},
343-
"import": {
344-
"types": "./dist/types/runtime.d.mts",
345-
"default": "./dist/types/runtime.mjs"
346-
},
347-
"default": {
348-
"types": "./dist/types/runtime.d.mts",
349-
"default": "./dist/types/runtime.mjs"
350-
}
351365
}
352366
},
353367
"main": "./dist/index.cjs",

packages/core/src/api.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ import type {
2222
DocsInlineConfig,
2323
LintInlineConfig,
2424
PluginConfig,
25-
PowerlinesAPI,
2625
PrepareInlineConfig
2726
} from "powerlines";
28-
import { createPowerlines } from "powerlines";
27+
import { createPowerlines, PowerlinesAPI } from "powerlines";
2928
import { plugin } from "./plugin";
3029
import type { UserConfig } from "./types/config";
3130

@@ -38,12 +37,19 @@ import type { UserConfig } from "./types/config";
3837
export class ShellShockAPI {
3938
#powerlines: PowerlinesAPI;
4039

41-
public static async from(config: UserConfig = {}): Promise<ShellShockAPI> {
42-
const powerlines = await createPowerlines({
40+
public static async from(
41+
config: UserConfig,
42+
workspaceRoot?: string
43+
): Promise<ShellShockAPI> {
44+
const userConfig = {
4345
framework: "shell-shock",
4446
...config,
4547
plugins: [plugin(), ...(config.plugins ?? [])] as PluginConfig<any>[]
46-
});
48+
};
49+
50+
const powerlines = await (workspaceRoot
51+
? PowerlinesAPI.from(workspaceRoot, userConfig)
52+
: createPowerlines(userConfig));
4753

4854
return new ShellShockAPI(powerlines);
4955
}
@@ -86,7 +92,5 @@ export class ShellShockAPI {
8692
export async function createShellShock(
8793
options: Partial<UserConfig> = {}
8894
): Promise<ShellShockAPI> {
89-
options.root ??= process.cwd();
90-
91-
return ShellShockAPI.from(options);
95+
return ShellShockAPI.from({ root: process.cwd(), ...options });
9296
}

packages/core/src/components/helpers.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,6 @@ export function CommandParameterType(props: { parameter: CommandParameter }) {
119119
? "number"
120120
: "string"
121121
}${
122-
(parameter.kind === CommandParameterKinds.string ||
123-
parameter.kind === CommandParameterKinds.number) &&
124-
parameter.variadic
125-
? "[]"
126-
: ""
122+
parameter.variadic ? "[]" : ""
127123
}${parameter.optional ? " | undefined" : ""}`;
128124
}

packages/core/src/components/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ export * from "./command-validation-logic";
2020
export * from "./docs";
2121
export * from "./helpers";
2222
export * from "./options-parser-logic";
23+
export * from "./spawn-builtin";
24+
export * from "./state-builtin";
2325
export * from "./usage";
2426
export * from "./utils-builtin";

packages/core/src/components/options-parser-logic.tsx

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -212,22 +212,20 @@ export function ArgumentsParserLogic(props: ArgumentsParserLogicProps) {
212212
type={<CommandParameterType parameter={arg} />}
213213
initializer={
214214
<>
215+
{code` ( `}
215216
<Show when={isSetString(arg.env)}>
216217
{code`env.${appSpecificEnvPrefix}_${constantCase(String(arg.env))} ?? `}
217218
</Show>
218219
<Show
219220
when={arg.default !== undefined}
220-
fallback={
221-
(arg.kind === CommandParameterKinds.string ||
222-
arg.kind === CommandParameterKinds.number) &&
223-
arg.variadic
224-
? code`[]`
225-
: code`undefined;`
226-
}>
221+
fallback={arg.variadic ? code`[]` : code`undefined`}>
227222
{arg.kind === CommandParameterKinds.string
228223
? code`"${arg.default}"`
229224
: code`${arg.default}`}
230225
</Show>
226+
{code`) as `}
227+
<CommandParameterType parameter={arg} />
228+
{code`; `}
231229
</>
232230
}
233231
/>
@@ -247,16 +245,12 @@ export function ArgumentsParserLogic(props: ArgumentsParserLogicProps) {
247245
/>
248246
}>
249247
<Show
250-
when={
251-
(arg.kind === CommandParameterKinds.string ||
252-
arg.kind === CommandParameterKinds.number) &&
253-
arg.variadic
254-
}
248+
when={arg.variadic}
255249
fallback={
256250
<Show
257251
when={arg.kind === CommandParameterKinds.number}
258-
fallback={code`args[argsIndex + ${index}]; `}>
259-
{code`Number(args[argsIndex + ${index}]); `}
252+
fallback={code`args[argsIndex + ${index}] `}>
253+
{code`Number(args[argsIndex + ${index}]) `}
260254
</Show>
261255
}>
262256
{code`args.slice(argsIndex + ${
@@ -266,6 +260,9 @@ export function ArgumentsParserLogic(props: ArgumentsParserLogicProps) {
266260
}).join(" ").split(",").map(item => item.trim().replace(/^("|')/, "").replace(/("|')$/, "")).filter(Boolean)`}
267261
</Show>
268262
</Show>
263+
{code` as `}
264+
<CommandParameterType parameter={arg} />
265+
{code`; `}
269266
</IfStatement>
270267
<Spacing />
271268
</>
@@ -654,10 +651,20 @@ export function OptionsMemberParserCondition(
654651
export function OptionsInterfaceDeclaration(props: { command: CommandTree }) {
655652
const { command } = props;
656653

657-
const options = computed(() => computedOptions(command));
654+
const options = computed(() =>
655+
computedOptions(
656+
Object.entries(command.options).map(([name, option]) => ({
657+
...option,
658+
name
659+
}))
660+
)
661+
);
658662

659663
return (
660-
<InterfaceDeclaration export name={`${pascalCase(command.name)}Options`}>
664+
<InterfaceDeclaration
665+
export
666+
name={`${pascalCase(command.name)}Options`}
667+
extends="GlobalOptions">
661668
<For each={Object.values(options.value)} hardline>
662669
{option => <OptionsMember option={option} />}
663670
</For>
@@ -690,7 +697,14 @@ export interface OptionsParserLogicProps {
690697
export function OptionsParserLogic(props: OptionsParserLogicProps) {
691698
const { command, appSpecificEnvPrefix, isCaseSensitive = false } = props;
692699

693-
const options = computed(() => computedOptions(command));
700+
const options = computed(() =>
701+
computedOptions(
702+
Object.entries(command.options).map(([name, option]) => ({
703+
...option,
704+
name
705+
}))
706+
)
707+
);
694708

695709
return (
696710
<>
@@ -755,7 +769,7 @@ export function OptionsParserLogic(props: OptionsParserLogicProps) {
755769
return "";
756770
})
757771
.join("")}
758-
} as ${pascalCase(command.name)}Options;`}
772+
} as unknown as ${pascalCase(command.name)}Options;`}
759773
/>
760774
<Spacing />
761775
{code`for (let i = 0; i < args.slice(${

0 commit comments

Comments
 (0)