Skip to content

Commit

Permalink
chore: update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
adbayb committed Nov 17, 2024
1 parent 838b409 commit c70ebcd
Show file tree
Hide file tree
Showing 11 changed files with 1,256 additions and 340 deletions.
8 changes: 4 additions & 4 deletions examples/task/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ program
.task({
key: "computedFromOtherTaskValues",
label: "Task can also access other persisted task values",
async handler(context) {
handler(context) {
if (context.size > 2000) {
return Promise.resolve("big" as const);
return "big" as const;
}

return Promise.resolve("small" as const);
return "small" as const;
},
})
.task({
Expand Down Expand Up @@ -68,7 +68,7 @@ program
.task({
handler(context) {
helpers.message(
`If you don't specify a label, the handler is executed in "live mode" (the output is not hidden by the label and is displayed gradually).`,
'If you don\'t specify a label, the handler is executed in "live mode" (the output is not hidden by the label and is displayed gradually).',
{ label: "Label & console output" },
);

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"release:version": "stack release --tag",
"release:publish": "stack release --publish"
},
"packageManager": "pnpm@9.12.3",
"packageManager": "pnpm@9.13.2",
"engines": {
"node": ">=22.0.0",
"pnpm": ">=9.0.0",
Expand All @@ -25,6 +25,6 @@
},
"prettier": "@adbayb/stack/prettier",
"devDependencies": {
"@adbayb/stack": "2.0.0"
"@adbayb/stack": "2.5.0"
}
}
1,486 changes: 1,203 additions & 283 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions termost/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
"picocolors": "^1.1.1"
},
"devDependencies": {
"@types/node": "22.8.4",
"quickbundle": "2.5.2",
"vitest": "2.1.4"
"@types/node": "22.9.0",
"quickbundle": "2.8.0",
"vitest": "2.1.5"
}
}
18 changes: 9 additions & 9 deletions termost/src/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`termost > should display \`help\` 1`] = `
"
USAGE:
[37m[37m[32m[32m@examples/default[32m[37m [...options][37m[39m
[37m[37m[32m[32m@examples/default[32m[37m [options][37m[39m

DESCRIPTION:
Program description placeholder. Program name and version are retrieved from your \`package.json\`. You can override this automatic retrieval by using the \`termost({ name, description, version })\` builder form.
Expand All @@ -17,7 +17,7 @@ OPTIONS:
exports[`termost > should display \`help\` 2`] = `
"
USAGE:
[37m[37m[32m[32m@examples/default[32m[37m [...options][37m[39m
[37m[37m[32m[32m@examples/default[32m[37m [options][37m[39m

DESCRIPTION:
Program description placeholder. Program name and version are retrieved from your \`package.json\`. You can override this automatic retrieval by using the \`termost({ name, description, version })\` builder form.
Expand All @@ -31,7 +31,7 @@ OPTIONS:
exports[`termost > should display \`help\` given empty command 1`] = `
"
USAGE:
[37m[37m[32m[32m@examples/empty[32m[37m <command> [...options][37m[39m
[37m[37m[32m[32m@examples/empty[32m[37m <command> [options][37m[39m

DESCRIPTION:
Example to showcase empty \`command\` fallback
Expand All @@ -48,7 +48,7 @@ OPTIONS:
exports[`termost > should display \`help\` given empty command 2`] = `
"
USAGE:
[37m[37m[32m[32m@examples/empty build[32m[37m [...options][37m[39m
[37m[37m[32m[32m@examples/empty build[32m[37m [options][37m[39m

DESCRIPTION:
Transpile and bundle in production mode
Expand All @@ -62,7 +62,7 @@ OPTIONS:
exports[`termost > should display \`help\` given empty command 3`] = `
"
USAGE:
[37m[37m[32m[32m@examples/empty build[32m[37m [...options][37m[39m
[37m[37m[32m[32m@examples/empty build[32m[37m [options][37m[39m

DESCRIPTION:
Transpile and bundle in production mode
Expand All @@ -76,7 +76,7 @@ OPTIONS:
exports[`termost > should display \`help\` given empty command 4`] = `
"
USAGE:
[37m[37m[32m[32m@examples/empty watch[32m[37m [...options][37m[39m
[37m[37m[32m[32m@examples/empty watch[32m[37m [options][37m[39m

DESCRIPTION:
Rebuild your assets on any code change
Expand All @@ -93,7 +93,7 @@ exports[`termost > should display \`version\` 2`] = `"0.0.0"`;
exports[`termost > should handle \`command\` api 1`] = `
"
USAGE:
[37m[37m[32m[32m@examples/command[32m[37m <command> [...options][37m[39m
[37m[37m[32m[32m@examples/command[32m[37m <command> [options][37m[39m

DESCRIPTION:
Example to showcase the \`command\` API
Expand Down Expand Up @@ -177,7 +177,7 @@ exports[`termost > should handle \`command\` api 5`] = `
exports[`termost > should handle \`command\` api 6`] = `
"
USAGE:
[37m[37m[32m[32m@examples/command build[32m[37m [...options][37m[39m
[37m[37m[32m[32m@examples/command build[32m[37m [options][37m[39m

DESCRIPTION:
Transpile and bundle in production mode
Expand All @@ -192,7 +192,7 @@ OPTIONS:
exports[`termost > should handle \`command\` api 7`] = `
"
USAGE:
[37m[37m[32m[32m@examples/command watch[32m[37m [...options][37m[39m
[37m[37m[32m[32m@examples/command watch[32m[37m [options][37m[39m

DESCRIPTION:
Rebuild your assets on any code change
Expand Down
2 changes: 1 addition & 1 deletion termost/src/api/command/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const showHelp = ({
{
color: "green",
},
)} ${hasCommands ? "<command> " : ""}${hasOptions ? "[...options]" : ""}`,
)} ${hasCommands ? "<command> " : ""}${hasOptions ? "[options]" : ""}`,
);

if (description) {
Expand Down
1 change: 1 addition & 0 deletions termost/src/api/option/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const createOption =
}
}

// eslint-disable-next-line unicorn/no-useless-promise-resolve-reject
return Promise.resolve({ key, value: value ?? defaultValue });
};
};
Expand Down
15 changes: 7 additions & 8 deletions termost/src/helpers/process/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import process from "node:process";
import { spawn } from "node:child_process";

export const exec = async (
command: string,
options: ExecOptions = { hasLiveOutput: false },
) => {
export const exec = async (command: string, options: ExecOptions = {}) => {
const { cwd, hasLiveOutput = false } = options;

return new Promise<string>((resolve, reject) => {
let stdout = "";
let stderr = "";
const [bin, ...args] = command.split(" ") as [string, ...string[]];
const [bin, ...arguments_] = command.split(" ") as [string, ...string[]];

// eslint-disable-next-line sonarjs/os-command
const childProcess = spawn(bin, args, {
cwd: options.cwd,
const childProcess = spawn(bin, arguments_, {
cwd,
env: {
// eslint-disable-next-line n/no-process-env
...process.env,
// @note: make sure to force color display for spawned processes
FORCE_COLOR: "1",
},
shell: true,
stdio: options.hasLiveOutput ? "inherit" : "pipe",
stdio: hasLiveOutput ? "inherit" : "pipe",
});

childProcess.stdout?.on("data", (chunk: string) => {
Expand Down
2 changes: 1 addition & 1 deletion termost/src/helpers/stdin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const getArguments = () => {
if (shortFlagMatchResult?.name) {
flushOptimisticOption();

const optionFlags = shortFlagMatchResult.name.split("");
const optionFlags = [...shortFlagMatchResult.name];
const lastIndex = optionFlags.length - 1;

optionFlags.forEach((flag, index) => {
Expand Down
24 changes: 10 additions & 14 deletions termost/src/helpers/stdout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,23 @@ import pico from "picocolors";
*/
export const format = (
message: string,
{
color,
modifiers,
}: {
options: {
color?: Color;
modifiers?: Modifier[];
} = {
color: "white",
modifiers: [],
},
} = {},
) => {
const { color = "white", modifiers = [] } = options;
const transformers: ((input: string) => string)[] = [];

transformers.push(pico[colorMapper[color ?? "white"]]);
transformers.push(pico[colorMapper[color]]);

(modifiers ?? []).forEach((mod: Modifier) => {
if (mod === "uppercase") {
modifiers.forEach((modifier: Modifier) => {
if (modifier === "uppercase") {
message = message.toUpperCase();
} else if (mod === "lowercase") {
} else if (modifier === "lowercase") {
message = message.toLowerCase();
} else {
transformers.push(pico[modifierMapper[mod]]);
transformers.push(pico[modifierMapper[modifier]]);
}
});

Expand Down Expand Up @@ -99,7 +94,8 @@ const compose = <T>(...fns: ((a: T) => T)[]) => {
);

return fns.reduce<(a: T) => T>(
(prevFn, nextFn) => (value) => prevFn(nextFn(value)),
(previousFunction, nextFunction) => (value) =>
previousFunction(nextFunction(value)),
fns[0],
);
};
Expand Down
30 changes: 15 additions & 15 deletions termost/src/termost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ export type Termost<Values extends ObjectLikeConstraint = EmptyObject> = {
* @returns The Command API.
*/
command: <CommandValues extends ObjectLikeConstraint = EmptyObject>(
params: CommandParameters,
parameters: CommandParameters,
) => Termost<CommandValues & Values>;
input: <Key extends keyof Values>(
params: InputParameters<Values, Key>,
parameters: InputParameters<Values, Key>,
) => Termost<Values>;
option: <Key extends keyof Values>(
params: OptionParameters<Values, Key>,
parameters: OptionParameters<Values, Key>,
) => Termost<Values>;
task: <Key extends keyof Values | undefined = undefined>(
params: TaskParameters<Values, Key>,
parameters: TaskParameters<Values, Key>,
) => Termost<Values>;
};

Expand Down Expand Up @@ -75,13 +75,13 @@ export const createProgram = <Values extends ObjectLikeConstraint>(
Parameters extends InstructionParameters<ObjectLikeConstraint>,
>(
factory: CreateInstruction<Parameters>,
params: InstructionParameters<Values>,
parameters: InstructionParameters<Values>,
) => {
const instruction = factory(params as Parameters);
const instruction = factory(parameters as Parameters);
const controller = getCommandController<Values>(currentCommandName);

controller.addInstruction(async () => {
const { skip } = params;
const { skip } = parameters;
const context = controller.getContext(rootCommandName);

if (skip?.(context, argv)) return;
Expand All @@ -95,28 +95,28 @@ export const createProgram = <Values extends ObjectLikeConstraint>(
};

const program: Termost<Values> = {
command<CommandValues>(params: CommandParameters) {
currentCommandName = createCommand(params, metadata);
command<CommandValues>(parameters: CommandParameters) {
currentCommandName = createCommand(parameters, metadata);
metadata.isEmptyCommand[currentCommandName] = true; // This flag is disabled only for instructions that introduce stdio side effects (`option` instructions are so ignored).

return this as Termost<CommandValues & Values>;
},
input(params) {
createInstruction(createInput, params);
input(parameters) {
createInstruction(createInput, parameters);
metadata.isEmptyCommand[currentCommandName] = false;

return this;
},
option(params) {
option(parameters) {
createInstruction(
createOption(getCommandController(currentCommandName), metadata),
params,
parameters,
);

return this;
},
task(params) {
createInstruction(createTask, params);
task(parameters) {
createInstruction(createTask, parameters);
metadata.isEmptyCommand[currentCommandName] = false;

return this;
Expand Down

0 comments on commit c70ebcd

Please sign in to comment.