UNPKG

voxa-cli

Version:
86 lines 4.27 kB
"use strict"; /* * Copyright (c) 2018 Rain Agency <contact@rain.agency> * Author: Rain Agency <contact@rain.agency> * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* tslint:disable:no-submodule-imports no-console */ 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 }); const fs_extra_1 = __importDefault(require("fs-extra")); const path_1 = __importDefault(require("path")); const InteractionBuilder_1 = require("../InteractionBuilder"); exports.name = "interaction"; exports.alias = ""; exports.description = "create a interaction.json"; exports.options = [{ flags: "-p, --path <path>", description: "overwrite root path" }]; function action(cmd) { return __awaiter(this, void 0, void 0, function* () { const rootPath = cmd.path || process.cwd(); const interactionFileName = cmd.interactionFileName || "interaction.json"; const interactionPath = path_1.default.isAbsolute(interactionFileName) ? interactionFileName : path_1.default.join(rootPath, interactionFileName); let interaction = {}; try { interaction = yield fs_extra_1.default.readJSON(interactionPath); } catch (e) { const sampleInteraction = { spreadsheets: ["INTENT SPREADSHEET", "PUBLISHING SPREADSHEET"] }; const sampleInteractionStr = JSON.stringify(sampleInteraction, null, 2); if (e.code === "MODULE_NOT_FOUND") { console.log(`mm... It seems you don\'t have a ${interactionPath}. Let me create it for you`); return fs_extra_1.default.outputFileSync(interactionPath, sampleInteractionStr, { flag: "w" }); } } interaction.rootPath = path_1.default.dirname(interactionFileName); yield InteractionBuilder_1.buildInteraction(interaction, getAuth(rootPath)); }); } exports.action = action; function getAuth(rootPath) { const authFileName = "client_secret.json"; const authPath = path_1.default.join(rootPath, authFileName); let auth = {}; try { // a path we KNOW is totally bogus and not a module auth = require(authPath); } catch (e) { // if (e.code === "MODULE_NOT_FOUND") { // console.log(`mm... Make sure to create ${authFileName} from Google console`); // return; // } } return auth; } //# sourceMappingURL=interaction.js.map