@veecode-platform/safira-cli
Version:
Generate a microservice project from your spec.
49 lines (48 loc) • 2.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfigMapOperation = void 0;
const file_system_utils_1 = require("../utils/file-system-utils");
const yaml_utils_1 = require("../utils/yaml-utils");
const string_utils_1 = require("../utils/string-utils");
const file_exception_1 = require("../exception/file-exception");
class ConfigMapOperation {
constructor() {
this._configmapFolder = file_system_utils_1.FileSystemUtils.buildPath(file_system_utils_1.FileSystemUtils.getCurrentPath(), "k8s", "configmap");
}
create(propertiesPath, appName, stage) {
const configmapFile = file_system_utils_1.FileSystemUtils.buildPath(this._configmapFolder, `${appName}-${stage}-configmap.yaml`);
const propertiesContent = file_system_utils_1.FileSystemUtils.loadFile(propertiesPath);
const fileName = string_utils_1.StringUtils.getFullFileName(propertiesPath);
const configMap = {
apiVersion: "v1",
kind: "ConfigMap",
metadata: {
name: `${appName}-${stage}-configmap`,
namespace: stage,
},
data: {
[fileName]: propertiesContent,
},
};
const configmapYamlContent = yaml_utils_1.YamlUtils.stringify(configMap);
file_system_utils_1.FileSystemUtils.writeFile(configmapFile, configmapYamlContent);
return configmapFile;
}
list(fullPath = true) {
if (fullPath)
return file_system_utils_1.FileSystemUtils.listFilesRecursive(this._configmapFolder);
return file_system_utils_1.FileSystemUtils.listFilesRecursive(this._configmapFolder).map(file => string_utils_1.StringUtils.getFullFileName(file));
}
findByFileName(fileName) {
const result = this.list().find(file => file.includes(fileName));
if (result)
return result;
throw new file_exception_1.FileNotFoundException("Configmap not found");
}
static get instance() {
if (!this._instance)
this._instance = new this();
return this._instance;
}
}
exports.ConfigMapOperation = ConfigMapOperation;