generate-types.js 1.3 KB

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