How to use @adonisjs/application - 10 common examples

To help you get started, we’ve selected a few @adonisjs/application 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 / ace / test / kernel.spec.ts View on Github external
test('inject dependencies to command methods', async (assert) => {
    assert.plan(1)

    const ioc = new Ioc()
    const app = new Application(__dirname, ioc, {}, {})
    const kernel = new Kernel(app)

    class Foo {}
    ioc.bind('App/Foo', () => {
      return new Foo()
    })

    class Install extends BaseCommand {
      public static commandName = 'install'

      @inject()
      public async handle (foo: Foo) {
        assert.instanceOf(foo, Foo)
      }
    }
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 / adonis-lucid / test / migrations / migration-source.spec.ts View on Github external
test('sort multiple migration directories seperately', async (assert) => {
    const app = new Application(fs.basePath, {} as any, {} as any, {})
    const config = Object.assign({}, db.getRawConnection('primary')!.config, {
      migrations: {
        paths: ['database/secondary', 'database/primary'],
      },
    })

    const migrationSource = new MigrationSource(config, app)

    await fs.add('database/secondary/a.js', 'module.exports = class Foo {}')
    await fs.add('database/secondary/c.js', 'module.exports = class Bar {}')

    await fs.add('database/primary/b.js', 'module.exports = class Foo {}')
    await fs.add('database/primary/d.js', 'module.exports = class Bar {}')

    const files = await migrationSource.getMigrations()
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-command.spec.ts View on Github external
test('make a command inside a custom directory', async (assert) => {
    await fs.add('.adonisrc.json', JSON.stringify({
      directories: {
        commands: './foo',
      },
    }))

    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('foo/Greet.ts')
    const CommandTemplate = await templates.get('command.txt')
    assert.deepEqual(
      toNewlineArray(GreetCommand),
      toNewlineArray(
        CommandTemplate
          .replace('${filename}', 'Greet')
          .replace('${toCommandName(filename)}', 'greet'),
      ),
    )
  })
github adonisjs / adonis-framework / test / health-check.spec.ts View on Github external
test('define checker as IoC container binding', async (assert) => {
    const ioc = new Ioc()
    const application = new Application(__dirname, ioc, {}, {})
    const healthCheck = new HealthCheck(application)

    class DbChecker {
      public async report () {
        return {
          health: {
            healthy: true,
          },
        }
      }
    }

    ioc.bind('App/Checkers/Db', () => {
      return new DbChecker()
    })
github adonisjs / ace / test / manifest.spec.ts View on Github external
@inject([null, null, 'App/Foo'])
    export default class Greet extends BaseCommand {
      public static commandName = 'greet'
      public static description = 'Greet a user'

      constructor (public app, public kernel, public foo) {
        super(app, kernel)
      }

      public async handle () {
        global['foo'] = this.foo.constructor.name
      }
    }`)

    const ioc = new Ioc()
    const app = new Application(__dirname, ioc, {}, {})
    const kernel = new Kernel(app)
    const manifest = new Manifest(fs.basePath)

    kernel.useManifest(manifest)

    await manifest.generate(['./Commands/Make.ts'])

    ioc.bind('App/Foo', () => {
      class Foo {}
      return new Foo()
    })

    await kernel.handle(['greet'])
    assert.equal(global['foo'], 'Foo')

    delete global['foo']
github adonisjs / ace / test / kernel.spec.ts View on Github external
@args.string()
      public name: string

      public async handle () {
        const username = await this.prompt.ask('What\'s your username?', {
          name: 'username',
          validate (value) {
            return !!value
          },
        })

        this.logger.info(username)
      }
    }

    const app = new Application(__dirname, new Ioc(), {}, {})
    app.environment = 'test'

    const kernel = new Kernel(app)
    kernel.register([Greet])

    const argv = ['greet', 'virk']
    const command = await kernel.find(argv)
    const commandInstance = new command!(app)

    /**
     * Responding to prompt programatically
     */
    commandInstance.prompt.on('prompt', (prompt) => {
      prompt.answer('')
    })
github adonisjs / ace / example / index.ts View on Github external
public static description = 'Create a HTTP controller'

  public async handle () {
  }
}

class MakeModel extends BaseCommand {
  public static commandName = 'make:model'
  public static description = 'Create database model'

  public async handle () {
    console.log(process.env.NODE_ENV)
  }
}

const app = new Application(__dirname, new Ioc(), {}, {})
const kernel = new Kernel(app)
kernel.register([Greet, MakeController, MakeModel])

kernel.flag('env', (value) => {
  process.env.NODE_ENV = value
}, { type: 'string' })

kernel.handle(process.argv.splice(2))
kernel.printHelp(Greet)
github AdonisCommunity / create-adonis-ts-app / index.ts View on Github external
return
  }

  /**
   * Set environment variables that can be used by the packages
   * to tweak their setup behavior
   */
  process.env['ADONIS_CREATE_APP_NAME'] = state.name
  process.env['ADONIS_CREATE_ESLINT'] = String(state.eslint)
  process.env['ADONIS_CREATE_APP_CLIENT'] = state.client
  process.env['ADONIS_CREATE_APP_BOILERPLATE'] = state.boilerplate

  /**
   * Setup application
   */
  const application = new Application(absPath, {} as any, {}, {})

  for (let task of tasks) {
    try {
      await task(absPath, application, state)
    } catch (err) {
      logger.error('Unable to create new project. Rolling back')
      logger.fatal(err)
      removeSync(absPath)
      return
    }
  }
}

@adonisjs/application

AdonisJS application class to read app related data

MIT
Latest version published 6 months ago

Package Health Score

68 / 100
Full package analysis