build.js 844 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { exec } from 'child_process'
  2. import { copyFile as _copyFile, existsSync, mkdirSync, readdir } from 'fs'
  3. import { basename, join } from 'path'
  4. const srcDir = 'src/plugins'
  5. const distDir = 'dist/plugins'
  6. // 创建 dist 目录
  7. if (!existsSync(distDir)) {
  8. mkdirSync(distDir, { recursive: true })
  9. }
  10. function copyFile(filePath) {
  11. const srcPath = filePath
  12. const distPath = join(distDir, basename(filePath))
  13. _copyFile(srcPath, distPath, (err) => {
  14. if (err) throw err
  15. console.log(`${srcPath} was copied to ${distPath}`)
  16. })
  17. }
  18. readdir(srcDir, (err, files) => {
  19. if (err) throw err
  20. files.forEach((file) => {
  21. if (file.endsWith('.yml')) {
  22. copyFile(join(srcDir, file))
  23. }
  24. })
  25. })
  26. exec('npx pkgroll --minify', (err, stdout, stderr) => {
  27. if (err) {
  28. console.error(err)
  29. return
  30. }
  31. console.log(stdout)
  32. })