zcatalyst-cli
Version:
Command Line Tool for CATALYST
150 lines (149 loc) • 7.09 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
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 ansi_colors_1 = require("ansi-colors");
const features_1 = require("../init/features");
const command_1 = __importDefault(require("../internal/command"));
const prompt_1 = __importDefault(require("../prompt"));
const runtime_store_1 = __importDefault(require("../runtime-store"));
const constants_1 = require("../util_modules/constants");
const scopes_js_1 = __importDefault(require("../authentication/constants/scopes.js"));
const env_1 = require("../util_modules/env");
const fs_1 = require("../util_modules/fs");
const js_1 = require("../util_modules/js");
const index_1 = require("../util_modules/logger/index");
exports.default = new command_1.default('pull [feature]')
.description('Pull resources of your project from the remote console to the local directory')
.needs('auth', [scopes_js_1.default.functions, scopes_js_1.default.webapp])
.needs('config', { optional: true })
.needs('rc')
.ci(false)
.action((feature) => __awaiter(void 0, void 0, void 0, function* () {
const config = runtime_store_1.default.get('config');
const homeDir = (yield Promise.resolve().then(() => __importStar(require('os')))).homedir();
const warnings = [];
if (fs_1.SYNC.isPathOutside(homeDir, runtime_store_1.default.get('cwd'))) {
warnings.push('You are currently outside your home directory');
}
if (runtime_store_1.default.get('cwd') === homeDir) {
warnings.push('You are initializing your home directory as a Catalyst project');
}
if (config.loaded) {
warnings.push('You are initializing in an existing Catalyst project directory');
}
let warningText = '';
if (warnings.length !== 0) {
warningText =
'\nBefore we get started, keep in mind:\n\n ' +
ansi_colors_1.yellow.bold('* ') +
warnings.join('\n ' + ansi_colors_1.yellow.bold('* ')) +
'\n';
}
(0, index_1.info)('\n' +
"\nYou're about to pull your Catalyst project in this directory:\n\n " +
(0, ansi_colors_1.bold)(runtime_store_1.default.get('project.root')) +
'\n' +
warningText);
const ans = env_1.isWindows
? yield prompt_1.default.ask(prompt_1.default.question('confirmation', 'Are you ready to proceed?', {
type: 'confirm'
}))
: { confirmation: true };
if (!ans.confirmation) {
(0, index_1.message)('Aborted by user.');
return;
}
let featureAns = { features: [feature] };
if (feature === undefined) {
const featureChoices = [
prompt_1.default.choice('Functions: Choose from a list of functions from remote', {
value: 'functions',
short: 'Functions'
}),
prompt_1.default.choice('Client: Choose from list of versions previously deployed', {
value: 'client',
short: 'Client'
}),
prompt_1.default.choice('API Gateway Rules: Get all the rules from server already configured', {
value: 'apig',
short: 'API Gateway Rules'
})
];
featureAns = (yield prompt_1.default.ask(prompt_1.default.question('features', 'Which are the features you want to pull?\n', {
type: 'checkbox',
choices: featureChoices,
validate: (ansArr) => {
if (js_1.JS.isEmpty(ansArr)) {
return ('Must select at least one feature.\n' +
'(Press ' +
(0, ansi_colors_1.cyan)('<space>') +
' to select, ' +
(0, ansi_colors_1.cyan)('<a>') +
' to toggle all, ' +
(0, ansi_colors_1.cyan)('<i>') +
' to invert selection)');
}
return true;
}
})));
}
const features = featureAns.features;
runtime_store_1.default.set('context.features', features);
const PULL = (yield Promise.resolve().then(() => __importStar(require('../pull')))).default;
yield PULL();
const payload = runtime_store_1.default.get('context.payload.features', []);
if (payload.length === 0) {
(0, index_1.info)();
(0, index_1.error)('No catalyst resources pulled !!!');
return;
}
payload.forEach((featureName) => {
(0, index_1.debug)(`Updating ${featureName} in ${constants_1.FILENAME.config} with respect to the pulled resouce`);
(0, features_1.setCatalystConfig)(featureName, true);
});
yield config.save();
(0, index_1.message)((0, ansi_colors_1.bold)(constants_1.FILENAME.config) + ' file has been successfully updated with feature details.');
(0, index_1.info)();
if ((runtime_store_1.default.get('context.payload.functions.status') ||
runtime_store_1.default.get('context.payload.client.status') ||
runtime_store_1.default.get('context.payload.apig.status')) === 1) {
(0, index_1.success)('Catalyst pull partially completed!');
}
else {
(0, index_1.success)('Catalyst pull completed!');
}
}));