generate-nutui.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 } = element;
  10. if (show) {
  11. importStr += `import ${name} from './packages/${name.toLowerCase()}/index.vue';\n`;
  12. packages.push(name);
  13. }
  14. });
  15. });
  16. let installFunction = `function install(app: App) {
  17. const packages = [${packages.join(',')}];
  18. packages.forEach((item:any) => {
  19. if (item.install) {
  20. app.use(item);
  21. } else if (item.name) {
  22. app.component(item.name, item);
  23. }
  24. });
  25. }`;
  26. let fileStr = `${importStr}
  27. ${installFunction}
  28. export { ${packages.join(',')} };
  29. export default { install, version:'${package.version}'};`;
  30. fs.writeFile(
  31. path.resolve(__dirname, '../src/nutui.ts'),
  32. fileStr,
  33. 'utf8',
  34. error => {
  35. // logger.success(`${package_config_path} 文件写入成功`);
  36. }
  37. );