@based/cli
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -1,5 +0,8 @@ | ||
export declare const add: ({ client, options, config }: { | ||
client: any; | ||
options: any; | ||
config: any; | ||
import { Config } from '../types'; | ||
import { Based } from '@based/client'; | ||
import { ApiKeysOptions } from '.'; | ||
export declare const add: ({ client, options, config, }: { | ||
client: Based; | ||
options: ApiKeysOptions; | ||
config: Config; | ||
}) => Promise<void>; |
@@ -8,2 +8,3 @@ "use strict"; | ||
const inquirer_1 = __importDefault(require("inquirer")); | ||
const fs_1 = __importDefault(require("fs")); | ||
const tui_1 = require("../tui"); | ||
@@ -13,16 +14,38 @@ const ids_1 = require("@based/ids"); | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const add = async ({ client, options, config }) => { | ||
const path_1 = __importDefault(require("path")); | ||
const add = async ({ client, options, config, }) => { | ||
options.output === 'fancy' && (0, tui_1.printAction)('Add apiKey'); | ||
const output = { data: [] }; | ||
const { name } = await inquirer_1.default.prompt({ | ||
...tui_1.inquirerConfig, | ||
type: 'input', | ||
name: 'name', | ||
message: 'What is the apiKey name?', | ||
}); | ||
let name; | ||
if (options.name) { | ||
name = options.name; | ||
} | ||
else { | ||
; | ||
({ name } = await inquirer_1.default.prompt({ | ||
...tui_1.inquirerConfig, | ||
type: 'input', | ||
name: 'name', | ||
message: 'What is the apiKey name?', | ||
})); | ||
} | ||
const orgId = (0, ids_1.orgId)(config.org); | ||
const spinner = (0, ora_1.default)('Adding apiKey').start(); | ||
let spinner; | ||
try { | ||
const { id } = await client.call('updateApiKey', { name, orgId }); | ||
spinner.stop(); | ||
if (options.output === 'fancy') { | ||
spinner = (0, ora_1.default)('Adding apiKey').start(); | ||
} | ||
const { id, token } = await client.call('updateApiKey', { name, orgId }); | ||
spinner && spinner.stop(); | ||
if (options.file) { | ||
const filePath = path_1.default.join(process.cwd(), options.file); | ||
await new Promise((resolve, reject) => { | ||
fs_1.default.writeFile(filePath, token, 'utf8', (err) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
resolve(true); | ||
}); | ||
}); | ||
} | ||
// TODO: save to file | ||
@@ -36,4 +59,7 @@ output.data.push({ id, name }); | ||
catch (error) { | ||
spinner.stop(); | ||
spinner && spinner.stop(); | ||
options.debug && (0, tui_1.printError)(error); | ||
if (/apiKey already exists/gm.test(error.message)) { | ||
(0, tui_1.fail)(`apiKey ${chalk_1.default.blue(name)} already exists`, output, options); | ||
} | ||
(0, tui_1.fail)('Cannot get apiKeys', output, options); | ||
@@ -40,0 +66,0 @@ } |
@@ -1,5 +0,8 @@ | ||
export declare const download: ({ client, options, config }: { | ||
client: any; | ||
options: any; | ||
config: any; | ||
import { Config } from '../types'; | ||
import { ApiKeysOptions } from '.'; | ||
import { Based } from '@based/client'; | ||
export declare const download: ({ client, options, config, }: { | ||
client: Based; | ||
options: ApiKeysOptions; | ||
config: Config; | ||
}) => Promise<void>; |
@@ -14,35 +14,65 @@ "use strict"; | ||
const path_1 = __importDefault(require("path")); | ||
const download = async ({ client, options, config }) => { | ||
const download = async ({ client, options, config, }) => { | ||
options.output === 'fancy' && (0, tui_1.printAction)('Download apiKey'); | ||
const output = { data: [] }; | ||
const orgId = (0, ids_1.orgId)(config.org); | ||
if (!options.name && !options.file && options.nonInteractive) { | ||
(0, tui_1.fail)('Need to use `name` and `file` arguments in nonInteractive mode', output, options); | ||
} | ||
let spinner; | ||
try { | ||
spinner = (0, ora_1.default)('Getting apiKeys').start(); | ||
if (options.output === 'fancy') { | ||
spinner = (0, ora_1.default)('Getting apiKeys').start(); | ||
} | ||
const { apiKeys } = await client.get('listApiKeys', { | ||
orgId, | ||
}); | ||
spinner.stop(); | ||
const { apiKey: { id, name }, } = await inquirer_1.default.prompt({ | ||
...tui_1.inquirerConfig, | ||
type: 'list', | ||
name: 'apiKey', | ||
message: 'Select apiKey to dwonload', | ||
choices: apiKeys.map((apiKey) => ({ | ||
value: { id: apiKey.id, name: apiKey.name }, | ||
name: apiKey.name, | ||
})), | ||
}); | ||
const { file } = await inquirer_1.default.prompt({ | ||
...tui_1.inquirerConfig, | ||
type: 'input', | ||
name: 'file', | ||
message: 'Path where to save the key:', | ||
default: './apiKey.key', | ||
}); | ||
spinner && spinner.stop(); | ||
let id; | ||
let name; | ||
if (options.name) { | ||
name = options.name; | ||
({ id } = apiKeys.find((k) => k.name === options.name) || {}); | ||
if (!id) { | ||
(0, tui_1.fail)(`apiKey with name ${chalk_1.default.blue(name)} not found`, output, options); | ||
} | ||
} | ||
else { | ||
; | ||
({ | ||
apiKey: { id, name }, | ||
} = await inquirer_1.default.prompt({ | ||
...tui_1.inquirerConfig, | ||
type: 'list', | ||
name: 'apiKey', | ||
message: 'Select apiKey to dwonload', | ||
choices: apiKeys.map((apiKey) => ({ | ||
value: { id: apiKey.id, name: apiKey.name }, | ||
name: apiKey.name, | ||
})), | ||
})); | ||
} | ||
let file; | ||
if (options.file) { | ||
file = options.file; | ||
} | ||
else { | ||
; | ||
({ file } = await inquirer_1.default.prompt({ | ||
...tui_1.inquirerConfig, | ||
type: 'input', | ||
name: 'file', | ||
message: 'Path where to save the key:', | ||
default: './apiKey.key', | ||
})); | ||
} | ||
const filePath = path_1.default.join(process.cwd(), file); | ||
spinner = (0, ora_1.default)('Downloading apiKey').start(); | ||
if (options.output === 'fancy') { | ||
spinner = (0, ora_1.default)('Downloading apiKey').start(); | ||
} | ||
const { id: downloadedId, token } = await client.get('getApiKey', { id }); | ||
spinner.stop(); | ||
spinner = (0, ora_1.default)('Saving file').start(); | ||
spinner && spinner.stop(); | ||
if (options.output === 'fancy') { | ||
spinner = (0, ora_1.default)('Saving file').start(); | ||
} | ||
await new Promise((resolve, reject) => { | ||
@@ -56,3 +86,3 @@ fs_1.default.writeFile(filePath, token, 'utf8', (err) => { | ||
}); | ||
spinner.stop(); | ||
spinner && spinner.stop(); | ||
output.data.push({ id: downloadedId, token, filePath }); | ||
@@ -66,3 +96,3 @@ if (options.output === 'fancy') { | ||
catch (error) { | ||
spinner.stop(); | ||
spinner && spinner.stop(); | ||
options.debug && (0, tui_1.printError)(error); | ||
@@ -69,0 +99,0 @@ (0, tui_1.fail)('Cannot get apiKeys', output, options); |
@@ -1,1 +0,11 @@ | ||
export {}; | ||
import { GlobalOptions } from '../command'; | ||
export declare type ApiKeysOptions = GlobalOptions & { | ||
name?: string; | ||
file?: string; | ||
}; | ||
export declare type ApiKeyData = { | ||
id: string; | ||
name: string; | ||
token?: string; | ||
updatedAt?: number; | ||
}; |
@@ -18,2 +18,4 @@ "use strict"; | ||
.command('apiKeys') | ||
.option('--name <name>', 'Name of apiKey') | ||
.option('--file <file>', 'Filepath to save the apiKey') | ||
.addArgument(new commander_1.Argument('<subcommand>', 'apiKeys subcommand').choices([ | ||
@@ -20,0 +22,0 @@ 'ls', |
@@ -1,5 +0,8 @@ | ||
export declare const ls: ({ client, options, config }: { | ||
client: any; | ||
options: any; | ||
config: any; | ||
import { Based } from '@based/client'; | ||
import { GlobalOptions } from '../command'; | ||
import { Config } from '../types'; | ||
export declare const ls: ({ client, options, config, }: { | ||
client: Based; | ||
options: GlobalOptions; | ||
config: Config; | ||
}) => Promise<void>; |
@@ -7,3 +7,2 @@ "use strict"; | ||
exports.ls = void 0; | ||
/* eslint-disable no-console */ | ||
const ids_1 = require("@based/ids"); | ||
@@ -13,7 +12,10 @@ const chalk_1 = __importDefault(require("chalk")); | ||
const tui_1 = require("../tui"); | ||
const ls = async ({ client, options, config }) => { | ||
const ls = async ({ client, options, config, }) => { | ||
options.output === 'fancy' && (0, tui_1.printAction)('List apiKeys'); | ||
const output = { data: [] }; | ||
const spinner = (0, ora_1.default)('Getting apiKeys').start(); | ||
let spinner; | ||
try { | ||
if (options.output === 'fancy') { | ||
spinner = (0, ora_1.default)('Getting apiKeys').start(); | ||
} | ||
const orgId = (0, ids_1.orgId)(config.org); | ||
@@ -23,3 +25,3 @@ const { apiKeys } = await client.get('listApiKeys', { | ||
}); | ||
spinner.stop(); | ||
spinner && spinner.stop(); | ||
if (!apiKeys.length && options.output === 'fancy') { | ||
@@ -30,5 +32,5 @@ console.info(tui_1.prefixNotice + 'No apiKeys found'); | ||
apiKeys.forEach((apiKey) => { | ||
const { id, name } = apiKey; | ||
const { /*id,*/ name } = apiKey; | ||
output.data.push({ | ||
id, | ||
// id, | ||
name, | ||
@@ -40,3 +42,3 @@ }); | ||
catch (error) { | ||
spinner.stop(); | ||
spinner && spinner.stop(); | ||
options.debug && (0, tui_1.printError)(error); | ||
@@ -48,3 +50,3 @@ (0, tui_1.fail)('Cannot get apiKeys', output, options); | ||
} | ||
else { | ||
else if (options.output === 'fancy') { | ||
printOutput(output); | ||
@@ -58,7 +60,10 @@ } | ||
const colSpacing = 2; | ||
const idHeader = 'id'; | ||
// const idHeader = 'id' | ||
const nameHeader = 'name'; | ||
const idColLength = Math.max(...output.data | ||
.map((item) => item.id.length) | ||
.concat(idHeader.length)) + colSpacing; | ||
// const idColLength = | ||
// Math.max( | ||
// ...output.data | ||
// .map((item: ApiKeyData) => item.id.length) | ||
// .concat(idHeader.length) | ||
// ) + colSpacing | ||
const nameColLength = Math.max(...output.data | ||
@@ -68,7 +73,7 @@ .map((item) => item.name.length) | ||
console.info(tui_1.prefix + | ||
(0, tui_1.padded)(idHeader, idColLength, chalk_1.default.gray) + | ||
// padded(idHeader, idColLength, chalk.gray) + | ||
(0, tui_1.padded)(nameHeader, nameColLength, chalk_1.default.gray)); | ||
output.data.forEach((item) => { | ||
console.info(tui_1.prefix + | ||
(0, tui_1.padded)(item.id, idColLength, chalk_1.default.blue) + | ||
// padded(item.id, idColLength, chalk.blue) + | ||
(0, tui_1.padded)(item.name, nameColLength)); | ||
@@ -75,0 +80,0 @@ }); |
@@ -1,5 +0,8 @@ | ||
export declare const remove: ({ client, options, config }: { | ||
client: any; | ||
options: any; | ||
config: any; | ||
import { Config } from '../types'; | ||
import { ApiKeysOptions } from '.'; | ||
import { Based } from '@based/client'; | ||
export declare const remove: ({ client, options, config, }: { | ||
client: Based; | ||
options: ApiKeysOptions; | ||
config: Config; | ||
}) => Promise<void>; |
@@ -12,3 +12,3 @@ "use strict"; | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const remove = async ({ client, options, config }) => { | ||
const remove = async ({ client, options, config, }) => { | ||
options.output === 'fancy' && (0, tui_1.printAction)('Remove apiKey'); | ||
@@ -19,22 +19,43 @@ const output = { data: [] }; | ||
try { | ||
spinner = (0, ora_1.default)('Getting apiKeys').start(); | ||
if (options.output === 'fancy') { | ||
spinner = (0, ora_1.default)('Getting apiKeys').start(); | ||
} | ||
const { apiKeys } = await client.get('listApiKeys', { | ||
orgId, | ||
}); | ||
spinner.stop(); | ||
const { apiKey: { id, name }, } = await inquirer_1.default.prompt({ | ||
...tui_1.inquirerConfig, | ||
type: 'list', | ||
name: 'apiKey', | ||
message: 'Select apiKey to remove', | ||
choices: apiKeys.map((apiKey) => ({ | ||
value: { id: apiKey.id, name: apiKey.name }, | ||
name: apiKey.name, | ||
})), | ||
}); | ||
spinner = (0, ora_1.default)('Removing apiKey').start(); | ||
spinner && spinner.stop(); | ||
let id; | ||
let name; | ||
if (options.name) { | ||
name = options.name; | ||
({ id } = apiKeys.find((k) => k.name === options.name) || {}); | ||
if (!id) { | ||
(0, tui_1.fail)(`apiKey with name ${chalk_1.default.blue(name)} not found`, output, options); | ||
} | ||
} | ||
else { | ||
; | ||
({ | ||
apiKey: { id, name }, | ||
} = await inquirer_1.default.prompt({ | ||
...tui_1.inquirerConfig, | ||
type: 'list', | ||
name: 'apiKey', | ||
message: 'Select apiKey to remove', | ||
choices: apiKeys.map((apiKey) => ({ | ||
value: { id: apiKey.id, name: apiKey.name }, | ||
name: apiKey.name, | ||
})), | ||
})); | ||
} | ||
if (options.output === 'fancy') { | ||
spinner = (0, ora_1.default)('Removing apiKey').start(); | ||
} | ||
const { id: removedId } = await client.call('removeApiKey', { id }); | ||
spinner.stop(); | ||
spinner && spinner.stop(); | ||
output.data.push({ id: removedId }); | ||
if (options.output === 'fancy') { | ||
if (options.output === 'json') { | ||
console.info(JSON.stringify(output, null, 2)); | ||
} | ||
else if (options.output === 'fancy') { | ||
(0, tui_1.printEmptyLine)(); | ||
@@ -45,11 +66,8 @@ console.info(tui_1.prefixSuccess + `Removed key ${chalk_1.default.blue(name)}`); | ||
catch (error) { | ||
spinner.stop(); | ||
spinner && spinner.stop(); | ||
options.debug && (0, tui_1.printError)(error); | ||
(0, tui_1.fail)('Cannot get apiKeys', output, options); | ||
} | ||
if (options.output === 'json') { | ||
console.info(JSON.stringify(output, null, 2)); | ||
} | ||
}; | ||
exports.remove = remove; | ||
//# sourceMappingURL=remove.js.map |
@@ -0,1 +1,2 @@ | ||
import { Command } from 'commander'; | ||
export declare type GlobalOptions = { | ||
@@ -7,3 +8,3 @@ org?: string; | ||
basedFile?: string; | ||
output: 'fancy' | 'json'; | ||
output: 'fancy' | 'json' | 'none'; | ||
debug?: boolean; | ||
@@ -13,2 +14,2 @@ nonInteractive: boolean; | ||
}; | ||
export declare const command: (command: any) => any; | ||
export declare const command: (command: Command) => Command; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.command = void 0; | ||
const commander_1 = require("commander"); | ||
const command = (command) => { | ||
@@ -11,7 +12,8 @@ command | ||
.option('-b, --based-file <basedFile>', 'Path to based config file') | ||
// .option('--no-based-file', 'No based file') | ||
.option('-o, --output <output>', 'Output type', 'fancy') | ||
.option('-d, --debug', 'Enable debug output') | ||
.option('--non-interactive', 'Non interactive mode', !process.stdout.isTTY) | ||
.option('-k, --api-key <apiKey>', 'Use apiKey from file'); | ||
.option('-k, --api-key <apiKey>', 'Use apiKey from file') | ||
.addOption(new commander_1.Option('-o, --output <output>', 'Output type') | ||
.choices(['fancy', 'json', 'none']) | ||
.default('fancy')); | ||
return command; | ||
@@ -18,0 +20,0 @@ }; |
@@ -26,9 +26,3 @@ "use strict"; | ||
const config = (await (0, findConfig_1.default)(basedFile)) || {}; | ||
if (options.output === 'fancy') { | ||
// @ts-ignore | ||
(0, tui_1.printBasedCliLogoWithVersion)(commander_1.program._version); | ||
(0, tui_1.printEmptyLine)(false); | ||
(0, tui_1.printConfig)(config); | ||
(0, tui_1.printAction)('Update schema.'); | ||
} | ||
(0, tui_1.printHeader)(options, config, 'Update schema.'); | ||
if (!cluster) { | ||
@@ -110,3 +104,8 @@ if (config.cluster) { | ||
try { | ||
await client.auth(token, { isBasedUser: true }); | ||
if (options.apiKey) { | ||
await client.auth(token, { isApiKey: true }); | ||
} | ||
else { | ||
await client.auth(token, { isBasedUser: true }); | ||
} | ||
} | ||
@@ -113,0 +112,0 @@ catch (error) { |
@@ -1,5 +0,8 @@ | ||
export declare const add: ({ client, options, config }: { | ||
client: any; | ||
options: any; | ||
config: any; | ||
import { Config } from '../types'; | ||
import { Based } from '@based/client'; | ||
import { GlobalOptions } from '../command'; | ||
export declare const add: ({ client, options, config, }: { | ||
client: Based; | ||
options: GlobalOptions; | ||
config: Config; | ||
}) => Promise<void>; |
@@ -13,34 +13,7 @@ "use strict"; | ||
const tui_1 = require("../tui"); | ||
const stripAnsi_1 = require("../tui/stripAnsi"); | ||
const printOrAddError = (output, options, error, danger = false) => { | ||
output.errors = output.errors || []; | ||
output.errors.push({ ...error, message: (0, stripAnsi_1.stripAnsi)(error.message) }); | ||
if (options.output === 'fancy') { | ||
(0, tui_1.printEmptyLine)(); | ||
console.info(danger | ||
? tui_1.prefixDanger + chalk_1.default.red(error.message) | ||
: tui_1.prefixError + error.message); | ||
} | ||
}; | ||
const exit = (errorCode = 0, options, output) => { | ||
if (options?.output === 'json' && output) { | ||
console.info(JSON.stringify(output, null, 2)); | ||
} | ||
process.exit(errorCode); | ||
}; | ||
const add = async ({ client, options, config }) => { | ||
let { project, org, env, cluster, basedFile } = options; | ||
if (!cluster) { | ||
if (config.cluster) { | ||
cluster = config.cluster; | ||
} | ||
} | ||
options.debug && (0, tui_1.printDebug)(options); | ||
options.output !== 'json' && (0, tui_1.printAction)('Create environment'); | ||
const add = async ({ client, options, config, }) => { | ||
options.output === 'fancy' && (0, tui_1.printAction)('Create environment'); | ||
const output = { data: [] }; | ||
if (options?.nonInteractive && (!project || !env)) { | ||
printOrAddError(output, options, { | ||
message: '`project` and `env` argument must be provided in non interactive mode.', | ||
}); | ||
exit(1, options, output); | ||
if (options?.nonInteractive && (!config.project || !config.env)) { | ||
(0, tui_1.fail)('`project` and `env` argument must be provided in non interactive mode.', output, options); | ||
} | ||
@@ -50,12 +23,12 @@ let spinner; | ||
// dont use based config... | ||
if (project && org && env) { | ||
if (options.project && options.org && options.env) { | ||
// make this env | ||
} | ||
else if (!org) { | ||
else if (!options.org) { | ||
try { | ||
const { orgs } = await client.get('listOrgs'); | ||
if (orgs.length === 1) { | ||
org = orgs[0].name; | ||
config.org = orgs[0].name; | ||
options.output === 'fancy' && | ||
console.info(tui_1.prefix + chalk_1.default.bold('Org: ') + chalk_1.default.blue(org)); | ||
console.info(tui_1.prefix + chalk_1.default.bold('Org: ') + chalk_1.default.blue(config.org)); | ||
} | ||
@@ -67,6 +40,3 @@ else { | ||
if (options.nonInteractive) { | ||
printOrAddError(output, options, { | ||
message: 'More than one org found. It must be provided as an argument in non interactive mode', | ||
}); | ||
exit(1, options, output); | ||
(0, tui_1.fail)('More than one org found. It must be provided as an argument in non interactive mode', output, options); | ||
} | ||
@@ -79,5 +49,6 @@ const x = await inquirer_1.default.prompt({ | ||
choices: orgs.map((v) => v.name), | ||
...(config?.org ? { default: config.org } : null), | ||
}); | ||
if (x.org) { | ||
org = x.org; | ||
config.org = x.org; | ||
} | ||
@@ -87,7 +58,6 @@ } | ||
catch (err) { | ||
console.error(chalk_1.default.red('Cannot find any organisations for this account')); | ||
process.exit(); | ||
(0, tui_1.fail)('Cannot find any organisations for this account', output, options); | ||
} | ||
} | ||
if (!project) { | ||
if (!options.project) { | ||
// fill in a default from config | ||
@@ -101,5 +71,5 @@ const x = await inquirer_1.default.prompt({ | ||
}); | ||
project = x.project; | ||
config.project = x.project; | ||
} | ||
if (!env) { | ||
if (!options.env) { | ||
// fill in a default from config | ||
@@ -111,7 +81,8 @@ const x = await inquirer_1.default.prompt({ | ||
message: `Provide an environment key ${chalk_1.default.grey('e.g. "dev", "production"')}:`, | ||
...(config?.env ? { default: config.env } : null), | ||
}); | ||
env = x.env; | ||
config.env = x.env; | ||
} | ||
// flag to not have inputs | ||
if (basedFile === undefined && !options.nonInteractive) { | ||
if (!options.basedFile && !options.nonInteractive) { | ||
const bFile = (0, path_1.join)(process.cwd(), 'based.json'); | ||
@@ -126,28 +97,24 @@ // do you want to overwrite file | ||
message: exists | ||
? `Do you want to update it to ${chalk_1.default.blue(org + '/' + project + '/' + env)}?` | ||
: `Do you want to create a based file for "${org}/${project}/${env}"? ${chalk_1.default.grey(bFile)}`, | ||
? `Do you want to update it to ${chalk_1.default.blue(config.org + '/' + config.project + '/' + config.env)}?` | ||
: `Do you want to create a based file for "${config.org}/${config.project}/${config.env}"? ${chalk_1.default.grey(bFile)}`, | ||
}); | ||
if (x.makebasedjson) { | ||
await (0, fs_extra_1.writeJson)(bFile, cluster | ||
? { | ||
env, | ||
org, | ||
project, | ||
cluster, | ||
} | ||
: { | ||
env, | ||
org, | ||
project, | ||
}); | ||
await (0, fs_extra_1.writeJson)(bFile, { | ||
env: config.env, | ||
org: config.org, | ||
project: config.project, | ||
...(config.cluster ? { cluster: config.cluster } : null), | ||
}); | ||
} | ||
} | ||
spinner = (0, ora_1.default)(`Creating environment ${chalk_1.default.blue(org)} ${chalk_1.default.blue(project)} ${chalk_1.default.blue(env)}`).start(); | ||
if (options.output === 'fancy') { | ||
spinner = (0, ora_1.default)(`Creating environment ${chalk_1.default.blue(config.org)} ${chalk_1.default.blue(config.project)} ${chalk_1.default.blue(config.env)}`).start(); | ||
} | ||
const envObj = { | ||
org, | ||
project, | ||
env, | ||
org: config.org, | ||
project: config.project, | ||
env: config.env, | ||
}; | ||
if (!org || !project || !env) { | ||
throw new Error('No full env'); | ||
if (!envObj.org || !envObj.project || !envObj.env) { | ||
(0, tui_1.fail)('No full env', output, options); | ||
} | ||
@@ -171,5 +138,7 @@ await client.call('createEnv', { | ||
} | ||
spinner.text = `Deploying ${rdy}/${d.machines.length}`; | ||
if (spinner) { | ||
spinner.text = `Deploying ${rdy}/${d.machines.length}`; | ||
} | ||
if (rdy === d.machines.length) { | ||
spinner.clear(); | ||
spinner && spinner.clear(); | ||
if (close) { | ||
@@ -189,26 +158,21 @@ close(); | ||
}); | ||
output.data.push({ org, project, env }); | ||
output.data.push(envObj); | ||
if (options.output === 'fancy') { | ||
(0, tui_1.printEmptyLine)(); | ||
console.info(tui_1.prefixSuccess + | ||
`Succesfully created environment ${chalk_1.default.blue(`${org}/${project}/${env}`)}`); | ||
`Succesfully created environment ${chalk_1.default.blue(`${envObj.org}/${envObj.project}/${envObj.env}`)}`); | ||
} | ||
} | ||
catch (err) { | ||
if (spinner) { | ||
spinner.clear(); | ||
} | ||
spinner && spinner.clear(); | ||
if (err.code === 'exists') { | ||
printOrAddError(output, options, { | ||
message: `Cannot create environment, ${chalk_1.default.blue(org + '/' + project + '/' + env)} already exists`, | ||
}); | ||
(0, tui_1.fail)(`Cannot create environment, ${chalk_1.default.blue(config.org + '/' + config.project + '/' + config.env)} already exists`, output, options); | ||
} | ||
else { | ||
printOrAddError(output, options, { message: `Cannot create environment` }, true); | ||
(0, tui_1.fail)('Cannot create environment', output, options); | ||
} | ||
options.debug && (0, tui_1.printError)(err); | ||
} | ||
exit(0, options, output); | ||
}; | ||
exports.add = add; | ||
//# sourceMappingURL=add.js.map |
@@ -11,3 +11,3 @@ "use strict"; | ||
const ls = async ({ client, options }) => { | ||
options.output !== 'json' && (0, tui_1.printAction)('List environments'); | ||
options.output === 'fancy' && (0, tui_1.printAction)('List environments'); | ||
const output = { data: [] }; | ||
@@ -75,3 +75,3 @@ const spinner = (0, ora_1.default)('Getting envs').start(); | ||
} | ||
else { | ||
else if (options.output === 'fancy') { | ||
printOutput(output); | ||
@@ -78,0 +78,0 @@ } |
@@ -1,5 +0,8 @@ | ||
export declare const remove: ({ client, options, config }: { | ||
client: any; | ||
options: any; | ||
config: any; | ||
import { Based } from '@based/client'; | ||
import { GlobalOptions } from '../command'; | ||
import { Config } from '../types'; | ||
export declare const remove: ({ client, options, config, }: { | ||
client: Based; | ||
options: GlobalOptions; | ||
config: Config; | ||
}) => Promise<void>; |
@@ -7,3 +7,2 @@ "use strict"; | ||
exports.remove = void 0; | ||
/* eslint-disable no-console */ | ||
const ora_1 = __importDefault(require("ora")); | ||
@@ -13,4 +12,3 @@ const chalk_1 = __importDefault(require("chalk")); | ||
const tui_1 = require("../tui"); | ||
const remove = async ({ client, options, config }) => { | ||
let { project, org, env } = options; | ||
const remove = async ({ client, options, config, }) => { | ||
// can also select an env | ||
@@ -20,16 +18,15 @@ // config | ||
// from config you take them | ||
options.output !== 'json' && (0, tui_1.printAction)('Remove an environment'); | ||
const output = { data: [] }; | ||
options.output === 'fancy' && (0, tui_1.printAction)('Remove an environment'); | ||
let spinner; | ||
if (env && project && org) { | ||
// no selection | ||
// TODO: implement non interactive | ||
spinner = (0, ora_1.default)('Removing environment').start(); | ||
console.error('this is no confirmation delete. will be reimplemented in non iteractive mode'); | ||
// DELETING | ||
// await client.call('removeEnv', { | ||
// org: org, | ||
// env: env, | ||
// project: project, | ||
// }) | ||
spinner.clear(); | ||
if (options.env && options.project && options.org && options.nonInteractive) { | ||
if (options.output === 'fancy') { | ||
spinner = (0, ora_1.default)('Removing environment').start(); | ||
} | ||
await client.call('removeEnv', { | ||
org: options.org, | ||
env: options.env, | ||
project: options.project, | ||
}); | ||
spinner && spinner.stop(); | ||
} | ||
@@ -48,7 +45,7 @@ else { | ||
if (envs.length === 1) { | ||
env = envs[0]; | ||
config.env = envs[0]; | ||
} | ||
else { | ||
if (envs.length === 0) { | ||
throw new Error('Cannot find envs'); | ||
(0, tui_1.fail)('Cannot find envs', output, options); | ||
} | ||
@@ -55,0 +52,0 @@ const x = await inquirer_1.default.prompt({ |
@@ -51,3 +51,3 @@ "use strict"; | ||
try { | ||
await client.auth(token, { isBasedUser: true }); | ||
await client.auth(token); | ||
} | ||
@@ -119,4 +119,3 @@ catch (error) { | ||
} | ||
// @ts-ignore | ||
code = result.outputFiles[0].text; | ||
options.code = result.outputFiles[0].text; | ||
spinner.clear(); | ||
@@ -123,0 +122,0 @@ console.info(tui_1.prefix + 'Build finished in ' + chalk_1.default.blue(Date.now() - d + 'ms')); |
@@ -21,22 +21,25 @@ "use strict"; | ||
if (!token) { | ||
(0, tui_1.printEmptyLine)(); | ||
console.info(tui_1.prefixWarn + 'Not logged in.'); | ||
process.exit(1); | ||
(0, tui_1.fail)('Not logged in.', output, options); | ||
} | ||
const p = (0, getBasedLocation_1.default)(config.cluster); | ||
const spinner = (0, ora_1.default)('Logging out').start(); | ||
await (0, fs_extra_1.emptyDir)(p); | ||
const client = (0, makeClient_1.default)(config.cluster); | ||
client.auth(token); | ||
let spinner; | ||
try { | ||
if (options.output === 'fancy') { | ||
spinner = (0, ora_1.default)('Logging out').start(); | ||
} | ||
await client.call('logout', { | ||
token, | ||
}); | ||
spinner.clear(); | ||
(0, tui_1.printEmptyLine)(); | ||
console.info(tui_1.prefixSuccess + 'Logged out.'); | ||
spinner && spinner.clear(); | ||
if (options.output === 'fancy') { | ||
(0, tui_1.printEmptyLine)(); | ||
console.info(tui_1.prefixSuccess + 'Logged out.'); | ||
} | ||
process.exit(0); | ||
} | ||
catch (err) { | ||
spinner.clear(); | ||
spinner && spinner.clear(); | ||
options.debug && (0, tui_1.printError)(err); | ||
@@ -43,0 +46,0 @@ (0, tui_1.fail)('Error loggin out.', output, options); |
@@ -30,3 +30,2 @@ "use strict"; | ||
// import inquirer from 'inquirer' | ||
const findConfig_1 = __importDefault(require("./findConfig")); | ||
const chalk_1 = __importDefault(require("chalk")); | ||
@@ -36,49 +35,36 @@ // import ora from 'ora' | ||
const makeClient_1 = __importDefault(require("./makeClient")); | ||
const makeConfig_1 = require("./makeConfig"); | ||
const tui_1 = require("./tui"); | ||
(0, command_1.command)(commander_1.program.command('restart')) | ||
.option('-db, --database <name>') | ||
.option('--database <name>') | ||
.option('--remote-backup', '❗️ DANGER ❗️ Restart the database instance discarding all local changes and reverting to the latest local backup') | ||
.action(async (options) => { | ||
let { org, project, env, cluster, basedFile, database, remoteBackup } = options; | ||
const config = (await (0, findConfig_1.default)(basedFile)) || {}; | ||
if (!cluster) { | ||
if (config.cluster) { | ||
cluster = config.cluster; | ||
} | ||
// let { org, project, env, cluster, basedFile, database, remoteBackup } = | ||
// options | ||
const config = await (0, makeConfig_1.makeConfig)(options); | ||
(0, tui_1.printHeader)(options, config, 'Restart machine'); | ||
const output = { data: [] }; | ||
if (!config.org) { | ||
(0, tui_1.fail)('Please provide an org', output, options); | ||
} | ||
let incomplete = false; | ||
if (!org) { | ||
if (config.org) { | ||
org = config.org; | ||
} | ||
else { | ||
console.info(chalk_1.default.red('Please provide an org')); | ||
incomplete = true; | ||
} | ||
if (!config.project) { | ||
(0, tui_1.fail)('Please provide a project', output, options); | ||
} | ||
if (!project) { | ||
if (config.project) { | ||
project = config.project; | ||
} | ||
else { | ||
console.info(chalk_1.default.red('Please provide a project')); | ||
incomplete = true; | ||
} | ||
if (!config.env) { | ||
(0, tui_1.fail)('Please provide an env', output, options); | ||
} | ||
if (!env) { | ||
if (config.env) { | ||
env = config.env; | ||
const token = await (0, checkAuth_1.default)(options); | ||
const client = (0, makeClient_1.default)(config.cluster); | ||
try { | ||
if (options.apiKey) { | ||
await client.auth(token, { isApiKey: true }); | ||
} | ||
else { | ||
console.info(chalk_1.default.red('Please provide an env')); | ||
incomplete = true; | ||
await client.auth(token); | ||
} | ||
} | ||
if (incomplete) { | ||
return; | ||
catch (error) { | ||
(0, tui_1.fail)(error, { data: [] }, options); | ||
} | ||
const token = await (0, checkAuth_1.default)(options); | ||
// const s = Date.now() | ||
const client = (0, makeClient_1.default)(cluster); | ||
client.auth(token); | ||
const envid = (0, ids_1.envId)(env, org, project); | ||
const envid = (0, ids_1.envId)(config.env, config.org, config.project); | ||
const { instances } = await client.get({ | ||
@@ -132,8 +118,8 @@ $id: envid, | ||
if (!instances || instances.length < 1) { | ||
return { err: `Couldn't find any db instance` }; | ||
(0, tui_1.fail)(`Couldn't find any db instance`, output, options); | ||
} | ||
const target = {}; | ||
if (database) { | ||
if (options.database) { | ||
for (const i of instances) { | ||
if (i.service?.dbName === database) { | ||
if (i.service?.dbName === options.database) { | ||
target.si = i.id; | ||
@@ -153,5 +139,5 @@ target.ma = i.machine.id; | ||
if (!target.ma) { | ||
return { err: `Could not find the right machine, maybe wrong name?` }; | ||
(0, tui_1.fail)('Could not find the right machine, maybe wrong name?', output, options); | ||
} | ||
if (remoteBackup) { | ||
if (options.remoteBackup) { | ||
const yes = await confirm('‼️ This will revert the database to its last online update, losing all local changes. Are you sure?'); | ||
@@ -158,0 +144,0 @@ if (!yes) { |
@@ -86,3 +86,3 @@ "use strict"; | ||
else { | ||
await client.auth(token, { isBasedUser: true }); | ||
await client.auth(token); | ||
} | ||
@@ -96,6 +96,9 @@ } | ||
} | ||
const spinner = (0, ora_1.default)('Updating schema').start(); | ||
let spinner; | ||
try { | ||
if (options.output === 'fancy') { | ||
spinner = (0, ora_1.default)('Updating schema').start(); | ||
} | ||
await client.updateSchema(payload); | ||
spinner.stop(); | ||
spinner && spinner.stop(); | ||
const isDefault = !payload.db || payload.db === 'default'; | ||
@@ -111,3 +114,3 @@ output.data.push({ | ||
} | ||
else { | ||
else if (options.output === 'fancy') { | ||
console.info(tui_1.prefixSuccess + | ||
@@ -120,20 +123,11 @@ 'Succesfully updated schema on ' + | ||
} | ||
process.exit(0); | ||
} | ||
catch (err) { | ||
spinner.stop(); | ||
const message = 'Cannot update schema.'; | ||
output.errors = output.errors || []; | ||
output.errors.push({ message }); | ||
if (options.output === 'json') { | ||
console.info(JSON.stringify(output, null, 2)); | ||
} | ||
else { | ||
console.info(tui_1.prefixError + message); | ||
} | ||
spinner && spinner.stop(); | ||
options.debug && (0, tui_1.printError)(err); | ||
process.exit(1); | ||
(0, tui_1.fail)('Cannot update schema.', output, options); | ||
} | ||
} | ||
process.exit(0); | ||
}); | ||
//# sourceMappingURL=schema.js.map |
@@ -35,9 +35,21 @@ "use strict"; | ||
const client = (0, makeClient_1.default)(config.cluster); | ||
client.auth(token); | ||
try { | ||
if (options.apiKey) { | ||
await client.auth(token, { isApiKey: true }); | ||
} | ||
else { | ||
await client.auth(token); | ||
} | ||
} | ||
catch (error) { | ||
(0, tui_1.fail)(error, { data: [] }, options); | ||
} | ||
let spinner; | ||
if (!config.org) { | ||
try { | ||
spinner = (0, ora_1.default)('Getting orgs').start(); | ||
if (options.output === 'fancy') { | ||
spinner = (0, ora_1.default)('Getting orgs').start(); | ||
} | ||
const { orgs } = await client.get('listOrgs'); | ||
spinner.stop(); | ||
spinner && spinner.stop(); | ||
if (orgs.length === 1) { | ||
@@ -63,3 +75,3 @@ config.org = orgs[0].name; | ||
catch (err) { | ||
spinner.stop(); | ||
spinner && spinner.stop(); | ||
options.debug && (0, tui_1.printError)(err); | ||
@@ -76,3 +88,5 @@ (0, tui_1.fail)('Cannot find any organizations for this account', output, options); | ||
if (isLs) { | ||
spinner = (0, ora_1.default)('Getting secrets').start(); | ||
if (options.output === 'fancy') { | ||
spinner = (0, ora_1.default)('Getting secrets').start(); | ||
} | ||
try { | ||
@@ -84,3 +98,3 @@ const { secrets } = await client.get('listSecrets', { | ||
}); | ||
spinner.stop(); | ||
spinner && spinner.stop(); | ||
secrets.forEach((secret) => { | ||
@@ -93,3 +107,3 @@ const { name, lastUpdated } = secret; | ||
} | ||
else { | ||
else if (options.output === 'fancy') { | ||
printOutput(output); | ||
@@ -99,3 +113,3 @@ } | ||
catch (err) { | ||
spinner.stop(); | ||
spinner && spinner.stop(); | ||
options.debug && (0, tui_1.printError)(err); | ||
@@ -106,3 +120,5 @@ (0, tui_1.fail)('Cannot read secrets', output, options); | ||
else if (options.delete) { | ||
spinner = (0, ora_1.default)('Deleting secret').start(); | ||
if (options.output === 'fancy') { | ||
spinner = (0, ora_1.default)('Deleting secret').start(); | ||
} | ||
try { | ||
@@ -114,3 +130,3 @@ await client.call('updateSecret', { | ||
}); | ||
spinner.stop(); | ||
spinner && spinner.stop(); | ||
output.data.push({ | ||
@@ -124,3 +140,3 @@ message: 'Succesfully removed secret.', | ||
} | ||
else { | ||
else if (options.output === 'fancy') { | ||
console.info(tui_1.prefixSuccess + | ||
@@ -134,3 +150,3 @@ 'Succesfully removed secret ' + | ||
catch (err) { | ||
spinner.stop(); | ||
spinner && spinner.stop(); | ||
options.debug && (0, tui_1.printError)(err); | ||
@@ -141,3 +157,5 @@ (0, tui_1.fail)('Cannot remove secret', output, options); | ||
else { | ||
spinner = (0, ora_1.default)('Updating secret').start(); | ||
if (options.output === 'fancy') { | ||
spinner = (0, ora_1.default)('Updating secret').start(); | ||
} | ||
let value = options.value; | ||
@@ -149,3 +167,3 @@ if (options.file) { | ||
catch (err) { | ||
spinner.stop(); | ||
spinner && spinner.stop(); | ||
options.debug && (0, tui_1.printError)(err); | ||
@@ -161,3 +179,3 @@ (0, tui_1.fail)(`Cannot read secret from ${chalk_1.default.blue(options.file)}`, output, options); | ||
}); | ||
spinner.stop(); | ||
spinner && spinner.stop(); | ||
output.data.push({ | ||
@@ -171,3 +189,3 @@ message: 'Succesfully updated secret', | ||
} | ||
else { | ||
else if (options.output === 'fancy') { | ||
console.info(tui_1.prefixSuccess + | ||
@@ -182,3 +200,3 @@ 'Succesfully updated secret ' + | ||
catch (err) { | ||
spinner.stop(); | ||
spinner && spinner.stop(); | ||
options.debug && (0, tui_1.printError)(err); | ||
@@ -185,0 +203,0 @@ (0, tui_1.fail)('Cannot update secret', output, options); |
@@ -82,3 +82,3 @@ "use strict"; | ||
} | ||
else { | ||
if (options.output === 'fancy') { | ||
(0, exports.printEmptyLine)(); | ||
@@ -85,0 +85,0 @@ console.info(exports.prefixError + message); |
@@ -0,2 +1,4 @@ | ||
import { Config } from './config'; | ||
export declare const printBasedLogo: () => void; | ||
export declare const printBasedCliLogoWithVersion: (version: string) => void; | ||
export declare const printHeader: (options: any, config: Config) => void; |
@@ -6,4 +6,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.printBasedCliLogoWithVersion = exports.printBasedLogo = void 0; | ||
exports.printHeader = exports.printBasedCliLogoWithVersion = exports.printBasedLogo = void 0; | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const _1 = require("."); | ||
const config_1 = require("./config"); | ||
const basedLogoAscii = ' _ _ \n' + | ||
@@ -28,2 +30,11 @@ '| | | |\n' + | ||
exports.printBasedCliLogoWithVersion = printBasedCliLogoWithVersion; | ||
const printHeader = (options, config) => { | ||
if (options.output === 'fancy') { | ||
// @ts-ignore | ||
(0, exports.printBasedCliLogoWithVersion)(program._version); | ||
(0, _1.printEmptyLine)(false); | ||
(0, config_1.printConfig)(config); | ||
} | ||
}; | ||
exports.printHeader = printHeader; | ||
//# sourceMappingURL=logo.js.map |
{ | ||
"name": "@based/cli", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "bin": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
223595
3223
19