From 7e764bb37e1e4f9ad2e815a5221c385627b7b298 Mon Sep 17 00:00:00 2001
From: Danny McCormick <damccorm@microsoft.com>
Date: Tue, 23 Jul 2019 11:50:47 -0400
Subject: [PATCH] Add lts version

---
 lib/installer.js | 16 ++++++++++++++++
 src/installer.ts | 16 ++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/lib/installer.js b/lib/installer.js
index 7e6a7dec..9b38f6a7 100644
--- a/lib/installer.js
+++ b/lib/installer.js
@@ -44,6 +44,9 @@ if (!tempDirectory) {
 }
 function getNode(versionSpec) {
     return __awaiter(this, void 0, void 0, function* () {
+        if (versionSpec.toLowerCase() === 'lts') {
+            versionSpec = getLtsVersion();
+        }
         // check cache
         let toolPath;
         toolPath = tc.find('node', versionSpec);
@@ -84,6 +87,19 @@ function getNode(versionSpec) {
     });
 }
 exports.getNode = getNode;
+// Schedule based off https://nodejs.org/en/about/releases/. TODO: would be nice to automate this so we don't drift
+function getLtsVersion() {
+    const today = new Date();
+    if (today < new Date(2019, 9, 22)) {
+        return '10.x';
+    }
+    else if (today < new Date(2020, 9, 20)) {
+        return '12.x';
+    }
+    else {
+        return '14.x';
+    }
+}
 function queryLatestMatch(versionSpec) {
     return __awaiter(this, void 0, void 0, function* () {
         // node offers a json list of versions
diff --git a/src/installer.ts b/src/installer.ts
index 1697cd4c..c307d529 100644
--- a/src/installer.ts
+++ b/src/installer.ts
@@ -36,6 +36,10 @@ interface INodeVersion {
 }
 
 export async function getNode(versionSpec: string) {
+  if (versionSpec.toLowerCase() === 'lts') {
+    versionSpec = getLtsVersion();
+  }
+
   // check cache
   let toolPath: string;
   toolPath = tc.find('node', versionSpec);
@@ -81,6 +85,18 @@ export async function getNode(versionSpec: string) {
   core.addPath(toolPath);
 }
 
+// Schedule based off https://nodejs.org/en/about/releases/. TODO: would be nice to automate this so we don't drift
+function getLtsVersion(): string {
+  const today = new Date();
+  if (today < new Date(2019, 9, 22)) {
+    return '10.x';
+  } else if (today < new Date(2020, 9, 20)) {
+    return '12.x';
+  } else {
+    return '14.x';
+  }
+}
+
 async function queryLatestMatch(versionSpec: string): Promise<string> {
   // node offers a json list of versions
   let dataFileName: string;