Improve code quality

This commit is contained in:
Shivam Mathur 2020-03-14 07:53:43 +05:30
parent 6a4159ba98
commit fa8a671e6f
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
11 changed files with 44 additions and 54 deletions

View File

@ -17,7 +17,6 @@
"camelcase": "off",
"require-atomic-updates": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/no-unused-vars": "off"
"@typescript-eslint/camelcase": "off"
}
}

View File

@ -69,6 +69,8 @@ jest.mock('../src/install', () => ({
* @param extension_csv
* @param ini_values_csv
* @param coverage_driver
* @param tools
* @param pecl
*/
function setEnv(
version: string | number,

View File

@ -1,16 +1,6 @@
import * as io from '@actions/io';
import * as path from 'path';
import * as fs from 'fs';
import * as matchers from '../src/matchers';
async function cleanup(path: string): Promise<void> {
fs.unlink(path, error => {
if (error) {
console.log(error);
}
});
}
jest.mock('@actions/io');
describe('Matchers', () => {

View File

@ -55,12 +55,12 @@ describe('Utils tests', () => {
path.join(__dirname, '../src/scripts/win32.ps1'),
'utf8'
);
expect(await utils.readScript('darwin.sh', '7.4', 'darwin')).toBe(darwin);
expect(await utils.readScript('darwin.sh', '7.3', 'darwin')).toBe(darwin);
expect(await utils.readScript('linux.sh', '7.4', 'linux')).toBe(linux);
expect(await utils.readScript('linux.sh', '7.3', 'linux')).toBe(linux);
expect(await utils.readScript('win32.ps1', '7.4', 'win32')).toBe(win32);
expect(await utils.readScript('win32.ps1', '7.3', 'win32')).toBe(win32);
expect(await utils.readScript('darwin.sh')).toBe(darwin);
expect(await utils.readScript('darwin.sh')).toBe(darwin);
expect(await utils.readScript('linux.sh')).toBe(linux);
expect(await utils.readScript('linux.sh')).toBe(linux);
expect(await utils.readScript('win32.ps1')).toBe(win32);
expect(await utils.readScript('win32.ps1')).toBe(win32);
});
it('checking writeScripts', async () => {

32
dist/index.js vendored
View File

@ -1072,7 +1072,6 @@ exports.color = color;
* @param message
* @param os_version
* @param log_type
* @param prefix
*/
function log(message, os_version, log_type) {
return __awaiter(this, void 0, void 0, function* () {
@ -1116,6 +1115,7 @@ exports.stepLog = stepLog;
* @param mark
* @param subject
* @param message
* @param os_version
*/
function addLog(mark, subject, message, os_version) {
return __awaiter(this, void 0, void 0, function* () {
@ -1135,10 +1135,8 @@ exports.addLog = addLog;
* Read the scripts
*
* @param filename
* @param version
* @param os_version
*/
function readScript(filename, version, os_version) {
function readScript(filename) {
return __awaiter(this, void 0, void 0, function* () {
return fs.readFileSync(path.join(__dirname, '../src/scripts/' + filename), 'utf8');
});
@ -1148,7 +1146,6 @@ exports.readScript = readScript;
* Write final script which runs
*
* @param filename
* @param version
* @param script
*/
function writeScript(filename, script) {
@ -1586,6 +1583,7 @@ const utils = __importStar(__webpack_require__(163));
* Function to get command to setup tools
*
* @param os_version
* @param suffix
*/
function getCommand(os_version, suffix) {
return __awaiter(this, void 0, void 0, function* () {
@ -1648,6 +1646,8 @@ exports.parseTool = parseTool;
/**
* Function to get the url of tool with the given version
*
* @param tool
* @param extension
* @param version
* @param prefix
* @param version_prefix
@ -1738,7 +1738,7 @@ function getCodeceptionUri(version, php_version) {
case /(^2\.(1\.[0-5]|0\.\d+)|^1\.[6-8]\.\d+).*/.test(version):
return codecept;
default:
return yield codecept;
return codecept;
}
});
}
@ -1746,9 +1746,7 @@ exports.getCodeceptionUri = getCodeceptionUri;
/**
* Helper function to get script to setup phive
*
* @param tool
* @param version
* @param url
* @param os_version
*/
function addPhive(version, os_version) {
@ -1771,6 +1769,9 @@ exports.addPhive = addPhive;
/**
* Function to get the phar url in domain/tool-version.phar format
*
* @param domain
* @param tool
* @param prefix
* @param version
*/
function getPharUrl(domain, tool, prefix, version) {
@ -1833,7 +1834,7 @@ exports.getSymfonyUri = getSymfonyUri;
/**
* Function to add/move composer in the tools list
*
* @param tools
* @param tools_list
*/
function addComposer(tools_list) {
return __awaiter(this, void 0, void 0, function* () {
@ -1926,7 +1927,8 @@ exports.addPackage = addPackage;
/**
* Setup tools
*
* @param tool_csv
* @param tools_csv
* @param php_version
* @param os_version
*/
function addTools(tools_csv, php_version, os_version) {
@ -1975,7 +1977,7 @@ function addTools(tools_csv, php_version, os_version) {
break;
case 'composer':
// If RC is released as latest release, switch to getcomposer.
// Prefered source is GitHub as it is faster.
// Preferred source is GitHub as it is faster.
// url = github + 'composer/composer/releases/latest/download/composer.phar';
url = 'https://getcomposer.org/composer-stable.phar';
script += yield addArchive(tool, version, url, os_version);
@ -2258,6 +2260,7 @@ exports.addINIValuesWindows = addINIValuesWindows;
*
* @param ini_values_csv
* @param os_version
* @param no_step
*/
function addINIValues(ini_values_csv, os_version, no_step = false) {
return __awaiter(this, void 0, void 0, function* () {
@ -2342,7 +2345,7 @@ function build(filename, version, os_version) {
/.*-(beta|alpha|devel|snapshot).*/.test(extension_csv)) {
tools_csv = 'pecl, ' + tools_csv;
}
let script = yield utils.readScript(filename, version, os_version);
let script = yield utils.readScript(filename);
script += yield tools.addTools(tools_csv, version, os_version);
if (extension_csv) {
script += yield extensions.addExtension(extension_csv, version, os_version);
@ -2721,9 +2724,8 @@ exports.addExtensionDarwin = addExtensionDarwin;
*
* @param extension_csv
* @param version
* @param pipe
*/
function addExtensionWindows(extension_csv, version, pipe) {
function addExtensionWindows(extension_csv, version) {
return __awaiter(this, void 0, void 0, function* () {
const extensions = yield utils.extensionArray(extension_csv);
let script = '\n';
@ -2862,7 +2864,7 @@ function addExtension(extension_csv, version, os_version, no_step = false) {
}
switch (os_version) {
case 'win32':
return script + (yield addExtensionWindows(extension_csv, version, pipe));
return script + (yield addExtensionWindows(extension_csv, version));
case 'darwin':
return script + (yield addExtensionDarwin(extension_csv, version, pipe));
case 'linux':

View File

@ -9,4 +9,4 @@ module.exports = {
},
verbose: true,
collectCoverage: true
};
};

View File

@ -44,6 +44,7 @@ export async function addINIValuesWindows(
*
* @param ini_values_csv
* @param os_version
* @param no_step
*/
export async function addINIValues(
ini_values_csv: string,

View File

@ -89,12 +89,10 @@ export async function addExtensionDarwin(
*
* @param extension_csv
* @param version
* @param pipe
*/
export async function addExtensionWindows(
extension_csv: string,
version: string,
pipe: string
version: string
): Promise<string> {
const extensions: Array<string> = await utils.extensionArray(extension_csv);
let script = '\n';
@ -235,7 +233,7 @@ export async function addExtension(
switch (os_version) {
case 'win32':
return script + (await addExtensionWindows(extension_csv, version, pipe));
return script + (await addExtensionWindows(extension_csv, version));
case 'darwin':
return script + (await addExtensionDarwin(extension_csv, version, pipe));
case 'linux':

View File

@ -37,7 +37,7 @@ export async function build(
tools_csv = 'pecl, ' + tools_csv;
}
let script: string = await utils.readScript(filename, version, os_version);
let script: string = await utils.readScript(filename);
script += await tools.addTools(tools_csv, version, os_version);
if (extension_csv) {

View File

@ -4,6 +4,7 @@ import * as utils from './utils';
* Function to get command to setup tools
*
* @param os_version
* @param suffix
*/
export async function getCommand(
os_version: string,
@ -69,6 +70,8 @@ export async function parseTool(
/**
* Function to get the url of tool with the given version
*
* @param tool
* @param extension
* @param version
* @param prefix
* @param version_prefix
@ -167,16 +170,14 @@ export async function getCodeceptionUri(
case /(^2\.(1\.[0-5]|0\.\d+)|^1\.[6-8]\.\d+).*/.test(version):
return codecept;
default:
return await codecept;
return codecept;
}
}
/**
* Helper function to get script to setup phive
*
* @param tool
* @param version
* @param url
* @param os_version
*/
export async function addPhive(
@ -204,6 +205,9 @@ export async function addPhive(
/**
* Function to get the phar url in domain/tool-version.phar format
*
* @param domain
* @param tool
* @param prefix
* @param version
*/
export async function getPharUrl(
@ -272,7 +276,7 @@ export async function getSymfonyUri(
/**
* Function to add/move composer in the tools list
*
* @param tools
* @param tools_list
*/
export async function addComposer(tools_list: string[]): Promise<string[]> {
const regex = /^composer($|:.*)/;
@ -381,7 +385,8 @@ export async function addPackage(
/**
* Setup tools
*
* @param tool_csv
* @param tools_csv
* @param php_version
* @param os_version
*/
export async function addTools(
@ -439,7 +444,7 @@ export async function addTools(
break;
case 'composer':
// If RC is released as latest release, switch to getcomposer.
// Prefered source is GitHub as it is faster.
// Preferred source is GitHub as it is faster.
// url = github + 'composer/composer/releases/latest/download/composer.phar';
url = 'https://getcomposer.org/composer-stable.phar';
script += await addArchive(tool, version, url, os_version);

View File

@ -65,7 +65,6 @@ export async function color(type: string): Promise<string> {
* @param message
* @param os_version
* @param log_type
* @param prefix
*/
export async function log(
message: string,
@ -121,6 +120,7 @@ export async function stepLog(
* @param mark
* @param subject
* @param message
* @param os_version
*/
export async function addLog(
mark: string,
@ -147,14 +147,8 @@ export async function addLog(
* Read the scripts
*
* @param filename
* @param version
* @param os_version
*/
export async function readScript(
filename: string,
version: string,
os_version: string
): Promise<string> {
export async function readScript(filename: string): Promise<string> {
return fs.readFileSync(
path.join(__dirname, '../src/scripts/' + filename),
'utf8'
@ -165,7 +159,6 @@ export async function readScript(
* Write final script which runs
*
* @param filename
* @param version
* @param script
*/
export async function writeScript(