Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 {}
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')),
)
})
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=')
})
})
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'),
),
)
})
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(), '')
})
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'],
})
})
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')),
)
})
})
/*
* @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
}