build-entry.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. var Components = require('../components.json')
  2. var fs = require('fs')
  3. var render = require('json-templater/string')
  4. var uppercamelcase = require('uppercamelcase')
  5. var path = require('path')
  6. var OUTPUT_PATH = path.join(__dirname, '../src/index.js')
  7. var IMPORT_TEMPLATE = `import {{name}} from '../packages/{{package}}/index.js';`
  8. var ISNTALL_COMPONENT_TEMPLATE = ` Vue.component({{name}}.name, {{name}});`
  9. var MAIN_TEMPLATE = `{{include}}
  10. const install = function(Vue) {
  11. if (install.installed) return;
  12. {{install}}
  13. Vue.use(Loading);
  14. Vue.prototype.$msgbox = MessageBox;
  15. Vue.prototype.$alert = MessageBox.alert;
  16. Vue.prototype.$confirm = MessageBox.confirm;
  17. Vue.prototype.$prompt = MessageBox.prompt;
  18. Vue.prototype.$notify = Notification;
  19. };
  20. // auto install
  21. if (typeof window !== 'undefined' && window.Vue) {
  22. install(window.Vue);
  23. };
  24. module.exports = {
  25. install,
  26. {{list}}
  27. };
  28. `
  29. delete Components.font
  30. var ComponentNames = Object.keys(Components)
  31. var includeComponentTemplate = []
  32. var installTemplate = []
  33. var listTemplate = []
  34. ComponentNames.forEach(name => {
  35. var componentName = uppercamelcase(name)
  36. includeComponentTemplate.push(render(IMPORT_TEMPLATE, {
  37. name: componentName,
  38. package: name
  39. }))
  40. if (['Loading', 'MessageBox', 'Notification'].indexOf(componentName) === -1) {
  41. installTemplate.push(render(ISNTALL_COMPONENT_TEMPLATE, {
  42. name: componentName,
  43. component: name
  44. }))
  45. }
  46. listTemplate.push(` ${componentName}`)
  47. })
  48. var template = render(MAIN_TEMPLATE, {
  49. include: includeComponentTemplate.join('\n'),
  50. install: installTemplate.join('\n'),
  51. list: listTemplate.join(',\n')
  52. })
  53. fs.writeFileSync(OUTPUT_PATH, template)
  54. console.log('[build entry] DONE:', OUTPUT_PATH)