UNPKG

esa-cli

Version:

A CLI for operating Alibaba Cloud ESA Functions and Pages.

81 lines (80 loc) 3.17 kB
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()); }); }; import { exec, execSync } from 'child_process'; import os from 'os'; import path from 'path'; import t from '../i18n/index.js'; import logger from '../libs/logger.js'; import { downloadRuntimeAndUnzipForWindows } from './download.js'; import { getDirName } from './fileUtils/base.js'; export function preCheckDeno() { return __awaiter(this, void 0, void 0, function* () { const command = yield checkDenoInstalled(); if (!command) { logger.error(t('install_runtime_explain').d('Our runtime does not yet support this OS. We are temporarily using Deno as the local development runtime, which needs to be installed first.')); yield installDeno(); return false; } return command; }); } export function checkDenoInstalled() { const homeDeno = path.resolve(os.homedir(), '.deno/bin/deno'); function checkDeno(command) { return new Promise((resolve, reject) => { exec(`${command} --version`, (err) => { if (err) { reject(); } else { resolve(command); } }); }); } return new Promise((resolve) => { // @ts-ignore Promise.any([checkDeno('deno'), checkDeno(homeDeno)]) .then((res) => { resolve(res); }) .catch(() => { resolve(false); }); }); } export function installDeno() { return __awaiter(this, void 0, void 0, function* () { let installCommand; const __dirname = getDirName(import.meta.url); const p = path.join(__dirname, './install'); switch (os.platform()) { case 'win32': yield downloadRuntimeAndUnzipForWindows(); return true; case 'darwin': case 'linux': installCommand = `sh ${p}/install.sh`; break; default: installCommand = `sh ${p}/install.sh`; } logger.warn(t('install_runtime_tip').d(`🔔 Runtime must be installed to use esa-cli dev. Installing...`)); try { execSync(installCommand, { stdio: 'inherit' }); logger.success(t('install_runtime_success').d(`Runtime installed.`)); return true; } catch (error) { logger.error(`Failed to install: ${error.message}`); return false; } }); }