UNPKG

zcatalyst-cli

Version:

Command Line Tool for CATALYST

109 lines (108 loc) 5.48 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 file_names_js_1 = __importDefault(require("../../../../util_modules/constants/lib/file-names.js")); const plugin_js_1 = __importDefault(require("../../../../util_modules/constants/lib/plugin.js")); const placeholders_js_1 = __importDefault(require("../../../../util_modules/constants/lib/placeholders.js")); const folder_names_js_1 = __importDefault(require("../../../../util_modules/constants/lib/folder-names.js")); const project_js_1 = require("../../../../util_modules/project.js"); const shell_js_1 = require("../../../../util_modules/shell.js"); const runtime_store_js_1 = __importDefault(require("../../../../runtime-store.js")); const logger_js_1 = require("../../../../util_modules/logger.js"); const ansi_colors_1 = require("ansi-colors"); const client_js_1 = require("../../../util/client.js"); const path_1 = require("path"); const ASYNC = __importStar(require("../../../../util_modules/fs/lib/async.js")); const error_js_1 = __importDefault(require("../../../../error.js")); const { angular } = plugin_js_1.default; const { client } = placeholders_js_1.default; exports.default = () => __awaiter(void 0, void 0, void 0, function* () { const clientName = yield (0, client_js_1.clientNamePrompt)('Please provide a name for your Angular App:', 'angular-app'); const clientDirPath = (0, project_js_1.resolveProjectPath)(folder_names_js_1.default.client); yield (0, client_js_1.directoryOverridePrompt)(clientDirPath); const opts = [ angular.runner_command[1], clientName, '--directory', folder_names_js_1.default.client, '--skip-git', 'true' ]; try { const collection = require.resolve((0, path_1.join)(angular.collection_name, 'package.json')); yield (0, shell_js_1.spawn)(angular.runner_command[0], [...opts, '--collection', (0, path_1.dirname)(collection)], { stdio: 'inherit', cwd: runtime_store_js_1.default.get('cwd') }).ASYNC(); } catch (e) { if (e === null) { throw new error_js_1.default('Process aborted!', { exit: 0, skipHelp: true }); } const err = error_js_1.default.getErrorInstance(e, { message: 'Failure when creating new Angular App' }).original; if (!err.code || err.code !== 'ENOENT') { throw err; } (0, logger_js_1.info)(`Angular CLI (${ansi_colors_1.red.italic('@angular/cli')}) not found....`); (0, logger_js_1.info)(`Installing ${(0, ansi_colors_1.bold)('@angular/cli')} using ${(0, ansi_colors_1.bold)('npx')}`); (0, logger_js_1.info)('Note: this may take a while...'); yield (0, shell_js_1.spawn)('npx', [ '-p', angular.collection_name, '-p', angular.runner_package, angular.runner_command[0], ...opts, '--collection', angular.collection_name ], { stdio: 'inherit', cwd: runtime_store_js_1.default.get('cwd') }) .ASYNC() .catch((err) => { throw error_js_1.default.getErrorInstance(err, { message: 'Failure when creating new Angular App with npx' }); }); } yield ASYNC.findAndReplace((0, path_1.join)(clientDirPath, file_names_js_1.default.client.package_json))(client.package.name, clientName); runtime_store_js_1.default.set('payload.client.plugin', angular.plugin); return (0, client_js_1.fillClientInitPayload)(clientDirPath, clientName); });