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.

147 lines
4.3 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. }
  48. const SHIMS = {
  49. jquery: {
  50. source: 'node_modules/jquery/dist/jquery.js',
  51. exports: '$'
  52. },
  53. diff2html: {
  54. source: 'node_modules/diff2html/dist/diff2html.min.js',
  55. exports: 'Diff2Html'
  56. },
  57. diff2htmlui: {
  58. source: 'node_modules/diff2html/dist/diff2html-ui.min.js',
  59. exports: 'Diff2HtmlUI'
  60. }
  61. }
  62. // ======================================================
  63. // Global Tasks
  64. // ======================================================
  65. console.info(colors.white('└── ') + colors.green('Running global tasks...'))
  66. let globalTasks = require('./.build/_tasks')
  67. // ======================================================
  68. // Fuse Tasks
  69. // ======================================================
  70. globalTasks.then(() => {
  71. let fuse = fsbx.FuseBox.init({
  72. homeDir: './client',
  73. output: './assets/js/$name.js',
  74. alias: ALIASES,
  75. target: 'browser',
  76. plugins: [
  77. fsbx.EnvPlugin({ NODE_ENV: (dev) ? 'development' : 'production' }),
  78. fsbx.VuePlugin(),
  79. ['.scss', fsbx.SassPlugin({ outputStyle: (dev) ? 'nested' : 'compressed' }), fsbx.CSSPlugin()],
  80. fsbx.BabelPlugin({ comments: false, presets: ['es2015'] }),
  81. fsbx.JSONPlugin(),
  82. /* !dev && fsbx.QuantumPlugin({
  83. target: 'browser',
  84. uglify: true,
  85. api: (core) => {
  86. core.solveComputed('default/js/components/editor-codeblock.vue', {
  87. mapping: '/js/ace/ace.js',
  88. fn: (statement, core) => {
  89. statement.setExpression(`'/js/ace/ace.js'`)
  90. }
  91. })
  92. core.solveComputed('default/js/components/editor.component.js', {
  93. mapping: '/js/simplemde/simplemde.min.js',
  94. fn: (statement, core) => {
  95. statement.setExpression(`'/js/simplemde/simplemde.min.js'`)
  96. }
  97. })
  98. }
  99. }) */
  100. !dev && fsbx.UglifyESPlugin()
  101. ],
  102. debug: false,
  103. log: true
  104. })
  105. // const bundleVendor = fuse.bundle('vendor').shim(SHIMS).instructions('~ index.js') // eslint-disable-line no-unused-vars
  106. // const bundleApp = fuse.bundle('app').instructions('!> [index.js]')
  107. const bundleApp = fuse.bundle('app').instructions('> index.js')
  108. const bundleSetup = fuse.bundle('configure').instructions('> configure.js')
  109. switch (mode) {
  110. case 'dev':
  111. bundleApp.watch()
  112. break
  113. case 'dev-configure':
  114. bundleSetup.watch()
  115. break
  116. }
  117. fuse.run().then(() => {
  118. console.info(colors.green.bold('\nAssets compilation + bundling completed.'))
  119. if (dev) {
  120. nodemon({
  121. exec: (args.d) ? 'node server' : 'node wiki configure',
  122. ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/'],
  123. ext: 'js json',
  124. watch: (args.d) ? ['server'] : ['server/configure.js'],
  125. env: { 'NODE_ENV': 'development' }
  126. })
  127. }
  128. }).catch(err => {
  129. console.error(colors.red(' X Bundle compilation failed! ' + err.message))
  130. process.exit(1)
  131. })
  132. })