@geek-fun/serverlessinsight
Version:
Full life cycle cross providers serverless application management for your fast-growing business.
102 lines (101 loc) • 4.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const commander_1 = require("commander");
const common_1 = require("../common");
const validate_1 = require("./validate");
const deploy_1 = require("./deploy");
const template_1 = require("./template");
const destroy_1 = require("./destroy");
const local_1 = require("./local");
const program = new commander_1.Command();
program.name('si').description('CLI for ServerlessInsight').version((0, common_1.getVersion)());
program
.command('show')
.description('show string')
.action(async (options) => {
await (0, common_1.setContext)({ ...options });
const context = (0, common_1.getContext)();
const result = await (0, common_1.getIamInfo)(context);
console.log('result:', JSON.stringify(result));
});
program
.command('validate [stackName]')
.description('validate serverless Iac yaml')
.option('-f, --file <path>', 'specify the yaml file')
.option('-s, --stage <stage>', 'specify the stage')
.action(async (stackName, { file, stage }) => {
common_1.logger.debug('log command info');
await (0, validate_1.validate)(stackName, { stage, location: file });
});
program
.command('deploy <stackName>')
.description('deploy serverless Iac yaml')
.option('-f, --file <path>', 'specify the yaml file')
.option('-s, --stage <stage>', 'specify the stage')
.option('-r, --region <region>', 'specify the region')
.option('-v, --provider <provider>', 'specify the provider')
.option('-k, --accessKeyId <accessKeyId>', 'specify the AccessKeyId')
.option('-x, --accessKeySecret <accessKeySecret>', 'specify the AccessKeySecret')
.option('-n, --securityToken <securityToken>', 'specify the SecurityToken')
.option('-p, --parameter <key=value>', 'override parameters', (value, previous) => {
const [key, val] = value.split('=');
previous[key] = val;
return previous;
}, {})
.action(async (stackName, { stage, parameter, file, region, provider, accessKeyId, accessKeySecret, securityToken }) => {
await (0, deploy_1.deploy)(stackName, {
stage,
parameters: parameter,
location: file,
region,
provider,
accessKeyId,
accessKeySecret,
securityToken,
});
});
program
.command('template <stackName>')
.description('print platform specific infrastructure as code template')
.option('-f, --file <path>', 'specify the yaml file')
.option('-s, --stage <stage>', 'specify the stage')
.option('-t, --format <type>', 'output content type (JSON or YAML)', 'JSON')
.action(async (stackName, { format, file, stage }) => {
await (0, template_1.template)(stackName, { format, location: file, stage });
});
program
.command('destroy <stackName>')
.option('-f, --file <path>', 'specify the yaml file')
.option('-r, --region <region>', 'specify the region')
.option('-v, --provider <provider>', 'specify the provider')
.option('-k, --accessKeyId <accessKeyId>', 'specify the AccessKeyId')
.option('-x, --accessKeySecret <accessKeySecret>', 'specify the AccessKeySecret')
.option('-n, --securityToken <securityToken>', 'specify the SecurityToken')
.description('destroy serverless stack')
.action(async (stackName, { file, region, provider, accessKeyId, accessKeySecret, securityToken }) => {
await (0, destroy_1.destroyStack)(stackName, {
location: file,
region,
provider,
accessKeyId,
accessKeySecret,
securityToken,
});
});
program
.command('local <stackName>')
.description('run Serverless application locally for debugging')
.option('-s, --stage <stage>', 'specify the stage', 'default')
.option('-p, --port <port>', 'specify the port', '3000')
.option('-d, --debug', 'enable debug mode')
.option('-w, --watch', 'enable file watch', true)
.action(async (stackName, { stage, port, debug, watch }) => {
await (0, local_1.runLocal)(stackName, {
stage,
port: Number(port) || 3000,
debug: !!debug,
watch: typeof watch === 'boolean' ? watch : true,
});
});
program.parse();