2019-12-27 08:26:49 +07:00
|
|
|
import * as utils from './utils';
|
2019-12-31 05:56:18 +07:00
|
|
|
|
2020-01-07 09:36:14 +07:00
|
|
|
/**
|
|
|
|
* Function to get tool version
|
|
|
|
*
|
2021-07-05 17:33:10 +07:00
|
|
|
* @param tool
|
2020-01-07 09:36:14 +07:00
|
|
|
* @param version
|
|
|
|
*/
|
2021-07-05 17:33:10 +07:00
|
|
|
export async function getToolVersion(
|
|
|
|
tool: string,
|
|
|
|
version: string
|
|
|
|
): Promise<string> {
|
2020-01-07 09:36:14 +07:00
|
|
|
// semver_regex - https://semver.org/
|
2021-05-31 06:51:18 +07:00
|
|
|
const semver_regex =
|
|
|
|
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
2020-06-03 16:21:22 +07:00
|
|
|
const composer_regex = /^stable$|^preview$|^snapshot$|^v?[1|2]$/;
|
2021-06-19 01:01:47 +07:00
|
|
|
version = version.replace(/[><=^]*/, '').replace(/^v(\d)/, '$1');
|
2020-01-07 09:36:14 +07:00
|
|
|
switch (true) {
|
2020-06-03 16:21:22 +07:00
|
|
|
case composer_regex.test(version):
|
2020-01-07 09:36:14 +07:00
|
|
|
case semver_regex.test(version):
|
|
|
|
return version;
|
|
|
|
default:
|
|
|
|
return 'latest';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-07-05 17:33:10 +07:00
|
|
|
* Function to parse the release tool:version
|
2020-01-07 09:36:14 +07:00
|
|
|
*
|
|
|
|
* @param release
|
2021-07-05 17:33:10 +07:00
|
|
|
* @param data
|
2020-01-07 09:36:14 +07:00
|
|
|
*/
|
2021-07-05 17:33:10 +07:00
|
|
|
export async function parseRelease(
|
|
|
|
release: string,
|
|
|
|
data: Record<string, string>
|
|
|
|
): Promise<{version: string; release: string}> {
|
2020-01-07 09:36:14 +07:00
|
|
|
const parts: string[] = release.split(':');
|
|
|
|
const tool: string = parts[0];
|
|
|
|
const version: string | undefined = parts[1];
|
2021-07-05 17:33:10 +07:00
|
|
|
release = release.includes('/')
|
|
|
|
? release.split('/')[1].replace(/\s+/, '')
|
|
|
|
: release;
|
|
|
|
release = release.includes(':')
|
|
|
|
? [data['tool'], release.split(':')[1]].join(':')
|
|
|
|
: data['tool'];
|
2021-04-17 04:26:47 +07:00
|
|
|
switch (true) {
|
|
|
|
case version === undefined:
|
2020-01-07 09:36:14 +07:00
|
|
|
return {
|
2021-07-05 17:33:10 +07:00
|
|
|
release: release,
|
2020-01-07 09:36:14 +07:00
|
|
|
version: 'latest'
|
|
|
|
};
|
2021-04-17 04:26:47 +07:00
|
|
|
case /^[\w.-]+\/[\w.-]+$/.test(tool):
|
|
|
|
return {
|
2021-07-05 17:33:10 +07:00
|
|
|
release: release,
|
2021-04-17 04:26:47 +07:00
|
|
|
version: version
|
|
|
|
};
|
2020-01-07 09:36:14 +07:00
|
|
|
default:
|
|
|
|
return {
|
2021-07-05 17:33:10 +07:00
|
|
|
release: release,
|
|
|
|
version: await getToolVersion(parts[0], parts[1])
|
2020-01-07 09:36:14 +07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-07-05 17:33:10 +07:00
|
|
|
* Function to add/move composer in the tools list
|
2020-01-07 09:36:14 +07:00
|
|
|
*
|
2021-07-05 17:33:10 +07:00
|
|
|
* @param tools_list
|
2020-01-07 09:36:14 +07:00
|
|
|
*/
|
2021-07-05 17:33:10 +07:00
|
|
|
export async function filterList(tools_list: string[]): Promise<string[]> {
|
|
|
|
const regex_any = /^composer($|:.*)/;
|
|
|
|
const regex_valid =
|
|
|
|
/^composer:?($|preview$|snapshot$|v?[1-2]$|v?\d+\.\d+\.\d+[\w-]*$)/;
|
|
|
|
const matches: string[] = tools_list.filter(tool => regex_valid.test(tool));
|
|
|
|
let composer = 'composer';
|
|
|
|
tools_list = tools_list.filter(tool => !regex_any.test(tool));
|
|
|
|
switch (true) {
|
|
|
|
case matches[0] == undefined:
|
|
|
|
break;
|
2020-01-07 09:36:14 +07:00
|
|
|
default:
|
2021-07-05 17:33:10 +07:00
|
|
|
composer = matches[matches.length - 1].replace(/v(\d\S*)/, '$1');
|
|
|
|
break;
|
2020-01-07 09:36:14 +07:00
|
|
|
}
|
2021-07-05 17:33:10 +07:00
|
|
|
tools_list.unshift(composer);
|
|
|
|
return tools_list;
|
2020-01-07 09:36:14 +07:00
|
|
|
}
|
|
|
|
|
2020-01-21 03:10:24 +07:00
|
|
|
/**
|
2021-07-05 17:33:10 +07:00
|
|
|
* Function to get the url of tool with the given version
|
2020-01-21 03:10:24 +07:00
|
|
|
*
|
2021-07-05 17:33:10 +07:00
|
|
|
* @param data
|
2020-01-21 03:10:24 +07:00
|
|
|
*/
|
2021-07-05 17:33:10 +07:00
|
|
|
export async function getUrl(data: Record<string, string>): Promise<string> {
|
|
|
|
if (data['version'] === 'latest') {
|
|
|
|
return [
|
|
|
|
data['domain'],
|
|
|
|
data['repository'],
|
|
|
|
data['prefix'],
|
|
|
|
data['version'],
|
|
|
|
data['verb'],
|
|
|
|
data['tool'] + data['extension']
|
|
|
|
]
|
|
|
|
.filter(Boolean)
|
|
|
|
.join('/');
|
|
|
|
} else {
|
|
|
|
return [
|
|
|
|
data['domain'],
|
|
|
|
data['repository'],
|
|
|
|
data['prefix'],
|
|
|
|
data['verb'],
|
|
|
|
data['version_prefix'] + data['version'],
|
|
|
|
data['tool'] + data['extension']
|
|
|
|
]
|
|
|
|
.filter(Boolean)
|
|
|
|
.join('/');
|
2020-01-21 03:10:24 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-07 09:36:14 +07:00
|
|
|
/**
|
2020-02-28 14:49:12 +07:00
|
|
|
* Function to get the phar url in domain/tool-version.phar format
|
2020-01-07 09:36:14 +07:00
|
|
|
*
|
2021-07-05 17:33:10 +07:00
|
|
|
* @param data
|
2020-01-07 09:36:14 +07:00
|
|
|
*/
|
2020-02-28 14:49:12 +07:00
|
|
|
export async function getPharUrl(
|
2021-07-05 17:33:10 +07:00
|
|
|
data: Record<string, string>
|
2020-01-07 09:36:14 +07:00
|
|
|
): Promise<string> {
|
2021-07-05 17:33:10 +07:00
|
|
|
if (data['version'] === 'latest') {
|
|
|
|
return data['domain'] + '/' + data['tool'] + '.phar';
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
data['domain'] +
|
|
|
|
'/' +
|
|
|
|
data['tool'] +
|
|
|
|
'-' +
|
|
|
|
data['version_prefix'] +
|
|
|
|
data['version'] +
|
|
|
|
'.phar'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to get script to setup a tool using a phar url
|
|
|
|
*
|
|
|
|
* @param data
|
|
|
|
*/
|
|
|
|
export async function addArchive(
|
|
|
|
data: Record<string, string>
|
|
|
|
): Promise<string> {
|
|
|
|
return (
|
|
|
|
(await utils.getCommand(data['os_version'], 'tool')) +
|
|
|
|
(await utils.joins(data['url'], data['tool'], data['version_parameter']))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to get script to setup a tool using composer
|
|
|
|
*
|
|
|
|
* @param data
|
|
|
|
*/
|
|
|
|
export async function addPackage(
|
|
|
|
data: Record<string, string>
|
|
|
|
): Promise<string> {
|
|
|
|
const command = await utils.getCommand(data['os_version'], 'composertool');
|
|
|
|
const parts: string[] = data['repository'].split('/');
|
|
|
|
return command + parts[1] + ' ' + data['release'] + ' ' + parts[0] + '/';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to add blackfire-player
|
|
|
|
*
|
|
|
|
* @param data
|
|
|
|
*/
|
|
|
|
export async function addBlackfirePlayer(
|
|
|
|
data: Record<string, string>
|
|
|
|
): Promise<string> {
|
|
|
|
if (
|
|
|
|
/5\.[5-6]|7\.0/.test(data['php_version']) &&
|
|
|
|
data['version'] == 'latest'
|
|
|
|
) {
|
|
|
|
data['version'] = '1.9.3';
|
2020-01-07 09:36:14 +07:00
|
|
|
}
|
2021-07-05 17:33:10 +07:00
|
|
|
data['url'] = await getPharUrl(data);
|
|
|
|
return addArchive(data);
|
2020-01-07 09:36:14 +07:00
|
|
|
}
|
|
|
|
|
2020-10-30 12:05:13 +07:00
|
|
|
/**
|
2021-07-05 17:33:10 +07:00
|
|
|
* Function to add composer
|
2020-10-30 12:05:13 +07:00
|
|
|
*
|
2021-07-05 17:33:10 +07:00
|
|
|
* @param data
|
2020-10-30 12:05:13 +07:00
|
|
|
*/
|
2021-07-05 17:33:10 +07:00
|
|
|
export async function addComposer(
|
|
|
|
data: Record<string, string>
|
2020-10-30 12:05:13 +07:00
|
|
|
): Promise<string> {
|
2021-07-05 17:33:10 +07:00
|
|
|
const github = data['github'];
|
|
|
|
const getcomposer = data['domain'];
|
|
|
|
let cache_url = `${github}/shivammathur/composer-cache/releases/latest/download/composer-${data[
|
|
|
|
'version'
|
|
|
|
].replace('latest', 'stable')}.phar`;
|
|
|
|
let source_url = `${getcomposer}/composer.phar`;
|
2020-10-30 12:05:13 +07:00
|
|
|
switch (true) {
|
2021-07-05 17:33:10 +07:00
|
|
|
case /^snapshot$/.test(data['version']):
|
2020-10-30 12:05:13 +07:00
|
|
|
break;
|
2021-07-05 17:33:10 +07:00
|
|
|
case /^preview$|^[1-2]$/.test(data['version']):
|
|
|
|
source_url = `${getcomposer}/composer-${data['version']}.phar`;
|
|
|
|
break;
|
|
|
|
case /^\d+\.\d+\.\d+[\w-]*$/.test(data['version']):
|
|
|
|
cache_url = `${github}/${data['repository']}/releases/download/${data['version']}/composer.phar`;
|
|
|
|
source_url = `${getcomposer}/composer-${data['version']}.phar`;
|
2020-10-30 12:05:13 +07:00
|
|
|
break;
|
2021-07-05 17:33:10 +07:00
|
|
|
default:
|
|
|
|
source_url = `${getcomposer}/composer-stable.phar`;
|
2020-10-30 12:05:13 +07:00
|
|
|
}
|
2021-07-05 17:33:10 +07:00
|
|
|
data['url'] = `${cache_url},${source_url}`;
|
|
|
|
data['version_parameter'] = data['version'];
|
|
|
|
return await addArchive(data);
|
2020-10-30 12:05:13 +07:00
|
|
|
}
|
|
|
|
|
2020-01-07 09:36:14 +07:00
|
|
|
/**
|
2021-07-05 17:33:10 +07:00
|
|
|
* Function to add Deployer
|
2020-01-07 09:36:14 +07:00
|
|
|
*
|
2021-07-05 17:33:10 +07:00
|
|
|
* @param data
|
2020-01-07 09:36:14 +07:00
|
|
|
*/
|
2021-07-05 17:33:10 +07:00
|
|
|
export async function addDeployer(
|
|
|
|
data: Record<string, string>
|
|
|
|
): Promise<string> {
|
|
|
|
if (data['version'] === 'latest') {
|
|
|
|
data['url'] = data['domain'] + '/deployer.phar';
|
|
|
|
} else {
|
|
|
|
data['url'] =
|
|
|
|
data['domain'] + '/releases/v' + data['version'] + '/deployer.phar';
|
2020-01-07 09:36:14 +07:00
|
|
|
}
|
2021-07-05 17:33:10 +07:00
|
|
|
return await addArchive(data);
|
2020-01-07 09:36:14 +07:00
|
|
|
}
|
|
|
|
|
2020-01-26 12:41:36 +07:00
|
|
|
/**
|
2021-07-05 17:33:10 +07:00
|
|
|
* Function to add php-config and phpize
|
2020-01-26 12:41:36 +07:00
|
|
|
*
|
2021-07-05 17:33:10 +07:00
|
|
|
* @param data
|
2020-01-26 12:41:36 +07:00
|
|
|
*/
|
2021-07-05 17:33:10 +07:00
|
|
|
export async function addDevTools(
|
|
|
|
data: Record<string, string>
|
2020-01-26 12:41:36 +07:00
|
|
|
): Promise<string> {
|
2021-07-05 17:33:10 +07:00
|
|
|
switch (data['os_version']) {
|
2020-01-26 12:41:36 +07:00
|
|
|
case 'linux':
|
|
|
|
case 'darwin':
|
2021-07-05 17:33:10 +07:00
|
|
|
return 'add_devtools ' + data['tool'];
|
2020-01-26 12:41:36 +07:00
|
|
|
case 'win32':
|
2021-07-05 17:33:10 +07:00
|
|
|
return await utils.addLog(
|
|
|
|
'$tick',
|
|
|
|
data['tool'],
|
|
|
|
data['tool'] + ' is not a windows tool',
|
|
|
|
'win32'
|
|
|
|
);
|
2020-01-26 12:41:36 +07:00
|
|
|
default:
|
|
|
|
return await utils.log(
|
2021-07-05 17:33:10 +07:00
|
|
|
'Platform ' + data['os_version'] + ' is not supported',
|
|
|
|
data['os_version'],
|
2020-01-26 12:41:36 +07:00
|
|
|
'error'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-22 11:36:14 +07:00
|
|
|
/**
|
2021-07-05 17:33:10 +07:00
|
|
|
* Function to add PECL
|
2020-02-22 11:36:14 +07:00
|
|
|
*
|
2021-07-05 17:33:10 +07:00
|
|
|
* @param data
|
2020-02-22 11:36:14 +07:00
|
|
|
*/
|
2021-07-05 17:33:10 +07:00
|
|
|
export async function addPECL(data: Record<string, string>): Promise<string> {
|
|
|
|
return await utils.getCommand(data['os_version'], 'pecl');
|
2020-02-22 11:36:14 +07:00
|
|
|
}
|
|
|
|
|
2020-01-07 09:36:14 +07:00
|
|
|
/**
|
2021-07-05 17:33:10 +07:00
|
|
|
* Function to add Phing
|
2020-01-07 09:36:14 +07:00
|
|
|
*
|
2021-07-05 17:33:10 +07:00
|
|
|
* @param data
|
2020-01-07 09:36:14 +07:00
|
|
|
*/
|
2021-07-05 17:33:10 +07:00
|
|
|
export async function addPhing(data: Record<string, string>): Promise<string> {
|
|
|
|
data['url'] =
|
|
|
|
data['domain'] + '/get/phing-' + data['version'] + data['extension'];
|
|
|
|
return await addArchive(data);
|
2020-01-07 09:36:14 +07:00
|
|
|
}
|
|
|
|
|
2020-06-03 16:21:22 +07:00
|
|
|
/**
|
2021-07-05 17:33:10 +07:00
|
|
|
* Helper function to add Phive
|
2020-06-03 16:21:22 +07:00
|
|
|
*
|
2021-07-05 17:33:10 +07:00
|
|
|
* @param data
|
2020-06-03 16:21:22 +07:00
|
|
|
*/
|
2021-07-05 17:33:10 +07:00
|
|
|
export async function addPhive(data: Record<string, string>): Promise<string> {
|
2020-10-30 19:59:39 +07:00
|
|
|
switch (true) {
|
2021-07-05 17:33:10 +07:00
|
|
|
case /5\.[3-5]/.test(data['php_version']):
|
|
|
|
return await utils.addLog(
|
|
|
|
'$cross',
|
|
|
|
'phive',
|
|
|
|
'Phive is not supported on PHP ' + data['php_version'],
|
|
|
|
data['os_version']
|
|
|
|
);
|
|
|
|
case /5\.6|7\.0/.test(data['php_version']):
|
|
|
|
data['version'] = data['version'].replace('latest', '0.12.1');
|
|
|
|
break;
|
|
|
|
case /7\.1/.test(data['php_version']):
|
|
|
|
data['version'] = data['version'].replace('latest', '0.13.5');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (data['version'] === 'latest') {
|
|
|
|
data['domain'] = data['domain'] + '/releases';
|
|
|
|
} else {
|
|
|
|
data['domain'] = [
|
|
|
|
data['github'],
|
|
|
|
data['repository'],
|
|
|
|
'releases/download',
|
|
|
|
data['version']
|
|
|
|
].join('/');
|
2020-06-03 16:21:22 +07:00
|
|
|
}
|
2021-07-05 17:33:10 +07:00
|
|
|
data['url'] = await getPharUrl(data);
|
|
|
|
return await addArchive(data);
|
2020-06-03 16:21:22 +07:00
|
|
|
}
|
|
|
|
|
2020-01-07 09:36:14 +07:00
|
|
|
/**
|
2021-07-05 17:33:10 +07:00
|
|
|
* Function to add PHPUnit and related tools
|
2020-01-07 09:36:14 +07:00
|
|
|
*
|
2021-07-05 17:33:10 +07:00
|
|
|
* @param data
|
2020-01-07 09:36:14 +07:00
|
|
|
*/
|
2021-07-05 17:33:10 +07:00
|
|
|
export async function addPHPUnitTools(
|
|
|
|
data: Record<string, string>
|
2020-01-07 09:36:14 +07:00
|
|
|
): Promise<string> {
|
2021-07-05 17:33:10 +07:00
|
|
|
data['url'] = await getPharUrl(data);
|
|
|
|
return await addArchive(data);
|
2020-01-07 09:36:14 +07:00
|
|
|
}
|
|
|
|
|
2020-01-17 14:28:28 +07:00
|
|
|
/**
|
2021-07-05 17:33:10 +07:00
|
|
|
* Function to add Symfony
|
2020-01-17 14:28:28 +07:00
|
|
|
*
|
2021-07-05 17:33:10 +07:00
|
|
|
* @param data
|
2020-01-17 14:28:28 +07:00
|
|
|
*/
|
2021-07-05 17:33:10 +07:00
|
|
|
export async function addSymfony(
|
|
|
|
data: Record<string, string>
|
2020-01-17 14:28:28 +07:00
|
|
|
): Promise<string> {
|
2021-07-05 17:33:10 +07:00
|
|
|
let filename: string;
|
|
|
|
switch (data['os_version']) {
|
2020-01-17 14:28:28 +07:00
|
|
|
case 'linux':
|
|
|
|
case 'darwin':
|
2021-07-05 17:33:10 +07:00
|
|
|
filename = 'symfony_' + data['os_version'] + '_amd64';
|
|
|
|
break;
|
2020-01-17 14:28:28 +07:00
|
|
|
case 'win32':
|
2021-07-05 17:33:10 +07:00
|
|
|
filename = 'symfony_windows_amd64.exe';
|
|
|
|
break;
|
2020-01-17 14:28:28 +07:00
|
|
|
default:
|
|
|
|
return await utils.log(
|
2021-07-05 17:33:10 +07:00
|
|
|
'Platform ' + data['os_version'] + ' is not supported',
|
|
|
|
data['os_version'],
|
2020-01-17 14:28:28 +07:00
|
|
|
'error'
|
|
|
|
);
|
|
|
|
}
|
2021-07-05 17:33:10 +07:00
|
|
|
if (data['version'] === 'latest') {
|
|
|
|
data['uri'] = ['releases/latest/download', filename].join('/');
|
|
|
|
} else {
|
|
|
|
data['uri'] = ['releases/download', 'v' + data['version'], filename].join(
|
|
|
|
'/'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
data['url'] = [data['domain'], data['repository'], data['uri']].join('/');
|
|
|
|
return await addArchive(data);
|
2020-01-17 14:28:28 +07:00
|
|
|
}
|
|
|
|
|
2020-01-07 09:36:14 +07:00
|
|
|
/**
|
2021-07-05 17:33:10 +07:00
|
|
|
* Function to add WP-CLI
|
2020-01-07 09:36:14 +07:00
|
|
|
*
|
2021-07-05 17:33:10 +07:00
|
|
|
* @param data
|
|
|
|
*/
|
|
|
|
export async function addWPCLI(data: Record<string, string>): Promise<string> {
|
|
|
|
if (data['version'] === 'latest') {
|
|
|
|
data['uri'] = 'wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true';
|
|
|
|
data['url'] = [data['domain'], data['uri']].join('/');
|
|
|
|
} else {
|
|
|
|
data['extension'] = '-' + data['version'] + data['extension'];
|
|
|
|
data['url'] = await getUrl(data);
|
|
|
|
}
|
|
|
|
return await addArchive(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
export const functionRecord: Record<
|
|
|
|
string,
|
|
|
|
(data: Record<string, string>) => Promise<string>
|
|
|
|
> = {
|
|
|
|
composer: addComposer,
|
|
|
|
deployer: addDeployer,
|
|
|
|
dev_tools: addDevTools,
|
|
|
|
phive: addPhive,
|
|
|
|
blackfire_player: addBlackfirePlayer,
|
|
|
|
pecl: addPECL,
|
|
|
|
phing: addPhing,
|
|
|
|
phpunit: addPHPUnitTools,
|
|
|
|
phpcpd: addPHPUnitTools,
|
|
|
|
symfony: addSymfony,
|
|
|
|
wp_cli: addWPCLI
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to initialize common data for the tool
|
|
|
|
*
|
|
|
|
* @param data
|
2020-01-07 09:36:14 +07:00
|
|
|
* @param release
|
2021-07-05 17:33:10 +07:00
|
|
|
* @param php_version
|
2020-01-07 09:36:14 +07:00
|
|
|
* @param os_version
|
|
|
|
*/
|
2021-07-05 17:33:10 +07:00
|
|
|
export async function initToolData(
|
|
|
|
data: Record<string, string>,
|
2020-01-07 09:36:14 +07:00
|
|
|
release: string,
|
2021-07-05 17:33:10 +07:00
|
|
|
php_version: string,
|
2020-01-07 09:36:14 +07:00
|
|
|
os_version: string
|
2021-07-05 17:33:10 +07:00
|
|
|
): Promise<Record<string, string>> {
|
|
|
|
const release_data: {release: string; version: string} = await parseRelease(
|
|
|
|
release,
|
|
|
|
data
|
|
|
|
);
|
|
|
|
data['version'] = release_data.version;
|
|
|
|
data['release'] = release_data.release;
|
|
|
|
data['version_parameter'] = JSON.stringify(data['version_parameter']);
|
|
|
|
data['os_version'] = os_version;
|
|
|
|
data['php_version'] = php_version;
|
|
|
|
data['github'] = 'https://github.com';
|
|
|
|
if (data['github'] === data['domain']) {
|
|
|
|
data['prefix'] = 'releases';
|
|
|
|
data['verb'] = 'download';
|
|
|
|
}
|
|
|
|
return data;
|
2020-01-07 09:36:14 +07:00
|
|
|
}
|
|
|
|
|
2019-12-27 08:26:49 +07:00
|
|
|
/**
|
|
|
|
* Setup tools
|
|
|
|
*
|
2020-03-12 09:27:40 +07:00
|
|
|
* @param tools_csv
|
|
|
|
* @param php_version
|
2019-12-27 08:26:49 +07:00
|
|
|
* @param os_version
|
|
|
|
*/
|
|
|
|
export async function addTools(
|
|
|
|
tools_csv: string,
|
2020-01-07 09:36:14 +07:00
|
|
|
php_version: string,
|
2019-12-27 08:26:49 +07:00
|
|
|
os_version: string
|
|
|
|
): Promise<string> {
|
2021-04-21 18:41:24 +07:00
|
|
|
let script = '\n';
|
|
|
|
if (tools_csv === 'none') {
|
|
|
|
return '';
|
|
|
|
} else {
|
|
|
|
script += await utils.stepLog('Setup Tools', os_version);
|
|
|
|
}
|
2021-07-05 17:33:10 +07:00
|
|
|
const tools_list = await filterList(await utils.CSVArray(tools_csv));
|
2020-05-08 07:11:00 +07:00
|
|
|
await utils.asyncForEach(tools_list, async function (release: string) {
|
2021-07-05 17:33:10 +07:00
|
|
|
const data: Record<string, string> = await initToolData(
|
|
|
|
await utils.getToolData(release.split(':')[0]),
|
|
|
|
release,
|
|
|
|
php_version,
|
|
|
|
os_version
|
2020-02-03 01:21:44 +07:00
|
|
|
);
|
2019-12-27 08:26:49 +07:00
|
|
|
script += '\n';
|
2021-04-17 04:26:47 +07:00
|
|
|
switch (true) {
|
2021-07-05 17:33:10 +07:00
|
|
|
case 'phar' === data['type']:
|
|
|
|
data['url'] = await getUrl(data);
|
|
|
|
script += await addArchive(data);
|
2020-07-19 02:30:54 +07:00
|
|
|
break;
|
2021-07-05 17:33:10 +07:00
|
|
|
case 'composer' === data['type']:
|
|
|
|
case /^[\w.-]+\/[\w.-]+$/.test(data['tool']):
|
|
|
|
script += await addPackage(data);
|
2020-07-19 18:10:14 +07:00
|
|
|
break;
|
2021-07-05 17:33:10 +07:00
|
|
|
case 'custom-package' === data['type']:
|
|
|
|
script += await utils.customPackage(
|
|
|
|
data['tool'].split('-')[0],
|
|
|
|
'tools',
|
|
|
|
data['version'],
|
|
|
|
data['os_version']
|
2021-02-20 11:45:25 +07:00
|
|
|
);
|
2020-07-19 17:18:00 +07:00
|
|
|
break;
|
2021-07-05 17:33:10 +07:00
|
|
|
case 'custom-function' === data['type']:
|
|
|
|
script += await functionRecord[data['function']](data);
|
2020-02-22 11:36:14 +07:00
|
|
|
break;
|
2021-07-05 17:33:10 +07:00
|
|
|
case /^none$/.test(data['tool']):
|
2021-04-17 04:26:47 +07:00
|
|
|
break;
|
2019-12-27 08:26:49 +07:00
|
|
|
default:
|
2020-01-07 09:36:14 +07:00
|
|
|
script += await utils.addLog(
|
|
|
|
'$cross',
|
2021-07-05 17:33:10 +07:00
|
|
|
data['tool'],
|
|
|
|
'Tool ' + data['tool'] + ' is not supported',
|
2020-01-07 09:36:14 +07:00
|
|
|
os_version
|
2019-12-27 08:26:49 +07:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return script;
|
|
|
|
}
|