generate-types.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const config = require('../src/config.json');
  2. const path = require('path');
  3. const fs = require('fs');
  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 } = element;
  12. if (show) {
  13. importStr += `declare class ${name} extends UIComponent {}\n`;
  14. packages.push(name);
  15. }
  16. });
  17. });
  18. let installFunction = `
  19. export interface InstallationOptions {
  20. locale?: any;
  21. lang?: any;
  22. }
  23. declare function install(app: App, options?: InstallationOptions): void;
  24. export { ${packages.join(',')} };
  25. declare const _default: {
  26. install: typeof install;
  27. version: string;
  28. };
  29. export default _default;`;
  30. let fileStr = importStr + installFunction;
  31. fs.writeFile(
  32. path.resolve(__dirname, '../dist/nutui.d.ts'),
  33. fileStr,
  34. 'utf8',
  35. error => {
  36. console.log(error);
  37. // logger.success(`${package_config_path} 文件写入成功`);
  38. }
  39. );
  40. fs.writeFile(
  41. path.resolve(__dirname, '../dist/index.d.ts'),
  42. `import * as NutUI from './nutui';
  43. export default NutUI;
  44. export * from './nutui';`,
  45. 'utf8',
  46. error => {
  47. // logger.success(`${package_config_path} 文件写入成功`);
  48. }
  49. );