Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"marked": "^4.3.0",
"relative": "^3.0.2",
"semver": "^7.7.2",
"sync-request": "^6.1.0",
"xmlhttprequest": "^1.8.0"
},
"description": "A collection of command line tools for EOLANG: compiling, parsing, transpiling to other languages, optimizing, and analyzing",
Expand Down
87 changes: 46 additions & 41 deletions src/parser-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,54 @@
*/

const {XMLParser} = require('fast-xml-parser');
const request = require('sync-request'),
const {execSync} = require('child_process');

/**
* Load the latest version from GitHub releases.
const repo = 'org/eolang/eo-maven-plugin';
const base = 'https://repo.maven.apache.org/maven2';

/**
* Load the latest version from Maven Central.
* @return {String} Latest version, for example '0.23.1'
*/
version = module.exports = {
value: '',
get() {
if (version.value === '') {
const repo = 'org/eolang/eo-maven-plugin',
url = `https://repo.maven.apache.org/maven2/${repo}/maven-metadata.xml`,
res = request('GET', url, {timeout: 100000, socketTimeout: 100000});
if (res.statusCode !== 200) {
throw new Error(`Invalid response status #${res.statusCode} from ${url}: ${res.body}`);
}
const xml = new XMLParser().parse(res.body);
version.value = xml.metadata.versioning.release;
console.info('The latest version of %s at %s is %s', repo, url, version.value);
}
return version.value;
},
/**
* Check if a specific parser version exists in Maven Central.
* @param {String} ver - Version to check, for example '0.23.1'
* @return {Boolean} True if version exists, false otherwise
*/
exists(ver) {
let result;
if (ver && ver !== 'undefined') {
try {
const repo = 'org/eolang/eo-maven-plugin',
artifactId = 'eo-maven-plugin',
url = `https://repo.maven.apache.org/maven2/${repo}/${ver}/${artifactId}-${ver}.pom`,
res = request('GET', url, {timeout: 10000, socketTimeout: 10000});
result = res.statusCode === 200;
} catch (e) {
console.debug('Unable to validate parser version (network error): %s', e.message);
result = false;
}
} else {
result = false;
const version = module.exports = {
value: '',
get() {
if (version.value === '') {
const url = `${base}/${repo}/maven-metadata.xml`;
let body;
try {
body = execSync(
`curl -sL --fail --max-time 30 "${url}"`,
{encoding: 'utf8', timeout: 35000}
);
} catch (e) {
throw new Error(`Failed to fetch ${url}: ${e.message}`, {cause: e});
}
return result;
const xml = new XMLParser().parse(body);
version.value = xml.metadata.versioning.release;
console.info('The latest version of %s at %s is %s', repo, url, version.value);
}
return version.value;
},
/**
* Check if a specific parser version exists in Maven Central.
* @param {String} ver - Version to check, for example '0.23.1'
* @return {Boolean} True if version exists, false otherwise
*/
exists(ver) {
if (!ver || ver === 'undefined') {
return false;
}
const artifactId = 'eo-maven-plugin';
const url = `${base}/${repo}/${ver}/${artifactId}-${ver}.pom`;
try {
execSync(
`curl -sL -o /dev/null --fail --max-time 10 "${url}"`,
{timeout: 15000}
);
return true;
} catch {
return false;
}
};
}
};
Loading