File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed
Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments