build-entry.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. {{install}}
  12. Vue.use(Loading);
  13. Vue.prototype.$msgbox = MessageBox;
  14. Vue.prototype.$alert = MessageBox.alert;
  15. Vue.prototype.$confirm = MessageBox.confirm;
  16. Vue.prototype.$prompt = MessageBox.prompt;
  17. Vue.prototype.$notify = Notification;
  18. };
  19. // auto install
  20. if (typeof window !== 'undefined' && window.Vue) {
  21. install(window.Vue);
  22. };
  23. module.exports = {
  24. install,
  25. {{list}}
  26. };
  27. `
  28. delete Components.font
  29. var ComponentNames = Object.keys(Components)
  30. var includeComponentTemplate = []
  31. var installTemplate = []
  32. var listTemplate = []
  33. ComponentNames.forEach(name => {
  34. var componentName = uppercamelcase(name)
  35. includeComponentTemplate.push(render(IMPORT_TEMPLATE, {
  36. name: componentName,
  37. package: name
  38. }))
  39. if (['Loading', 'MessageBox', 'Notification'].indexOf(componentName) === -1) {
  40. installTemplate.push(render(ISNTALL_COMPONENT_TEMPLATE, {
  41. name: componentName,
  42. component: name
  43. }))
  44. }
  45. listTemplate.push(` ${componentName}`)
  46. })
  47. var template = render(MAIN_TEMPLATE, {
  48. include: includeComponentTemplate.join('\n'),
  49. install: installTemplate.join('\n'),
  50. list: listTemplate.join(',\n')
  51. })
  52. fs.writeFileSync(OUTPUT_PATH, template)
  53. console.log('[build entry] DONE:', OUTPUT_PATH)