optimize code

This commit is contained in:
Dmitry Shibanov 2022-12-14 19:08:19 +01:00
parent 15798eaae7
commit 785620d55b
6 changed files with 16 additions and 92 deletions

View file

@ -24,7 +24,6 @@ export default abstract class BaseDistribution {
}
protected abstract getDistributionUrl(): string;
protected abstract getNodejsVersions(): Promise<INodeVersion[]>;
protected abstract evaluateVersions(nodeVersions: string[]): string;
public async getNodeJsInfo() {
@ -48,6 +47,14 @@ export default abstract class BaseDistribution {
return tc.find('node', this.nodeInfo.versionSpec, this.nodeInfo.arch);
}
protected async getNodejsVersions(): Promise<INodeVersion[]> {
const initialUrl = this.getDistributionUrl();
const dataUrl = `${initialUrl}/index.json`;
let response = await this.httpClient.getJson<INodeVersion[]>(dataUrl);
return response.result || [];
}
protected getNodejsDistInfo(version: string, osPlat: string) {
let osArch: string = this.translateArchToDistUrl(this.nodeInfo.arch);
version = semver.clean(version) || '';

View file

@ -69,14 +69,6 @@ export default class NightlyNodejs extends BaseDistribution {
return 'https://nodejs.org/download/nightly';
}
async getNodejsVersions(): Promise<INodeVersion[]> {
const initialUrl = this.getDistributionUrl();
const dataUrl = `${initialUrl}/index.json`;
let response = await this.httpClient.getJson<INodeVersion[]>(dataUrl);
return response.result || [];
}
protected createRangePreRelease(
versionSpec: string,
distribution: string = ''

View file

@ -131,14 +131,6 @@ export default class OfficialBuilds extends BaseDistribution {
return `https://nodejs.org/dist`;
}
protected async getNodejsVersions(): Promise<INodeVersion[]> {
const initialUrl = this.getDistributionUrl();
const dataUrl = `${initialUrl}/index.json`;
let response = await this.httpClient.getJson<INodeVersion[]>(dataUrl);
return response.result || [];
}
private getManifest(): Promise<tc.IToolRelease[]> {
core.debug('Getting manifest from actions/node-versions@main');
return tc.getManifestFromRepo(

View file

@ -10,14 +10,6 @@ export default class RcBuild extends BaseDistribution {
super(nodeInfo);
}
protected async getNodejsVersions(): Promise<INodeVersion[]> {
const initialUrl = this.getDistributionUrl();
const dataUrl = `${initialUrl}/index.json`;
let response = await this.httpClient.getJson<INodeVersion[]>(dataUrl);
return response.result || [];
}
protected evaluateVersions(versions: string[]): string {
let version = '';

View file

@ -70,14 +70,6 @@ export default class CanaryBuild extends BaseDistribution {
return version;
}
async getNodejsVersions(): Promise<INodeVersion[]> {
const initialUrl = this.getDistributionUrl();
const dataUrl = `${initialUrl}/index.json`;
let response = await this.httpClient.getJson<INodeVersion[]>(dataUrl);
return response.result || [];
}
protected createRangePreRelease(
versionSpec: string,
distribution: string = ''