o3-panther-cli
Version:
Panther CLI for developing and editing sites.
97 lines (87 loc) • 2.46 kB
JavaScript
const app = require('commander');
const path = require('path');
const { prompt } = require('inquirer');
const fs = require('fs');
let cnf = {};
const createCnf = (chk) => {
let hasCnf = fs.existsSync('./o3.json');
let promise = Promise.resolve();
if (!chk || (chk && !hasCnf)) {
promise = prompt(qConfig).then(a => {
a.remote.https = true;
fs.writeFileSync('o3.json', JSON.stringify(a, null, 2));
});
}
return promise.then(() => {
cnf = require(path.resolve(process.cwd(), 'o3.json'));
});
}
const qConfig = [{
type: 'input',
name: 'remote.domain',
message: 'Panther site domain (panther.origami3.com):',
default: 'panther.origami3.com'
}, {
type: 'input',
name: 'remote.host',
message: 'Panther site host (Panther):',
default: 'Panther'
}, {
type: 'input',
name: 'remote.uri_auth',
message: 'URI for password authentication:',
default: '/auth/pass'
}, {
type: 'input',
name: 'remote.uri_update',
message: 'URI endpoint for update action:',
default: '/api/site-update'
}, {
type: 'input',
name: 'local.port',
message: 'Local port (8443):',
default: 8443
}, {
type: 'input',
name: 'local.www',
message: 'Local www directory (public):',
default: 'public'
}];
const qLogin = [{
type: 'input',
name: 'user',
message: 'Username:'
}, {
type: 'password',
name: 'pass',
message: 'Password:'
}]
app.version('Panther CLI tools version 1.0.8', '-v, --version');
app.command('server')
.action(function (dir, cmd) {
createCnf(true).then(a => require('./src/proxy')());
}).description('Start a local http server and proxy remote Panther requests.');
app.command('deploy')
.action(function (dir, cmd) {
createCnf(true)
.then(a => {
if (process.env.panther_username) {
return {
user: process.env.panther_username,
pass: process.env.panther_password
}
} else {
return prompt(qLogin);
}
}).then(info => {
info.uri = cnf.remote.domain + cnf.remote.uri_auth;
info.https = cnf.remote.https;
return require('./src/login')(info);
}).then(a => require('./src/deploy')())
.catch((err) => console.error(err.message));
}).description('Upload the local www directory to the Panther site.');
app.command('init')
.action(function (dir, cmd) {
createCnf();
}).description('Create an o3.json configuration file');
app.parse(process.argv);