UNPKG

simba-cli

Version:

A simple CLI to handle most basic and everyday usage cli command wishes

48 lines 2.14 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.setV4WorkEnvironment = void 0; const yargs_1 = __importDefault(require("yargs")); const path_1 = __importDefault(require("path")); const process_1 = require("process"); const fs_1 = require("fs"); const log_1 = require("../../log"); // Example command: as env v4work --prod const setV4WorkEnvironment = () => { const options = yargs_1.default.argv; const cwDir = (0, process_1.cwd)(); const isProd = !!options.prod; // update config file try { const configPath = path_1.default.normalize(cwDir + '/lib/shared/utils/config.dart'); const file = (0, fs_1.readFileSync)(configPath).toString(); const lines = file.split('\n'); const mark = 'static bool isProd'; for (let a = 0; a < lines.length; a++) { const line = lines[a]; if (line.includes(mark)) { const newline = line.substr(0, line.indexOf(mark) + mark.length) + ` = ${isProd};`; lines[a] = newline; } } (0, fs_1.writeFileSync)(configPath, lines.join('\n')); } catch (e) { throw Error('Error while reading and updating V4Work config file'); } // update google-services.json file try { const gsBasePath = '/android/app'; const googleServices = (0, fs_1.readFileSync)(path_1.default.normalize(cwDir + gsBasePath + `/google-services ${isProd ? 'prod' : 'dev'}.json`)).toString(); (0, fs_1.writeFileSync)(path_1.default.normalize(cwDir + gsBasePath + `/google-services.json`), googleServices); } catch (e) { throw Error('Error while reading and updating V4Work google services file'); } log_1.Log.info(`Environment now pointing to ${isProd ? 'production' : 'dev'}`); console.log('Please, run `flutter clean` command next to ensure a clean build.'); }; exports.setV4WorkEnvironment = setV4WorkEnvironment; //# sourceMappingURL=v4work_env.js.map