generate-nutui.cjs 1.9 KB

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