Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(core): replace commander and ts-command-line-args with cli-forge #254

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"types": "dist/index.d.ts",
"bin": "./stitch.mjs",
"scripts": {
"build": "tsc --build",
"build": "tsc --build tsconfig.json",
"clean": "rimraf build dist *.tsbuildinfo **/*.tsbuildinfo",
"test": "mocha --config ../../config/.mocharc.cjs --parallel=false --timeout=30000",
"test:dev": "mocha --config ../../config/.mocharc.cjs --forbid-only=false --parallel=false --timeout=9999999999",
Expand All @@ -68,6 +68,7 @@
"archiver": "6.0.1",
"chalk": "5.3.0",
"change-case": "5.1.2",
"cli-forge": "0.8.0",
"commander": "11.1.0",
"debug": "4.3.4",
"fs-extra": "11.1.1",
Expand Down
23 changes: 12 additions & 11 deletions packages/core/src/cli/lib/addDebugOption.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import type { Command } from 'commander';
import { debug } from '../../utility/log.js';
import { makeComposableBuilder } from 'cli-forge';

export function addDebugOptions(cli: Command) {
return cli
.option(
'--debug',
'Run in debug mode, which writes more logs to help triangulate bugs.',
)
.action(function (options) {
if (options.debug) {
export const addDebugOptions = makeComposableBuilder((cli) =>
cli
.option('debug', {
type: 'boolean',
description:
'Run in debug mode, which writes more logs to help triangulate bugs.',
})
.middleware((args) => {
if (args.debug) {
process.env.DEBUG = 'true';
debug('Running in debug mode');
}
});
}
}),
);
42 changes: 28 additions & 14 deletions packages/core/src/cli/lib/cli-options.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
import { oneline } from '@bscotch/utility';
import { makeComposableBuilder } from 'cli-forge';

export default {
force: [
'-f --force',
oneline`
export const force = makeComposableBuilder((argv) =>
argv.option('force', {
type: 'boolean',
alias: ['f'],
description: oneline`
Bypass safety checks, including the normal requirement that the project be
in a clean git state. Only use this option if you know what you're doing.
`,
],
targetProject: [
'-t --target-project <path>',
oneline`
}),
);
export const targetProject = makeComposableBuilder((argv) =>
argv.option('targetProject', {
type: 'string',
alias: ['t'],
description: oneline`
Path to the target GameMaker Studio 2 project.
If not set, will auto-search the current directory.
`,
],
watch: [
'--watch',
oneline`
}),
);
export const watch = makeComposableBuilder((argv) =>
argv.option('watch', {
type: 'boolean',
alias: ['w'],
description: oneline`
Run the command with a watcher, so that it will re-run
any time there is a change to the source files that might
warrant a re-run.
`,
],
} as const;
}),
);

export default {
force,
targetProject,
watch,
};
116 changes: 56 additions & 60 deletions packages/core/src/cli/lib/params.global.ts
Original file line number Diff line number Diff line change
@@ -1,76 +1,72 @@
import { oneline } from '@bscotch/utility';
import type { ArgumentConfig } from 'ts-command-line-args';
import type {
StitchCliGlobalParams,
StitchCliTargetParams,
} from './params.types.js';
import { makeComposableBuilder } from 'cli-forge';

const globalParamsGroup = 'General Options';

export const targetProjectParam: ArgumentConfig<{ targetProject?: string }> = {
targetProject: {
alias: 't',
type: String,
optional: true,
defaultValue: process.cwd(),
export const withTargetProjectParam = makeComposableBuilder((args) =>
args.option('targetProject', {
alias: ['t'],
type: 'string',
default: {
value: process.cwd(),
description: 'Current directory',
},
description: oneline`
Path to the target GameMaker Studio 2 project.
If not set, will auto-search the current directory.
`,
Path to the target GameMaker Studio 2 project.
If not set, will auto-search the current directory.
`,
group: globalParamsGroup,
},
};
}),
);

export const targetParams: ArgumentConfig<StitchCliTargetParams> = {
...targetProjectParam,
force: {
alias: 'f',
type: Boolean,
optional: true,
description: oneline`
Bypass safety checks, including the normal requirement that the project be
in a clean git state. Only use this option if you know what you're doing.
`,
group: globalParamsGroup,
},
readOnly: {
type: Boolean,
optional: true,
description: oneline`
Prevent any file-writes from occurring. Useful to prevent
automatic fixes from being applied and for testing purposes.
Commands may behave unexpectedly when this option is enabled.
`,
group: globalParamsGroup,
},
};
export const withTargetParams = makeComposableBuilder((args) =>
withTargetProjectParam(args)
.option('force', {
alias: ['f'],
type: 'boolean',
description: oneline`
Bypass safety checks, including the normal requirement that the project be
in a clean git state. Only use this option if you know what you're doing.
`,
group: globalParamsGroup,
})
.option('readOnly', {
type: 'boolean',
description: oneline`
Prevent any file-writes from occurring. Useful to prevent
automatic fixes from being applied and for testing purposes.
Commands may behave unexpectedly when this option is enabled.
`,
group: globalParamsGroup,
}),
);

export const watchParam: ArgumentConfig<{ watch?: boolean }> = {
watch: {
alias: 'w',
type: Boolean,
export const withWatchParam = makeComposableBuilder((args) =>
args.option('watch', {
alias: ['w'],
type: 'boolean',
optional: true,
description: oneline`
Run the command with a watcher, so that it will re-run
any time there is a change to the source files that might
warrant a re-run.
`,
group: globalParamsGroup,
},
};
}),
);

export const globalParams: ArgumentConfig<StitchCliGlobalParams> = {
help: {
alias: 'h',
type: Boolean,
optional: true,
group: globalParamsGroup,
},
debug: {
alias: 'd',
type: Boolean,
optional: true,
defaultValue: !!process.env.DEBUG,
group: globalParamsGroup,
},
};
export const withGlobalParams = makeComposableBuilder((args) =>
args
.option('help', {
alias: ['h'],
type: 'boolean',
description: 'Show help',
group: globalParamsGroup,
})
.option('debug', {
alias: ['d'],
type: 'boolean',
description: 'Run in debug mode',
group: globalParamsGroup,
}),
);
Loading