Skip to content

Commit

Permalink
feat(core): detect cli env, upgrade cordis
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed May 3, 2024
1 parent 81bd683 commit 80985be
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
27 changes: 24 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,36 @@
"cli",
"script"
],
"cordis": {
"ecosystem": {
"inject": [
"yakumo"
],
"pattern": [
"yakumo-*"
]
},
"exports": {
"./list": {},
"./prepare": {},
"./publish": {},
"./test": {},
"./upgrade": {},
"./version": {}
}
},
"devDependencies": {
"@types/picomatch": "^2.3.3",
"@types/prompts": "^2.4.9",
"@types/which-pm-runs": "^1.0.2",
"@types/yargs-parser": "^21.0.3"
},
"peerDependencies": {
"cordis": "^3.14.0"
},
"dependencies": {
"cordis": "^3.13.3",
"cosmokit": "^1.5.2",
"cordis": "^3.14.0",
"cosmokit": "^1.6.2",
"detect-indent": "^6.1.0",
"execa": "^5.1.1",
"get-registry": "^1.1.0",
Expand All @@ -60,7 +81,7 @@
"p-map": "^4.0.0",
"picomatch": "^2.3.1",
"prompts": "^2.4.2",
"semver": "^7.5.4",
"semver": "^7.6.0",
"which-pm-runs": "^1.1.0",
"yargs-parser": "^21.1.1",
"yargs-unparser": "^2.0.0"
Expand Down
20 changes: 9 additions & 11 deletions packages/core/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ for (let i = 2; i < process.argv.length; i++) {

await start({
name: 'yakumo',
fallback: {
config: [
{ name: 'yakumo' },
{ name: 'yakumo/list' },
{ name: 'yakumo/prepare' },
{ name: 'yakumo/publish' },
{ name: 'yakumo/test' },
{ name: 'yakumo/upgrade' },
{ name: 'yakumo/version' },
],
},
initial: [
{ name: 'yakumo' },
{ name: 'yakumo/list' },
{ name: 'yakumo/prepare' },
{ name: 'yakumo/publish' },
{ name: 'yakumo/test' },
{ name: 'yakumo/upgrade' },
{ name: 'yakumo/version' },
],
})
21 changes: 10 additions & 11 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ const builtin = [

export default class Yakumo extends cordis.Service<Yakumo.Config, Context> {
cwd: string
args = process.argv.slice(2)
argv!: Arguments
manager: Manager
workspaces!: Dict<PackageJson>
Expand All @@ -111,11 +110,11 @@ export default class Yakumo extends cordis.Service<Yakumo.Config, Context> {
this.manager = manager

for (const name in config.pipeline || {}) {
this.register(name, async () => {
this.register(name, async (...rest: any[]) => {
const tasks = config.pipeline![name]
for (const task of tasks) {
const [name, ...args] = task.split(/\s+/g)
await this.execute(name, ...args)
await this.execute(name, ...args, ...rest)
}
})
}
Expand Down Expand Up @@ -216,30 +215,30 @@ export default class Yakumo extends cordis.Service<Yakumo.Config, Context> {
await this.ctx.events.flush()
if (!this.commands[name]) {
if (builtin.includes(name)) {
this.ctx.loader.config.push({
await this.ctx.loader.create({
name: 'yakumo/' + name,
} as any)
await this.ctx.loader.writeConfig()
await this.ctx.loader.start()
})
return this.execute(name, ...args)
}
console.error(kleur.red(`unknown command: ${name}`))
process.exit(1)
}

const [callback, options] = this.commands[name]
const argv = yargs([...this.args.slice(1), ...args], options) as Arguments
const argv = yargs(args, options) as Arguments
argv.config = options
await this.initialize(argv)
return callback()
return callback(...args)
}

async start() {
if (!this.args.length) {
if (this.ctx.get('loader')?.options.name !== 'yakumo') return
const [name, ...args] = process.argv.slice(2)
if (!name) {
console.log('yakumo')
process.exit(0)
}
this.execute(this.args[0])
this.execute(name, ...args)
}

async install() {
Expand Down

0 comments on commit 80985be

Please sign in to comment.