Skip to content

Commit

Permalink
feat: add toolkit binary for creating packages
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Mar 3, 2023
1 parent c72034d commit 88e959a
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
11 changes: 10 additions & 1 deletion modules/ace/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,13 @@

export { Kernel } from './kernel.js'
export { BaseCommand, ListCommand } from './commands.js'
export { args, flags, errors, Parser, FsLoader, ListLoader, HelpCommand } from '@adonisjs/ace'
export {
args,
flags,
errors,
Parser,
FsLoader,
ListLoader,
HelpCommand,
IndexGenerator,
} from '@adonisjs/ace'
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
"build/providers",
"build/services",
"build/factories",
"build/toolkit",
"build/types",
"build/src",
"build/stubs",
"build/index.d.ts",
"build/index.js"
],
"bin": {
"toolkit": "./build/toolkit/main.js"
},
"exports": {
".": "./build/index.js",
"./commands": "./build/commands/main.js",
Expand Down Expand Up @@ -89,7 +93,7 @@
"format": "prettier --write .",
"sync-labels": "github-label-sync --labels .github/labels.json adonisjs/core",
"vscode:test": "node --loader=ts-node/esm --experimental-import-meta-resolve bin/test.ts",
"index:commands": "ace-toolkit index build/commands"
"index:commands": "node --loader=ts-node/esm toolkit/main.js index build/commands"
},
"keywords": [
"adonisjs",
Expand Down
27 changes: 27 additions & 0 deletions toolkit/commands/index_commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* @adonisjs/core
*
* (c) AdonisJS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import { join } from 'node:path'
import { args, BaseCommand, IndexGenerator } from '@adonisjs/ace'

/**
* Generates index of commands with a loader. Must be called against
* the TypeScript compiled output.
*/
export default class IndexCommand extends BaseCommand {
static commandName = 'index'
static description: string = 'Create an index of commands along with a lazy loader'

@args.string({ description: 'Relative path from cwd to the commands directory' })
declare commandsDir: string

async run(): Promise<any> {
await new IndexGenerator(join(process.cwd(), this.commandsDir)).generate()
}
}
33 changes: 33 additions & 0 deletions toolkit/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env node

/*
* @adonisjs/core
*
* (c) AdonisJS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import IndexCommand from './commands/index_commands.js'
import { Kernel, ListLoader, HelpCommand } from '@adonisjs/ace'

const kernel = Kernel.create()
kernel.addLoader(new ListLoader([IndexCommand]))

kernel.defineFlag('help', {
type: 'boolean',
description: HelpCommand.description,
})

/**
* Flag listener to display the help
*/
kernel.on('help', async (command, $kernel, parsed) => {
parsed.args.unshift(command.commandName)
const help = new HelpCommand($kernel, parsed, kernel.ui, kernel.prompt)
await help.exec()
return $kernel.shortcircuit()
})

await kernel.handle(process.argv.splice(2))

0 comments on commit 88e959a

Please sign in to comment.