zcatalyst-cli
Version:
Command Line Tool for CATALYST
83 lines (82 loc) • 4.74 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 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 ASYNC = __importStar(require("../../../../util_modules/fs/lib/async.js"));
const path_1 = require("path");
const os_1 = require("os");
const index_js_1 = __importDefault(require("../../../../prompt/index.js"));
const client_js_1 = require("../../../util/client.js");
const plugin_js_1 = __importDefault(require("../../../../util_modules/constants/lib/plugin.js"));
const template_js_1 = __importDefault(require("../../../../util_modules/constants/lib/template.js"));
const placeholders_js_1 = __importDefault(require("../../../../util_modules/constants/lib/placeholders.js"));
const error_js_1 = __importDefault(require("../../../../error.js"));
const { react } = plugin_js_1.default;
const { client } = placeholders_js_1.default;
exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
const flavourPrompt = yield index_js_1.default.ask(index_js_1.default.question('flavour', `Choose an option to create the React App:`, {
type: 'list',
choices: [
index_js_1.default.choice('JavaScript', { value: 'js', short: 'JavaScript' }),
index_js_1.default.choice('TypeScript', { value: 'ts', short: 'TypeScript' })
]
}));
const clientName = yield (0, client_js_1.clientNamePrompt)('Please provide a name for your React App:', 'react-app');
const clientDirPath = (0, project_js_1.resolveProjectPath)(clientName);
yield (0, client_js_1.directoryOverridePrompt)(clientDirPath);
const catalystTempDir = (0, path_1.join)((0, os_1.tmpdir)(), '.catalyst');
const reactPluginDir = (0, path_1.join)(catalystTempDir, 'react');
yield ASYNC.emptyDir(reactPluginDir);
yield ASYNC.copyDir(flavourPrompt.flavour === 'ts' ? template_js_1.default.client.react.ts : template_js_1.default.client.react.js, reactPluginDir);
yield (0, client_js_1.addDependency)((0, path_1.join)(reactPluginDir, 'template.json'), { [react.plugin]: 'latest' }, { depPath: ['package'] });
yield ASYNC.findAndReplace(reactPluginDir)(client.package.name, clientName);
yield (0, shell_js_1.spawn)('npx', [react.runner_command[0], clientName, '--template', 'file:' + reactPluginDir], {
stdio: 'inherit',
cwd: runtime_store_js_1.default.get('cwd')
})
.ASYNC()
.catch((err) => {
throw error_js_1.default.getErrorInstance(err, {
message: 'Failure while Creating react app',
skipHelp: false
});
});
runtime_store_js_1.default.set('payload.client.plugin', react.plugin);
return (0, client_js_1.fillClientInitPayload)(clientDirPath, clientName);
});