(ctx: Context)
| 17 | const tmpdir = path.resolve(os.tmpdir(), 'hydro'); |
| 18 | |
| 19 | export async function apply(ctx: Context) { |
| 20 | fs.ensureDirSync(tmpdir); |
| 21 | require('../utils'); |
| 22 | require('../error'); |
| 23 | require('../service/bus').apply(ctx); |
| 24 | const url = await MongoService.getUrl(); |
| 25 | if (!url) { |
| 26 | logger.info('Starting setup'); |
| 27 | await require('./setup').load(ctx); |
| 28 | } |
| 29 | const pending = global.addons; |
| 30 | const fail = []; |
| 31 | await locale(pending, fail); |
| 32 | await ctx.plugin(MongoService, load() || {}); |
| 33 | await ctx.plugin(SettingService); |
| 34 | await ctx.plugin(SystemModel.Service); |
| 35 | ctx = await new Promise((resolve) => { |
| 36 | ctx.inject(['loader', 'setting', 'db', 'model:system'], (c) => { |
| 37 | resolve(c); |
| 38 | }); |
| 39 | }); |
| 40 | await ctx.plugin(require('../service/hmr').default, { watch: argv.options.watch }); |
| 41 | await Promise.all([ |
| 42 | ctx.loader.reloadPlugin(require.resolve('../service/storage'), 'file'), |
| 43 | ctx.loader.reloadPlugin(require.resolve('../service/worker'), 'worker'), |
| 44 | ctx.loader.reloadPlugin(require.resolve('../service/server'), 'server'), |
| 45 | ]); |
| 46 | ctx = await new Promise((resolve) => { |
| 47 | ctx.inject(['server'], (c) => { |
| 48 | resolve(c); |
| 49 | }); |
| 50 | }); |
| 51 | require('../lib/index'); |
| 52 | |
| 53 | ctx.plugin(require('../service/monitor')); |
| 54 | ctx.plugin(require('../service/check').default); |
| 55 | await service(pending, fail, ctx); |
| 56 | await builtinModel(ctx); |
| 57 | await model(pending, fail, ctx); |
| 58 | ctx = await new Promise((resolve) => { |
| 59 | ctx.inject(['worker', 'setting'], (c) => { |
| 60 | resolve(c); |
| 61 | }); |
| 62 | }); |
| 63 | const loadDir = async (dir: string) => Promise.all((await fs.readdir(dir)).filter((i) => i.endsWith('.ts')) |
| 64 | .map((h) => ctx.loader.reloadPlugin(path.resolve(dir, h), ''))); |
| 65 | await loadDir(path.resolve(__dirname, '..', 'handler')); |
| 66 | await ctx.plugin(require('../service/migration').default); |
| 67 | await addon(pending, fail, ctx); |
| 68 | await loadDir(path.resolve(__dirname, '..', 'script')); |
| 69 | await ctx.parallel('app/started'); |
| 70 | if (process.env.NODE_APP_INSTANCE === '0') { |
| 71 | const staticDir = path.join(os.homedir(), '.hydro/static'); |
| 72 | await fs.emptyDir(staticDir); |
| 73 | // Use ordered copy to allow resource override |
| 74 | for (const f of Object.values(global.addons)) { |
| 75 | const dir = path.join(f, 'public'); |
| 76 | // eslint-disable-next-line no-await-in-loop |
nothing calls this directly
no test coverage detected