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.

157 lines
4.1 KiB

  1. 'use strict'
  2. /**
  3. * FUSEBOX
  4. *
  5. * Client & Server compiler / bundler / watcher
  6. */
  7. const autoprefixer = require('autoprefixer')
  8. const colors = require('colors/safe')
  9. const fsbx = require('fuse-box')
  10. const nodemon = require('nodemon')
  11. const fs = require('fs-extra')
  12. // -------------------------------------------------------
  13. // Parse cmd arguments
  14. // -------------------------------------------------------
  15. const args = require('yargs')
  16. .option('d', {
  17. alias: 'dev',
  18. describe: 'Start in Developer mode',
  19. type: 'boolean'
  20. })
  21. .help('h')
  22. .alias('h', 'help')
  23. .argv
  24. const dev = args.dev
  25. if (dev) {
  26. console.info(colors.bgWhite.black(' Starting Fuse in DEVELOPER mode... '))
  27. } else {
  28. console.info(colors.bgWhite.black(' Starting Fuse in BUILD mode... '))
  29. }
  30. // -------------------------------------------------------
  31. // BUILD VARS
  32. // -------------------------------------------------------
  33. const ALIASES = {
  34. 'brace-ext-modelist': 'brace/ext/modelist.js',
  35. 'simplemde': 'simplemde/dist/simplemde.min.js',
  36. 'socket-io-client': 'socket.io-client/dist/socket.io.js',
  37. 'vue': (dev) ? 'vue/dist/vue.js' : 'vue/dist/vue.min.js',
  38. 'vue-lodash': 'vue-lodash/dist/vue-lodash.min.js',
  39. 'vue-resource': (dev) ? 'vue-resource/dist/vue-resource.js' : 'vue-resource/dist/vue-resource.es2015.js'
  40. }
  41. const SHIMS = {
  42. jquery: {
  43. source: '../node_modules/jquery/dist/jquery.js',
  44. exports: '$'
  45. },
  46. diff2html: {
  47. source: '../node_modules/diff2html/dist/diff2html.min.js',
  48. exports: 'Diff2Html'
  49. },
  50. diff2htmlui: {
  51. source: '../node_modules/diff2html/dist/diff2html-ui.min.js',
  52. exports: 'Diff2HtmlUI'
  53. }
  54. }
  55. // -------------------------------------------------------
  56. // Global Tasks
  57. // -------------------------------------------------------
  58. console.info(colors.white('└── ') + colors.green('Running global tasks...'))
  59. let globalTasks = require('./fuse_tasks')
  60. // -------------------------------------------------------
  61. // FUSEBOX PRODUCER
  62. // -------------------------------------------------------
  63. const babelrc = fs.readJsonSync('.babelrc')
  64. const scssChain = [
  65. fsbx.SassPlugin({
  66. includePaths: ['node_modules'],
  67. outputStyle: dev ? 'nested' : 'compressed'
  68. }),
  69. fsbx.PostCSS([
  70. autoprefixer({
  71. remove: false,
  72. browsers: babelrc.presets[0][1].targets.browsers
  73. })
  74. ]),
  75. fsbx.CSSPlugin()
  76. ]
  77. globalTasks.then(() => {
  78. let fuse = fsbx.FuseBox.init({
  79. homeDir: '../client',
  80. output: '../assets/js/$name.js',
  81. alias: ALIASES,
  82. target: 'browser',
  83. tsConfig: './tsconfig.json',
  84. plugins: [
  85. fsbx.EnvPlugin({ NODE_ENV: (dev) ? 'development' : 'production' }),
  86. fsbx.VueComponentPlugin({
  87. script: fsbx.BabelPlugin(babelrc),
  88. template: fsbx.ConsolidatePlugin({
  89. engine: 'pug'
  90. }),
  91. style: scssChain
  92. }),
  93. scssChain,
  94. fsbx.BabelPlugin(babelrc),
  95. fsbx.JSONPlugin()
  96. ],
  97. debug: false,
  98. log: true
  99. })
  100. // -------------------------------------------------------
  101. // FUSEBOX DEV
  102. // -------------------------------------------------------
  103. if (dev) {
  104. fuse.dev({
  105. port: 5555,
  106. httpServer: false
  107. })
  108. }
  109. // -------------------------------------------------------
  110. // FUSEBOX BUNDLES
  111. // -------------------------------------------------------
  112. if (dev) {
  113. fuse.bundle('libs').shim(SHIMS).instructions('~ index.js')
  114. fuse.bundle('app').instructions('!> [index.js]').hmr({ reload: true }).watch()
  115. } else {
  116. fuse.bundle('bundle.min.js').shim(SHIMS).instructions('> index.js')
  117. }
  118. // -------------------------------------------------------
  119. // FUSEBOX RUN
  120. // -------------------------------------------------------
  121. fuse.run().then(() => {
  122. console.info(colors.green.bold('\nAssets compilation + bundling completed.'))
  123. if (dev) {
  124. nodemon({
  125. exec: 'node server',
  126. ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/', 'tools/'],
  127. ext: 'js json graphql',
  128. watch: ['server'],
  129. env: { 'NODE_ENV': 'development' }
  130. })
  131. }
  132. return true
  133. }).catch(err => {
  134. console.error(colors.red(' X Bundle compilation failed! ' + err.message))
  135. process.exit(1)
  136. })
  137. })