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.

137 lines
3.5 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. _preinit: {
  50. source: '.build/_preinit.js',
  51. exports: '_preinit'
  52. },
  53. jquery: {
  54. source: 'node_modules/jquery/dist/jquery.js',
  55. exports: '$'
  56. },
  57. mathjax: {
  58. source: 'node_modules/mathjax/MathJax.js',
  59. exports: 'MathJax'
  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.min.js',
  74. alias: ALIASES,
  75. shim: SHIMS,
  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.UglifyESPlugin({
  83. compress: { unused: false },
  84. output: { 'max_line_len': 1000000 }
  85. })
  86. ],
  87. debug: false,
  88. log: true
  89. })
  90. if (dev) {
  91. fuse.dev({
  92. port: 4444,
  93. httpServer: false
  94. })
  95. }
  96. const bundleApp = fuse.bundle('app').instructions('> index.js')
  97. const bundleSetup = fuse.bundle('configure').instructions('> configure.js')
  98. switch (mode) {
  99. case 'dev':
  100. bundleApp.watch()
  101. break
  102. case 'dev-configure':
  103. bundleSetup.watch()
  104. break
  105. }
  106. fuse.run().then(() => {
  107. console.info(colors.green.bold('\nAssets compilation + bundling completed.'))
  108. if (dev) {
  109. nodemon({
  110. exec: (args.d) ? 'node server' : 'node wiki configure',
  111. ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/'],
  112. ext: 'js json',
  113. watch: (args.d) ? ['server'] : ['server/configure.js'],
  114. env: { 'NODE_ENV': 'development' }
  115. })
  116. }
  117. }).catch(err => {
  118. console.error(colors.red(' X Bundle compilation failed! ' + err.message))
  119. process.exit(1)
  120. })
  121. })