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.

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