diff --git a/packages/core/package.json b/packages/core/package.json index 016da13..c15966a 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,11 +1,23 @@ { "name": "yakumo", "description": "Manage complex workspaces with ease", - "version": "1.0.0-beta.9", + "version": "1.0.0-beta.11", "type": "module", "main": "lib/index.js", "typings": "lib/index.d.ts", "bin": "lib/cli.js", + "exports": { + ".": "./lib/index.js", + "./cli": "./lib/cli.js", + "./utils": "./lib/utils.js", + "./list": "./lib/plugins/list.js", + "./prepare": "./lib/plugins/prepare.js", + "./publish": "./lib/plugins/publish.js", + "./test": "./lib/plugins/test.js", + "./upgrade": "./lib/plugins/upgrade.js", + "./version": "./lib/plugins/version.js", + "./package.json": "./package.json" + }, "engines": { "node": "^18.0.0 || >=20.0.0" }, @@ -36,7 +48,7 @@ "@types/yargs-parser": "^21.0.3" }, "dependencies": { - "cordis": "^3.8.0", + "cordis": "^3.13.2", "cosmokit": "^1.5.2", "detect-indent": "^6.1.0", "execa": "^5.1.1", diff --git a/packages/core/src/cli.ts b/packages/core/src/cli.ts index 94dbb04..ee21ccc 100644 --- a/packages/core/src/cli.ts +++ b/packages/core/src/cli.ts @@ -13,4 +13,17 @@ for (let i = 2; i < process.argv.length; i++) { --i } -await start({ name: 'yakumo' }) +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' }, + ], + }, +}) diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 975da30..009aacd 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -6,18 +6,7 @@ import { manager, spawnAsync } from './utils.js' import kleur from 'kleur' import { promises as fs, readFileSync } from 'node:fs' import { Dict, makeArray } from 'cosmokit' -import list from './plugins/list.js' -import prepare from './plugins/prepare.js' -import publish from './plugins/publish.js' -import test from './plugins/test.js' -import upgrade from './plugins/upgrade.js' -import version from './plugins/version.js' - -export * from './plugins/prepare.js' -export * from './plugins/publish.js' -export * from './plugins/test.js' -export * from './plugins/upgrade.js' -export * from './plugins/version.js' + export * from './utils.js' export const cwd = process.cwd() @@ -73,8 +62,9 @@ export interface Context { } export class Context extends cordis.Context { - constructor(config: any) { + constructor(config?: any) { super(config) + this.provide('yakumo', undefined, true) this.plugin(Yakumo, config) } } @@ -96,7 +86,16 @@ export namespace Yakumo { } } -export default class Yakumo { +const builtin = [ + 'list', + 'prepare', + 'publish', + 'test', + 'upgrade', + 'version', +] + +export default class Yakumo extends cordis.Service { cwd: string args = process.argv.slice(2) argv!: Arguments @@ -105,20 +104,12 @@ export default class Yakumo { indent = detect(content).indent commands: Dict = {} - constructor(ctx: Context, public config: Yakumo.Config) { - ctx.provide('yakumo', undefined, true) + constructor(public ctx: Context, public config: Yakumo.Config) { + super(ctx, 'yakumo', true) ctx.mixin('yakumo', ['register']) - ctx.yakumo = this this.cwd = cwd this.manager = manager - ctx.plugin(list) - ctx.plugin(prepare) - ctx.plugin(publish) - ctx.plugin(test) - ctx.plugin(upgrade) - ctx.plugin(version) - for (const name in config.pipeline || {}) { this.register(name, async () => { const tasks = config.pipeline![name] @@ -128,8 +119,6 @@ export default class Yakumo { } }) } - - ctx.on('ready', () => this.start()) } register(name: string, callback: () => void, options: Options = {}) { @@ -156,7 +145,7 @@ export default class Yakumo { } resolveIntercept(): Yakumo.Intercept { - const caller: Context = this[Context.current] + const caller = this[Context.current] let result = this.config let intercept = caller[Context.intercept] while (intercept) { @@ -224,7 +213,16 @@ export default class Yakumo { } async execute(name: string, ...args: string[]) { + await this.ctx.events.flush() if (!this.commands[name]) { + if (builtin.includes(name)) { + this.ctx.loader.config.push({ + 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) } @@ -241,7 +239,7 @@ export default class Yakumo { console.log('yakumo') process.exit(0) } - await this.execute(this.args[0]) + this.execute(this.args[0]) } async install() { diff --git a/packages/core/src/plugins/list.ts b/packages/core/src/plugins/list.ts index 9f69135..5644a1c 100644 --- a/packages/core/src/plugins/list.ts +++ b/packages/core/src/plugins/list.ts @@ -8,7 +8,9 @@ interface Node { tree: Dict } -export default function apply(ctx: Context) { +export const inject = ['yakumo'] + +export function apply(ctx: Context) { function createNode(path: string): Node { return { name: ctx.yakumo.workspaces[path].name, path, children: [], tree: {} } } diff --git a/packages/core/src/plugins/prepare.ts b/packages/core/src/plugins/prepare.ts index 83d3931..829f55f 100644 --- a/packages/core/src/plugins/prepare.ts +++ b/packages/core/src/plugins/prepare.ts @@ -1,7 +1,9 @@ import { Context } from '../index.js' import picomatch from 'picomatch' -export default function apply(ctx: Context) { +export const inject = ['yakumo'] + +export function apply(ctx: Context) { ctx.register('prepare', async () => { const { workspaces } = ctx.yakumo.workspaces[''] const current = new Set(workspaces) diff --git a/packages/core/src/plugins/publish.ts b/packages/core/src/plugins/publish.ts index 54728d2..b93b771 100644 --- a/packages/core/src/plugins/publish.ts +++ b/packages/core/src/plugins/publish.ts @@ -53,7 +53,9 @@ async function serial(list: S[], fn: (item: S) => Promise) { for (const item of list) await fn(item) } -export default function apply(ctx: Context) { +export const inject = ['yakumo'] + +export function apply(ctx: Context) { ctx.register('publish', async () => { const { argv } = ctx.yakumo const spinner = ora() diff --git a/packages/core/src/plugins/test.ts b/packages/core/src/plugins/test.ts index 6845834..6ee6381 100644 --- a/packages/core/src/plugins/test.ts +++ b/packages/core/src/plugins/test.ts @@ -4,7 +4,9 @@ import parse from 'yargs-parser' import unparse from 'yargs-unparser' import globby from 'globby' -export default function apply(ctx: Context) { +export const inject = ['yakumo'] + +export function apply(ctx: Context) { ctx.register('test', async () => { function getFiles(names: string[]) { if (!names.length) return ['**/tests/*.spec.ts'] diff --git a/packages/core/src/plugins/upgrade.ts b/packages/core/src/plugins/upgrade.ts index a67d7e0..23440ad 100644 --- a/packages/core/src/plugins/upgrade.ts +++ b/packages/core/src/plugins/upgrade.ts @@ -15,7 +15,9 @@ declare module '../index.js' { } } -export default function apply(ctx: Context, config: Config = {}) { +export const inject = ['yakumo'] + +export function apply(ctx: Context, config: Config = {}) { ctx.register('upgrade', async () => { const paths = ctx.yakumo.locate(ctx.yakumo.argv._, { includeRoot: true }) const { manager } = ctx.yakumo diff --git a/packages/core/src/plugins/version.ts b/packages/core/src/plugins/version.ts index 4c2a742..eed0284 100644 --- a/packages/core/src/plugins/version.ts +++ b/packages/core/src/plugins/version.ts @@ -146,7 +146,9 @@ class Graph { } } -export default function apply(ctx: Context) { +export const inject = ['yakumo'] + +export function apply(ctx: Context) { ctx.register('version', async () => { if (!ctx.yakumo.argv._.length) { const yes = await confirm('You did not specify any packages to bump. Do you want to bump all the packages?') diff --git a/tsconfig.json b/tsconfig.json index 40580e9..a03daa5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,10 @@ "compilerOptions": { "baseUrl": ".", "paths": { - "yakumo": ["packages/core/src"], + "yakumo": [ + "packages/core/src", + "packages/core/src/plugins", + ], "yakumo-*": ["packages/*/src"], "@yakumojs/*": ["packages/*/src"], },