1 | const path = require('path')
|
2 | const fs = require('fs-extra')
|
3 | const chalk = require('chalk')
|
4 | const { dist } = require('../config/paths')
|
5 | const { isInstalled } = require('../lib/utils')
|
6 |
|
7 | if (!isInstalled('@mfelibs/mfe-deploy-check')) {
|
8 | console.log(chalk.yellow('😉 还差一步,请安装以下依赖'))
|
9 | console.log('👉 yarn add @mfelibs/mfe-deploy-check -D')
|
10 |
|
11 | process.exit(0)
|
12 | }
|
13 |
|
14 | const deployCheck = require('@mfelibs/mfe-deploy-check')
|
15 |
|
16 | async function checkLatestDistView() {
|
17 | const getStat = f =>
|
18 | fs.stat(path.join(dist, f)).then(stat => {
|
19 | stat['_name'] = f
|
20 | return stat
|
21 | })
|
22 | const files = await fs.readdir(dist)
|
23 | const stats = await Promise.all(files.map(getStat))
|
24 | const dir = stats.filter(stat => stat.isDirectory())
|
25 | const target = dir.sort((a, b) => b.birthtime - a.birthtime)[0]
|
26 |
|
27 | return deployCheck.check({ viewName: target._name, env: 'local' })
|
28 | }
|
29 |
|
30 | async function doCheck(argv, context) {
|
31 | if (!fs.existsSync(dist)) return
|
32 |
|
33 | const viewName = argv._[2]
|
34 |
|
35 | if (viewName) {
|
36 | return deployCheck.check({ viewName, env: 'local' })
|
37 | }
|
38 |
|
39 | return checkLatestDistView()
|
40 | }
|
41 |
|
42 | module.exports = doCheck
|