schangxiang@126.com
2025-04-29 e71bc24daa8f00768787e18f5daba09128abfc62
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const { writeFileSync, rmSync } = require('fs')
const { spawn } = require('node:child_process')
const { globSync } = require('glob')
const path = require('path')
 
let isSingleBuild = false
const isWin = process.platform === 'win32'
const argvPath = './script/.argv'
const widgetName = process.argv[process.argv.length - 1]
const widgetsPath = globSync(`./src/widgets/*/index.ts`)
const getWidgetNames = widgetsPath.map((file) => {
  const parts = isWin
    ? path.resolve(file).split('\\')
    : path.resolve(file).split('/')
  return parts[parts.length - 2]
})
 
if (getWidgetNames.includes(widgetName)) {
  isSingleBuild = true
  writeFileSync(argvPath, widgetName)
}
 
const run = spawn(process.platform === 'win32' ? 'npm.cmd' : 'npm', [
  'run',
  'build-lib',
])
 
run.stdout.on('data', (data) => console.info(data.toString('utf8')))
 
run.stderr.on('data', (data) => console.info(data.toString('utf8')))
 
run.on('close', (code) => {
  if (code == 0 && isSingleBuild) rmSync(argvPath)
})