mirror of
https://github.com/iconify/iconify.git
synced 2024-11-09 23:00:56 +00:00
Custom options for run command in monorepo manager
This commit is contained in:
parent
4086eb38f7
commit
fc76ac74c5
@ -49,3 +49,5 @@ Options for all commands:
|
||||
- `--silent` will execute command silently.
|
||||
- `--workspace <workspace>` or `-w=<workspace>` filters by workspace directory, such as `-w=packages/core`. You can use this option several times to specify multiple workspaces.
|
||||
- `--package <package>` or `-p=<package>` filter by package name, such as `-p=@iconify/core`. You can use this option several times to specify multiple packages.
|
||||
|
||||
You can add custom parameters for `run` or `run-script` commands by listing them after `--` argument: `run <command> -- <param1> <param2>`. Everything after `--` argument is treated as parameters for `run` command, so you need to specify other options before it.
|
||||
|
@ -26,6 +26,11 @@ const actionFunctions: Record<string, () => void> = {
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Extra parameters for `run` or `run-script`
|
||||
*/
|
||||
let runParams: string[] | undefined;
|
||||
|
||||
/**
|
||||
* Actions that require parameter
|
||||
*/
|
||||
@ -35,12 +40,13 @@ interface ActionWithParam {
|
||||
}
|
||||
const actionWithParamsFunctions: Record<string, (param: string) => void> = {
|
||||
run: (param: string) => {
|
||||
runAction(`Running "npm run ${param}"`, (workspace) => {
|
||||
const params = ['run', param].concat(runParams);
|
||||
runAction(`Running "npm ${params.join(' ')}"`, (workspace) => {
|
||||
if (
|
||||
!actionOptions.ifPresent ||
|
||||
workspace.scripts.indexOf(param) !== -1
|
||||
) {
|
||||
runNPMCommand(workspace, ['run', param]);
|
||||
runNPMCommand(workspace, params);
|
||||
}
|
||||
});
|
||||
},
|
||||
@ -56,10 +62,20 @@ export function run() {
|
||||
// List of actions
|
||||
const actions: (string | ActionWithParam)[] = [];
|
||||
|
||||
// Process args
|
||||
let args = process.argv.slice(2);
|
||||
|
||||
// Check for extra options for `run`
|
||||
const customParamsIndex = args.indexOf('--');
|
||||
if (customParamsIndex > 0) {
|
||||
runParams = args.slice(customParamsIndex);
|
||||
args = args.slice(0, customParamsIndex);
|
||||
}
|
||||
|
||||
// Process args
|
||||
let nextActionParam: string | null = null;
|
||||
let nextOptionValue: string | null = null;
|
||||
process.argv.slice(2).forEach((arg) => {
|
||||
args.forEach((arg) => {
|
||||
// Parameter for action with param
|
||||
if (nextActionParam !== null) {
|
||||
actions.push({
|
||||
|
Loading…
Reference in New Issue
Block a user