UNPKG

t-comm

Version:

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

63 lines (58 loc) 1.91 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var tslib_es6 = require('../tslib.es6-01322ba9.js'); var rainbow_rainbowUser = require('./rainbow-user.js'); require('axios'); require('./helper/helper.js'); require('./sdk.js'); require('../json/json-parse.js'); require('../list/flat.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 tslib_es6.__awaiter(this, void 0, void 0, function () { var appId, userId, secretKey, str; return tslib_es6.__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*/, rainbow_rainbowUser.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 }); } exports.writeEnvFromRainbow = writeEnvFromRainbow;