UNPKG

riof

Version:

Rio framework

76 lines (73 loc) 2.91 kB
#!/usr/bin/env node import yargs, {CommandModule} from "yargs"; import {hideBin} from 'yargs/helpers' import {compile} from "./compiler"; import {execSync} from "child_process"; import path from "path"; import fs from "fs-extra"; (async () => { yargs(hideBin(process.argv)) .usage('Usage: riof <command> [options]') .demandCommand() .command({ command: 'init', description: 'Initialize template project', aliases: ['i'], handler: async (args) => { fs.copySync(path.join(__dirname, '..', 'sample-project'), '.') } } as CommandModule) .command({ command: 'compile', description: 'Compile the project', aliases: ['c'], handler: async (args) => { await compile() } } as CommandModule) .command({ command: 'deploy', description: 'Deploy the project', aliases: ['d'], builder: (yargs) => { yargs.options('project-id', { describe: 'Project id', type: 'string', demandOption: true, }) yargs.options('profile', { describe: 'Rio cli Profile', type: 'string', }) yargs.options('secret-id', { describe: 'Rio cli secret id', type: 'string', }) yargs.options('secret-key', { describe: 'Rio cli secret key', type: 'string', }) yargs.options('endpoint', { describe: 'Rio cli endpoint', type: 'string', }) yargs.options('endpoint', { describe: 'Rio cli endpoint', type: 'string', }) return yargs }, handler: async (args) => { process.chdir(path.join('dist', 'dist')) if (args["profile"]) { execSync(`npm run rio -- deploy --profile ${args["profile"]} --project-id ${args["project-id"]} --skip-diff-check --ignore-approval`, {stdio: 'inherit'}) } else { execSync(`npm run rio -- set-profile --profile-name RIOF --secret-id ${args["secret-id"]} --secret-key --skip-diff-check ${args["secret-key"]} ${args["endpoint"] ? '--endpoint ' + args["endpoint"] : '' }`, {stdio: 'inherit'}) execSync(`npm run rio -- deploy --profile RIOF --project-id ${args["project-id"]} --skip-diff-check --ignore-approval`, {stdio: 'inherit'}) } } } as CommandModule) .showHelpOnFail(false) .strict() .parse() })().then().catch();