mirror of https://github.com/requarks/wiki
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.
193 lines
6.2 KiB
193 lines
6.2 KiB
8 years ago
|
'use strict'
|
||
|
|
||
|
/**
|
||
|
* FUSEBOX
|
||
|
*
|
||
8 years ago
|
* Client & Server compiler / bundler / watcher
|
||
8 years ago
|
*/
|
||
|
|
||
8 years ago
|
const colors = require('colors/safe')
|
||
|
const fsbx = require('fuse-box')
|
||
|
const nodemon = require('nodemon')
|
||
7 years ago
|
const babel = require('babel-core')
|
||
|
const uglify = require('uglify-es')
|
||
|
const fs = require('fs-extra')
|
||
8 years ago
|
|
||
8 years ago
|
// ======================================================
|
||
8 years ago
|
// Parse cmd arguments
|
||
8 years ago
|
// ======================================================
|
||
8 years ago
|
|
||
|
const args = require('yargs')
|
||
8 years ago
|
.option('d', {
|
||
|
alias: 'dev',
|
||
|
describe: 'Start in Developer mode',
|
||
|
type: 'boolean'
|
||
|
})
|
||
|
.option('c', {
|
||
|
alias: 'dev-configure',
|
||
|
describe: 'Start in Configure Developer mode',
|
||
|
type: 'boolean'
|
||
|
})
|
||
|
.help('h')
|
||
|
.alias('h', 'help')
|
||
|
.argv
|
||
8 years ago
|
|
||
8 years ago
|
let mode = 'build'
|
||
8 years ago
|
const dev = args.d || args.c
|
||
8 years ago
|
if (args.d) {
|
||
|
console.info(colors.bgWhite.black(' Starting Fuse in DEVELOPER mode... '))
|
||
|
mode = 'dev'
|
||
|
} else if (args.c) {
|
||
|
console.info(colors.bgWhite.black(' Starting Fuse in CONFIGURE DEVELOPER mode... '))
|
||
|
mode = 'dev-configure'
|
||
|
} else {
|
||
|
console.info(colors.bgWhite.black(' Starting Fuse in BUILD mode... '))
|
||
|
}
|
||
|
|
||
8 years ago
|
// ======================================================
|
||
|
// BUILD VARS
|
||
|
// ======================================================
|
||
|
|
||
|
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',
|
||
7 years ago
|
'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'
|
||
8 years ago
|
}
|
||
|
const SHIMS = {
|
||
|
jquery: {
|
||
7 years ago
|
source: '../node_modules/jquery/dist/jquery.js',
|
||
8 years ago
|
exports: '$'
|
||
8 years ago
|
},
|
||
|
diff2html: {
|
||
7 years ago
|
source: '../node_modules/diff2html/dist/diff2html.min.js',
|
||
8 years ago
|
exports: 'Diff2Html'
|
||
|
},
|
||
|
diff2htmlui: {
|
||
7 years ago
|
source: '../node_modules/diff2html/dist/diff2html-ui.min.js',
|
||
8 years ago
|
exports: 'Diff2HtmlUI'
|
||
8 years ago
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
// ======================================================
|
||
|
// Global Tasks
|
||
|
// ======================================================
|
||
8 years ago
|
|
||
8 years ago
|
console.info(colors.white('└── ') + colors.green('Running global tasks...'))
|
||
7 years ago
|
let globalTasks = require('./fuse_tasks')
|
||
8 years ago
|
|
||
|
// ======================================================
|
||
|
// Fuse Tasks
|
||
|
// ======================================================
|
||
|
|
||
|
globalTasks.then(() => {
|
||
8 years ago
|
let fuse = fsbx.FuseBox.init({
|
||
7 years ago
|
homeDir: '../client',
|
||
|
output: '../assets/js/$name.js',
|
||
8 years ago
|
alias: ALIASES,
|
||
8 years ago
|
target: 'browser',
|
||
7 years ago
|
tsConfig: './tsconfig.json',
|
||
8 years ago
|
plugins: [
|
||
|
fsbx.EnvPlugin({ NODE_ENV: (dev) ? 'development' : 'production' }),
|
||
|
fsbx.VuePlugin(),
|
||
8 years ago
|
['.scss', fsbx.SassPlugin({ outputStyle: (dev) ? 'nested' : 'compressed' }), fsbx.CSSPlugin()],
|
||
8 years ago
|
fsbx.BabelPlugin({ comments: false, presets: ['es2015'] }),
|
||
7 years ago
|
fsbx.JSONPlugin()
|
||
8 years ago
|
/* !dev && fsbx.QuantumPlugin({
|
||
|
target: 'browser',
|
||
|
uglify: true,
|
||
|
api: (core) => {
|
||
|
core.solveComputed('default/js/components/editor-codeblock.vue', {
|
||
|
mapping: '/js/ace/ace.js',
|
||
|
fn: (statement, core) => {
|
||
|
statement.setExpression(`'/js/ace/ace.js'`)
|
||
|
}
|
||
|
})
|
||
|
core.solveComputed('default/js/components/editor.component.js', {
|
||
|
mapping: '/js/simplemde/simplemde.min.js',
|
||
|
fn: (statement, core) => {
|
||
|
statement.setExpression(`'/js/simplemde/simplemde.min.js'`)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}) */
|
||
7 years ago
|
// !dev && fsbx.UglifyESPlugin()
|
||
8 years ago
|
],
|
||
|
debug: false,
|
||
|
log: true
|
||
|
})
|
||
8 years ago
|
|
||
8 years ago
|
const bundleVendor = fuse.bundle('vendor').shim(SHIMS).instructions('~ index.js') // eslint-disable-line no-unused-vars
|
||
|
const bundleApp = fuse.bundle('app').instructions('!> [index.js]')
|
||
|
// const bundleApp = fuse.bundle('app').shim(SHIMS).instructions('> index.js')
|
||
8 years ago
|
const bundleSetup = fuse.bundle('configure').instructions('> configure.js')
|
||
8 years ago
|
|
||
8 years ago
|
switch (mode) {
|
||
|
case 'dev':
|
||
|
bundleApp.watch()
|
||
8 years ago
|
break
|
||
|
case 'dev-configure':
|
||
8 years ago
|
bundleSetup.watch()
|
||
8 years ago
|
break
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
fuse.run().then(() => {
|
||
|
console.info(colors.green.bold('\nAssets compilation + bundling completed.'))
|
||
8 years ago
|
|
||
8 years ago
|
if (dev) {
|
||
|
nodemon({
|
||
|
exec: (args.d) ? 'node server' : 'node wiki configure',
|
||
|
ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/'],
|
||
|
ext: 'js json',
|
||
|
watch: (args.d) ? ['server'] : ['server/configure.js'],
|
||
|
env: { 'NODE_ENV': 'development' }
|
||
8 years ago
|
})
|
||
7 years ago
|
} else {
|
||
|
console.info(colors.yellow.bold('\nTranspiling vendor bundle...'))
|
||
|
let appCode = babel.transform(fs.readFileSync('./assets/js/app.js', 'utf8'), {
|
||
|
babelrc: false,
|
||
|
compact: false,
|
||
|
filename: 'app.js',
|
||
|
plugins: ['transform-object-assign']
|
||
|
}).code
|
||
|
let vendorCode = babel.transform(fs.readFileSync('./assets/js/vendor.js', 'utf8'), {
|
||
|
babelrc: false,
|
||
|
comments: false,
|
||
|
compact: false,
|
||
|
filename: 'vendor.js',
|
||
|
plugins: [
|
||
|
'transform-es2015-arrow-functions',
|
||
|
'transform-es2015-block-scoped-functions',
|
||
|
'transform-es2015-block-scoping',
|
||
|
'transform-es2015-classes',
|
||
|
'transform-es2015-computed-properties',
|
||
|
'transform-es2015-destructuring',
|
||
|
'transform-es2015-duplicate-keys',
|
||
|
'transform-es2015-for-of',
|
||
|
'transform-es2015-function-name',
|
||
|
'transform-es2015-literals',
|
||
|
'transform-es2015-object-super',
|
||
|
'transform-es2015-parameters',
|
||
|
'transform-es2015-shorthand-properties',
|
||
|
'transform-es2015-spread',
|
||
|
'transform-es2015-sticky-regex',
|
||
|
'transform-es2015-template-literals',
|
||
|
'transform-es2015-typeof-symbol',
|
||
|
'transform-es2015-unicode-regex'
|
||
|
]
|
||
|
}).code
|
||
|
console.info(colors.yellow.bold('Minifing bundles...'))
|
||
|
fs.writeFileSync('./assets/js/vendor.js', uglify.minify(vendorCode).code, 'utf8')
|
||
|
fs.writeFileSync('./assets/js/app.js', uglify.minify(appCode).code, 'utf8')
|
||
|
fs.writeFileSync('./assets/js/configure.js', uglify.minify(fs.readFileSync('./assets/js/configure.js', 'utf8')).code, 'utf8')
|
||
|
console.info(colors.green.bold('\nBUILD SUCCEEDED.'))
|
||
|
return true
|
||
8 years ago
|
}
|
||
|
}).catch(err => {
|
||
|
console.error(colors.red(' X Bundle compilation failed! ' + err.message))
|
||
|
process.exit(1)
|
||
|
})
|
||
8 years ago
|
})
|