From ebba1db2c36c55943d258b601abf042bf3b7126b Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Fri, 2 Oct 2020 14:51:40 +0530 Subject: [PATCH] Add alias latest --- __tests__/utils.test.ts | 6 ++++++ dist/index.js | 24 +++++++++++++++++++++--- src/install.ts | 5 +++-- src/utils.ts | 19 +++++++++++++++++++ 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/__tests__/utils.test.ts b/__tests__/utils.test.ts index d8bd303e..e0f796e3 100644 --- a/__tests__/utils.test.ts +++ b/__tests__/utils.test.ts @@ -26,6 +26,12 @@ describe('Utils tests', () => { expect(await utils.getInput('DoesNotExist', false)).toBe(''); }); + it('checking parseVersion', async () => { + expect(await utils.parseVersion('7')).toBe('7.0'); + expect(await utils.parseVersion('7.4')).toBe('7.4'); + expect(await utils.parseVersion('latest')).toBe('7.4'); + }); + it('checking asyncForEach', async () => { const array: Array = ['a', 'b', 'c']; let concat = ''; diff --git a/dist/index.js b/dist/index.js index 46eb3be3..0a720549 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1097,7 +1097,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.customPackage = exports.scriptExtension = exports.joins = exports.getCommand = exports.getUnsupportedLog = exports.suppressOutput = exports.getExtensionPrefix = exports.CSVArray = exports.extensionArray = exports.writeScript = exports.readScript = exports.addLog = exports.stepLog = exports.log = exports.color = exports.asyncForEach = exports.getInput = void 0; +exports.customPackage = exports.scriptExtension = exports.joins = exports.getCommand = exports.getUnsupportedLog = exports.suppressOutput = exports.getExtensionPrefix = exports.CSVArray = exports.extensionArray = exports.writeScript = exports.readScript = exports.addLog = exports.stepLog = exports.log = exports.color = exports.asyncForEach = exports.parseVersion = exports.getInput = void 0; const fs = __importStar(__webpack_require__(747)); const path = __importStar(__webpack_require__(622)); const core = __importStar(__webpack_require__(470)); @@ -1118,6 +1118,25 @@ async function getInput(name, mandatory) { } } exports.getInput = getInput; +/** + * Function to parse PHP version. + * + * @param version + */ +async function parseVersion(version) { + switch (version) { + case 'latest': + return '7.4'; + default: + switch (true) { + case version.length > 1: + return version.slice(0, 3); + default: + return version + '.0'; + } + } +} +exports.parseVersion = parseVersion; /** * Async foreach loop * @@ -2567,8 +2586,7 @@ exports.build = build; */ async function run() { try { - let version = await utils.getInput('php-version', true); - version = version.length > 1 ? version.slice(0, 3) : version + '.0'; + const version = await utils.parseVersion(await utils.getInput('php-version', true)); const os_version = process.platform; // check the os version and run the respective script let script_path = ''; diff --git a/src/install.ts b/src/install.ts index 046204e3..5dea6708 100644 --- a/src/install.ts +++ b/src/install.ts @@ -61,8 +61,9 @@ export async function build( */ export async function run(): Promise { try { - let version: string = await utils.getInput('php-version', true); - version = version.length > 1 ? version.slice(0, 3) : version + '.0'; + const version: string = await utils.parseVersion( + await utils.getInput('php-version', true) + ); const os_version: string = process.platform; // check the os version and run the respective script diff --git a/src/utils.ts b/src/utils.ts index 109e9217..c54e8e58 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -22,6 +22,25 @@ export async function getInput( } } +/** + * Function to parse PHP version. + * + * @param version + */ +export async function parseVersion(version: string): Promise { + switch (version) { + case 'latest': + return '7.4'; + default: + switch (true) { + case version.length > 1: + return version.slice(0, 3); + default: + return version + '.0'; + } + } +} + /** * Async foreach loop *