appcenter-cli
Version:
Command line tool for Visual Studio App Center
55 lines (54 loc) • 1.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getProfileDirParent = exports.getProfileDir = void 0;
const fs = require("fs");
const os = require("os");
const path = require("path");
const constants_1 = require("./constants");
const debug = require("debug")("appcenter-cli:util:misc:get-profile-dir");
function getProfileDir() {
const profileDir = path.join(getProfileDirParent(), constants_1.profileDirName);
const oldProfileDir = path.join(getProfileDirParent(), constants_1.oldProfileDirName);
if (!existsSync(profileDir) && existsSync(oldProfileDir)) {
copyDirSync(oldProfileDir, profileDir);
}
return profileDir;
}
exports.getProfileDir = getProfileDir;
function getProfileDirParent() {
if (os.platform() === "win32") {
return process.env.AppData;
}
else {
return os.homedir();
}
}
exports.getProfileDirParent = getProfileDirParent;
function existsSync(path) {
try {
fs.statSync(path);
return true;
}
catch (err) {
if (err.code === "ENOENT") {
return false;
}
throw err;
}
}
//
// Copy the old profile directory over to the new name.
//
function copyDirSync(srcPath, destPath) {
debug(`Copying profile from ${srcPath} to ${destPath}`);
fs.mkdirSync(destPath);
const files = fs.readdirSync(srcPath);
files
.map((f) => [path.join(srcPath, f), path.join(destPath, f)])
.filter(([src, dest]) => isFileSync(src))
.forEach(([src, dest]) => fs.copyFileSync(src, dest));
}
function isFileSync(file) {
const stats = fs.statSync(file);
return stats.isFile();
}