UNPKG

zcatalyst-cli

Version:

Command Line Tool for CATALYST

140 lines (139 loc) 6.65 kB
'use strict'; 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 fs_1 = require("../util_modules/fs"); const js_1 = require("../util_modules/js"); const index_1 = require("../util_modules/logger/index"); const shell_1 = require("../util_modules/shell"); const saveAndComplete = (config) => __awaiter(void 0, void 0, void 0, function* () { yield config.save(); (0, index_1.message)((0, ansi_colors_1.bold)(constants_1.FILENAME.config) + ' file has been successfully created with feature details.'); (0, index_1.info)(); (0, index_1.success)('Catalyst initialization complete!'); }); exports.default = new command_1.default('init [feature]') .description('Initialize a Catalyst project, function, and client resources in the local directory') .option('--force', 'force initialise a project for this directory') .ignore(['project']) .needs('auth', [scopes_js_1.default.projects, scopes_js_1.default.project_import_create]) .needs('config', { optional: true }) .needs('rc', { optional: true, resolveOnNotFound: true }) .ci(false) .action((feature) => __awaiter(void 0, void 0, void 0, function* () { var _a; 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 (!js_1.JS.isEmpty(warnings)) { 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, shell_1.clearStdout)(true); const bannerString = yield fs_1.ASYNC.readFile(constants_1.TEMPLATE.banner); (0, index_1.info)('\n' + ansi_colors_1.blueBright.bold(bannerString) + "\nYou're about to initialize a Catalyst project in this directory:\n\n " + (0, ansi_colors_1.bold)(runtime_store_1.default.get('project.root')) + '\n' + warningText); if (feature !== 'project') { try { yield (0, features_1.project)(); } catch (er) { (0, index_1.debug)(er); return; } } (0, index_1.info)(); const featureAns = yield prompt_1.default.ask(prompt_1.default.question('features', 'Which are the features you want to setup for this folder?\n This step is optional! Press ' + (0, ansi_colors_1.cyan)('<return> ') + 'to proceed.\n', { type: 'checkbox', choices: [ prompt_1.default.choice('Functions: Configure and deploy http/non-http functions', { value: 'functions', short: 'Functions' }), prompt_1.default.choice('Client: Configure and deploy client files', { value: 'client', short: 'Client' }), prompt_1.default.choice('AppSail: Configure and deploy AppSails', { value: 'appsail', short: 'AppSail' }), prompt_1.default.choice('Slate: Configure and deploy slate apps', { value: 'slate', short: 'Slate' }) ], when: !runtime_store_1.default.get('context.payload.project.import', false) && typeof feature !== 'string' })); if (!((_a = featureAns.features) === null || _a === void 0 ? void 0 : _a.length) && (runtime_store_1.default.get('context.payload.project.import', false) || typeof feature !== 'string')) { return saveAndComplete(config); } if (typeof feature === 'string') { featureAns.features = [feature]; } runtime_store_1.default.set('context.features', featureAns.features); yield (yield Promise.resolve().then(() => __importStar(require('../init')))).default(); return saveAndComplete(config); }));