Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const removeDir = (dir, baseDir) => {
if (isDir(dir)) {
if (!isSubDir(dir, baseDir)) {
throw new Error(`${dir} is not a subdirectory of ${baseDir}.`);
}
// NOTE: remove version detection when node 10 reaches EOL
const {version: nodeVersion} = process;
const result = compareSemVer(nodeVersion, "12.10.0");
if (result >= 0) {
fs.rmdirSync(dir, {recursive: true});
} else {
const files = fs.readdirSync(dir);
files.length && files.forEach(file => {
const cur = path.join(dir, file);
if (fs.lstatSync(cur).isDirectory()) {
removeDir(cur, baseDir);
} else {
fs.unlinkSync(cur);
}
});
fs.rmdirSync(dir);
}
}
};
const convertUriToFilePath = uri => {
if (!isString(uri)) {
throw new TypeError(`Expected String but got ${getType(uri)}.`);
}
const {protocol, pathname} = new URL(uri);
let file;
if (protocol === "file:" && pathname) {
// NOTE: remove version detection when node 10 reaches EOL
const {version: nodeVersion} = process;
const result = compareSemVer(nodeVersion, "10.16.0");
if (result >= 0) {
file = fileURLToPath(uri);
} else {
file = IS_WIN && path.normalize(decodeURIComponent(pathname).slice(1)) ||
decodeURIComponent(pathname);
}
}
return file || null;
};
parseVersions() {
this.installed_version = this.dataSet.installed_version;
let latestStable = this.dataSet.current_stable_version;
// For Testing
//latestStable = "2.8.0"; //-beta.30";
let html = '';
// See https://github.com/asamuzaK/semverParser
// for details available
let outcome = compareSemVer(latestStable, this.installed_version)
if (!!outcome) {
// See if difference is simple a Patch, or something larger
let latest = parseSemVer(latestStable);
let installed = parseSemVer(this.installed_version);
html = `Installed Version: <b>${this.installed_version}</b>. Latest version: `;
if (latest.major > installed.major) {
html += `<span class="alert alert-danger mini-alert">${latestStable}</span>`
} else if (latest.minor > installed.minor) {
html += `<span class="alert alert-danger mini-alert">${latestStable}</span>`
} else if (latest.patch > installed.patch) {
html += `<span class="alert alert-warning mini-alert">${latestStable}</span>`
} else {
// This would normally be beta releases
html += `<span class="alert alert-info mini-alert">${latestStable}</span>`
this.installed_version = this.dataSet.installed_version;
let latestStable = this.dataSet.current_stable_version;
// For Testing
//latestStable = "2.8.0"; //-beta.30";
let html = '';
// See https://github.com/asamuzaK/semverParser
// for details available
let outcome = compareSemVer(latestStable, this.installed_version)
if (!!outcome) {
// See if difference is simple a Patch, or something larger
let latest = parseSemVer(latestStable);
let installed = parseSemVer(this.installed_version);
html = `Installed Version: <b>${this.installed_version}</b>. Latest version: `;
if (latest.major > installed.major) {
html += `<span class="alert alert-danger mini-alert">${latestStable}</span>`
} else if (latest.minor > installed.minor) {
html += `<span class="alert alert-danger mini-alert">${latestStable}</span>`
} else if (latest.patch > installed.patch) {
html += `<span class="alert alert-warning mini-alert">${latestStable}</span>`
} else {
// This would normally be beta releases
html += `<span class="alert alert-info mini-alert">${latestStable}</span>`
}
html += '<br><b>Consider upgrading!</b>'
} else {
html = `You are on the current version: <span class="alert alert-success mini-alert">${this.installed_version}</span>`
parseVersions() {
this.installed_version = this.dataSet.installed_version;
let latestStable = this.dataSet.current_stable_version;
// For Testing
//latestStable = "2.8.0"; //-beta.30";
let html = '';
// See https://github.com/asamuzaK/semverParser
// for details available
let outcome = compareSemVer(latestStable, this.installed_version)
if (!!outcome) {
// See if difference is simple a Patch, or something larger
let latest = parseSemVer(latestStable);
let installed = parseSemVer(this.installed_version);
html = `Installed Version: <b>${this.installed_version}</b>. Latest version: `;
if (latest.major > installed.major) {
html += `<span class="alert alert-danger mini-alert">${latestStable}</span>`
} else if (latest.minor > installed.minor) {
html += `<span class="alert alert-danger mini-alert">${latestStable}</span>`
} else if (latest.patch > installed.patch) {
html += `<span class="alert alert-warning mini-alert">${latestStable}</span>`
} else {
// This would normally be beta releases
html += `<span class="alert alert-info mini-alert">${latestStable}</span>`
}
html += '<br><b>Consider upgrading!</b>'
} else {
const exportHostVersion = async minVer => {
if (!isString(minVer)) {
throw new TypeError(`Expected String but got ${getType(minVer)}.`);
}
if (!isValidSemVer(minVer)) {
throw new Error(`${minVer} is not valid SemVer.`);
}
const result = await compareSemVer(hostVersion, minVer);
const latest = await getLatestHostVersion();
let isLatest;
if (latest) {
const currentResult = await compareSemVer(hostVersion, latest);
isLatest = currentResult >= 0;
}
const msg = {
[HOST_VERSION]: {
isLatest,
latest,
result,
},
};
const func = writeStdout(msg);
return func;
};
const exportHostVersion = async minVer => {
if (!isString(minVer)) {
throw new TypeError(`Expected String but got ${getType(minVer)}.`);
}
if (!isValidSemVer(minVer)) {
throw new Error(`${minVer} is not valid SemVer.`);
}
const result = await compareSemVer(hostVersion, minVer);
const latest = await getLatestHostVersion();
let isLatest;
if (latest) {
const currentResult = await compareSemVer(hostVersion, latest);
isLatest = currentResult >= 0;
}
const msg = {
[HOST_VERSION]: {
isLatest,
latest,
result,
},
};
const func = writeStdout(msg);
return func;
};
const exportHostVersion = async minVer => {
if (!isString(minVer)) {
throw new TypeError(`Expected String but got ${getType(minVer)}.`);
}
if (!isValidSemVer(minVer)) {
throw new Error(`${minVer} is not valid SemVer.`);
}
const result = await compareSemVer(hostVersion, minVer);
const latest = await getLatestHostVersion();
let isLatest;
if (latest) {
const currentResult = await compareSemVer(hostVersion, latest);
isLatest = currentResult >= 0;
}
const msg = {
[HOST_VERSION]: {
isLatest,
latest,
result,
},
};