Skip to content

Commit 3d8e309

Browse files
authored
Merge pull request #22 from Triumph-light/feature-compDir-watch
feat: 增加mpx-cube-ui的watch模式
2 parents 0301c73 + 454a5a6 commit 3d8e309

3 files changed

Lines changed: 36 additions & 25 deletions

File tree

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@
5252
"jest": "^27.5.1",
5353
"jest-environment-jsdom": "^27.5.1",
5454
"lint-staged": "^9.5.0",
55+
"minimist": "^1.2.8",
5556
"path": "^0.12.7",
57+
"picocolors": "^1.1.1",
5658
"release-it": "^16.2.1",
5759
"shelljs": "^0.8.5",
5860
"stylus-loader": "^3.0.2",

packages/mpx-cube-ui/build/genLib.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const path = require('path')
22
const util = require('util')
33
const copy = require('copy')
44
const fs = require('fs')
5+
const minimist = require('minimist')
6+
const c = require('picocolors')
57
const exec = util.promisify(require('child_process').exec)
68

79
const libTsConfig = path.resolve(__dirname, '../tsconfig.lib.json')
@@ -60,12 +62,17 @@ async function copyStatic() {
6062
}
6163

6264
async function build() {
63-
await exec(`rm -rf ${libDir}/*`) // 确保每次gen lib都是最新的
64-
await compileTs(libDir, libTsConfig)
65-
await copyStatic()
66-
modifyMpxScriptRef()
67-
68-
// console.log('Done: compile component lib dir')
65+
try {
66+
console.log(c.blue('start building'))
67+
await exec(`rm -rf ${libDir}/*`) // 确保每次gen lib都是最新的
68+
await compileTs(libDir, libTsConfig)
69+
await copyStatic()
70+
modifyMpxScriptRef()
71+
} catch (error) {
72+
console.log(c.redBright('build fail'))
73+
throw Error(error)
74+
}
75+
console.log(c.greenBright('Done: compile component lib dir!'))
6976
}
7077

7178
function modifyMpxScriptRef() {
@@ -97,4 +104,16 @@ function modifyMpxScriptRef() {
97104
})
98105
}
99106

100-
build()
107+
const argv = minimist(process.argv.slice(2))
108+
function runBuild() {
109+
const { w: watch } = argv
110+
if (watch) {
111+
console.log(c.blue('watching file....'))
112+
const watchDir = path.resolve(__dirname, '../src')
113+
fs.watch(watchDir, { recursive: true }, (eventType, filename) => {
114+
build()
115+
})
116+
}
117+
build()
118+
}
119+
runBuild()

pnpm-lock.yaml

Lines changed: 8 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)