forked from requarks/wiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuse.js
137 lines (121 loc) · 3.54 KB
/
fuse.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
'use strict'
/**
* FUSEBOX
*
* Client & Server compiler / bundler / watcher
*/
const colors = require('colors/safe')
const fsbx = require('fuse-box')
const nodemon = require('nodemon')
// ======================================================
// Parse cmd arguments
// ======================================================
const args = require('yargs')
.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
let mode = 'build'
const dev = args.d || args.c
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... '))
}
// ======================================================
// 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',
'vue-lodash': 'vue-lodash/dist/vue-lodash.min.js'
}
const SHIMS = {
_preinit: {
source: '.build/_preinit.js',
exports: '_preinit'
},
jquery: {
source: 'node_modules/jquery/dist/jquery.js',
exports: '$'
},
mathjax: {
source: 'node_modules/mathjax/MathJax.js',
exports: 'MathJax'
}
}
// ======================================================
// Global Tasks
// ======================================================
console.info(colors.white('└── ') + colors.green('Running global tasks...'))
let globalTasks = require('./.build/_tasks')
// ======================================================
// Fuse Tasks
// ======================================================
globalTasks.then(() => {
let fuse = fsbx.FuseBox.init({
homeDir: './client',
output: './assets/js/$name.min.js',
alias: ALIASES,
shim: SHIMS,
plugins: [
fsbx.EnvPlugin({ NODE_ENV: (dev) ? 'development' : 'production' }),
fsbx.VuePlugin(),
['.scss', fsbx.SassPlugin({ outputStyle: (dev) ? 'nested' : 'compressed' }), fsbx.CSSPlugin()],
fsbx.BabelPlugin({ comments: false, presets: ['es2015'] }),
fsbx.JSONPlugin(),
!dev && fsbx.UglifyESPlugin({
compress: { unused: false },
output: { 'max_line_len': 1000000 }
})
],
debug: false,
log: true
})
if (dev) {
fuse.dev({
port: 4444,
httpServer: false
})
}
const bundleApp = fuse.bundle('app').instructions('> index.js')
const bundleSetup = fuse.bundle('configure').instructions('> configure.js')
switch (mode) {
case 'dev':
bundleApp.watch()
break
case 'dev-configure':
bundleSetup.watch()
break
}
fuse.run().then(() => {
console.info(colors.green.bold('\nAssets compilation + bundling completed.'))
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' }
})
}
}).catch(err => {
console.error(colors.red(' X Bundle compilation failed! ' + err.message))
process.exit(1)
})
})