-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(core): replace commander and ts-command-line-args with cli-forge
- Loading branch information
1 parent
53267eb
commit 1b77803
Showing
25 changed files
with
806 additions
and
828 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
}); | ||
} | ||
}), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}), | ||
); |
Oops, something went wrong.