Skip to content

Commit 419dce7

Browse files
author
Danny McCormick
authored
Add lts version (#17)
1 parent cf52edc commit 419dce7

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/installer.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ if (!tempDirectory) {
4444
}
4545
function getNode(versionSpec) {
4646
return __awaiter(this, void 0, void 0, function* () {
47+
if (versionSpec.toLowerCase() === 'lts') {
48+
versionSpec = getLtsVersion();
49+
}
4750
// check cache
4851
let toolPath;
4952
toolPath = tc.find('node', versionSpec);
@@ -84,6 +87,19 @@ function getNode(versionSpec) {
8487
});
8588
}
8689
exports.getNode = getNode;
90+
// Schedule based off https://nodejs.org/en/about/releases/. TODO: would be nice to automate this so we don't drift
91+
function getLtsVersion() {
92+
const today = new Date();
93+
if (today < new Date(2019, 9, 22)) {
94+
return '10.x';
95+
}
96+
else if (today < new Date(2020, 9, 20)) {
97+
return '12.x';
98+
}
99+
else {
100+
return '14.x';
101+
}
102+
}
87103
function queryLatestMatch(versionSpec) {
88104
return __awaiter(this, void 0, void 0, function* () {
89105
// node offers a json list of versions

src/installer.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ interface INodeVersion {
3636
}
3737

3838
export async function getNode(versionSpec: string) {
39+
if (versionSpec.toLowerCase() === 'lts') {
40+
versionSpec = getLtsVersion();
41+
}
42+
3943
// check cache
4044
let toolPath: string;
4145
toolPath = tc.find('node', versionSpec);
@@ -81,6 +85,18 @@ export async function getNode(versionSpec: string) {
8185
core.addPath(toolPath);
8286
}
8387

88+
// Schedule based off https://nodejs.org/en/about/releases/. TODO: would be nice to automate this so we don't drift
89+
function getLtsVersion(): string {
90+
const today = new Date();
91+
if (today < new Date(2019, 9, 22)) {
92+
return '10.x';
93+
} else if (today < new Date(2020, 9, 20)) {
94+
return '12.x';
95+
} else {
96+
return '14.x';
97+
}
98+
}
99+
84100
async function queryLatestMatch(versionSpec: string): Promise<string> {
85101
// node offers a json list of versions
86102
let dataFileName: string;

0 commit comments

Comments
 (0)