mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-22 03:41:06 +07:00
Rename os_version => os
This commit is contained in:
parent
c2c73b16c1
commit
cad2a1bda3
@ -2,7 +2,7 @@ import * as config from '../src/config';
|
||||
|
||||
describe('Config tests', () => {
|
||||
it.each`
|
||||
ini_values | os_version | output
|
||||
ini_values | os | output
|
||||
${'a=b, c=d'} | ${'win32'} | ${'Add-Content "$php_dir\\php.ini" "a=b\nc=d"'}
|
||||
${'a=b, c=d'} | ${'linux'} | ${'echo "a=b\nc=d" | sudo tee -a "${pecl_file:-${ini_file[@]}}"'}
|
||||
${'a=b, c=d'} | ${'darwin'} | ${'echo "a=b\nc=d" | sudo tee -a "${pecl_file:-${ini_file[@]}}"'}
|
||||
@ -10,12 +10,7 @@ describe('Config tests', () => {
|
||||
${'a="~(b)"'} | ${'win32'} | ${'Add-Content "$php_dir\\php.ini" "a=\'~(b)\'"'}
|
||||
${'a="b, c"'} | ${'win32'} | ${'Add-Content "$php_dir\\php.ini" "a=b, c"'}
|
||||
${'a=b, c=d'} | ${'openbsd'} | ${'Platform openbsd is not supported'}
|
||||
`(
|
||||
'checking addINIValues on $os_version',
|
||||
async ({ini_values, os_version, output}) => {
|
||||
expect(await config.addINIValues(ini_values, os_version)).toContain(
|
||||
output
|
||||
);
|
||||
}
|
||||
);
|
||||
`('checking addINIValues on $os', async ({ini_values, os, output}) => {
|
||||
expect(await config.addINIValues(ini_values, os)).toContain(output);
|
||||
});
|
||||
});
|
||||
|
@ -110,7 +110,9 @@ describe('Extension tests', () => {
|
||||
const [formula, extension]: string[] = line.split('=');
|
||||
const prefix: string =
|
||||
extension == 'xdebug' ? 'zend_extension' : 'extension';
|
||||
const output: string = fs.existsSync(`src/scripts/extensions/${extension}.sh`)
|
||||
const output: string = fs.existsSync(
|
||||
`src/scripts/extensions/${extension}.sh`
|
||||
)
|
||||
? `add_${extension}`
|
||||
: `add_brew_extension ${formula} ${prefix}`;
|
||||
return [formula, '7.3', output];
|
||||
|
@ -18,17 +18,17 @@ jest.mock('../src/install', () => ({
|
||||
return script;
|
||||
}),
|
||||
run: jest.fn().mockImplementation(async (): Promise<string> => {
|
||||
const os_version: string = process.env['RUNNER_OS'] || '';
|
||||
const os: string = process.env['RUNNER_OS'] || '';
|
||||
const version: string = await utils.parseVersion(
|
||||
await utils.getInput('php-version', true)
|
||||
);
|
||||
const ini_file: string = await utils.parseIniFile(
|
||||
await utils.getInput('ini-file', false)
|
||||
);
|
||||
const tool = await utils.scriptTool(os_version);
|
||||
const filename = os_version + (await utils.scriptExtension(os_version));
|
||||
const tool = await utils.scriptTool(os);
|
||||
const filename = os + (await utils.scriptExtension(os));
|
||||
return [
|
||||
await install.getScript(filename, version, os_version),
|
||||
await install.getScript(filename, version, os),
|
||||
tool,
|
||||
filename,
|
||||
version,
|
||||
|
@ -6,7 +6,7 @@ interface IData {
|
||||
version?: string;
|
||||
domain?: string;
|
||||
extension?: string;
|
||||
os_version?: string;
|
||||
os?: string;
|
||||
php_version?: string;
|
||||
release?: string;
|
||||
repository?: string;
|
||||
@ -23,7 +23,7 @@ function getData(data: IData): Record<string, string> {
|
||||
version: data.version || '',
|
||||
domain: data.domain || 'https://example.com',
|
||||
extension: data.extension || '.phar',
|
||||
os_version: data.os_version || 'linux',
|
||||
os: data.os || 'linux',
|
||||
php_version: data.php_version || '7.4',
|
||||
release: data.release || [data.tool, data.version].join(':'),
|
||||
repository: data.repository || '',
|
||||
@ -197,45 +197,42 @@ describe('Tools tests', () => {
|
||||
);
|
||||
|
||||
it.each`
|
||||
os_version | script
|
||||
os | script
|
||||
${'linux'} | ${'add_tool https://example.com/tool.phar tool "-v"'}
|
||||
${'darwin'} | ${'add_tool https://example.com/tool.phar tool "-v"'}
|
||||
${'win32'} | ${'Add-Tool https://example.com/tool.phar tool "-v"'}
|
||||
${'openbsd'} | ${'Platform openbsd is not supported'}
|
||||
`('checking addArchive: $os_version', async ({os_version, script}) => {
|
||||
`('checking addArchive: $os', async ({os, script}) => {
|
||||
const data = getData({
|
||||
tool: 'tool',
|
||||
version: 'latest',
|
||||
version_parameter: JSON.stringify('-v'),
|
||||
os_version: os_version
|
||||
os: os
|
||||
});
|
||||
data['url'] = 'https://example.com/tool.phar';
|
||||
expect(await tools.addArchive(data)).toContain(script);
|
||||
});
|
||||
|
||||
it.each`
|
||||
os_version | script | scope
|
||||
os | script | scope
|
||||
${'linux'} | ${'add_composertool tool tool:1.2.3 user/ global'} | ${'global'}
|
||||
${'darwin'} | ${'add_composertool tool tool:1.2.3 user/ scoped'} | ${'scoped'}
|
||||
${'win32'} | ${'Add-Composertool tool tool:1.2.3 user/ scoped'} | ${'scoped'}
|
||||
${'openbsd'} | ${'Platform openbsd is not supported'} | ${'global'}
|
||||
`(
|
||||
'checking addPackage: $os_version, $scope',
|
||||
async ({os_version, script, scope}) => {
|
||||
const data = getData({
|
||||
tool: 'tool',
|
||||
version: '1.2.3',
|
||||
repository: 'user/tool',
|
||||
os_version: os_version,
|
||||
scope: scope
|
||||
});
|
||||
data['release'] = [data['tool'], data['version']].join(':');
|
||||
expect(await tools.addPackage(data)).toContain(script);
|
||||
}
|
||||
);
|
||||
`('checking addPackage: $os, $scope', async ({os, script, scope}) => {
|
||||
const data = getData({
|
||||
tool: 'tool',
|
||||
version: '1.2.3',
|
||||
repository: 'user/tool',
|
||||
os: os,
|
||||
scope: scope
|
||||
});
|
||||
data['release'] = [data['tool'], data['version']].join(':');
|
||||
expect(await tools.addPackage(data)).toContain(script);
|
||||
});
|
||||
|
||||
it.each`
|
||||
version | php_version | os_version | script
|
||||
version | php_version | os | script
|
||||
${'latest'} | ${'7.4'} | ${'linux'} | ${'add_tool https://github.com/phar-io/phive/releases/download/3.2.1/phive-3.2.1.phar phive'}
|
||||
${'1.2.3'} | ${'7.4'} | ${'darwin'} | ${'add_tool https://github.com/phar-io/phive/releases/download/1.2.3/phive-1.2.3.phar phive'}
|
||||
${'1.2.3'} | ${'7.2'} | ${'win32'} | ${'Add-Tool https://github.com/phar-io/phive/releases/download/0.14.5/phive-0.14.5.phar phive'}
|
||||
@ -243,15 +240,15 @@ describe('Tools tests', () => {
|
||||
${'latest'} | ${'5.6'} | ${'win32'} | ${'Add-Tool https://github.com/phar-io/phive/releases/download/0.12.1/phive-0.12.1.phar phive'}
|
||||
${'latest'} | ${'5.5'} | ${'win32'} | ${'Phive is not supported on PHP 5.5'}
|
||||
`(
|
||||
'checking addPhive: $version, $php_version, $os_version',
|
||||
async ({version, php_version, os_version, script}) => {
|
||||
'checking addPhive: $version, $php_version, $os',
|
||||
async ({version, php_version, os, script}) => {
|
||||
const data = getData({
|
||||
tool: 'phive',
|
||||
repository: 'phar-io/phive',
|
||||
version_parameter: 'status',
|
||||
version: version,
|
||||
php_version: php_version,
|
||||
os_version: os_version
|
||||
os: os
|
||||
});
|
||||
script = await tools.addPhive(data);
|
||||
expect(script).toContain(script);
|
||||
@ -322,7 +319,7 @@ describe('Tools tests', () => {
|
||||
);
|
||||
|
||||
it.each`
|
||||
version | os_version | uri
|
||||
version | os | uri
|
||||
${'latest'} | ${'linux'} | ${'releases/latest/download/symfony_linux_amd64'}
|
||||
${'1.2.3'} | ${'linux'} | ${'releases/download/v1.2.3/symfony_linux_amd64'}
|
||||
${'latest'} | ${'darwin'} | ${'releases/latest/download/symfony_darwin_amd64'}
|
||||
@ -330,18 +327,15 @@ describe('Tools tests', () => {
|
||||
${'latest'} | ${'win32'} | ${'releases/latest/download/symfony_windows_amd64.exe'}
|
||||
${'1.2.3'} | ${'win32'} | ${'releases/download/v1.2.3/symfony_windows_amd64.exe'}
|
||||
${'latest'} | ${'openbsd'} | ${'Platform openbsd is not supported'}
|
||||
`(
|
||||
'checking addSymfony: $version, $os_version',
|
||||
async ({version, os_version, uri}) => {
|
||||
const data = getData({
|
||||
tool: 'symfony',
|
||||
php_version: '7.4',
|
||||
version: version,
|
||||
os_version: os_version
|
||||
});
|
||||
expect(await tools.addSymfony(data)).toContain(uri);
|
||||
}
|
||||
);
|
||||
`('checking addSymfony: $version, $os', async ({version, os, uri}) => {
|
||||
const data = getData({
|
||||
tool: 'symfony',
|
||||
php_version: '7.4',
|
||||
version: version,
|
||||
os: os
|
||||
});
|
||||
expect(await tools.addSymfony(data)).toContain(uri);
|
||||
});
|
||||
|
||||
it.each`
|
||||
version | uri
|
||||
@ -359,7 +353,7 @@ describe('Tools tests', () => {
|
||||
});
|
||||
|
||||
it.each`
|
||||
tool | os_version | script
|
||||
tool | os | script
|
||||
${'phpize'} | ${'linux'} | ${'add_devtools phpize'}
|
||||
${'php-config'} | ${'linux'} | ${'add_devtools php-config'}
|
||||
${'phpize'} | ${'darwin'} | ${'add_devtools phpize'}
|
||||
@ -367,17 +361,14 @@ describe('Tools tests', () => {
|
||||
${'phpize'} | ${'win32'} | ${'Add-Log "$tick" "phpize" "phpize is not a windows tool"'}
|
||||
${'php-config'} | ${'win32'} | ${'Add-Log "$tick" "php-config" "php-config is not a windows tool"'}
|
||||
${'phpize'} | ${'openbsd'} | ${'Platform openbsd is not supported'}
|
||||
`(
|
||||
'checking addDevTools: $tool, $os_version',
|
||||
async ({tool, os_version, script}) => {
|
||||
const data = getData({
|
||||
version: '7.4',
|
||||
tool: tool,
|
||||
os_version: os_version
|
||||
});
|
||||
expect(await tools.addDevTools(data)).toContain(script);
|
||||
}
|
||||
);
|
||||
`('checking addDevTools: $tool, $os', async ({tool, os, script}) => {
|
||||
const data = getData({
|
||||
version: '7.4',
|
||||
tool: tool,
|
||||
os: os
|
||||
});
|
||||
expect(await tools.addDevTools(data)).toContain(script);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[
|
||||
|
@ -70,7 +70,7 @@ describe('Utils tests', () => {
|
||||
expect(await utils.parseIniFile('php.ini-production')).toBe('production');
|
||||
expect(await utils.parseIniFile('php.ini-development')).toBe('development');
|
||||
expect(await utils.parseIniFile('invalid')).toBe('production');
|
||||
})
|
||||
});
|
||||
|
||||
it('checking asyncForEach', async () => {
|
||||
const array: Array<string> = ['a', 'b', 'c'];
|
||||
|
172
dist/index.js
vendored
172
dist/index.js
vendored
@ -51,28 +51,28 @@ async function addINIValuesWindows(ini_values_csv) {
|
||||
return ('Add-Content "$php_dir\\php.ini" "' + ini_values.join('\n') + '"' + script);
|
||||
}
|
||||
exports.addINIValuesWindows = addINIValuesWindows;
|
||||
async function addINIValues(ini_values_csv, os_version, no_step = false) {
|
||||
async function addINIValues(ini_values_csv, os, no_step = false) {
|
||||
let script = '\n';
|
||||
switch (no_step) {
|
||||
case true:
|
||||
script +=
|
||||
(await utils.stepLog('Add php.ini values', os_version)) +
|
||||
(await utils.suppressOutput(os_version)) +
|
||||
(await utils.stepLog('Add php.ini values', os)) +
|
||||
(await utils.suppressOutput(os)) +
|
||||
'\n';
|
||||
break;
|
||||
case false:
|
||||
default:
|
||||
script += (await utils.stepLog('Add php.ini values', os_version)) + '\n';
|
||||
script += (await utils.stepLog('Add php.ini values', os)) + '\n';
|
||||
break;
|
||||
}
|
||||
switch (os_version) {
|
||||
switch (os) {
|
||||
case 'win32':
|
||||
return script + (await addINIValuesWindows(ini_values_csv));
|
||||
case 'darwin':
|
||||
case 'linux':
|
||||
return script + (await addINIValuesUnix(ini_values_csv));
|
||||
default:
|
||||
return await utils.log('Platform ' + os_version + ' is not supported', os_version, 'error');
|
||||
return await utils.log('Platform ' + os + ' is not supported', os, 'error');
|
||||
}
|
||||
}
|
||||
exports.addINIValues = addINIValues;
|
||||
@ -117,69 +117,65 @@ async function checkXdebugError(extension, version) {
|
||||
return '';
|
||||
}
|
||||
exports.checkXdebugError = checkXdebugError;
|
||||
async function addCoverageXdebug(extension, version, os_version, pipe) {
|
||||
async function addCoverageXdebug(extension, version, os, pipe) {
|
||||
let script = '\n';
|
||||
let message = await checkXdebugError(extension, version);
|
||||
let status = '$cross';
|
||||
if (!message) {
|
||||
script +=
|
||||
(await extensions.addExtension(':pcov:false', version, os_version, true)) + pipe;
|
||||
(await extensions.addExtension(':pcov:false', version, os, true)) + pipe;
|
||||
extension = extension == 'xdebug3' ? 'xdebug' : extension;
|
||||
script +=
|
||||
(await extensions.addExtension(extension, version, os_version, true)) +
|
||||
pipe;
|
||||
(await extensions.addExtension(extension, version, os, true)) + pipe;
|
||||
message = 'Xdebug enabled as coverage driver';
|
||||
status = '$tick';
|
||||
}
|
||||
script += await utils.addLog(status, extension, message, os_version);
|
||||
script += await utils.addLog(status, extension, message, os);
|
||||
return script;
|
||||
}
|
||||
exports.addCoverageXdebug = addCoverageXdebug;
|
||||
async function addCoveragePCOV(version, os_version, pipe) {
|
||||
async function addCoveragePCOV(version, os, pipe) {
|
||||
let script = '\n';
|
||||
switch (true) {
|
||||
default:
|
||||
script +=
|
||||
(await extensions.addExtension(':xdebug:false', version, os_version, true)) + pipe;
|
||||
script +=
|
||||
(await extensions.addExtension('pcov', version, os_version, true)) +
|
||||
(await extensions.addExtension(':xdebug:false', version, os, true)) +
|
||||
pipe;
|
||||
script +=
|
||||
(await config.addINIValues('pcov.enabled=1', os_version, true)) + '\n';
|
||||
script += await utils.addLog('$tick', 'coverage: pcov', 'PCOV enabled as coverage driver', os_version);
|
||||
(await extensions.addExtension('pcov', version, os, true)) + pipe;
|
||||
script += (await config.addINIValues('pcov.enabled=1', os, true)) + '\n';
|
||||
script += await utils.addLog('$tick', 'coverage: pcov', 'PCOV enabled as coverage driver', os);
|
||||
break;
|
||||
case /5\.[3-6]|7\.0/.test(version):
|
||||
script += await utils.addLog('$cross', 'pcov', 'PHP 7.1 or newer is required', os_version);
|
||||
script += await utils.addLog('$cross', 'pcov', 'PHP 7.1 or newer is required', os);
|
||||
break;
|
||||
}
|
||||
return script;
|
||||
}
|
||||
exports.addCoveragePCOV = addCoveragePCOV;
|
||||
async function disableCoverage(version, os_version, pipe) {
|
||||
async function disableCoverage(version, os, pipe) {
|
||||
let script = '\n';
|
||||
script +=
|
||||
(await extensions.addExtension(':pcov:false', version, os_version, true)) +
|
||||
pipe;
|
||||
(await extensions.addExtension(':pcov:false', version, os, true)) + pipe;
|
||||
script +=
|
||||
(await extensions.addExtension(':xdebug:false', version, os_version, true)) + pipe;
|
||||
script += await utils.addLog('$tick', 'none', 'Disabled Xdebug and PCOV', os_version);
|
||||
(await extensions.addExtension(':xdebug:false', version, os, true)) + pipe;
|
||||
script += await utils.addLog('$tick', 'none', 'Disabled Xdebug and PCOV', os);
|
||||
return script;
|
||||
}
|
||||
exports.disableCoverage = disableCoverage;
|
||||
async function addCoverage(coverage_driver, version, os_version) {
|
||||
async function addCoverage(coverage_driver, version, os) {
|
||||
coverage_driver = coverage_driver.toLowerCase();
|
||||
const script = '\n' + (await utils.stepLog('Setup Coverage', os_version));
|
||||
const pipe = (await utils.suppressOutput(os_version)) + '\n';
|
||||
const script = '\n' + (await utils.stepLog('Setup Coverage', os));
|
||||
const pipe = (await utils.suppressOutput(os)) + '\n';
|
||||
switch (coverage_driver) {
|
||||
case 'pcov':
|
||||
return script + (await addCoveragePCOV(version, os_version, pipe));
|
||||
return script + (await addCoveragePCOV(version, os, pipe));
|
||||
case 'xdebug':
|
||||
case 'xdebug2':
|
||||
case 'xdebug3':
|
||||
return (script +
|
||||
(await addCoverageXdebug(coverage_driver, version, os_version, pipe)));
|
||||
return (script + (await addCoverageXdebug(coverage_driver, version, os, pipe)));
|
||||
case 'none':
|
||||
return script + (await disableCoverage(version, os_version, pipe));
|
||||
return script + (await disableCoverage(version, os, pipe));
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
@ -381,19 +377,19 @@ async function addExtensionLinux(extension_csv, version) {
|
||||
return add_script + remove_script;
|
||||
}
|
||||
exports.addExtensionLinux = addExtensionLinux;
|
||||
async function addExtension(extension_csv, version, os_version, no_step = false) {
|
||||
const log = await utils.stepLog('Setup Extensions', os_version);
|
||||
async function addExtension(extension_csv, version, os, no_step = false) {
|
||||
const log = await utils.stepLog('Setup Extensions', os);
|
||||
let script = '\n';
|
||||
switch (no_step) {
|
||||
case true:
|
||||
script += log + (await utils.suppressOutput(os_version));
|
||||
script += log + (await utils.suppressOutput(os));
|
||||
break;
|
||||
case false:
|
||||
default:
|
||||
script += log;
|
||||
break;
|
||||
}
|
||||
switch (os_version) {
|
||||
switch (os) {
|
||||
case 'win32':
|
||||
return script + (await addExtensionWindows(extension_csv, version));
|
||||
case 'darwin':
|
||||
@ -401,7 +397,7 @@ async function addExtension(extension_csv, version, os_version, no_step = false)
|
||||
case 'linux':
|
||||
return script + (await addExtensionLinux(extension_csv, version));
|
||||
default:
|
||||
return await utils.log('Platform ' + os_version + ' is not supported', os_version, 'error');
|
||||
return await utils.log('Platform ' + os + ' is not supported', os, 'error');
|
||||
}
|
||||
}
|
||||
exports.addExtension = addExtension;
|
||||
@ -447,7 +443,7 @@ const tools = __importStar(__nccwpck_require__(740));
|
||||
const utils = __importStar(__nccwpck_require__(918));
|
||||
const path_1 = __importDefault(__nccwpck_require__(17));
|
||||
const fs_1 = __importDefault(__nccwpck_require__(147));
|
||||
async function getScript(filename, version, os_version) {
|
||||
async function getScript(filename, version, os) {
|
||||
const url = 'https://setup-php.com/sponsor';
|
||||
process.env['fail_fast'] = await utils.getInput('fail-fast', false);
|
||||
const extension_csv = await utils.getInput('extensions', false);
|
||||
@ -457,17 +453,17 @@ async function getScript(filename, version, os_version) {
|
||||
const script_path = path_1.default.join(__dirname, '../src/scripts', filename);
|
||||
let script = '\n';
|
||||
if (extension_csv) {
|
||||
script += await extensions.addExtension(extension_csv, version, os_version);
|
||||
script += await extensions.addExtension(extension_csv, version, os);
|
||||
}
|
||||
script += await tools.addTools(tools_csv, version, os_version);
|
||||
script += await tools.addTools(tools_csv, version, os);
|
||||
if (coverage_driver) {
|
||||
script += await coverage.addCoverage(coverage_driver, version, os_version);
|
||||
script += await coverage.addCoverage(coverage_driver, version, os);
|
||||
}
|
||||
if (ini_values_csv) {
|
||||
script += await config.addINIValues(ini_values_csv, os_version);
|
||||
script += await config.addINIValues(ini_values_csv, os);
|
||||
}
|
||||
script += '\n' + (await utils.stepLog(`Sponsor setup-php`, os_version));
|
||||
script += '\n' + (await utils.addLog('$tick', 'setup-php', url, os_version));
|
||||
script += '\n' + (await utils.stepLog(`Sponsor setup-php`, os));
|
||||
script += '\n' + (await utils.addLog('$tick', 'setup-php', url, os));
|
||||
fs_1.default.appendFileSync(script_path, script, { mode: 0o755 });
|
||||
return script_path;
|
||||
}
|
||||
@ -481,10 +477,10 @@ async function run() {
|
||||
const version = await utils.parseVersion(await utils.getInput('php-version', true));
|
||||
const ini_file = await utils.parseIniFile(await utils.getInput('ini-file', false));
|
||||
if (version) {
|
||||
const os_version = process.platform;
|
||||
const tool = await utils.scriptTool(os_version);
|
||||
const script = os_version + (await utils.scriptExtension(os_version));
|
||||
const location = await getScript(script, version, os_version);
|
||||
const os = process.platform;
|
||||
const tool = await utils.scriptTool(os);
|
||||
const script = os + (await utils.scriptExtension(os));
|
||||
const location = await getScript(script, version, os);
|
||||
await (0, exec_1.exec)(await utils.joins(tool, location, version, ini_file, __dirname));
|
||||
}
|
||||
else {
|
||||
@ -659,12 +655,12 @@ async function getPharUrl(data) {
|
||||
}
|
||||
exports.getPharUrl = getPharUrl;
|
||||
async function addArchive(data) {
|
||||
return ((await utils.getCommand(data['os_version'], 'tool')) +
|
||||
return ((await utils.getCommand(data['os'], 'tool')) +
|
||||
(await utils.joins(data['url'], data['tool'], data['version_parameter'])));
|
||||
}
|
||||
exports.addArchive = addArchive;
|
||||
async function addPackage(data) {
|
||||
const command = await utils.getCommand(data['os_version'], 'composertool');
|
||||
const command = await utils.getCommand(data['os'], 'composertool');
|
||||
const parts = data['repository'].split('/');
|
||||
const args = await utils.joins(parts[1], data['release'], parts[0] + '/', data['scope']);
|
||||
return command + args;
|
||||
@ -715,19 +711,19 @@ async function addDeployer(data) {
|
||||
}
|
||||
exports.addDeployer = addDeployer;
|
||||
async function addDevTools(data) {
|
||||
switch (data['os_version']) {
|
||||
switch (data['os']) {
|
||||
case 'linux':
|
||||
case 'darwin':
|
||||
return 'add_devtools ' + data['tool'];
|
||||
case 'win32':
|
||||
return await utils.addLog('$tick', data['tool'], data['tool'] + ' is not a windows tool', 'win32');
|
||||
default:
|
||||
return await utils.log('Platform ' + data['os_version'] + ' is not supported', data['os_version'], 'error');
|
||||
return await utils.log('Platform ' + data['os'] + ' is not supported', data['os'], 'error');
|
||||
}
|
||||
}
|
||||
exports.addDevTools = addDevTools;
|
||||
async function addPECL(data) {
|
||||
return await utils.getCommand(data['os_version'], 'pecl');
|
||||
return await utils.getCommand(data['os'], 'pecl');
|
||||
}
|
||||
exports.addPECL = addPECL;
|
||||
async function addPhing(data) {
|
||||
@ -739,7 +735,7 @@ exports.addPhing = addPhing;
|
||||
async function addPhive(data) {
|
||||
switch (true) {
|
||||
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']);
|
||||
return await utils.addLog('$cross', 'phive', 'Phive is not supported on PHP ' + data['php_version'], data['os']);
|
||||
case /5\.6|7\.0/.test(data['php_version']):
|
||||
data['version'] = '0.12.1';
|
||||
break;
|
||||
@ -765,16 +761,16 @@ async function addPHPUnitTools(data) {
|
||||
exports.addPHPUnitTools = addPHPUnitTools;
|
||||
async function addSymfony(data) {
|
||||
let filename;
|
||||
switch (data['os_version']) {
|
||||
switch (data['os']) {
|
||||
case 'linux':
|
||||
case 'darwin':
|
||||
filename = 'symfony_' + data['os_version'] + '_amd64';
|
||||
filename = 'symfony_' + data['os'] + '_amd64';
|
||||
break;
|
||||
case 'win32':
|
||||
filename = 'symfony_windows_amd64.exe';
|
||||
break;
|
||||
default:
|
||||
return await utils.log('Platform ' + data['os_version'] + ' is not supported', data['os_version'], 'error');
|
||||
return await utils.log('Platform ' + data['os'] + ' is not supported', data['os'], 'error');
|
||||
}
|
||||
if (data['version'] === 'latest') {
|
||||
data['uri'] = ['releases/latest/download', filename].join('/');
|
||||
@ -798,7 +794,7 @@ async function addWPCLI(data) {
|
||||
return await addArchive(data);
|
||||
}
|
||||
exports.addWPCLI = addWPCLI;
|
||||
async function getData(release, php_version, os_version) {
|
||||
async function getData(release, php_version, os) {
|
||||
var _a, _b, _c, _d, _e;
|
||||
const json_file_path = path_1.default.join(__dirname, '../src/configs/tools.json');
|
||||
const json_file = fs_1.default.readFileSync(json_file_path, 'utf8');
|
||||
@ -832,7 +828,7 @@ async function getData(release, php_version, os_version) {
|
||||
data['github'] = 'https://github.com';
|
||||
(_a = data['domain']) !== null && _a !== void 0 ? _a : (data['domain'] = data['github']);
|
||||
(_b = data['extension']) !== null && _b !== void 0 ? _b : (data['extension'] = '.phar');
|
||||
data['os_version'] = os_version;
|
||||
data['os'] = os;
|
||||
data['php_version'] = php_version;
|
||||
data['prefix'] = data['github'] === data['domain'] ? 'releases' : '';
|
||||
data['verb'] = data['github'] === data['domain'] ? 'download' : '';
|
||||
@ -860,21 +856,21 @@ exports.functionRecord = {
|
||||
symfony: addSymfony,
|
||||
wp_cli: addWPCLI
|
||||
};
|
||||
async function addTools(tools_csv, php_version, os_version) {
|
||||
async function addTools(tools_csv, php_version, os) {
|
||||
let script = '\n';
|
||||
if (tools_csv === 'none') {
|
||||
return '';
|
||||
}
|
||||
else {
|
||||
script += await utils.stepLog('Setup Tools', os_version);
|
||||
script += await utils.stepLog('Setup Tools', os);
|
||||
}
|
||||
const tools_list = await filterList(await utils.CSVArray(tools_csv));
|
||||
await utils.asyncForEach(tools_list, async function (release) {
|
||||
const data = await getData(release, php_version, os_version);
|
||||
const data = await getData(release, php_version, os);
|
||||
script += '\n';
|
||||
switch (true) {
|
||||
case data['error'] !== undefined:
|
||||
script += await utils.addLog('$cross', data['tool'], data['error'], data['os_version']);
|
||||
script += await utils.addLog('$cross', data['tool'], data['error'], data['os']);
|
||||
break;
|
||||
case 'phar' === data['type']:
|
||||
data['url'] = await getUrl(data);
|
||||
@ -884,7 +880,7 @@ async function addTools(tools_csv, php_version, os_version) {
|
||||
script += await addPackage(data);
|
||||
break;
|
||||
case 'custom-package' === data['type']:
|
||||
script += await utils.customPackage(data['tool'].split('-')[0], 'tools', data['version'], data['os_version']);
|
||||
script += await utils.customPackage(data['tool'].split('-')[0], 'tools', data['version'], data['os']);
|
||||
break;
|
||||
case 'custom-function' === data['type']:
|
||||
script += await exports.functionRecord[data['function']](data);
|
||||
@ -892,7 +888,7 @@ async function addTools(tools_csv, php_version, os_version) {
|
||||
case /^none$/.test(data['tool']):
|
||||
break;
|
||||
default:
|
||||
script += await utils.addLog('$cross', data['tool'], 'Tool ' + data['tool'] + ' is not supported', data['os_version']);
|
||||
script += await utils.addLog('$cross', data['tool'], 'Tool ' + data['tool'] + ' is not supported', data['os']);
|
||||
break;
|
||||
}
|
||||
});
|
||||
@ -1037,8 +1033,8 @@ async function color(type) {
|
||||
}
|
||||
}
|
||||
exports.color = color;
|
||||
async function log(message, os_version, log_type) {
|
||||
switch (os_version) {
|
||||
async function log(message, os, log_type) {
|
||||
switch (os) {
|
||||
case 'win32':
|
||||
return ('printf "\\033[' +
|
||||
(await color(log_type)) +
|
||||
@ -1052,27 +1048,27 @@ async function log(message, os_version, log_type) {
|
||||
}
|
||||
}
|
||||
exports.log = log;
|
||||
async function stepLog(message, os_version) {
|
||||
switch (os_version) {
|
||||
async function stepLog(message, os) {
|
||||
switch (os) {
|
||||
case 'win32':
|
||||
return 'Step-Log "' + message + '"';
|
||||
case 'linux':
|
||||
case 'darwin':
|
||||
return 'step_log "' + message + '"';
|
||||
default:
|
||||
return await log('Platform ' + os_version + ' is not supported', os_version, 'error');
|
||||
return await log('Platform ' + os + ' is not supported', os, 'error');
|
||||
}
|
||||
}
|
||||
exports.stepLog = stepLog;
|
||||
async function addLog(mark, subject, message, os_version) {
|
||||
switch (os_version) {
|
||||
async function addLog(mark, subject, message, os) {
|
||||
switch (os) {
|
||||
case 'win32':
|
||||
return 'Add-Log "' + mark + '" "' + subject + '" "' + message + '"';
|
||||
case 'linux':
|
||||
case 'darwin':
|
||||
return 'add_log "' + mark + '" "' + subject + '" "' + message + '"';
|
||||
default:
|
||||
return await log('Platform ' + os_version + ' is not supported', os_version, 'error');
|
||||
return await log('Platform ' + os + ' is not supported', os, 'error');
|
||||
}
|
||||
}
|
||||
exports.addLog = addLog;
|
||||
@ -1126,33 +1122,33 @@ async function getExtensionPrefix(extension) {
|
||||
}
|
||||
}
|
||||
exports.getExtensionPrefix = getExtensionPrefix;
|
||||
async function suppressOutput(os_version) {
|
||||
switch (os_version) {
|
||||
async function suppressOutput(os) {
|
||||
switch (os) {
|
||||
case 'win32':
|
||||
return ' >$null 2>&1';
|
||||
case 'linux':
|
||||
case 'darwin':
|
||||
return ' >/dev/null 2>&1';
|
||||
default:
|
||||
return await log('Platform ' + os_version + ' is not supported', os_version, 'error');
|
||||
return await log('Platform ' + os + ' is not supported', os, 'error');
|
||||
}
|
||||
}
|
||||
exports.suppressOutput = suppressOutput;
|
||||
async function getUnsupportedLog(extension, version, os_version) {
|
||||
async function getUnsupportedLog(extension, version, os) {
|
||||
return ('\n' +
|
||||
(await addLog('$cross', extension, [extension, 'is not supported on PHP', version].join(' '), os_version)) +
|
||||
(await addLog('$cross', extension, [extension, 'is not supported on PHP', version].join(' '), os)) +
|
||||
'\n');
|
||||
}
|
||||
exports.getUnsupportedLog = getUnsupportedLog;
|
||||
async function getCommand(os_version, suffix) {
|
||||
switch (os_version) {
|
||||
async function getCommand(os, suffix) {
|
||||
switch (os) {
|
||||
case 'linux':
|
||||
case 'darwin':
|
||||
return 'add_' + suffix + ' ';
|
||||
case 'win32':
|
||||
return 'Add-' + suffix.charAt(0).toUpperCase() + suffix.slice(1) + ' ';
|
||||
default:
|
||||
return await log('Platform ' + os_version + ' is not supported', os_version, 'error');
|
||||
return await log('Platform ' + os + ' is not supported', os, 'error');
|
||||
}
|
||||
}
|
||||
exports.getCommand = getCommand;
|
||||
@ -1160,35 +1156,35 @@ async function joins(...str) {
|
||||
return [...str].join(' ');
|
||||
}
|
||||
exports.joins = joins;
|
||||
async function scriptExtension(os_version) {
|
||||
switch (os_version) {
|
||||
async function scriptExtension(os) {
|
||||
switch (os) {
|
||||
case 'win32':
|
||||
return '.ps1';
|
||||
case 'linux':
|
||||
case 'darwin':
|
||||
return '.sh';
|
||||
default:
|
||||
return await log('Platform ' + os_version + ' is not supported', os_version, 'error');
|
||||
return await log('Platform ' + os + ' is not supported', os, 'error');
|
||||
}
|
||||
}
|
||||
exports.scriptExtension = scriptExtension;
|
||||
async function scriptTool(os_version) {
|
||||
switch (os_version) {
|
||||
async function scriptTool(os) {
|
||||
switch (os) {
|
||||
case 'win32':
|
||||
return 'pwsh';
|
||||
case 'linux':
|
||||
case 'darwin':
|
||||
return 'bash';
|
||||
default:
|
||||
return await log('Platform ' + os_version + ' is not supported', os_version, 'error');
|
||||
return await log('Platform ' + os + ' is not supported', os, 'error');
|
||||
}
|
||||
}
|
||||
exports.scriptTool = scriptTool;
|
||||
async function customPackage(pkg, type, version, os_version) {
|
||||
async function customPackage(pkg, type, version, os) {
|
||||
const pkg_name = pkg.replace(/\d+|(pdo|pecl)[_-]/, '');
|
||||
const script_extension = await scriptExtension(os_version);
|
||||
const script_extension = await scriptExtension(os);
|
||||
const script = path.join(__dirname, '../src/scripts/' + type + '/' + pkg_name + script_extension);
|
||||
const command = await getCommand(os_version, pkg_name);
|
||||
const command = await getCommand(os, pkg_name);
|
||||
return '\n. ' + script + '\n' + command + version;
|
||||
}
|
||||
exports.customPackage = customPackage;
|
||||
|
@ -45,28 +45,28 @@ export async function addINIValuesWindows(
|
||||
* Function to add custom ini values
|
||||
*
|
||||
* @param ini_values_csv
|
||||
* @param os_version
|
||||
* @param os
|
||||
* @param no_step
|
||||
*/
|
||||
export async function addINIValues(
|
||||
ini_values_csv: string,
|
||||
os_version: string,
|
||||
os: string,
|
||||
no_step = false
|
||||
): Promise<string> {
|
||||
let script = '\n';
|
||||
switch (no_step) {
|
||||
case true:
|
||||
script +=
|
||||
(await utils.stepLog('Add php.ini values', os_version)) +
|
||||
(await utils.suppressOutput(os_version)) +
|
||||
(await utils.stepLog('Add php.ini values', os)) +
|
||||
(await utils.suppressOutput(os)) +
|
||||
'\n';
|
||||
break;
|
||||
case false:
|
||||
default:
|
||||
script += (await utils.stepLog('Add php.ini values', os_version)) + '\n';
|
||||
script += (await utils.stepLog('Add php.ini values', os)) + '\n';
|
||||
break;
|
||||
}
|
||||
switch (os_version) {
|
||||
switch (os) {
|
||||
case 'win32':
|
||||
return script + (await addINIValuesWindows(ini_values_csv));
|
||||
case 'darwin':
|
||||
@ -74,8 +74,8 @@ export async function addINIValues(
|
||||
return script + (await addINIValuesUnix(ini_values_csv));
|
||||
default:
|
||||
return await utils.log(
|
||||
'Platform ' + os_version + ' is not supported',
|
||||
os_version,
|
||||
'Platform ' + os + ' is not supported',
|
||||
os,
|
||||
'error'
|
||||
);
|
||||
}
|
||||
|
@ -20,13 +20,13 @@ export async function checkXdebugError(
|
||||
*
|
||||
* @param extension
|
||||
* @param version
|
||||
* @param os_version
|
||||
* @param os
|
||||
* @param pipe
|
||||
*/
|
||||
export async function addCoverageXdebug(
|
||||
extension: string,
|
||||
version: string,
|
||||
os_version: string,
|
||||
os: string,
|
||||
pipe: string
|
||||
): Promise<string> {
|
||||
let script = '\n';
|
||||
@ -34,20 +34,14 @@ export async function addCoverageXdebug(
|
||||
let status = '$cross';
|
||||
if (!message) {
|
||||
script +=
|
||||
(await extensions.addExtension(
|
||||
':pcov:false',
|
||||
version,
|
||||
os_version,
|
||||
true
|
||||
)) + pipe;
|
||||
(await extensions.addExtension(':pcov:false', version, os, true)) + pipe;
|
||||
extension = extension == 'xdebug3' ? 'xdebug' : extension;
|
||||
script +=
|
||||
(await extensions.addExtension(extension, version, os_version, true)) +
|
||||
pipe;
|
||||
(await extensions.addExtension(extension, version, os, true)) + pipe;
|
||||
message = 'Xdebug enabled as coverage driver';
|
||||
status = '$tick';
|
||||
}
|
||||
script += await utils.addLog(status, extension, message, os_version);
|
||||
script += await utils.addLog(status, extension, message, os);
|
||||
return script;
|
||||
}
|
||||
|
||||
@ -55,36 +49,30 @@ export async function addCoverageXdebug(
|
||||
* Function to setup PCOV
|
||||
*
|
||||
* @param version
|
||||
* @param os_version
|
||||
* @param os
|
||||
* @param pipe
|
||||
*/
|
||||
export async function addCoveragePCOV(
|
||||
version: string,
|
||||
os_version: string,
|
||||
os: string,
|
||||
pipe: string
|
||||
): Promise<string> {
|
||||
let script = '\n';
|
||||
switch (true) {
|
||||
default:
|
||||
script +=
|
||||
(await extensions.addExtension(
|
||||
':xdebug:false',
|
||||
version,
|
||||
os_version,
|
||||
true
|
||||
)) + pipe;
|
||||
script +=
|
||||
(await extensions.addExtension('pcov', version, os_version, true)) +
|
||||
(await extensions.addExtension(':xdebug:false', version, os, true)) +
|
||||
pipe;
|
||||
script +=
|
||||
(await config.addINIValues('pcov.enabled=1', os_version, true)) + '\n';
|
||||
(await extensions.addExtension('pcov', version, os, true)) + pipe;
|
||||
script += (await config.addINIValues('pcov.enabled=1', os, true)) + '\n';
|
||||
|
||||
// success
|
||||
script += await utils.addLog(
|
||||
'$tick',
|
||||
'coverage: pcov',
|
||||
'PCOV enabled as coverage driver',
|
||||
os_version
|
||||
os
|
||||
);
|
||||
// version is not supported
|
||||
break;
|
||||
@ -94,7 +82,7 @@ export async function addCoveragePCOV(
|
||||
'$cross',
|
||||
'pcov',
|
||||
'PHP 7.1 or newer is required',
|
||||
os_version
|
||||
os
|
||||
);
|
||||
break;
|
||||
}
|
||||
@ -106,31 +94,20 @@ export async function addCoveragePCOV(
|
||||
* Function to disable Xdebug and PCOV
|
||||
*
|
||||
* @param version
|
||||
* @param os_version
|
||||
* @param os
|
||||
* @param pipe
|
||||
*/
|
||||
export async function disableCoverage(
|
||||
version: string,
|
||||
os_version: string,
|
||||
os: string,
|
||||
pipe: string
|
||||
): Promise<string> {
|
||||
let script = '\n';
|
||||
script +=
|
||||
(await extensions.addExtension(':pcov:false', version, os_version, true)) +
|
||||
pipe;
|
||||
(await extensions.addExtension(':pcov:false', version, os, true)) + pipe;
|
||||
script +=
|
||||
(await extensions.addExtension(
|
||||
':xdebug:false',
|
||||
version,
|
||||
os_version,
|
||||
true
|
||||
)) + pipe;
|
||||
script += await utils.addLog(
|
||||
'$tick',
|
||||
'none',
|
||||
'Disabled Xdebug and PCOV',
|
||||
os_version
|
||||
);
|
||||
(await extensions.addExtension(':xdebug:false', version, os, true)) + pipe;
|
||||
script += await utils.addLog('$tick', 'none', 'Disabled Xdebug and PCOV', os);
|
||||
|
||||
return script;
|
||||
}
|
||||
@ -140,29 +117,27 @@ export async function disableCoverage(
|
||||
*
|
||||
* @param coverage_driver
|
||||
* @param version
|
||||
* @param os_version
|
||||
* @param os
|
||||
*/
|
||||
export async function addCoverage(
|
||||
coverage_driver: string,
|
||||
version: string,
|
||||
os_version: string
|
||||
os: string
|
||||
): Promise<string> {
|
||||
coverage_driver = coverage_driver.toLowerCase();
|
||||
const script: string =
|
||||
'\n' + (await utils.stepLog('Setup Coverage', os_version));
|
||||
const pipe: string = (await utils.suppressOutput(os_version)) + '\n';
|
||||
const script: string = '\n' + (await utils.stepLog('Setup Coverage', os));
|
||||
const pipe: string = (await utils.suppressOutput(os)) + '\n';
|
||||
switch (coverage_driver) {
|
||||
case 'pcov':
|
||||
return script + (await addCoveragePCOV(version, os_version, pipe));
|
||||
return script + (await addCoveragePCOV(version, os, pipe));
|
||||
case 'xdebug':
|
||||
case 'xdebug2':
|
||||
case 'xdebug3':
|
||||
return (
|
||||
script +
|
||||
(await addCoverageXdebug(coverage_driver, version, os_version, pipe))
|
||||
script + (await addCoverageXdebug(coverage_driver, version, os, pipe))
|
||||
);
|
||||
case 'none':
|
||||
return script + (await disableCoverage(version, os_version, pipe));
|
||||
return script + (await disableCoverage(version, os, pipe));
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
|
@ -327,20 +327,20 @@ export async function addExtensionLinux(
|
||||
*
|
||||
* @param extension_csv
|
||||
* @param version
|
||||
* @param os_version
|
||||
* @param os
|
||||
* @param no_step
|
||||
*/
|
||||
export async function addExtension(
|
||||
extension_csv: string,
|
||||
version: string,
|
||||
os_version: string,
|
||||
os: string,
|
||||
no_step = false
|
||||
): Promise<string> {
|
||||
const log: string = await utils.stepLog('Setup Extensions', os_version);
|
||||
const log: string = await utils.stepLog('Setup Extensions', os);
|
||||
let script = '\n';
|
||||
switch (no_step) {
|
||||
case true:
|
||||
script += log + (await utils.suppressOutput(os_version));
|
||||
script += log + (await utils.suppressOutput(os));
|
||||
break;
|
||||
case false:
|
||||
default:
|
||||
@ -348,7 +348,7 @@ export async function addExtension(
|
||||
break;
|
||||
}
|
||||
|
||||
switch (os_version) {
|
||||
switch (os) {
|
||||
case 'win32':
|
||||
return script + (await addExtensionWindows(extension_csv, version));
|
||||
case 'darwin':
|
||||
@ -357,8 +357,8 @@ export async function addExtension(
|
||||
return script + (await addExtensionLinux(extension_csv, version));
|
||||
default:
|
||||
return await utils.log(
|
||||
'Platform ' + os_version + ' is not supported',
|
||||
os_version,
|
||||
'Platform ' + os + ' is not supported',
|
||||
os,
|
||||
'error'
|
||||
);
|
||||
}
|
||||
|
@ -13,12 +13,12 @@ import fs from 'fs';
|
||||
*
|
||||
* @param filename
|
||||
* @param version
|
||||
* @param os_version
|
||||
* @param os
|
||||
*/
|
||||
export async function getScript(
|
||||
filename: string,
|
||||
version: string,
|
||||
os_version: string
|
||||
os: string
|
||||
): Promise<string> {
|
||||
const url = 'https://setup-php.com/sponsor';
|
||||
// taking inputs
|
||||
@ -30,17 +30,17 @@ export async function getScript(
|
||||
const script_path = path.join(__dirname, '../src/scripts', filename);
|
||||
let script = '\n';
|
||||
if (extension_csv) {
|
||||
script += await extensions.addExtension(extension_csv, version, os_version);
|
||||
script += await extensions.addExtension(extension_csv, version, os);
|
||||
}
|
||||
script += await tools.addTools(tools_csv, version, os_version);
|
||||
script += await tools.addTools(tools_csv, version, os);
|
||||
if (coverage_driver) {
|
||||
script += await coverage.addCoverage(coverage_driver, version, os_version);
|
||||
script += await coverage.addCoverage(coverage_driver, version, os);
|
||||
}
|
||||
if (ini_values_csv) {
|
||||
script += await config.addINIValues(ini_values_csv, os_version);
|
||||
script += await config.addINIValues(ini_values_csv, os);
|
||||
}
|
||||
script += '\n' + (await utils.stepLog(`Sponsor setup-php`, os_version));
|
||||
script += '\n' + (await utils.addLog('$tick', 'setup-php', url, os_version));
|
||||
script += '\n' + (await utils.stepLog(`Sponsor setup-php`, os));
|
||||
script += '\n' + (await utils.addLog('$tick', 'setup-php', url, os));
|
||||
|
||||
fs.appendFileSync(script_path, script, {mode: 0o755});
|
||||
|
||||
@ -65,10 +65,10 @@ export async function run(): Promise<void> {
|
||||
await utils.getInput('ini-file', false)
|
||||
);
|
||||
if (version) {
|
||||
const os_version: string = process.platform;
|
||||
const tool = await utils.scriptTool(os_version);
|
||||
const script = os_version + (await utils.scriptExtension(os_version));
|
||||
const location = await getScript(script, version, os_version);
|
||||
const os: string = process.platform;
|
||||
const tool = await utils.scriptTool(os);
|
||||
const script = os + (await utils.scriptExtension(os));
|
||||
const location = await getScript(script, version, os);
|
||||
await exec(
|
||||
await utils.joins(tool, location, version, ini_file, __dirname)
|
||||
);
|
||||
|
42
src/tools.ts
42
src/tools.ts
@ -185,7 +185,7 @@ export async function getPharUrl(data: RS): Promise<string> {
|
||||
*/
|
||||
export async function addArchive(data: RS): Promise<string> {
|
||||
return (
|
||||
(await utils.getCommand(data['os_version'], 'tool')) +
|
||||
(await utils.getCommand(data['os'], 'tool')) +
|
||||
(await utils.joins(data['url'], data['tool'], data['version_parameter']))
|
||||
);
|
||||
}
|
||||
@ -196,7 +196,7 @@ export async function addArchive(data: RS): Promise<string> {
|
||||
* @param data
|
||||
*/
|
||||
export async function addPackage(data: RS): Promise<string> {
|
||||
const command = await utils.getCommand(data['os_version'], 'composertool');
|
||||
const command = await utils.getCommand(data['os'], 'composertool');
|
||||
const parts: string[] = data['repository'].split('/');
|
||||
const args: string = await utils.joins(
|
||||
parts[1],
|
||||
@ -275,7 +275,7 @@ export async function addDeployer(data: RS): Promise<string> {
|
||||
* @param data
|
||||
*/
|
||||
export async function addDevTools(data: RS): Promise<string> {
|
||||
switch (data['os_version']) {
|
||||
switch (data['os']) {
|
||||
case 'linux':
|
||||
case 'darwin':
|
||||
return 'add_devtools ' + data['tool'];
|
||||
@ -288,8 +288,8 @@ export async function addDevTools(data: RS): Promise<string> {
|
||||
);
|
||||
default:
|
||||
return await utils.log(
|
||||
'Platform ' + data['os_version'] + ' is not supported',
|
||||
data['os_version'],
|
||||
'Platform ' + data['os'] + ' is not supported',
|
||||
data['os'],
|
||||
'error'
|
||||
);
|
||||
}
|
||||
@ -301,7 +301,7 @@ export async function addDevTools(data: RS): Promise<string> {
|
||||
* @param data
|
||||
*/
|
||||
export async function addPECL(data: RS): Promise<string> {
|
||||
return await utils.getCommand(data['os_version'], 'pecl');
|
||||
return await utils.getCommand(data['os'], 'pecl');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -327,7 +327,7 @@ export async function addPhive(data: RS): Promise<string> {
|
||||
'$cross',
|
||||
'phive',
|
||||
'Phive is not supported on PHP ' + data['php_version'],
|
||||
data['os_version']
|
||||
data['os']
|
||||
);
|
||||
case /5\.6|7\.0/.test(data['php_version']):
|
||||
data['version'] = '0.12.1';
|
||||
@ -364,18 +364,18 @@ export async function addPHPUnitTools(data: RS): Promise<string> {
|
||||
*/
|
||||
export async function addSymfony(data: RS): Promise<string> {
|
||||
let filename: string;
|
||||
switch (data['os_version']) {
|
||||
switch (data['os']) {
|
||||
case 'linux':
|
||||
case 'darwin':
|
||||
filename = 'symfony_' + data['os_version'] + '_amd64';
|
||||
filename = 'symfony_' + data['os'] + '_amd64';
|
||||
break;
|
||||
case 'win32':
|
||||
filename = 'symfony_windows_amd64.exe';
|
||||
break;
|
||||
default:
|
||||
return await utils.log(
|
||||
'Platform ' + data['os_version'] + ' is not supported',
|
||||
data['os_version'],
|
||||
'Platform ' + data['os'] + ' is not supported',
|
||||
data['os'],
|
||||
'error'
|
||||
);
|
||||
}
|
||||
@ -411,12 +411,12 @@ export async function addWPCLI(data: RS): Promise<string> {
|
||||
*
|
||||
* @param release
|
||||
* @param php_version
|
||||
* @param os_version
|
||||
* @param os
|
||||
*/
|
||||
export async function getData(
|
||||
release: string,
|
||||
php_version: string,
|
||||
os_version: string
|
||||
os: string
|
||||
): Promise<RS> {
|
||||
const json_file_path = path.join(__dirname, '../src/configs/tools.json');
|
||||
const json_file: string = fs.readFileSync(json_file_path, 'utf8');
|
||||
@ -450,7 +450,7 @@ export async function getData(
|
||||
data['github'] = 'https://github.com';
|
||||
data['domain'] ??= data['github'];
|
||||
data['extension'] ??= '.phar';
|
||||
data['os_version'] = os_version;
|
||||
data['os'] = os;
|
||||
data['php_version'] = php_version;
|
||||
data['prefix'] = data['github'] === data['domain'] ? 'releases' : '';
|
||||
data['verb'] = data['github'] === data['domain'] ? 'download' : '';
|
||||
@ -484,22 +484,22 @@ export const functionRecord: Record<string, (data: RS) => Promise<string>> = {
|
||||
*
|
||||
* @param tools_csv
|
||||
* @param php_version
|
||||
* @param os_version
|
||||
* @param os
|
||||
*/
|
||||
export async function addTools(
|
||||
tools_csv: string,
|
||||
php_version: string,
|
||||
os_version: string
|
||||
os: string
|
||||
): Promise<string> {
|
||||
let script = '\n';
|
||||
if (tools_csv === 'none') {
|
||||
return '';
|
||||
} else {
|
||||
script += await utils.stepLog('Setup Tools', os_version);
|
||||
script += await utils.stepLog('Setup Tools', os);
|
||||
}
|
||||
const tools_list = await filterList(await utils.CSVArray(tools_csv));
|
||||
await utils.asyncForEach(tools_list, async function (release: string) {
|
||||
const data: RS = await getData(release, php_version, os_version);
|
||||
const data: RS = await getData(release, php_version, os);
|
||||
script += '\n';
|
||||
switch (true) {
|
||||
case data['error'] !== undefined:
|
||||
@ -507,7 +507,7 @@ export async function addTools(
|
||||
'$cross',
|
||||
data['tool'],
|
||||
data['error'],
|
||||
data['os_version']
|
||||
data['os']
|
||||
);
|
||||
break;
|
||||
case 'phar' === data['type']:
|
||||
@ -522,7 +522,7 @@ export async function addTools(
|
||||
data['tool'].split('-')[0],
|
||||
'tools',
|
||||
data['version'],
|
||||
data['os_version']
|
||||
data['os']
|
||||
);
|
||||
break;
|
||||
case 'custom-function' === data['type']:
|
||||
@ -535,7 +535,7 @@ export async function addTools(
|
||||
'$cross',
|
||||
data['tool'],
|
||||
'Tool ' + data['tool'] + ' is not supported',
|
||||
data['os_version']
|
||||
data['os']
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
98
src/utils.ts
98
src/utils.ts
@ -170,15 +170,15 @@ export async function color(type: string): Promise<string> {
|
||||
* Log to console
|
||||
*
|
||||
* @param message
|
||||
* @param os_version
|
||||
* @param os
|
||||
* @param log_type
|
||||
*/
|
||||
export async function log(
|
||||
message: string,
|
||||
os_version: string,
|
||||
os: string,
|
||||
log_type: string
|
||||
): Promise<string> {
|
||||
switch (os_version) {
|
||||
switch (os) {
|
||||
case 'win32':
|
||||
return (
|
||||
'printf "\\033[' +
|
||||
@ -201,24 +201,17 @@ export async function log(
|
||||
* Function to log a step
|
||||
*
|
||||
* @param message
|
||||
* @param os_version
|
||||
* @param os
|
||||
*/
|
||||
export async function stepLog(
|
||||
message: string,
|
||||
os_version: string
|
||||
): Promise<string> {
|
||||
switch (os_version) {
|
||||
export async function stepLog(message: string, os: string): Promise<string> {
|
||||
switch (os) {
|
||||
case 'win32':
|
||||
return 'Step-Log "' + message + '"';
|
||||
case 'linux':
|
||||
case 'darwin':
|
||||
return 'step_log "' + message + '"';
|
||||
default:
|
||||
return await log(
|
||||
'Platform ' + os_version + ' is not supported',
|
||||
os_version,
|
||||
'error'
|
||||
);
|
||||
return await log('Platform ' + os + ' is not supported', os, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,26 +220,22 @@ export async function stepLog(
|
||||
* @param mark
|
||||
* @param subject
|
||||
* @param message
|
||||
* @param os_version
|
||||
* @param os
|
||||
*/
|
||||
export async function addLog(
|
||||
mark: string,
|
||||
subject: string,
|
||||
message: string,
|
||||
os_version: string
|
||||
os: string
|
||||
): Promise<string> {
|
||||
switch (os_version) {
|
||||
switch (os) {
|
||||
case 'win32':
|
||||
return 'Add-Log "' + mark + '" "' + subject + '" "' + message + '"';
|
||||
case 'linux':
|
||||
case 'darwin':
|
||||
return 'add_log "' + mark + '" "' + subject + '" "' + message + '"';
|
||||
default:
|
||||
return await log(
|
||||
'Platform ' + os_version + ' is not supported',
|
||||
os_version,
|
||||
'error'
|
||||
);
|
||||
return await log('Platform ' + os + ' is not supported', os, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
@ -322,21 +311,17 @@ export async function getExtensionPrefix(extension: string): Promise<string> {
|
||||
/**
|
||||
* Function to get the suffix to suppress console output
|
||||
*
|
||||
* @param os_version
|
||||
* @param os
|
||||
*/
|
||||
export async function suppressOutput(os_version: string): Promise<string> {
|
||||
switch (os_version) {
|
||||
export async function suppressOutput(os: string): Promise<string> {
|
||||
switch (os) {
|
||||
case 'win32':
|
||||
return ' >$null 2>&1';
|
||||
case 'linux':
|
||||
case 'darwin':
|
||||
return ' >/dev/null 2>&1';
|
||||
default:
|
||||
return await log(
|
||||
'Platform ' + os_version + ' is not supported',
|
||||
os_version,
|
||||
'error'
|
||||
);
|
||||
return await log('Platform ' + os + ' is not supported', os, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
@ -345,12 +330,12 @@ export async function suppressOutput(os_version: string): Promise<string> {
|
||||
*
|
||||
* @param extension
|
||||
* @param version
|
||||
* @param os_version
|
||||
* @param os
|
||||
*/
|
||||
export async function getUnsupportedLog(
|
||||
extension: string,
|
||||
version: string,
|
||||
os_version: string
|
||||
os: string
|
||||
): Promise<string> {
|
||||
return (
|
||||
'\n' +
|
||||
@ -358,7 +343,7 @@ export async function getUnsupportedLog(
|
||||
'$cross',
|
||||
extension,
|
||||
[extension, 'is not supported on PHP', version].join(' '),
|
||||
os_version
|
||||
os
|
||||
)) +
|
||||
'\n'
|
||||
);
|
||||
@ -367,25 +352,18 @@ export async function getUnsupportedLog(
|
||||
/**
|
||||
* Function to get command to setup tools
|
||||
*
|
||||
* @param os_version
|
||||
* @param os
|
||||
* @param suffix
|
||||
*/
|
||||
export async function getCommand(
|
||||
os_version: string,
|
||||
suffix: string
|
||||
): Promise<string> {
|
||||
switch (os_version) {
|
||||
export async function getCommand(os: string, suffix: string): Promise<string> {
|
||||
switch (os) {
|
||||
case 'linux':
|
||||
case 'darwin':
|
||||
return 'add_' + suffix + ' ';
|
||||
case 'win32':
|
||||
return 'Add-' + suffix.charAt(0).toUpperCase() + suffix.slice(1) + ' ';
|
||||
default:
|
||||
return await log(
|
||||
'Platform ' + os_version + ' is not supported',
|
||||
os_version,
|
||||
'error'
|
||||
);
|
||||
return await log('Platform ' + os + ' is not supported', os, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
@ -401,42 +379,34 @@ export async function joins(...str: string[]): Promise<string> {
|
||||
/**
|
||||
* Function to get script extensions
|
||||
*
|
||||
* @param os_version
|
||||
* @param os
|
||||
*/
|
||||
export async function scriptExtension(os_version: string): Promise<string> {
|
||||
switch (os_version) {
|
||||
export async function scriptExtension(os: string): Promise<string> {
|
||||
switch (os) {
|
||||
case 'win32':
|
||||
return '.ps1';
|
||||
case 'linux':
|
||||
case 'darwin':
|
||||
return '.sh';
|
||||
default:
|
||||
return await log(
|
||||
'Platform ' + os_version + ' is not supported',
|
||||
os_version,
|
||||
'error'
|
||||
);
|
||||
return await log('Platform ' + os + ' is not supported', os, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get script tool
|
||||
*
|
||||
* @param os_version
|
||||
* @param os
|
||||
*/
|
||||
export async function scriptTool(os_version: string): Promise<string> {
|
||||
switch (os_version) {
|
||||
export async function scriptTool(os: string): Promise<string> {
|
||||
switch (os) {
|
||||
case 'win32':
|
||||
return 'pwsh';
|
||||
case 'linux':
|
||||
case 'darwin':
|
||||
return 'bash';
|
||||
default:
|
||||
return await log(
|
||||
'Platform ' + os_version + ' is not supported',
|
||||
os_version,
|
||||
'error'
|
||||
);
|
||||
return await log('Platform ' + os + ' is not supported', os, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
@ -446,21 +416,21 @@ export async function scriptTool(os_version: string): Promise<string> {
|
||||
* @param pkg
|
||||
* @param type
|
||||
* @param version
|
||||
* @param os_version
|
||||
* @param os
|
||||
*/
|
||||
export async function customPackage(
|
||||
pkg: string,
|
||||
type: string,
|
||||
version: string,
|
||||
os_version: string
|
||||
os: string
|
||||
): Promise<string> {
|
||||
const pkg_name: string = pkg.replace(/\d+|(pdo|pecl)[_-]/, '');
|
||||
const script_extension: string = await scriptExtension(os_version);
|
||||
const script_extension: string = await scriptExtension(os);
|
||||
const script: string = path.join(
|
||||
__dirname,
|
||||
'../src/scripts/' + type + '/' + pkg_name + script_extension
|
||||
);
|
||||
const command: string = await getCommand(os_version, pkg_name);
|
||||
const command: string = await getCommand(os, pkg_name);
|
||||
return '\n. ' + script + '\n' + command + version;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user