generate-nutui.js 1.1 KB

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