Skip to content

Commit

Permalink
feat(core): support experimental hooks, fix #23
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Aug 13, 2024
1 parent 5bd357d commit 6fe266b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
17 changes: 13 additions & 4 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ export default class Yakumo extends cordis.Service<Yakumo.Config, Context> {
this.commands[name] = [callback, options]
}

async initialize(argv: Arguments) {
this.argv = argv
async initialize() {
const folders = await globby(meta.workspaces || [], {
cwd,
onlyDirectories: true,
Expand Down Expand Up @@ -235,10 +234,20 @@ export default class Yakumo extends cordis.Service<Yakumo.Config, Context> {
}

const [callback, options] = this.commands[name]
const index = args.indexOf('--')
const rest = index === -1 ? [] : args.splice(index + 1)
const argv = yargs(args, options) as Arguments
argv['--'] = rest
await this.initialize()
if (!name.startsWith('yakumo:') && name !== 'run') {
await this.execute('run', ...argv._, '--', `yakumo:before:${name}`)
}
argv.config = options
await this.initialize(argv)
return callback(...args)
this.argv = argv
await callback(...args)
if (!name.startsWith('yakumo:') && name !== 'run') {
await this.execute('run', ...argv._.slice(0, index === -1 ? undefined : index), '--', `yakumo:after:${name}`)
}
}

async start() {
Expand Down
11 changes: 5 additions & 6 deletions packages/core/src/plugins/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ 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 [command, ...rest] = argv['--'] as string[]
if (!command) throw new Error('Missing command')
const paths = ctx.yakumo.locate(argv._, {
filter: (meta) => !!meta.scripts?.[command],
filter: () => true,
}).filter(path => {
return !!ctx.yakumo.workspaces[path].scripts?.[command]
})
for (const path of paths) {
const agent = manager?.name || 'npm'
Expand Down

0 comments on commit 6fe266b

Please sign in to comment.