chore: Updated fusebox scripts

This commit is contained in:
NGPixel 2017-05-13 17:03:32 -04:00
parent 9e801548e0
commit 8f974a3ac7
8 changed files with 94 additions and 160 deletions

226
fuse.js
View File

@ -30,17 +30,12 @@ const args = require('yargs')
describe: 'Start in Configure Developer mode', describe: 'Start in Configure Developer mode',
type: 'boolean' type: 'boolean'
}) })
.option('i', {
alias: 'inspect',
describe: 'Enable Inspector for debugging',
type: 'boolean',
implies: 'd'
})
.help('h') .help('h')
.alias('h', 'help') .alias('h', 'help')
.argv .argv
let mode = 'build' let mode = 'build'
const dev = args.d || args.c
if (args.d) { if (args.d) {
console.info(colors.bgWhite.black(' Starting Fuse in DEVELOPER mode... ')) console.info(colors.bgWhite.black(' Starting Fuse in DEVELOPER mode... '))
mode = 'dev' mode = 'dev'
@ -51,31 +46,6 @@ if (args.d) {
console.info(colors.bgWhite.black(' Starting Fuse in BUILD mode... ')) console.info(colors.bgWhite.black(' Starting Fuse in BUILD mode... '))
} }
// ======================================================
// Define aliases / shims
// ======================================================
const ALIASES = {
'brace-ext-modelist': 'brace/ext/modelist.js',
'simplemde': 'simplemde/dist/simplemde.min.js',
'socket.io-client': 'socket.io-client/dist/socket.io.min.js',
'vue': 'vue/dist/vue.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 // Global Tasks
// ====================================================== // ======================================================
@ -169,6 +139,12 @@ let globalTasks = Promise.mapSeries([
}).then(() => { }).then(() => {
return fs.outputFileAsync('./.build/_preinit.js', preInitContent, 'utf8') return fs.outputFileAsync('./.build/_preinit.js', preInitContent, 'utf8')
}) })
},
/**
* Delete Fusebox cache
*/
() => {
return fs.emptyDirAsync('./.fusebox')
} }
], f => { return f() }) ], f => { return f() })
@ -176,129 +152,83 @@ let globalTasks = Promise.mapSeries([
// Fuse Tasks // Fuse Tasks
// ====================================================== // ======================================================
let fuse 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': 'vue/dist/vue.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'
}
}
globalTasks.then(() => { 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.UglifyJSPlugin({
compress: { unused: false },
output: { 'max_line_len': 1000000 }
})
],
debug: false,
log: true
})
if (dev) {
fuse.dev({
port: 4444,
httpServer: false
})
}
const bundleLibs = fuse.bundle('libs').instructions('~ index.js')
const bundleApp = fuse.bundle('app').instructions('!> index.js')
const bundleSetup = fuse.bundle('configure').instructions('> configure.js')
switch (mode) { switch (mode) {
// =============================================
// DEVELOPER MODE
// =============================================
case 'dev': case 'dev':
// Client bundleLibs.watch()
bundleApp.watch()
fuse = fsbx.FuseBox.init({
homeDir: './client',
output: './assets/js/$name.min.js',
alias: ALIASES,
shim: SHIMS,
plugins: [
fsbx.VuePlugin(),
[ '.scss', fsbx.SassPlugin(), fsbx.CSSPlugin() ],
fsbx.BabelPlugin({ comments: false, presets: ['es2015'] }),
fsbx.JSONPlugin()
],
debug: false,
log: true
})
fuse.dev({
port: 4444,
httpServer: false
})
fuse.bundle('bundle')
.instructions('> index.js')
.watch()
fuse.run().then(() => {
nodemon({
exec: (args.i) ? 'node --inspect server' : 'node server',
ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/'],
ext: 'js json',
watch: ['server'],
env: { 'NODE_ENV': 'development' }
})
})
break break
// =============================================
// CONFIGURE - DEVELOPER MODE
// =============================================
case 'dev-configure': case 'dev-configure':
// Client bundleSetup.watch()
fuse = fsbx.FuseBox.init({
homeDir: './client',
output: './assets/js/$name.min.js',
alias: ALIASES,
shim: SHIMS,
plugins: [
[ '.scss', fsbx.SassPlugin(), fsbx.CSSPlugin() ],
fsbx.BabelPlugin({ comments: false, presets: ['es2015'] }),
fsbx.JSONPlugin()
],
debug: false,
log: true
})
fuse.dev({
port: 4444,
httpServer: false
})
fuse.bundle('configure')
.instructions('> configure.js')
.watch()
fuse.run().then(() => {
nodemon({
exec: 'node wiki configure',
ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/'],
ext: 'js json',
watch: ['server/configure.js'],
env: { 'NODE_ENV': 'development' }
})
})
break
// =============================================
// BUILD ONLY MODE
// =============================================
case 'build':
fuse = fsbx.FuseBox.init({
homeDir: './client',
output: './assets/js/$name.min.js',
alias: ALIASES,
shim: SHIMS,
plugins: [
fsbx.EnvPlugin({ NODE_ENV: 'production' }),
fsbx.VuePlugin(),
[ '.scss', fsbx.SassPlugin({ outputStyle: 'compressed' }), fsbx.CSSPlugin() ],
fsbx.BabelPlugin({
config: {
comments: false,
presets: ['es2015']
}
}),
fsbx.JSONPlugin(),
fsbx.UglifyJSPlugin({
compress: { unused: false },
output: { 'max_line_len': 1000000 }
})
],
debug: false,
log: true
})
fuse.bundle('bundle').instructions('> index.js')
fuse.bundle('configure').instructions('> configure.js')
fuse.run().then(() => {
console.info(colors.green.bold('\nAssets compilation + bundling completed.'))
}).catch(err => {
console.error(colors.red(' X Bundle compilation failed! ' + err.message))
process.exit(1)
})
break 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)
})
}) })

