Refactored install + handle long code lines + fuse skip ace

This commit is contained in:
NGPixel 2017-04-08 16:16:13 -04:00
parent f6e8e91f7e
commit 3c63718328
5 changed files with 177 additions and 121 deletions

View File

@ -1,7 +1,20 @@
.has-mkcontent {
width:100%;
overflow:hidden;
.columns, .column {
width: 100%;
overflow: hidden;
}
}
.mkcontent { .mkcontent {
font-size: 14px; font-size: 14px;
color: mc('grey', '700'); color: mc('grey', '700');
padding: 0 0 20px 0; padding: 0 0 20px 0;
width: 100%;
overflow: hidden;
h1, h2, h3 { h1, h2, h3 {
font-weight: 400; font-weight: 400;
@ -243,6 +256,7 @@
padding: 20px 20px 20px 13px; padding: 20px 20px 20px 13px;
font-family: $core-font-monospace; font-family: $core-font-monospace;
white-space: pre; white-space: pre;
overflow-x: scroll;
> code { > code {
border-radius: 5px; border-radius: 5px;

View File

@ -66,7 +66,7 @@ router.post('/login', bruteforce.prevent, function (req, res, next) {
req.brute.reset(function () { req.brute.reset(function () {
return res.redirect('/') return res.redirect('/')
}) })
}) }) || true
}).catch(err => { }).catch(err => {
// LOGIN FAIL // LOGIN FAIL
if (err.message === 'INVALID_LOGIN') { if (err.message === 'INVALID_LOGIN') {

25
fuse.js
View File

@ -70,15 +70,24 @@ console.info(colors.white('└── ') + colors.green('Running global tasks...'
let globalTasks = Promise.mapSeries([ let globalTasks = Promise.mapSeries([
() => { () => {
console.info(colors.white(' └── ') + colors.green('Copy + Minify ACE modes to assets...')) fs.accessAsync('./assets/js/ace').then(() => {
return fs.ensureDirAsync('./assets/js/ace').then(() => { console.info(colors.white(' └── ') + colors.magenta('ACE modes directory already exists. Task aborted.'))
return fs.readdirAsync('./node_modules/brace/mode').then(modeList => { return true
return Promise.map(modeList, mdFile => { }).catch(err => {
console.info(colors.white(' mode-' + mdFile)) if (err.code === 'ENOENT') {
let result = uglify.minify(path.join('./node_modules/brace/mode', mdFile), { output: { 'max_line_len': 1000000 } }) console.info(colors.white(' └── ') + colors.green('Copy + Minify ACE modes to assets...'))
return fs.writeFileAsync(path.join('./assets/js/ace', 'mode-' + mdFile), result.code) return fs.ensureDirAsync('./assets/js/ace').then(() => {
return fs.readdirAsync('./node_modules/brace/mode').then(modeList => {
return Promise.map(modeList, mdFile => {
console.info(colors.white(' mode-' + mdFile))
let result = uglify.minify(path.join('./node_modules/brace/mode', mdFile), { output: { 'max_line_len': 1000000 } })
return fs.writeFileAsync(path.join('./assets/js/ace', 'mode-' + mdFile), result.code)
})
})
}) })
}) } else {
throw err
}
}) })
} }
], f => { return f() }) ], f => { return f() })

View File

@ -1,145 +1,151 @@
'use strict' 'use strict'
// =====================================================
// Wiki.js
// Installation Script
// =====================================================
const Promise = require('bluebird') const Promise = require('bluebird')
const _ = require('lodash')
const colors = require('colors/safe')
const exec = require('execa') const exec = require('execa')
const fs = Promise.promisifyAll(require('fs-extra')) const fs = Promise.promisifyAll(require('fs-extra'))
const https = require('follow-redirects').https const https = require('follow-redirects').https
const inquirer = require('inquirer')
const os = require('os')
const path = require('path') const path = require('path')
const pm2 = Promise.promisifyAll(require('pm2')) const pm2 = Promise.promisifyAll(require('pm2'))
const tar = require('tar') const tar = require('tar')
const zlib = require('zlib') const zlib = require('zlib')
const inquirer = require('inquirer')
const colors = require('colors/safe')
const _ = require('lodash')
const os = require('os')
let installDir = path.resolve(__dirname, '../..') const installDir = path.resolve(__dirname, '../..')
console.info(colors.yellow( // =====================================================
' __ __ _ _ _ _ \n' + // INSTALLATION TASKS
'/ / /\\ \\ (_) | _(_) (_)___ \n' + // =====================================================
'\\ \\/ \\/ / | |/ / | | / __| \n' +
' \\ /\\ /| | <| |_ | \\__ \\ \n' +
' \\/ \\/ |_|_|\\_\\_(_)/ |___/ \n' +
' |__/\n'))
var ora = require('ora')({ text: 'Initializing...', spinner: 'dots12' }).start() const tasks = {
ora.text = 'Looking for running instances...'
pm2.connectAsync().then(() => {
/** /**
* Stop and delete existing instances * Stop and delete existing instances
*/ */
return pm2.describeAsync('wiki').then(() => { stopAndDeleteInstances () {
ora.text = 'Stopping and deleting process from pm2...' ora.text = 'Looking for running instances...'
return pm2.deleteAsync('wiki') return pm2.connectAsync().then(() => {
}).catch(err => { // eslint-disable-line handle-callback-err return pm2.describeAsync('wiki').then(() => {
return true ora.text = 'Stopping and deleting process from pm2...'
}) return pm2.deleteAsync('wiki')
}).then(() => { }).catch(err => { // eslint-disable-line handle-callback-err
return true
}).finally(() => {
pm2.disconnect()
})
})
},
/** /**
* Check for sufficient memory * Check for sufficient memory
*/ */
if (os.totalmem() < 1024 * 1024 * 768) { checkRequirements () {
throw new Error('Not enough memory to install dependencies. Minimum is 768 MB.') ora.text = 'Checking system requirements...'
} if (os.totalmem() < 1024 * 1024 * 768) {
return true return Promise.reject(new Error('Not enough memory to install dependencies. Minimum is 768 MB.'))
}).then(() => { } else {
return Promise.resolve(true)
}
},
/** /**
* Install via local tarball if present * Install via local tarball if present
*/ */
let skipHttp = true installFromLocal () {
let tbPath = path.join(installDir, 'wiki-js.tar.gz') let hasTarball = true
return fs.accessAsync(tbPath) let tbPath = path.join(installDir, 'wiki-js.tar.gz')
.catch(err => { // eslint-disable-line handle-callback-err return fs.accessAsync(tbPath)
skipHttp = false .catch(err => { // eslint-disable-line handle-callback-err
}).then(() => { hasTarball = false
if (skipHttp) { }).then(() => {
ora.text = 'Local tarball found. Extracting...' if (hasTarball) {
ora.text = 'Local tarball found. Extracting...'
return new Promise((resolve, reject) => {
fs.createReadStream(tbPath).pipe(zlib.createGunzip())
.pipe(tar.Extract({ path: installDir }))
.on('error', err => reject(err))
.on('end', () => {
ora.text = 'Tarball extracted successfully.'
resolve(true)
})
})
} else {
return false
}
})
},
/**
* Install from GitHub release download
*/
installFromRemote () {
// Fetch version from npm package
return fs.readJsonAsync('package.json').then((packageObj) => {
let versionGet = _.chain(packageObj.version).split('.').take(4).join('.')
let remoteURL = _.replace('https://github.com/Requarks/wiki/releases/download/v{0}/wiki-js.tar.gz', '{0}', versionGet)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
fs.createReadStream(tbPath).pipe(zlib.createGunzip()) // Fetch tarball
ora.text = 'Looking for latest release...'
https.get(remoteURL, resp => {
if (resp.statusCode !== 200) {
return reject(new Error('Remote file not found'))
}
ora.text = 'Remote wiki.js tarball found. Downloading...'
// Extract tarball
resp.pipe(zlib.createGunzip())
.pipe(tar.Extract({ path: installDir })) .pipe(tar.Extract({ path: installDir }))
.on('error', err => reject(err)) .on('error', err => reject(err))
.on('end', () => { .on('end', () => {
ora.text = 'Tarball extracted successfully.' ora.text = 'Tarball extracted successfully.'
resolve(true) resolve(true)
}) })
})
} else {
return false
}
})
}).then((skipHttp) => {
/**
* Install via remote tarball
*/
if (skipHttp) { return true }
/**
* Fetch version from npm package
*/
return fs.readJsonAsync('package.json').then((packageObj) => {
let versionGet = _.chain(packageObj.version).split('.').take(4).join('.')
let remoteURL = _.replace('https://github.com/Requarks/wiki/releases/download/v{0}/wiki-js.tar.gz', '{0}', versionGet)
return new Promise((resolve, reject) => {
/**
* Fetch tarball
*/
ora.text = 'Looking for latest release...'
https.get(remoteURL, resp => {
if (resp.statusCode !== 200) {
return reject(new Error('Remote file not found'))
}
ora.text = 'Install tarball found. Downloading...'
/**
* Extract tarball
*/
resp.pipe(zlib.createGunzip())
.pipe(tar.Extract({ path: installDir }))
.on('error', err => reject(err))
.on('end', () => {
ora.text = 'Tarball extracted successfully.'
resolve(true)
}) })
}) })
}) })
}) },
}).then(() => { /**
ora.text = 'Installing Wiki.js npm dependencies...' * Install npm dependencies
return exec.stdout('npm', ['install', '--only=production', '--no-optional'], { */
cwd: installDir installDependencies () {
}).then(results => { ora.text = 'Installing Wiki.js npm dependencies...'
ora.text = 'Wiki.js npm dependencies installed successfully.' return exec.stdout('npm', ['install', '--only=production', '--no-optional'], {
return true cwd: installDir
}) }).then(results => {
}).then(() => { ora.text = 'Wiki.js npm dependencies installed successfully.'
fs.accessAsync(path.join(installDir, 'config.yml')).then(() => { return true
/** })
* Upgrade mode },
*/ /**
ora.succeed('Upgrade completed.') * Create default config.yml file if new installation
console.info(colors.yellow('\n!!! IMPORTANT !!!')) */
console.info(colors.yellow('Running the configuration wizard is optional but recommended after an upgrade to ensure your config file is using the latest available settings.')) ensureConfigFile () {
console.info(colors.yellow('Note that the contents of your config file will be displayed during the configuration wizard. It is therefor highly recommended to run the wizard on a non-publicly accessible port or skip this step completely.\n')) return fs.accessAsync(path.join(installDir, 'config.yml')).then(() => {
return false // Is Upgrade
}).catch(err => { ora.succeed('Upgrade completed.')
/** console.info(colors.yellow('\n!!! IMPORTANT !!!'))
* Install mode console.info(colors.yellow('Running the configuration wizard is optional but recommended after an upgrade to ensure your config file is using the latest available settings.'))
*/ console.info(colors.yellow('Note that the contents of your config file will be displayed during the configuration wizard. It is therefor highly recommended to run the wizard on a non-publicly accessible port or skip this step completely.\n'))
if (err.code === 'ENOENT') { return true
ora.text = 'First-time install, creating a new config.yml...' }).catch(err => {
return fs.copyAsync(path.join(installDir, 'config.sample.yml'), path.join(installDir, 'config.yml')).then(() => { // Is New Install
ora.succeed('Installation succeeded.') if (err.code === 'ENOENT') {
return true ora.text = 'First-time install, creating a new config.yml...'
}) return fs.copyAsync(path.join(installDir, 'config.sample.yml'), path.join(installDir, 'config.yml')).then(() => {
} else { ora.succeed('Installation succeeded.')
return err return true
} })
}).then((isNewInstall) => { } else {
return err
}
})
},
startConfigurationWizard () {
if (process.stdout.isTTY) { if (process.stdout.isTTY) {
inquirer.prompt([{ inquirer.prompt([{
type: 'list', type: 'list',
@ -192,9 +198,36 @@ pm2.connectAsync().then(() => {
} else { } else {
console.info(colors.cyan('[WARNING] Non-interactive terminal detected. You must manually start the configuration wizard using the command: node wiki configure')) console.info(colors.cyan('[WARNING] Non-interactive terminal detected. You must manually start the configuration wizard using the command: node wiki configure'))
} }
}
}
// =====================================================
// INSTALL SEQUENCE
// =====================================================
console.info(colors.yellow(
' __ __ _ _ _ _ \n' +
'/ / /\\ \\ (_) | _(_) (_)___ \n' +
'\\ \\/ \\/ / | |/ / | | / __| \n' +
' \\ /\\ /| | <| |_ | \\__ \\ \n' +
' \\/ \\/ |_|_|\\_\\_(_)/ |___/ \n' +
' |__/\n'))
let ora = require('ora')({ text: 'Initializing...', spinner: 'dots12' }).start()
Promise.join(
tasks.stopAndDeleteInstances(),
tasks.checkRequirements()
).then(() => {
return tasks.installFromLocal().then(succeeded => {
return (!succeeded) ? tasks.installFromRemote() : true
}) })
}).then(() => {
return tasks.installDependencies()
}).then(() => {
return tasks.ensureConfigFile()
}).then(() => {
return tasks.startConfigurationWizard()
}).catch(err => { }).catch(err => {
ora.fail(err) ora.fail(err)
}).finally(() => {
pm2.disconnect()
}) })

View File

@ -29,7 +29,7 @@ block rootNavRight
block content block content
#page-type-view(data-entrypath=pageData.meta.path) #page-type-view(data-entrypath=pageData.meta.path)
.container.is-fluid .container.is-fluid.has-mkcontent
.columns.is-gapless .columns.is-gapless
.column.is-narrow.is-hidden-touch.sidebar .column.is-narrow.is-hidden-touch.sidebar