@metacall/deploy
Version:
Tool for deploying into MetaCall FaaS platform.
68 lines (65 loc) • 2.73 kB
JavaScript
;
/*
* About File:
it is for dealing with the local configuration of the cli, for storing there the data
*/
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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.save = exports.load = exports.configFilePath = exports.defaultPath = exports.Config = void 0;
const fs_1 = require("fs");
const ini_1 = require("ini");
const path_1 = require("path");
const z = __importStar(require("zod"));
const utils_1 = require("./utils");
exports.Config = z.object({
baseURL: z.string(),
apiURL: z.string(),
devURL: z.string(),
renewTime: z.number(),
token: z.string().optional()
});
const defaultConfig = {
baseURL: 'https://dashboard.metacall.io',
apiURL: 'https://api.metacall.io',
devURL: 'http://localhost:9000',
renewTime: 1000 * 60 * 60 * 24 * 15
};
exports.defaultPath = (0, utils_1.configDir)((0, path_1.join)('metacall', 'deploy'));
const configFilePath = (path = exports.defaultPath) => (0, path_1.join)(path, 'config.ini');
exports.configFilePath = configFilePath;
const load = async (path = exports.defaultPath) => {
const data = (0, ini_1.parse)(await (0, utils_1.loadFile)((0, exports.configFilePath)(await (0, utils_1.ensureFolderExists)(path))));
return exports.Config.nonstrict().parse({
...defaultConfig,
...data,
...(data.renewTime ? { renewTime: Number(data.renewTime) } : {})
});
};
exports.load = load;
const save = async (data, path = exports.defaultPath) => fs_1.promises.writeFile((0, exports.configFilePath)(await (0, utils_1.ensureFolderExists)(path)), (0, ini_1.stringify)((0, utils_1.filter)(defaultConfig, {
...(await (0, exports.load)(path)),
...data
})));
exports.save = save;