2017-03-27 02:07:40 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FUSEBOX
|
|
|
|
*
|
2017-04-02 17:18:33 +00:00
|
|
|
* Client & Server compiler / bundler / watcher
|
2017-03-27 02:07:40 +00:00
|
|
|
*/
|
|
|
|
|
2017-10-07 01:35:02 +00:00
|
|
|
const autoprefixer = require('autoprefixer')
|
2017-04-02 17:18:33 +00:00
|
|
|
const colors = require('colors/safe')
|
|
|
|
const fsbx = require('fuse-box')
|
|
|
|
const nodemon = require('nodemon')
|
2017-07-22 14:33:31 +00:00
|
|
|
const fs = require('fs-extra')
|
2017-03-27 02:07:40 +00:00
|
|
|
|
2017-10-07 01:35:02 +00:00
|
|
|
// -------------------------------------------------------
|
2017-03-27 02:07:40 +00:00
|
|
|
// Parse cmd arguments
|
2017-10-07 01:35:02 +00:00
|
|
|
// -------------------------------------------------------
|
2017-03-27 02:07:40 +00:00
|
|
|
|
|
|
|
const args = require('yargs')
|
2017-04-02 17:18:33 +00:00
|
|
|
.option('d', {
|
|
|
|
alias: 'dev',
|
|
|
|
describe: 'Start in Developer mode',
|
|
|
|
type: 'boolean'
|
|
|
|
})
|
|
|
|
.help('h')
|
|
|
|
.alias('h', 'help')
|
|
|
|
.argv
|
2017-03-27 02:07:40 +00:00
|
|
|
|
2017-10-07 01:35:02 +00:00
|
|
|
const dev = args.dev
|
|
|
|
|
|
|
|
if (dev) {
|
2017-04-02 17:18:33 +00:00
|
|
|
console.info(colors.bgWhite.black(' Starting Fuse in DEVELOPER mode... '))
|
|
|
|
} else {
|
|
|
|
console.info(colors.bgWhite.black(' Starting Fuse in BUILD mode... '))
|
|
|
|
}
|
|
|
|
|
2017-10-07 01:35:02 +00:00
|
|
|
// -------------------------------------------------------
|
2017-05-26 00:54:03 +00:00
|
|
|
// BUILD VARS
|
2017-10-07 01:35:02 +00:00
|
|
|
// -------------------------------------------------------
|
2017-05-26 00:54:03 +00:00
|
|
|
|
|
|
|
const ALIASES = {
|
|
|
|
'brace-ext-modelist': 'brace/ext/modelist.js',
|
|
|
|
'simplemde': 'simplemde/dist/simplemde.min.js',
|
|
|
|
'socket-io-client': 'socket.io-client/dist/socket.io.js',
|
|
|
|
'vue': (dev) ? 'vue/dist/vue.js' : 'vue/dist/vue.min.js',
|
2017-07-20 22:17:23 +00:00
|
|
|
'vue-lodash': 'vue-lodash/dist/vue-lodash.min.js',
|
|
|
|
'vue-resource': (dev) ? 'vue-resource/dist/vue-resource.js' : 'vue-resource/dist/vue-resource.es2015.js'
|
2017-05-26 00:54:03 +00:00
|
|
|
}
|
|
|
|
const SHIMS = {
|
2017-07-02 22:15:05 +00:00
|
|
|
diff2html: {
|
2017-08-12 19:11:27 +00:00
|
|
|
source: '../node_modules/diff2html/dist/diff2html.min.js',
|
2017-07-02 22:15:05 +00:00
|
|
|
exports: 'Diff2Html'
|
|
|
|
},
|
|
|
|
diff2htmlui: {
|
2017-08-12 19:11:27 +00:00
|
|
|
source: '../node_modules/diff2html/dist/diff2html-ui.min.js',
|
2017-07-02 22:15:05 +00:00
|
|
|
exports: 'Diff2HtmlUI'
|
2017-05-26 00:54:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-07 01:35:02 +00:00
|
|
|
// -------------------------------------------------------
|
2017-04-02 17:18:33 +00:00
|
|
|
// Global Tasks
|
2017-10-07 01:35:02 +00:00
|
|
|
// -------------------------------------------------------
|
2017-03-27 02:07:40 +00:00
|
|
|
|
2017-04-02 17:18:33 +00:00
|
|
|
console.info(colors.white('└── ') + colors.green('Running global tasks...'))
|
2017-08-12 19:11:27 +00:00
|
|
|
let globalTasks = require('./fuse_tasks')
|
2017-04-02 17:18:33 +00:00
|
|
|
|
2017-10-07 01:35:02 +00:00
|
|
|
// -------------------------------------------------------
|
|
|
|
// FUSEBOX PRODUCER
|
|
|
|
// -------------------------------------------------------
|
|
|
|
|
|
|
|
const babelrc = fs.readJsonSync('.babelrc')
|
|
|
|
const scssChain = [
|
|
|
|
fsbx.SassPlugin({
|
|
|
|
includePaths: ['node_modules'],
|
|
|
|
outputStyle: dev ? 'nested' : 'compressed'
|
|
|
|
}),
|
|
|
|
fsbx.PostCSS([
|
|
|
|
autoprefixer({
|
|
|
|
remove: false,
|
|
|
|
browsers: babelrc.presets[0][1].targets.browsers
|
|
|
|
})
|
|
|
|
]),
|
|
|
|
fsbx.CSSPlugin()
|
|
|
|
]
|
2017-04-02 17:18:33 +00:00
|
|
|
|
|
|
|
globalTasks.then(() => {
|
2017-05-13 21:03:32 +00:00
|
|
|
let fuse = fsbx.FuseBox.init({
|
2017-08-12 19:11:27 +00:00
|
|
|
homeDir: '../client',
|
|
|
|
output: '../assets/js/$name.js',
|
2017-05-13 21:03:32 +00:00
|
|
|
alias: ALIASES,
|
2017-07-08 21:33:09 +00:00
|
|
|
target: 'browser',
|
2017-08-12 19:11:27 +00:00
|
|
|
tsConfig: './tsconfig.json',
|
2017-05-13 21:03:32 +00:00
|
|
|
plugins: [
|
|
|
|
fsbx.EnvPlugin({ NODE_ENV: (dev) ? 'development' : 'production' }),
|
2017-10-07 01:35:02 +00:00
|
|
|
fsbx.VueComponentPlugin({
|
|
|
|
script: fsbx.BabelPlugin(babelrc),
|
|
|
|
template: fsbx.ConsolidatePlugin({
|
|
|
|
engine: 'pug'
|
|
|
|
}),
|
|
|
|
style: scssChain
|
|
|
|
}),
|
|
|
|
scssChain,
|
2017-10-29 05:30:46 +00:00
|
|
|
fsbx.RawPlugin(['.svg']),
|
2017-10-07 01:35:02 +00:00
|
|
|
fsbx.BabelPlugin(babelrc),
|
2017-07-22 14:33:31 +00:00
|
|
|
fsbx.JSONPlugin()
|
2017-05-13 21:03:32 +00:00
|
|
|
],
|
|
|
|
debug: false,
|
|
|
|
log: true
|
|
|
|
})
|
2017-03-29 00:19:01 +00:00
|
|
|
|
2017-10-07 01:35:02 +00:00
|
|
|
// -------------------------------------------------------
|
|
|
|
// FUSEBOX DEV
|
|
|
|
// -------------------------------------------------------
|
|
|
|
|
|
|
|
if (dev) {
|
|
|
|
fuse.dev({
|
|
|
|
port: 5555,
|
|
|
|
httpServer: false
|
|
|
|
})
|
2017-05-13 21:03:32 +00:00
|
|
|
}
|
2017-03-27 02:07:40 +00:00
|
|
|
|
2017-10-07 01:35:02 +00:00
|
|
|
// -------------------------------------------------------
|
|
|
|
// FUSEBOX BUNDLES
|
|
|
|
// -------------------------------------------------------
|
|
|
|
|
|
|
|
if (dev) {
|
|
|
|
fuse.bundle('libs').shim(SHIMS).instructions('~ index.js')
|
|
|
|
fuse.bundle('app').instructions('!> [index.js]').hmr({ reload: true }).watch()
|
|
|
|
} else {
|
|
|
|
fuse.bundle('bundle.min.js').shim(SHIMS).instructions('> index.js')
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------
|
|
|
|
// FUSEBOX RUN
|
|
|
|
// -------------------------------------------------------
|
|
|
|
|
2017-05-13 21:03:32 +00:00
|
|
|
fuse.run().then(() => {
|
|
|
|
console.info(colors.green.bold('\nAssets compilation + bundling completed.'))
|
2017-05-05 02:41:33 +00:00
|
|
|
|
2017-05-13 21:03:32 +00:00
|
|
|
if (dev) {
|
|
|
|
nodemon({
|
2017-10-07 01:35:02 +00:00
|
|
|
exec: 'node server',
|
|
|
|
ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/', 'tools/'],
|
2017-08-09 02:36:29 +00:00
|
|
|
ext: 'js json graphql',
|
2017-10-07 01:35:02 +00:00
|
|
|
watch: ['server'],
|
2017-05-13 21:03:32 +00:00
|
|
|
env: { 'NODE_ENV': 'development' }
|
2017-04-02 17:18:33 +00:00
|
|
|
})
|
2017-05-13 21:03:32 +00:00
|
|
|
}
|
2017-10-07 01:35:02 +00:00
|
|
|
return true
|
2017-05-13 21:03:32 +00:00
|
|
|
}).catch(err => {
|
|
|
|
console.error(colors.red(' X Bundle compilation failed! ' + err.message))
|
|
|
|
process.exit(1)
|
|
|
|
})
|
2017-04-02 17:18:33 +00:00
|
|
|
})
|