forked from TryGhost/Ghost-CLI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ls): show stopped ghost instances as well as running ones
closes TryGhost#178 - remove register/deregister from ghost start/stop - change system config file structure and pull url/port/process manager data from individual instance configs rather than a global list
- Loading branch information
Showing
4 changed files
with
45 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,48 @@ | ||
'use strict'; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const chalk = require('chalk'); | ||
const each = require('lodash/each'); | ||
const Config = require('../utils/config'); | ||
|
||
module.exports.execute = function execute() { | ||
let systemConfig = Config.load('system'); | ||
let rows = []; | ||
let instances = systemConfig.get('instances', {}); | ||
let save = false; | ||
|
||
each(systemConfig.get('instances', {}), (instance, name) => { | ||
rows.push([name, instance.url, instance.port, instance.mode, instance.process, instance.cwd]); | ||
each(instances, (dir, name) => { | ||
if (typeof dir !== 'string') { | ||
dir = dir.cwd; | ||
instances[name] = dir; | ||
save = true; | ||
} | ||
|
||
if (!fs.existsSync(path.join(dir, '.ghost-cli'))) { | ||
// install has been removed, so we want to remove it from the list | ||
delete instances[name]; | ||
save = true; | ||
return; | ||
} | ||
|
||
let installConfig = Config.load(path.join(dir, '.ghost-cli')); | ||
let environment = installConfig.get('running', false); | ||
|
||
if (!environment) { | ||
rows.push([name, dir, chalk.red('stopped'), chalk.red('n/a'), chalk.red('n/a'), chalk.red('n/a')]); | ||
return; | ||
} | ||
|
||
let instanceConfig = Config.load(path.join(dir, `config.${environment}.json`)); | ||
rows.push([name, dir, `${chalk.green('running')} (${environment})`, instanceConfig.get('url'), instanceConfig.get('server.port'), instanceConfig.get('process')]); | ||
}); | ||
|
||
this.ui.table(['Name', 'Url', 'Port', 'Environment', 'Process Manager', 'Location'], rows, { | ||
if (save) { | ||
// There have been instances removed, re-save the instance list | ||
systemConfig.save(); | ||
} | ||
|
||
this.ui.table(['Name', 'Location', 'Status', 'Url', 'Port', 'Process Manager'], rows, { | ||
style: {head: ['cyan']} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters