auditjs
Version:
Audit dependencies to identify known vulnerabilities and maintenance problems
65 lines • 2.42 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 = __importDefault(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';
}
else if (this.type == 'guide') {
this.directoryName = '.sonatype-guide';
this.fileName = '.sonatype-guide-config';
}
}
getConfigLocation() {
this.tryCreateDirectory();
return path_1.default.join(os_1.default.homedir(), this.directoryName, this.fileName);
}
tryCreateDirectory() {
const dir = path_1.default.join(os_1.default.homedir(), this.directoryName);
if (!(0, fs_1.existsSync)(dir)) {
(0, fs_1.mkdirSync)(dir);
}
}
saveFile(objectToSave) {
const location = this.getConfigLocation();
(0, fs_2.writeFileSync)(location, (0, js_yaml_1.dump)(objectToSave, { skipInvalid: true }));
(0, fs_2.chmodSync)(location, 0o600);
this.getConfigFromFile();
return true;
}
exists() {
return (0, fs_1.existsSync)(path_1.default.join(os_1.default.homedir(), this.directoryName, this.fileName));
}
}
exports.Config = Config;
//# sourceMappingURL=Config.js.map