auditjs
Version:
Audit dependencies to identify known vulnerabilities and maintenance problems
60 lines • 2.21 kB
JavaScript
"use strict";
/*
* Copyright 2019-Present Sonatype Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Config = void 0;
const path_1 = __importDefault(require("path"));
const os_1 = require("os");
const fs_1 = require("fs");
const fs_2 = require("fs");
const js_yaml_1 = require("js-yaml");
class Config {
constructor(type, username, token) {
this.type = type;
this.username = username;
this.token = token;
this.directoryName = '.ossindex';
this.fileName = '.oss-index-config';
if (this.type == 'iq') {
this.directoryName = '.iqserver';
this.fileName = '.iq-server-config';
}
this.configLocation = path_1.default.join((0, os_1.homedir)(), this.directoryName, this.fileName);
}
getConfigLocation() {
this.tryCreateDirectory();
return this.configLocation;
}
tryCreateDirectory() {
if (!(0, fs_1.existsSync)(path_1.default.join((0, os_1.homedir)(), this.directoryName))) {
(0, fs_1.mkdirSync)(path_1.default.join((0, os_1.homedir)(), this.directoryName));
}
return;
}
saveFile(objectToSave) {
(0, fs_2.writeFileSync)(this.getConfigLocation(), (0, js_yaml_1.safeDump)(objectToSave, { skipInvalid: true }));
this.getConfigFromFile();
return true;
}
exists() {
return (0, fs_1.existsSync)(this.configLocation);
}
}
exports.Config = Config;
//# sourceMappingURL=Config.js.map