generate-types.cjs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const config = require('../src/config.json');
  2. const pck = require('./../package.json');
  3. const path = require('path');
  4. const fs = require('fs');
  5. const sourceDir = path.resolve(__dirname, './../tsc/type/src/packages') // 拷贝的源文件夹
  6. const toDir = path.resolve(__dirname, './../dist/types'); // ./../dist
  7. const basePath = path.join(toDir, '__VUE');
  8. const fileList = [];
  9. const getCompList = (basePath) => {
  10. const files = fs.readdirSync(basePath);
  11. files.forEach((filename) => {
  12. const filedir = path.join(basePath, filename);
  13. //根据文件路径获取文件信息,返回一个fs.Stats对象
  14. const stats = fs.statSync(filedir);
  15. const isFile = stats.isFile();//是文件
  16. const isDir = stats.isDirectory();//是文件夹
  17. if(isFile){
  18. fileList.push(filedir);
  19. }
  20. if(isDir){
  21. getCompList(filedir);//递归,如果是文件夹,就继续遍历该文件夹下面的文件
  22. }
  23. });
  24. }
  25. fs.cp(sourceDir, toDir, { recursive: true }, (err) => {
  26. if(err) {
  27. console.error(err);
  28. return;
  29. }
  30. const oldName = path.join(toDir, 'nutui.vue.build.d.ts');
  31. const newName = path.join(toDir, 'nutui.d.ts');
  32. fs.rename(oldName, newName, (err) => {
  33. if(err) {
  34. console.error(err);
  35. }
  36. })
  37. getCompList(basePath);
  38. // fileList.forEach((item) => {
  39. // // 获取文件中的内容
  40. // });
  41. });