Skip to content

Commit c84d2ce

Browse files
committed
feat: add cicheck hook
1 parent ecd8792 commit c84d2ce

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

packages/mara-x/hooks/cicheck.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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) => a.birthtime - b.birthtime)[0]
26+
27+
return deployCheck.check({ viewName: target._name, env: 'local' })
28+
}
29+
30+
async function doCheck(argv) {
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

packages/mara-x/scripts/hook.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ module.exports = function applyHook(argv) {
44
const hookName = argv._[1]
55

66
if (isInstalled(`../hooks/${hookName}`)) {
7-
require(`../hooks/${hookName}`)
7+
const mod = require(`../hooks/${hookName}`)
8+
9+
if (typeof mod === 'function') mod(argv)
810
}
911
}

0 commit comments

Comments
 (0)