generate-nutui.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const package = require('../package.json');
  2. const config = require('../src/config.json');
  3. const path = require('path');
  4. const fs = require('fs-extra');
  5. let importStr = `import { App } from 'vue';\n`;
  6. let importScssStr = `\n`;
  7. const packages = [];
  8. config.nav.map((item) => {
  9. item.packages.forEach((element) => {
  10. let { name, show, type, exportEmpty } = element;
  11. if (show || exportEmpty) {
  12. importStr += `import ${name} from './__VUE/${name.toLowerCase()}/index${
  13. type === 'methods' ? '' : '.vue'
  14. }';\n`;
  15. importScssStr += `import './__VUE/${name.toLowerCase()}/index.scss';\n`;
  16. packages.push(name);
  17. }
  18. });
  19. });
  20. let installFunction = `function install(app: App) {
  21. const packages = [${packages.join(',')}];
  22. packages.forEach((item:any) => {
  23. if (item.install) {
  24. app.use(item);
  25. } else if (item.name) {
  26. app.component(item.name, item);
  27. }
  28. });
  29. }`;
  30. let fileStr = `${importStr}
  31. ${installFunction}
  32. export { install, ${packages.join(',')} };
  33. export default { install, version:'${package.version}'};`;
  34. fs.outputFile(
  35. path.resolve(__dirname, '../src/packages/nutui.vue.build.ts'),
  36. fileStr,
  37. 'utf8',
  38. (error) => {
  39. // logger.success(`${package_config_path} 文件写入成功`);
  40. }
  41. );
  42. fileStr += importScssStr;
  43. fs.outputFile(
  44. path.resolve(__dirname, '../src/packages/nutui.vue.ts'),
  45. fileStr,
  46. 'utf8',
  47. (error) => {
  48. // logger.success(`${package_config_path} 文件写入成功`);
  49. }
  50. );