Skip to content

Commit

Permalink
feat(core): support run command
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Aug 13, 2024
1 parent f3de46d commit 80ef61d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
".": "./lib/index.js",
"./cli": "./lib/cli.js",
"./utils": "./lib/utils.js",
"./exec": "./lib/plugins/exec.js",
"./list": "./lib/plugins/list.js",
"./prepare": "./lib/plugins/prepare.js",
"./publish": "./lib/plugins/publish.js",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface PackageJson extends Partial<Record<DependencyType, Dict<string>
private?: boolean
version: string
workspaces?: string[]
scripts?: Dict<string>
yakumo?: PackageConfig
peerDependenciesMeta?: Dict<{ optional?: boolean }>
}
Expand Down Expand Up @@ -90,6 +91,7 @@ const builtin = [
'list',
'prepare',
'publish',
'run',
'test',
'upgrade',
'version',
Expand Down
21 changes: 21 additions & 0 deletions packages/core/src/plugins/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Context, manager, spawnAsync } from '../index.js'

export const inject = ['yakumo']

export function apply(ctx: Context) {
ctx.register('run', async () => {
const { argv, cwd } = ctx.yakumo
const index = argv._.indexOf('--')
if (index === -1 || index === argv._.length - 1) {
throw new Error('Missing command')
}
const [, command, ...rest] = argv._.splice(index)
const paths = ctx.yakumo.locate(argv._, {
filter: (meta) => !!meta.scripts?.[command],
})
for (const path of paths) {
const agent = manager?.name || 'npm'
await spawnAsync([agent, 'run', command, ...rest], { cwd: cwd + path })
}
})
}

0 comments on commit 80ef61d

Please sign in to comment.