UNPKG

@viewdo/dxp-story-cli

Version:

DXP Story Management CLI

390 lines 19.1 kB
#!/usr/bin/env node "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); require("colors"); const commander_1 = require("commander"); const dotenv_1 = __importDefault(require("dotenv")); require("es6-shim"); const figlet_1 = __importDefault(require("figlet")); const path_1 = __importDefault(require("path")); require("reflect-metadata"); require("source-map-support/register"); const typedi_1 = require("typedi"); const ConsoleService_1 = require("./app/services/ConsoleService"); const add_action_1 = require("./commands/add-action"); const add_service_1 = require("./commands/add-service"); const build_1 = require("./commands/build"); const check_1 = require("./commands/check"); const export_organization_1 = require("./commands/export-organization"); const export_story_1 = require("./commands/export-story"); const import_organization_1 = require("./commands/import-organization"); const import_story_1 = require("./commands/import-story"); const init_1 = require("./commands/init"); const login_1 = require("./commands/login"); const preview_1 = require("./commands/preview"); const pull_1 = require("./commands/pull"); const pull_email_1 = require("./commands/pull-email"); const push_1 = require("./commands/push"); const reset_unpack_1 = require("./commands/reset-unpack"); const scaffold_episode_1 = require("./commands/scaffold-episode"); const scaffold_scene_1 = require("./commands/scaffold-scene"); const scaffold_state_1 = require("./commands/scaffold-state"); const scaffold_story_1 = require("./commands/scaffold-story"); const scaffold_template_1 = require("./commands/scaffold-template"); const update_1 = require("./commands/update"); const validate_1 = require("./commands/validate"); const secret_list_1 = require("./commands/secret-list"); const secret_set_1 = require("./commands/secret-set"); // @ts-ignore const pkg = require("../package.json"); commander_1.program.version(pkg.version); process.on("uncaughtException", (err) => { console.error(err); process.exit(1); }); commander_1.program.on("command:*", () => { console.error("Invalid command: %s\nSee --help for a list of available commands.", commander_1.program.args.join(" ")); process.exit(1); }); process.on("unhandledRejection", (reason, p) => { console.error("Unhandled Rejection at: Promise", p, "reason:", reason); process.exit(1); }); dotenv_1.default.config({ path: path_1.default.resolve(process.cwd(), ".env") }); const runCommand = (context, command, additional_args) => __awaiter(void 0, void 0, void 0, function* () { const flattenOptions = (cmd) => { let options = {}; // cmd?.parent || {}; return Object.assign(options, cmd, additional_args); }; global.console.log(figlet_1.default.textSync("Story CLI", { horizontalLayout: "default" }).blue); global.console.log(`v${pkg.version}`.blue); try { let options = flattenOptions(context); let result = yield command.run(options); process.exit(result); } catch (err) { let console = typedi_1.Container.get(ConsoleService_1.ConsoleService); console.error(err.message || err); if (process.env.DEBUG == "true") console.error(err.stack); process.exit(1); } }); /* GLOBAL ============================== */ commander_1.program .command("help") .alias("h") .action(() => { commander_1.program.outputHelp(); }); commander_1.program .command("init") .alias("i") .description("Set up the required configuration files for using the CLI within a folder. Pass in org keys if they exist.") .option("-a, --auto", "For use when created during automation. [No auth]") .option("-o, --overwrite", "Overwrite existing files.") .option("-g, --git", "This flag will setup git as well. Use this the first time!") .action((cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(init_1.InitCommand), {}); })); commander_1.program .command("update [keys...]") .description("Update repository files to newer DXP/CLI configurations and settings.") .option("-r, --root", "Update files in root and .dxp folders (webpack,gitignore, pipeline, etc)") .option("-d, --dxp", "Update files in .dxp folder (templates and schemas)") .option("-s, --stories", "Update story build files for each story.") .option("-o, --organizations", "Update organization folders for each org.") .option("-p, --packages", "Update dependencies in package.json") .option("-a, --all", "Update everything") .action((keys, cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(update_1.UpdateCommand), { keys }); })); commander_1.program .command("login [email] [code]") .alias("auth") .description("Authenticates to the output using email verification code") .option("-f, --force", "Force new authentication") .option("-i, --client_id <client_id>", "Auth0 client id") .option("-s, --client_secret <secret>", "Auth0 client secret") .option("-n, --namespace <namespace>", "Override the namespace") .action((email, code, cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(login_1.LoginCommand), { email, code }); })); commander_1.program .command("add-action [story-key]") .description("Creates a new action for a given story using definitions from DXP") .action((storyKey, cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(add_action_1.AddActionCommand), { storyKey }); })); commander_1.program .command("add-service [org-key]") .description("Creates a new Service Configuration for a given organization using definitions from DXP") .action((orgKey, cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(add_service_1.AddServiceCommand), { orgKey }); })); commander_1.program .command("scaffold-story [story-key]") .alias("ss") .description("Creates all the asset files and folders for new story") .option("-t, --template <template>", "Provide a template key to build a story based on an existing template") .option("-o, --org <org>", "Specify an org for multi-org repos") .option("-e, --extra_args <args...>", "Provide additional arguments to the scaffold-story command to use for specific templates") .action((storyKey, cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(scaffold_story_1.ScaffoldStoryCommand), { storyKey }); })); commander_1.program .command("scaffold-episode [story-key] [episode-key]") .alias("se") .description("Creates a new episode within a specified story") .option("-t, --template <template>", "Provide a template key to build a story based on an existing template") .action((storyKey, episodeKey, cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(scaffold_episode_1.ScaffoldEpisodeCommand), { storyKey, episodeKey, }); })); commander_1.program .command("scaffold-state [story-key] [episode-key] [state-type] [state-key]") .alias("st") .description("Creates a blank state") .action((storyKey, episodeKey, stateType, stateKey, cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(scaffold_state_1.ScaffoldStateCommand), { storyKey, episodeKey, stateType, stateKey, }); })); commander_1.program .command("scaffold-scene [story-key] [episode-key] [template-key] [scene-key] [scene-id] ") .alias("sc") .description("Creates a scene using a prebuilt template") .action((storyKey, episodeKey, templateKey, sceneKey, sceneId, cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(scaffold_scene_1.ScaffoldSceneCommand), { storyKey, episodeKey, templateKey, sceneKey, sceneId, }); })); commander_1.program .command("scaffold-template [story-key] [template-key] [template-type]") .alias("t") .description("Creates a new text template to use within a story") .action((storyKey, episodeKey, templateKey, templateType, cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(scaffold_template_1.ScaffoldTemplateCommand), { storyKey, episodeKey, templateKey, templateType, }); })); commander_1.program .command("build [keys...]") .alias("b") .description("Performs a webpack build on configured stories") .option("-v, --verbose", "Verbose logging") .option("-k, --key <key>", "Build only this story key") .option("-a, --all", "Build all stories without prompting") .action((keys, cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(build_1.BuildCommand), { keys }); })); commander_1.program .command("pull [keys...]") .alias("p") .description("Pulls down all the associated assets for a given set of story keys") .option("-k, --key <key>", "Pull all stories for a given organization") .option("-a, --all", "Pull all stories without prompting") .option("-f, --force", "Overwrite story build files") .option("-c, --client_id <client_id>", "Auth0 client id") .option("-s, --client_secret <secret>", "Auth0 client secret") .option("-n, --namespace <namespace>", "Override the namespace") .action((keys, cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(pull_1.PullCommand), { keys }); })); commander_1.program .command("pull-as <story_key> <as_key> <org_key>") .alias("pa") .description("Pulls down a story as a new key with the given organization key") .option("-c, --client_id <client_id>", "Auth0 client id") .option("-s, --client_secret <secret>", "Auth0 client secret") .option("-n, --namespace <namespace>", "Override the namespace") .action((story_key, as_key, org_key, cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(pull_1.PullCommand), { story_key, as_key, org_key, }); })); commander_1.program .command("push [keys...]") .alias("u") .description("Pushes all the associated assets to a given story") .option("-k, --key <key>", "Push all stories for a given organization") .option("-a, --all", "Push all stories without prompting") .option("-S, --skip-cdn", "Skip CDN assets", false) .option("-b, --build_id", "The commit/sync identifier for this push (defaults to BUILD_ID)") .option("-B, --build", "Build stories before pushing") .option("-c, --client_id <client_id>", "Auth0 client id") .option("-s, --client_secret <secret>", "Auth0 client secret") .option("-n, --namespace <namespace>", "Override the namespace") .action((keys, cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(push_1.PushCommand), { keys }); })); commander_1.program .command("pull-email [keys...]") .alias("pe") .description("Pulls down all the associated Stripo email templates for a given set of story keys") .option("-k, --key <key>", "Pull all stories for a given organization") .option("-a, --all", "Pull all stories without prompting") .action((keys, cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(pull_email_1.PullEmailsCommand), { keys }); })); // program // .command("push-cdn <file> [output]") // .description( // "Uploads a local file to the viewDo static bucket (requires authentication file)" // ) // .action(async (file, output, cmd) => { // await runCommand(cmd, Container.get(UploadStaticFile), { file, output }); // }); // // program // .command("push-assets [keys...]") // .alias("gcp") // .description("Push story assets directory (requires authentication file)") // .action(async (keys, cmd) => { // await runCommand(cmd, Container.get(PushAssetsCommand), { keys }); // }); commander_1.program .command("preview [key] [episode]") .alias("u") .description("Previews a given story") .option("-p, --port", "Overrides the port for previewing") .option("-f, --force", "Overwrites the preview config for all specified stories") .action((key, episode, cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(preview_1.PreviewCommand), { key, episode }); })); commander_1.program .command("check [keys...]") .alias("c") .description("Checks to see what files are different on disc from the platform") .option("-a, --all", "Checks all stories without prompting") .option("-c, --client_id <client_id>", "Auth0 client id") .option("-s, --client_secret <secret>", "Auth0 client secret") .option("-n, --namespace <namespace>", "Override the namespace") .action((keys, cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(check_1.CheckCommand), { keys }); })); commander_1.program .command("validate [keys...]") .alias("v") .description("Validate tokens in local files using the configured story") .option("-k, --key <key>", "Story key to validate") .option("-a, --all", "Validates all stories without prompting") .option("-c, --client_id <client_id>", "Auth0 client id") .option("-s, --client_secret <secret>", "Auth0 client secret") .option("-n, --namespace <namespace>", "Override the namespace") .action((keys, cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(validate_1.ValidateCommand), { keys }); })); commander_1.program .command("export-story [keys...]") .alias("v") .description("Export stories") .option("-k, --key <key>", "Story key to export") .option("-a, --all", "Export all stories without prompting") .option("-c, --client_id <client_id>", "Auth0 client id") .option("-s, --client_secret <secret>", "Auth0 client secret") .option("-n, --namespace <namespace>", "Override the namespace") .action((keys, cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(export_story_1.ExportStoryCommand), { keys }); })); commander_1.program .command("import-story [keys...]") .alias("v") .description("Import stories") .option("-k, --key <key>", "Story key to import") .option("-a, --all", "Import all stories without prompting") .option("-c, --client_id <client_id>", "Auth0 client id") .option("-s, --client_secret <secret>", "Auth0 client secret") .option("-n, --namespace <namespace>", "Override the namespace") .action((keys, cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(import_story_1.ImportStoryCommand), { keys }); })); commander_1.program .command("export-organization [keys...]") .alias("v") .description("Export organizations") .option("-k, --key <key>", "Organization key to export") .option("-a, --all", "Export all organizations without prompting") .option("-c, --client_id <client_id>", "Auth0 client id") .option("-s, --client_secret <secret>", "Auth0 client secret") .option("-n, --namespace <namespace>", "Override the namespace") .action((keys, cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(export_organization_1.ExportOrganizationCommand), { keys }); })); commander_1.program .command("import-organization [keys...]") .alias("v") .description("Import organizations") .option("-k, --key <key>", "Organization key to import") .option("-a, --all", "Import all organizations without prompting") .option("-c, --client_id <client_id>", "Auth0 client id") .option("-s, --client_secret <secret>", "Auth0 client secret") .option("-n, --namespace <namespace>", "Override the namespace") .action((keys, cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(import_organization_1.ImportOrganizationCommand), { keys }); })); commander_1.program .command("secret-list") .description("List available secrets") .option("-o, --org [org]", "Specify an org for multi-org repos") .action((cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(secret_list_1.ListSecretsCommand), {}); })); commander_1.program .command("secret-set <seretKey>") .description("et the value of an organization secret. A new secret version will be returned.") .option("-o, --org [org]", "Specify an org for multi-org repos") .action((secretKey, cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(secret_set_1.SetSecretCommand), { secretKey }); })); // program // .command("json-yaml <file> [output]") // .alias("to-yaml") // .description("Convert JSON to YAML") // .action(async (file, output, cmd) => { // await runCommand(cmd, Container.get(JsonToYamlCommand), { file, output }); // }); // // program // .command("yaml-json <file> [output]") // .alias("to-json") // .description("Convert YAML to JSON") // .action(async (file, output, cmd) => { // await runCommand(cmd, Container.get(JsonFromYamlCommand), { file, output }); // }); commander_1.program .command("reset-unpack") .option("-f, --force", "Reset without prompting.") .description(`This command looks at all stories configured in the repository and packs, then unpacks them using the latest unpacking technique.`) .action((cmd) => __awaiter(void 0, void 0, void 0, function* () { yield runCommand(cmd, typedi_1.Container.get(reset_unpack_1.ResetUnpackCommand), {}); })); commander_1.program.parse(process.argv); //# sourceMappingURL=index.js.map