You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
4.4 KiB

  1. 'use strict'
  2. /**
  3. * FUSEBOX
  4. *
  5. * Client & Server compiler / bundler / watcher
  6. */
  7. const colors = require('colors/safe')
  8. const fsbx = require('fuse-box')
  9. const nodemon = require('nodemon')
  10. // ======================================================
  11. // Parse cmd arguments
  12. // ======================================================
  13. const args = require('yargs')
  14. .option('d', {
  15. alias: 'dev',
  16. describe: 'Start in Developer mode',
  17. type: 'boolean'
  18. })
  19. .option('c', {
  20. alias: 'dev-configure',
  21. describe: 'Start in Configure Developer mode',
  22. type: 'boolean'
  23. })
  24. .help('h')
  25. .alias('h', 'help')
  26. .argv
  27. let mode = 'build'
  28. const dev = args.d || args.c
  29. if (args.d) {
  30. console.info(colors.bgWhite.black(' Starting Fuse in DEVELOPER mode... '))
  31. mode = 'dev'
  32. } else if (args.c) {
  33. console.info(colors.bgWhite.black(' Starting Fuse in CONFIGURE DEVELOPER mode... '))
  34. mode = 'dev-configure'
  35. } else {
  36. console.info(colors.bgWhite.black(' Starting Fuse in BUILD mode... '))
  37. }
  38. // ======================================================
  39. // BUILD VARS
  40. // ======================================================
  41. const ALIASES = {
  42. 'brace-ext-modelist': 'brace/ext/modelist.js',
  43. 'simplemde': 'simplemde/dist/simplemde.min.js',
  44. 'socket-io-client': 'socket.io-client/dist/socket.io.js',
  45. 'vue': (dev) ? 'vue/dist/vue.js' : 'vue/dist/vue.min.js',
  46. 'vue-lodash': 'vue-lodash/dist/vue-lodash.min.js',
  47. 'vue-resource': (dev) ? 'vue-resource/dist/vue-resource.js' : 'vue-resource/dist/vue-resource.es2015.js'
  48. }
  49. const SHIMS = {
  50. jquery: {
  51. source: 'node_modules/jquery/dist/jquery.js',
  52. exports: '$'
  53. },
  54. diff2html: {
  55. source: 'node_modules/diff2html/dist/diff2html.min.js',
  56. exports: 'Diff2Html'
  57. },
  58. diff2htmlui: {
  59. source: 'node_modules/diff2html/dist/diff2html-ui.min.js',
  60. exports: 'Diff2HtmlUI'
  61. }
  62. }
  63. // ======================================================
  64. // Global Tasks
  65. // ======================================================
  66. console.info(colors.white('└── ') + colors.green('Running global tasks...'))
  67. let globalTasks = require('./.build/_tasks')
  68. // ======================================================
  69. // Fuse Tasks
  70. // ======================================================
  71. globalTasks.then(() => {
  72. let fuse = fsbx.FuseBox.init({
  73. homeDir: './client',
  74. output: './assets/js/$name.js',
  75. alias: ALIASES,
  76. target: 'browser',
  77. plugins: [
  78. fsbx.EnvPlugin({ NODE_ENV: (dev) ? 'development' : 'production' }),
  79. fsbx.VuePlugin(),
  80. ['.scss', fsbx.SassPlugin({ outputStyle: (dev) ? 'nested' : 'compressed' }), fsbx.CSSPlugin()],
  81. fsbx.BabelPlugin({ comments: false, presets: ['es2015'] }),
  82. fsbx.JSONPlugin(),
  83. /* !dev && fsbx.QuantumPlugin({
  84. target: 'browser',
  85. uglify: true,
  86. api: (core) => {
  87. core.solveComputed('default/js/components/editor-codeblock.vue', {
  88. mapping: '/js/ace/ace.js',
  89. fn: (statement, core) => {
  90. statement.setExpression(`'/js/ace/ace.js'`)
  91. }
  92. })
  93. core.solveComputed('default/js/components/editor.component.js', {
  94. mapping: '/js/simplemde/simplemde.min.js',
  95. fn: (statement, core) => {
  96. statement.setExpression(`'/js/simplemde/simplemde.min.js'`)
  97. }
  98. })
  99. }
  100. }) */
  101. !dev && fsbx.UglifyESPlugin()
  102. ],
  103. debug: false,
  104. log: true
  105. })
  106. const bundleVendor = fuse.bundle('vendor').shim(SHIMS).instructions('~ index.js') // eslint-disable-line no-unused-vars
  107. const bundleApp = fuse.bundle('app').instructions('!> [index.js]')
  108. // const bundleApp = fuse.bundle('app').shim(SHIMS).instructions('> index.js')
  109. const bundleSetup = fuse.bundle('configure').instructions('> configure.js')
  110. switch (mode) {
  111. case 'dev':
  112. bundleApp.watch()
  113. break
  114. case 'dev-configure':
  115. bundleSetup.watch()
  116. break
  117. }
  118. fuse.run().then(() => {
  119. console.info(colors.green.bold('\nAssets compilation + bundling completed.'))
  120. if (dev) {
  121. nodemon({
  122. exec: (args.d) ? 'node server' : 'node wiki configure',
  123. ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/'],
  124. ext: 'js json',
  125. watch: (args.d) ? ['server'] : ['server/configure.js'],
  126. env: { 'NODE_ENV': 'development' }
  127. })
  128. }
  129. }).catch(err => {
  130. console.error(colors.red(' X Bundle compilation failed! ' + err.message))
  131. process.exit(1)
  132. })
  133. })