generate-types.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const config = require('../src/config.json');
  2. const path = require('path');
  3. const fs = require('fs-extra');
  4. let importStr = `import { App } from 'vue';
  5. declare class UIComponent {
  6. static install(vue: App): void;
  7. $props: any;
  8. }\n`;
  9. const packages = [];
  10. config.nav.map((item) => {
  11. item.packages.forEach((element) => {
  12. let { name, show, exportEmpty, type } = element;
  13. if (show || exportEmpty) {
  14. importStr +=
  15. type == 'methods' ? `declare const ${name}: any;\n` : `declare class ${name} extends UIComponent {}\n`;
  16. packages.push(name);
  17. }
  18. });
  19. });
  20. let installFunction = `
  21. export interface InstallationOptions {
  22. locale?: any;
  23. lang?: any;
  24. }
  25. declare function install(app: App, options?: InstallationOptions): void;
  26. export { ${packages.join(',')},install };
  27. declare const _default: {
  28. install: typeof install;
  29. version: string;
  30. };
  31. export default _default;`;
  32. let fileStr = importStr + installFunction;
  33. fs.outputFile(path.resolve(__dirname, '../dist/nutui.d.ts'), fileStr, 'utf8', (error) => {
  34. // logger.success(`${package_config_path} 文件写入成功`);
  35. });
  36. fs.outputFile(
  37. path.resolve(__dirname, '../dist/index.d.ts'),
  38. `import * as NutUI from './nutui';
  39. export default NutUI;
  40. export * from './nutui';`,
  41. 'utf8',
  42. (error) => {
  43. // logger.success(`${package_config_path} 文件写入成功`);
  44. }
  45. );