View File

@ -6,6 +6,7 @@
"scripts": { "scripts": {
"start": "node wiki start", "start": "node wiki start",
"stop": "node wiki stop", "stop": "node wiki stop",
"restart": "node wiki restart",
"build": "node fuse", "build": "node fuse",
"dev": "node fuse -d", "dev": "node fuse -d",
"dev-configure": "node fuse -c", "dev-configure": "node fuse -c",

View File

@ -44,8 +44,7 @@ const Promise = require('bluebird')
const fs = Promise.promisifyAll(require('fs-extra')) const fs = Promise.promisifyAll(require('fs-extra'))
const klaw = require('klaw') const klaw = require('klaw')
const Cron = require('cron').CronJob const Cron = require('cron').CronJob
const i18nextBackend = require('i18next-node-fs-backend') const i18nBackend = require('i18next-node-fs-backend')
const i18nextMw = require('i18next-express-middleware')
const entryHelper = require('./helpers/entry') const entryHelper = require('./helpers/entry')
@ -54,15 +53,14 @@ const entryHelper = require('./helpers/entry')
// ---------------------------------------- // ----------------------------------------
global.lang global.lang
.use(i18nextBackend) .use(i18nBackend)
.use(i18nextMw.LanguageDetector)
.init({ .init({
load: 'languageOnly', load: 'languageOnly',
ns: ['common', 'errors', 'git'], ns: ['common', 'admin', 'auth', 'errors', 'git'],
defaultNS: 'common', defaultNS: 'common',
saveMissing: false, saveMissing: false,
supportedLngs: ['en', 'fr'], preload: [appconfig.lang],
preload: ['en', 'fr'], lng: appconfig.lang,
fallbackLng: 'en', fallbackLng: 'en',
backend: { backend: {
loadPath: path.join(SERVERPATH, 'locales/{{lng}}/{{ns}}.json') loadPath: path.join(SERVERPATH, 'locales/{{lng}}/{{ns}}.json')

View File

@ -18,7 +18,8 @@ html(data-logic='login')
link(rel='manifest', href='/manifest.json') link(rel='manifest', href='/manifest.json')
// JS / CSS // JS / CSS
script(type='text/javascript', src='/js/bundle.min.js') script(type='text/javascript', src='/js/libs.min.js')
script(type='text/javascript', src='/js/app.min.js')
body body
#bg #bg

View File

@ -18,7 +18,8 @@ html(data-logic='error')
link(rel='manifest', href='/manifest.json') link(rel='manifest', href='/manifest.json')
// JS / CSS // JS / CSS
script(type='text/javascript', src='/js/bundle.min.js') script(type='text/javascript', src='/js/libs.min.js')
script(type='text/javascript', src='/js/app.min.js')
body(class='is-forbidden') body(class='is-forbidden')
.container .container

View File

@ -18,7 +18,8 @@ html(data-logic='error')
link(rel='manifest', href='/manifest.json') link(rel='manifest', href='/manifest.json')
// JS / CSS // JS / CSS
script(type='text/javascript', src='/js/bundle.min.js') script(type='text/javascript', src='/js/libs.min.js')
script(type='text/javascript', src='/js/app.min.js')
body(class='is-notexist') body(class='is-notexist')
.container .container

View File

@ -18,7 +18,8 @@ html(data-logic='error')
link(rel='manifest', href='/manifest.json') link(rel='manifest', href='/manifest.json')
// JS / CSS // JS / CSS
script(type='text/javascript', src='/js/bundle.min.js') script(type='text/javascript', src='/js/libs.min.js')
script(type='text/javascript', src='/js/app.min.js')
body(class='is-error') body(class='is-error')
.container .container

View File

@ -18,7 +18,8 @@ html
link(rel='manifest', href='/manifest.json') link(rel='manifest', href='/manifest.json')
// JS / CSS // JS / CSS
script(type='text/javascript', src='/js/bundle.min.js') script(type='text/javascript', src='/js/libs.min.js')
script(type='text/javascript', src='/js/app.min.js')
block head block head