UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

60 lines (57 loc) 1.83 kB
import { b as __awaiter, c as __generator } from '../tslib.es6-096fffdd.js'; import { fetchRainbowConfig } from './rainbow-user.js'; import 'axios'; import '../list/flat.js'; import '@babel/runtime/helpers/typeof'; import './helper/helper.js'; import './sdk.js'; import '../json/json-parse.js'; function writeEnvFromRainbow(_a) { var envPath = _a.envPath, rainbowAppId = _a.rainbowAppId, rainbowUserId = _a.rainbowUserId, rainbowSecretKey = _a.rainbowSecretKey, rainbowKey = _a.rainbowKey, envName = _a.envName, groupName = _a.groupName, sdk = _a.sdk; return __awaiter(this, void 0, void 0, function () { var appId, userId, secretKey, str; return __generator(this, function (_b) { switch (_b.label) { case 0: readLocalEnv(envPath); appId = rainbowAppId || process.env.RAINBOW_APP_ID || ''; userId = rainbowUserId || process.env.RAINBOW_USER_ID || ''; secretKey = rainbowSecretKey || process.env.RAINBOW_SECRET_KEY || ''; if (!appId) { throw new Error('缺少 RAINBOW_APP_ID'); } return [4 /*yield*/, fetchRainbowConfig(rainbowKey, { appId: appId, envName: envName, groupName: groupName, userId: userId, secretKey: secretKey }, { sdk: sdk })["catch"](function (err) { console.log('[fetchRainbowConfig] err', err); })]; case 1: str = _b.sent(); require('fs').writeFileSync(envPath, str, { encoding: 'utf-8' }); readLocalEnv(envPath); return [2 /*return*/, true]; } }); }); } function readLocalEnv(envPath) { require('dotenv').config({ path: envPath }); } export { writeEnvFromRainbow };