How to use the @adonisjs/ace.Kernel function in @adonisjs/ace

To help you get started, we’ve selected a few @adonisjs/ace examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adonisjs / adonis-framework / src / Ignitor / Ace.ts View on Github external
public async handle (argv: string[]) {
    const { Kernel, handleError, Manifest, BaseCommand } = require('@adonisjs/ace')

    const manifest = new Manifest(this._ignitor.application.appRoot)
    const kernel = new Kernel()
    kernel.useManifest(manifest)

    /**
     * Print help when no command is defined
     */
    if (!argv.length) {
      await kernel.handle() // This will load the commands from manifest
      this._printHelp(kernel)
      return
    }

    /**
     * Generate manifest when command is `generate:manifest`
     */
    if (argv[0] === 'generate:manifest') {
      class Noop extends BaseCommand {}
github adonisjs / assembler / test / make-controller.spec.ts View on Github external
test('make a controller inside the default directory', async (assert) => {
    await fs.add('.adonisrc.json', JSON.stringify({}))

    const app = new Application(fs.basePath, new Ioc(), {}, {})

    const controller = new MakeController(app, new Kernel(app))
    controller.name = 'user'
    await controller.handle()

    const UsersController = await fs.get('app/Controllers/Http/UsersController.ts')
    const ControllerTemplate = await templates.get('controller.txt')
    assert.deepEqual(
      toNewlineArray(UsersController),
      toNewlineArray(ControllerTemplate.replace('${filename}', 'UsersController')),
    )
  })
github adonisjs / assembler / test / invoke-command.spec.ts View on Github external
test('execute instructions defined in package.json file', async (assert) => {
    process.env.ADONIS_ACE_CWD = fs.basePath

    await fs.add('node_modules/@adonisjs/sample/package.json', JSON.stringify({
      name: '@adonisjs/sample',
      adonisjs: {
        env: {
          'PORT': '3333',
        },
      },
    }))

    const app = new Application(fs.basePath, new Ioc(), {}, {})

    const invoke = new Invoke(app, new Kernel(app))
    invoke.name = '@adonisjs/sample'
    await invoke.handle()

    const envFile = await fs.fsExtra.readFile(join(fs.basePath, '.env'), 'utf-8')
    const envExampleFile = await fs.fsExtra.readFile(join(fs.basePath, '.env.example'), 'utf-8')

    assert.equal(envFile.trim(), 'PORT=3333')
    assert.equal(envExampleFile.trim(), 'PORT=')
  })
})
github adonisjs / assembler / test / make-command.spec.ts View on Github external
test('make a command inside the default directory', async (assert) => {
    await fs.add('.adonisrc.json', JSON.stringify({}))

    const app = new Application(fs.basePath, new Ioc(), {}, {})

    const command = new MakeCommand(app, new Kernel(app))
    command.name = 'greet'
    await command.handle()

    const GreetCommand = await fs.get('commands/Greet.ts')
    const CommandTemplate = await templates.get('command.txt')
    assert.deepEqual(
      toNewlineArray(GreetCommand),
      toNewlineArray(
        CommandTemplate
          .replace('${filename}', 'Greet')
          .replace('${toCommandName(filename)}', 'greet'),
      ),
    )
  })
github adonisjs / assembler / test / make-view.spec.ts View on Github external
test('make an empty view inside the default directory', async (assert) => {
    await fs.add('.adonisrc.json', JSON.stringify({}))

    const app = new Application(fs.basePath, new Ioc(), {}, {})

    const view = new MakeView(app, new Kernel(app))
    view.name = 'welcome'
    await view.handle()

    const welcomeView = await fs.get('resources/views/welcome.edge')
    assert.deepEqual(welcomeView.trim(), '')
  })
github adonisjs / assembler / test / make-provider.spec.ts View on Github external
test('make a provider inside the default directory', async (assert) => {
    await fs.add('.adonisrc.json', JSON.stringify({}))

    const app = new Application(fs.basePath, new Ioc(), {}, {})

    const provider = new MakeProvider(app, new Kernel(app))
    provider.name = 'app'
    await provider.handle()

    const AppProvider = await fs.get('providers/AppProvider.ts')
    const ProviderTemplate = await templates.get('provider.txt')
    assert.deepEqual(
      toNewlineArray(AppProvider),
      toNewlineArray(ProviderTemplate.replace('${filename}', 'AppProvider')),
    )

    const rcContents = await fs.get('.adonisrc.json')
    assert.deepEqual(JSON.parse(rcContents), {
      providers: ['./providers/AppProvider'],
    })
  })
github adonisjs / assembler / test / make-middleware.spec.ts View on Github external
test('make a middleware inside the default directory', async (assert) => {
    await fs.add('.adonisrc.json', JSON.stringify({}))

    const app = new Application(fs.basePath, new Ioc(), {}, {})

    const middleware = new MakeMiddleware(app, new Kernel(app))
    middleware.name = 'spoof_accept'
    await middleware.handle()

    const SpoofMiddleware = await fs.get('app/Middleware/SpoofAccept.ts')
    const MiddlewareTemplate = await templates.get('middleware.txt')
    assert.deepEqual(
      toNewlineArray(SpoofMiddleware),
      toNewlineArray(MiddlewareTemplate.replace('${filename}', 'SpoofAccept')),
    )
  })
})
github adonisjs / adonis-cli / index.ts View on Github external
/*
 * @adonisjs/cli
 *
 * (c) Harminder Virk 
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
*/

import { join } from 'path'
import { yellow, underline } from 'kleur'

import { Kernel, Manifest } from '@adonisjs/ace'
import { getCliVersion, getAdonisCoreVersion, dumpAsciiLogo } from './src/helpers'

const kernel = new Kernel()

/**
 * Using manifest file over loading all commands all the
 * time
 */
const manifest = new Manifest(join(__dirname))
kernel.useManifest(manifest)

/**
 * Printing the help screen
 */
kernel.flag('help', (value, _options, command) => {
  if (!value) {
    return
  }