UNPKG

1.11 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3const logger = require('@acyort/logger')()
4const { join } = require('path')
5const parser = require('../lib/cli/parser')
6const acyort = require('../lib')
7const getConfig = require('../lib/config')
8
9const argv = process.argv.slice(2)
10const base = process.cwd()
11const ignores = ['init', '-h', '--help', '-v', '--version']
12
13try {
14 const config = getConfig(base)
15
16 if (config) {
17 const ctx = acyort(config)
18 const { scripts, plugins } = config
19 const exec = (path) => {
20 // eslint-disable-next-line global-require, import/no-dynamic-require
21 require(path)({ ...ctx, process: undefined })
22 }
23
24 scripts.forEach(name => exec(join(base, 'scripts', name)))
25 plugins.forEach(name => exec(join(base, 'node_modules', name)))
26
27 parser(argv, {
28 process: ctx.process,
29 logger: ctx.logger,
30 version: ctx.version,
31 config: ctx.config,
32 store: ctx.store,
33 })
34 } else if (argv[0] && !ignores.includes(argv[0])) {
35 logger.error('cannot find `config.yml` or configuration error')
36 } else {
37 parser(argv)
38 }
39} catch (e) {
40 logger.error(e)
41}