@ -19,6 +19,8 @@ const tar = require('tar')
const zlib = require ( 'zlib' )
const zlib = require ( 'zlib' )
const installDir = path . resolve ( _ _dirname , '../..' )
const installDir = path . resolve ( _ _dirname , '../..' )
const isContainerBased = ( process . env . WIKI _JS _HEROKU || process . env . WIKI _JS _DOCKER )
let installMode = 'new'
// =====================================================
// =====================================================
// INSTALLATION TASKS
// INSTALLATION TASKS
@ -39,6 +41,8 @@ const tasks = {
} ) . finally ( ( ) => {
} ) . finally ( ( ) => {
pm2 . disconnect ( )
pm2 . disconnect ( )
} )
} )
} ) . catch ( err => { // eslint-disable-line handle-callback-err
return true
} )
} )
} ,
} ,
/ * *
/ * *
@ -46,7 +50,7 @@ const tasks = {
* /
* /
checkRequirements ( ) {
checkRequirements ( ) {
ora . text = 'Checking system requirements...'
ora . text = 'Checking system requirements...'
if ( os . totalmem ( ) < 10 24 * 1024 * 768 ) {
if ( os . totalmem ( ) < 10 00 * 1000 * 768 ) {
return Promise . reject ( new Error ( 'Not enough memory to install dependencies. Minimum is 768 MB.' ) )
return Promise . reject ( new Error ( 'Not enough memory to install dependencies. Minimum is 768 MB.' ) )
} else {
} else {
return Promise . resolve ( true )
return Promise . resolve ( true )
@ -67,7 +71,7 @@ const tasks = {
return new Promise ( ( resolve , reject ) => {
return new Promise ( ( resolve , reject ) => {
fs . createReadStream ( tbPath ) . pipe ( zlib . createGunzip ( ) )
fs . createReadStream ( tbPath ) . pipe ( zlib . createGunzip ( ) )
. pipe ( tar . Extract( { path : installDir } ) )
. pipe ( tar . extract( { cwd : 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.'
@ -96,10 +100,11 @@ const tasks = {
return reject ( new Error ( 'Remote file not found' ) )
return reject ( new Error ( 'Remote file not found' ) )
}
}
ora . text = 'Remote wiki.js tarball found. Downloading...'
ora . text = 'Remote wiki.js tarball found. Downloading...'
isContainerBased && console . info ( '>> Extracting to ' + installDir )
// Extract tarball
// Extract tarball
resp . pipe ( zlib . createGunzip ( ) )
resp . pipe ( zlib . createGunzip ( ) )
. pipe ( tar . Extract( { path : installDir } ) )
. pipe ( tar . extract( { cwd : 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.'
@ -109,54 +114,58 @@ const tasks = {
} )
} )
} )
} )
} ,
} ,
/ * *
* Install npm dependencies
* /
installDependencies ( ) {
ora . text = 'Installing Wiki.js npm dependencies...'
return exec . stdout ( 'npm' , [ 'install' , '--only=production' , '--no-optional' ] , {
cwd : installDir
} ) . then ( results => {
ora . text = 'Wiki.js npm dependencies installed successfully.'
return true
} )
} ,
/ * *
/ * *
* Create default config . yml file if new installation
* Create default config . yml file if new installation
* /
* /
ensureConfigFile ( ) {
ensureConfigFile ( ) {
return fs . accessAsync ( path . join ( installDir , 'config.yml' ) ) . then ( ( ) => {
return fs . accessAsync ( path . join ( installDir , 'config.yml' ) ) . then ( ( ) => {
// Is Upgrade
// Is Upgrade
ora . succeed ( 'Upgrade completed.' )
ora . text = 'Existing config.yml found. Upgrade mode.'
console . info ( colors . yellow ( '\n!!! IMPORTANT !!!' ) )
installMode = 'upgrade'
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' ) )
return true
return true
} ) . catch ( err => {
} ) . catch ( err => {
// Is New Install
// Is New Install
if ( err . code === 'ENOENT' ) {
if ( err . code === 'ENOENT' ) {
ora . text = 'First-time install, creating a new config.yml...'
ora . text = 'First-time install, creating a new config.yml...'
installMode = 'new'
let sourceConfigFile = path . join ( installDir , 'config.sample.yml' )
let sourceConfigFile = path . join ( installDir , 'config.sample.yml' )
if ( process . env . WIKI _JS _HEROKU ) {
if ( process . env . WIKI _JS _HEROKU ) {
sourceConfigFile = path . join ( _ _dirname , 'configs/config.heroku.yml' )
sourceConfigFile = path . join ( _ _dirname , 'configs/config.heroku.yml' )
} else if ( process . env . WIKI _JS _DOCKER ) {
} else if ( process . env . WIKI _JS _DOCKER ) {
sourceConfigFile = path . join ( _ _dirname , 'configs/config.docker.yml' )
sourceConfigFile = path . join ( _ _dirname , 'configs/config.docker.yml' )
}
}
return fs . copyAsync ( sourceConfigFile , path . join ( installDir , 'config.yml' ) ) . then ( ( ) => {
return fs . copyAsync ( sourceConfigFile , path . join ( installDir , 'config.yml' ) )
ora . succeed ( 'Installation succeeded.' )
return true
} )
} else {
} else {
return err
return err
}
}
} )
} )
} ,
} ,
/ * *
* Install npm dependencies
* /
installDependencies ( ) {
ora . text = 'Installing Wiki.js npm dependencies...'
return exec . stdout ( 'npm' , [ 'install' , '--only=production' , '--no-optional' ] , {
cwd : installDir
} ) . then ( results => {
ora . text = 'Wiki.js npm dependencies installed successfully.'
return true
} )
} ,
startConfigurationWizard ( ) {
startConfigurationWizard ( ) {
ora . succeed ( 'Installation succeeded.' )
if ( process . env . WIKI _JS _HEROKU ) {
if ( process . env . WIKI _JS _HEROKU ) {
console . info ( 'Wiki.js has been installed and is configured to use Heroku configuration.' )
console . info ( '> Wiki.js has been installed and is configured to use Heroku configuration.' )
return true
} else if ( process . env . WIKI _JS _DOCKER ) {
} else if ( process . env . WIKI _JS _DOCKER ) {
console . info ( 'Docker environment detected. Skipping setup wizard auto-start.' )
console . info ( 'Docker environment detected. Skipping setup wizard auto-start.' )
return true
} else if ( process . stdout . isTTY ) {
} else if ( process . stdout . isTTY ) {
if ( installMode === 'upgrade' ) {
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.' ) )
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' ) )
}
inquirer . prompt ( [ {
inquirer . prompt ( [ {
type : 'list' ,
type : 'list' ,
name : 'action' ,
name : 'action' ,
@ -215,7 +224,7 @@ const tasks = {
// INSTALL SEQUENCE
// INSTALL SEQUENCE
// =====================================================
// =====================================================
if ( ! process. env . WIKI _JS _HEROKU && ! process . env . WIKI _JS _DOCKER ) {
if ( ! isContainerBased ) {
console . info ( colors . yellow (
console . info ( colors . yellow (
' __ __ _ _ _ _ \n' +
' __ __ _ _ _ _ \n' +
'/ / /\\ \\ (_) | _(_) (_)___ \n' +
'/ / /\\ \\ (_) | _(_) (_)___ \n' +
@ -233,15 +242,19 @@ Promise.join(
tasks . stopAndDeleteInstances ( ) ,
tasks . stopAndDeleteInstances ( ) ,
tasks . checkRequirements ( )
tasks . checkRequirements ( )
) . then ( ( ) => {
) . then ( ( ) => {
isContainerBased && console . info ( '>> Fetching tarball...' )
return tasks . installFromLocal ( ) . then ( succeeded => {
return tasks . installFromLocal ( ) . then ( succeeded => {
return ( ! succeeded ) ? tasks . installFromRemote ( ) : true
return ( ! succeeded ) ? tasks . installFromRemote ( ) : true
} )
} )
} ) . then ( ( ) => {
} ) . then ( ( ) => {
return tasks . installDependencies ( )
isContainerBased && console . info ( '>> Creating config file...' )
} ) . then ( ( ) => {
return tasks . ensureConfigFile ( )
return tasks . ensureConfigFile ( )
} ) . then ( ( ) => {
isContainerBased && console . info ( '>> Installing dependencies...' )
return tasks . installDependencies ( )
} ) . then ( ( ) => {
} ) . then ( ( ) => {
return tasks . startConfigurationWizard ( )
return tasks . startConfigurationWizard ( )
} ) . catch ( err => {
} ) . catch ( err => {
isContainerBased && console . error ( err )
ora . fail ( err )
ora . fail ( err )
} )
} )