mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-22 20:01:06 +07:00
Move tools config to tools.json
Refactor tools functions to use Records and object literals
This commit is contained in:
parent
60ff774608
commit
6449431df2
@ -1,333 +1,415 @@
|
|||||||
import * as tools from '../src/tools';
|
import * as tools from '../src/tools';
|
||||||
|
|
||||||
|
function getData(
|
||||||
|
tool: string,
|
||||||
|
version: string,
|
||||||
|
php_version: string,
|
||||||
|
os_version: string
|
||||||
|
): Record<string, string> {
|
||||||
|
return {
|
||||||
|
tool: tool,
|
||||||
|
version: version,
|
||||||
|
extension: '.phar',
|
||||||
|
prefix: 'releases',
|
||||||
|
repository: 'user/tool',
|
||||||
|
version_prefix: '',
|
||||||
|
verb: 'download',
|
||||||
|
php_version: php_version,
|
||||||
|
os_version: os_version,
|
||||||
|
domain: 'https://example.com',
|
||||||
|
github: 'https://github.com'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
describe('Tools tests', () => {
|
describe('Tools tests', () => {
|
||||||
it('checking parseToolVersion', async () => {
|
it('checking getToolVersion', async () => {
|
||||||
expect(await tools.getToolVersion('latest')).toBe('latest');
|
expect(await tools.getToolVersion('tool', 'latest')).toBe('latest');
|
||||||
expect(await tools.getToolVersion('1.2.3')).toBe('1.2.3');
|
expect(await tools.getToolVersion('tool', '1.2.3')).toBe('1.2.3');
|
||||||
expect(await tools.getToolVersion('^1.2.3')).toBe('1.2.3');
|
expect(await tools.getToolVersion('tool', '^1.2.3')).toBe('1.2.3');
|
||||||
expect(await tools.getToolVersion('>=1.2.3')).toBe('1.2.3');
|
expect(await tools.getToolVersion('tool', '>=1.2.3')).toBe('1.2.3');
|
||||||
expect(await tools.getToolVersion('>1.2.3')).toBe('1.2.3');
|
expect(await tools.getToolVersion('tool', '>1.2.3')).toBe('1.2.3');
|
||||||
expect(await tools.getToolVersion('1.2.3-ALPHA')).toBe('1.2.3-ALPHA');
|
expect(await tools.getToolVersion('tool', '1.2.3-ALPHA')).toBe(
|
||||||
expect(await tools.getToolVersion('1.2.3-alpha')).toBe('1.2.3-alpha');
|
'1.2.3-ALPHA'
|
||||||
expect(await tools.getToolVersion('1.2.3-beta')).toBe('1.2.3-beta');
|
);
|
||||||
expect(await tools.getToolVersion('1.2.3-rc')).toBe('1.2.3-rc');
|
expect(await tools.getToolVersion('tool', '1.2.3-alpha')).toBe(
|
||||||
expect(await tools.getToolVersion('1.2.3-dev')).toBe('1.2.3-dev');
|
'1.2.3-alpha'
|
||||||
expect(await tools.getToolVersion('1.2.3-alpha1')).toBe('1.2.3-alpha1');
|
);
|
||||||
expect(await tools.getToolVersion('1.2.3-alpha.1')).toBe('1.2.3-alpha.1');
|
expect(await tools.getToolVersion('tool', '1.2.3-beta')).toBe('1.2.3-beta');
|
||||||
|
expect(await tools.getToolVersion('tool', '1.2.3-rc')).toBe('1.2.3-rc');
|
||||||
|
expect(await tools.getToolVersion('tool', '1.2.3-dev')).toBe('1.2.3-dev');
|
||||||
|
expect(await tools.getToolVersion('tool', '1.2.3-alpha1')).toBe(
|
||||||
|
'1.2.3-alpha1'
|
||||||
|
);
|
||||||
|
expect(await tools.getToolVersion('tool', '1.2.3-alpha.1')).toBe(
|
||||||
|
'1.2.3-alpha.1'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checking parseTool', async () => {
|
it('checking parseRelease', async () => {
|
||||||
expect(await tools.parseTool('phpunit')).toStrictEqual({
|
const data = getData('tool', 'latest', '7.4', 'linux');
|
||||||
name: 'phpunit',
|
expect(await tools.parseRelease('tool', data)).toStrictEqual({
|
||||||
|
release: 'tool',
|
||||||
version: 'latest'
|
version: 'latest'
|
||||||
});
|
});
|
||||||
expect(await tools.parseTool('phpunit:1.2.3')).toStrictEqual({
|
expect(await tools.parseRelease('alias:1.2.3', data)).toStrictEqual({
|
||||||
name: 'phpunit',
|
release: 'tool:1.2.3',
|
||||||
version: '1.2.3'
|
version: '1.2.3'
|
||||||
});
|
});
|
||||||
expect(await tools.parseTool('phpunit:^1.2.3')).toStrictEqual({
|
expect(await tools.parseRelease('tool:1.2.3', data)).toStrictEqual({
|
||||||
name: 'phpunit',
|
release: 'tool:1.2.3',
|
||||||
version: '1.2.3'
|
version: '1.2.3'
|
||||||
});
|
});
|
||||||
expect(await tools.parseTool('phpunit:>=1.2.3')).toStrictEqual({
|
expect(await tools.parseRelease('tool:^1.2.3', data)).toStrictEqual({
|
||||||
name: 'phpunit',
|
release: 'tool:^1.2.3',
|
||||||
version: '1.2.3'
|
version: '1.2.3'
|
||||||
});
|
});
|
||||||
expect(await tools.parseTool('phpunit:>1.2.3')).toStrictEqual({
|
expect(await tools.parseRelease('tool:>=1.2.3', data)).toStrictEqual({
|
||||||
name: 'phpunit',
|
release: 'tool:>=1.2.3',
|
||||||
version: '1.2.3'
|
version: '1.2.3'
|
||||||
});
|
});
|
||||||
expect(await tools.parseTool('phpunit:1.2.3-ALPHA')).toStrictEqual({
|
expect(await tools.parseRelease('tool:>1.2.3', data)).toStrictEqual({
|
||||||
name: 'phpunit',
|
release: 'tool:>1.2.3',
|
||||||
|
version: '1.2.3'
|
||||||
|
});
|
||||||
|
expect(await tools.parseRelease('tool:1.2.3-ALPHA', data)).toStrictEqual({
|
||||||
|
release: 'tool:1.2.3-ALPHA',
|
||||||
version: '1.2.3-ALPHA'
|
version: '1.2.3-ALPHA'
|
||||||
});
|
});
|
||||||
expect(await tools.parseTool('phpunit:1.2.3-alpha')).toStrictEqual({
|
expect(await tools.parseRelease('tool:1.2.3-beta', data)).toStrictEqual({
|
||||||
name: 'phpunit',
|
release: 'tool:1.2.3-beta',
|
||||||
version: '1.2.3-alpha'
|
|
||||||
});
|
|
||||||
expect(await tools.parseTool('phpunit:1.2.3-beta')).toStrictEqual({
|
|
||||||
name: 'phpunit',
|
|
||||||
version: '1.2.3-beta'
|
version: '1.2.3-beta'
|
||||||
});
|
});
|
||||||
expect(await tools.parseTool('phpunit:1.2.3-rc')).toStrictEqual({
|
expect(await tools.parseRelease('tool:1.2.3-rc', data)).toStrictEqual({
|
||||||
name: 'phpunit',
|
release: 'tool:1.2.3-rc',
|
||||||
version: '1.2.3-rc'
|
version: '1.2.3-rc'
|
||||||
});
|
});
|
||||||
expect(await tools.parseTool('phpunit:1.2.3-dev')).toStrictEqual({
|
expect(await tools.parseRelease('tool:1.2.3-dev', data)).toStrictEqual({
|
||||||
name: 'phpunit',
|
release: 'tool:1.2.3-dev',
|
||||||
version: '1.2.3-dev'
|
version: '1.2.3-dev'
|
||||||
});
|
});
|
||||||
expect(await tools.parseTool('phpunit:1.2.3-alpha1')).toStrictEqual({
|
expect(await tools.parseRelease('tool:1.2.3-alpha1', data)).toStrictEqual({
|
||||||
name: 'phpunit',
|
release: 'tool:1.2.3-alpha1',
|
||||||
version: '1.2.3-alpha1'
|
version: '1.2.3-alpha1'
|
||||||
});
|
});
|
||||||
expect(await tools.parseTool('phpunit:1.2.3-alpha.1')).toStrictEqual({
|
expect(await tools.parseRelease('tool:1.2.3-alpha.1', data)).toStrictEqual({
|
||||||
name: 'phpunit',
|
release: 'tool:1.2.3-alpha.1',
|
||||||
version: '1.2.3-alpha.1'
|
version: '1.2.3-alpha.1'
|
||||||
});
|
});
|
||||||
expect(await tools.parseTool('phpunit/phpunit:^1.2.3')).toStrictEqual({
|
expect(await tools.parseRelease('user/tool:^1.2.3', data)).toStrictEqual({
|
||||||
name: 'phpunit/phpunit',
|
release: 'tool:^1.2.3',
|
||||||
version: '^1.2.3'
|
version: '^1.2.3'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checking getUri', async () => {
|
it('checking getUrl', async () => {
|
||||||
expect(
|
const data = getData('tool', 'latest', '7.4', 'linux');
|
||||||
await tools.getUri('tool', '.phar', 'latest', 'releases', '', 'download')
|
expect(await tools.getUrl(data)).toBe(
|
||||||
).toBe('releases/latest/download/tool.phar');
|
'https://example.com/user/tool/releases/latest/download/tool.phar'
|
||||||
expect(
|
);
|
||||||
await tools.getUri('tool', '.phar', '1.2.3', 'releases', '', 'download')
|
data['version'] = '1.2.3';
|
||||||
).toBe('releases/download/1.2.3/tool.phar');
|
expect(await tools.getUrl(data)).toBe(
|
||||||
expect(
|
'https://example.com/user/tool/releases/download/1.2.3/tool.phar'
|
||||||
await tools.getUri('tool', '.phar', '1.2.3', 'releases', 'v', 'download')
|
);
|
||||||
).toBe('releases/download/v1.2.3/tool.phar');
|
data['version_prefix'] = 'v';
|
||||||
|
expect(await tools.getUrl(data)).toBe(
|
||||||
|
'https://example.com/user/tool/releases/download/v1.2.3/tool.phar'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checking addPhive', async () => {
|
it('checking addPhive', async () => {
|
||||||
let script: string = await tools.addPhive('1.2.3', '7.4', 'linux');
|
const data = getData('phive', '1.2.3', '7.4', 'linux');
|
||||||
|
data['domain'] = 'https://phar.io';
|
||||||
|
data['repository'] = 'phar-io/phive';
|
||||||
|
data['version_parameter'] = 'status';
|
||||||
|
|
||||||
|
let script: string = await tools.addPhive(data);
|
||||||
expect(script).toContain(
|
expect(script).toContain(
|
||||||
'add_tool https://github.com/phar-io/phive/releases/download/1.2.3/phive-1.2.3.phar phive'
|
'add_tool https://github.com/phar-io/phive/releases/download/1.2.3/phive-1.2.3.phar phive'
|
||||||
);
|
);
|
||||||
|
|
||||||
script = await tools.addPhive('latest', '5.5', 'win32');
|
data['version'] = 'latest';
|
||||||
|
data['php_version'] = '5.5';
|
||||||
|
data['os_version'] = 'win32';
|
||||||
|
script = await tools.addPhive(data);
|
||||||
expect(script).toContain('Phive is not supported on PHP 5.5');
|
expect(script).toContain('Phive is not supported on PHP 5.5');
|
||||||
|
|
||||||
script = await tools.addPhive('latest', '5.6', 'win32');
|
data['php_version'] = '5.6';
|
||||||
|
script = await tools.addPhive(data);
|
||||||
expect(script).toContain(
|
expect(script).toContain(
|
||||||
'Add-Tool https://github.com/phar-io/phive/releases/download/0.12.1/phive-0.12.1.phar phive'
|
'Add-Tool https://github.com/phar-io/phive/releases/download/0.12.1/phive-0.12.1.phar phive'
|
||||||
);
|
);
|
||||||
|
|
||||||
script = await tools.addPhive('latest', '7.1', 'win32');
|
data['php_version'] = '7.1';
|
||||||
|
data['version'] = 'latest';
|
||||||
|
script = await tools.addPhive(data);
|
||||||
expect(script).toContain(
|
expect(script).toContain(
|
||||||
'Add-Tool https://github.com/phar-io/phive/releases/download/0.13.5/phive-0.13.5.phar phive'
|
'Add-Tool https://github.com/phar-io/phive/releases/download/0.13.5/phive-0.13.5.phar phive'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checking getPharUri', async () => {
|
it('checking getPharUrl', async () => {
|
||||||
expect(await tools.getPharUrl('domain', 'tool', '', 'latest')).toBe(
|
const data = getData('tool', 'latest', '7.4', 'linux');
|
||||||
'domain/tool.phar'
|
data['version_prefix'] = '';
|
||||||
);
|
expect(await tools.getPharUrl(data)).toBe('https://example.com/tool.phar');
|
||||||
expect(await tools.getPharUrl('domain', 'tool', 'v', '1.2.3')).toBe(
|
data['version'] = '1.2.3';
|
||||||
'domain/tool-v1.2.3.phar'
|
data['version_prefix'] = 'v';
|
||||||
|
expect(await tools.getPharUrl(data)).toBe(
|
||||||
|
'https://example.com/tool-v1.2.3.phar'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checking getBlackfirePlayerUrl', async () => {
|
it('checking addBlackfirePlayer', async () => {
|
||||||
expect(await tools.getBlackfirePlayerUrl('latest', '7.4')).toBe(
|
const data = getData('blackfire-player', 'latest', '7.4', 'linux');
|
||||||
|
data['domain'] = 'https://get.blackfire.io';
|
||||||
|
data['version_prefix'] = 'v';
|
||||||
|
expect(await tools.addBlackfirePlayer(data)).toContain(
|
||||||
'https://get.blackfire.io/blackfire-player.phar'
|
'https://get.blackfire.io/blackfire-player.phar'
|
||||||
);
|
);
|
||||||
expect(await tools.getBlackfirePlayerUrl('latest', '5.5')).toBe(
|
data['php_version'] = '5.5';
|
||||||
|
expect(await tools.addBlackfirePlayer(data)).toContain(
|
||||||
'https://get.blackfire.io/blackfire-player-v1.9.3.phar'
|
'https://get.blackfire.io/blackfire-player-v1.9.3.phar'
|
||||||
);
|
);
|
||||||
expect(await tools.getBlackfirePlayerUrl('latest', '7.0')).toBe(
|
data['php_version'] = '7.0';
|
||||||
|
expect(await tools.addBlackfirePlayer(data)).toContain(
|
||||||
'https://get.blackfire.io/blackfire-player-v1.9.3.phar'
|
'https://get.blackfire.io/blackfire-player-v1.9.3.phar'
|
||||||
);
|
);
|
||||||
expect(await tools.getBlackfirePlayerUrl('1.2.3', '7.0')).toBe(
|
data['version'] = '1.2.3';
|
||||||
|
expect(await tools.addBlackfirePlayer(data)).toContain(
|
||||||
'https://get.blackfire.io/blackfire-player-v1.2.3.phar'
|
'https://get.blackfire.io/blackfire-player-v1.2.3.phar'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checking getDeployerUri', async () => {
|
it('checking addDeployer', async () => {
|
||||||
expect(await tools.getDeployerUrl('latest')).toBe(
|
const data = getData('deployer', 'latest', '7.4', 'linux');
|
||||||
|
data['domain'] = 'https://deployer.org';
|
||||||
|
expect(await tools.addDeployer(data)).toContain(
|
||||||
'https://deployer.org/deployer.phar'
|
'https://deployer.org/deployer.phar'
|
||||||
);
|
);
|
||||||
expect(await tools.getDeployerUrl('1.2.3')).toBe(
|
data['version'] = '1.2.3';
|
||||||
|
expect(await tools.addDeployer(data)).toContain(
|
||||||
'https://deployer.org/releases/v1.2.3/deployer.phar'
|
'https://deployer.org/releases/v1.2.3/deployer.phar'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checking addComposer', async () => {
|
it('checking filterList', async () => {
|
||||||
expect(await tools.addComposer(['a', 'b'])).toStrictEqual([
|
expect(await tools.filterList(['a', 'b'])).toStrictEqual([
|
||||||
'composer',
|
'composer',
|
||||||
'a',
|
'a',
|
||||||
'b'
|
'b'
|
||||||
]);
|
]);
|
||||||
expect(await tools.addComposer(['a', 'b', 'composer'])).toStrictEqual([
|
expect(await tools.filterList(['a', 'b', 'composer'])).toStrictEqual([
|
||||||
'composer',
|
'composer',
|
||||||
'a',
|
'a',
|
||||||
'b'
|
'b'
|
||||||
]);
|
]);
|
||||||
expect(await tools.addComposer(['a', 'b', 'composer:1.2'])).toStrictEqual([
|
expect(await tools.filterList(['a', 'b', 'composer:1.2'])).toStrictEqual([
|
||||||
'composer',
|
'composer',
|
||||||
'a',
|
'a',
|
||||||
'b'
|
'b'
|
||||||
]);
|
]);
|
||||||
expect(await tools.addComposer(['a', 'b', 'composer:1.2.3'])).toStrictEqual(
|
expect(await tools.filterList(['a', 'b', 'composer:1.2.3'])).toStrictEqual([
|
||||||
|
'composer:1.2.3',
|
||||||
|
'a',
|
||||||
|
'b'
|
||||||
|
]);
|
||||||
|
expect(await tools.filterList(['a', 'b', 'composer:v1.2.3'])).toStrictEqual(
|
||||||
['composer:1.2.3', 'a', 'b']
|
['composer:1.2.3', 'a', 'b']
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
await tools.addComposer(['a', 'b', 'composer:v1.2.3'])
|
await tools.filterList(['a', 'b', 'composer:snapshot'])
|
||||||
).toStrictEqual(['composer:1.2.3', 'a', 'b']);
|
|
||||||
expect(
|
|
||||||
await tools.addComposer(['a', 'b', 'composer:snapshot'])
|
|
||||||
).toStrictEqual(['composer:snapshot', 'a', 'b']);
|
).toStrictEqual(['composer:snapshot', 'a', 'b']);
|
||||||
expect(
|
expect(
|
||||||
await tools.addComposer(['a', 'b', 'composer:preview'])
|
await tools.filterList(['a', 'b', 'composer:preview'])
|
||||||
).toStrictEqual(['composer:preview', 'a', 'b']);
|
).toStrictEqual(['composer:preview', 'a', 'b']);
|
||||||
|
expect(await tools.filterList(['a', 'b', 'c', 'composer:1'])).toStrictEqual(
|
||||||
|
['composer:1', 'a', 'b', 'c']
|
||||||
|
);
|
||||||
|
expect(await tools.filterList(['a', 'b', 'c', 'composer:2'])).toStrictEqual(
|
||||||
|
['composer:2', 'a', 'b', 'c']
|
||||||
|
);
|
||||||
expect(
|
expect(
|
||||||
await tools.addComposer(['a', 'b', 'c', 'composer:1'])
|
await tools.filterList(['a', 'b', 'c', 'composer:v1'])
|
||||||
).toStrictEqual(['composer:1', 'a', 'b', 'c']);
|
).toStrictEqual(['composer:1', 'a', 'b', 'c']);
|
||||||
expect(
|
expect(
|
||||||
await tools.addComposer(['a', 'b', 'c', 'composer:2'])
|
await tools.filterList(['a', 'b', 'c', 'composer:v2'])
|
||||||
).toStrictEqual(['composer:2', 'a', 'b', 'c']);
|
|
||||||
expect(
|
|
||||||
await tools.addComposer(['a', 'b', 'c', 'composer:v1'])
|
|
||||||
).toStrictEqual(['composer:1', 'a', 'b', 'c']);
|
|
||||||
expect(
|
|
||||||
await tools.addComposer(['a', 'b', 'c', 'composer:v2'])
|
|
||||||
).toStrictEqual(['composer:2', 'a', 'b', 'c']);
|
).toStrictEqual(['composer:2', 'a', 'b', 'c']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checking getComposerUrl', async () => {
|
it('checking addComposer', async () => {
|
||||||
expect(await tools.getComposerUrl('latest')).toContain(
|
const data = getData('composer', 'latest', '7.4', 'linux');
|
||||||
|
data['domain'] = 'https://getcomposer.org';
|
||||||
|
data['repository'] = 'composer/composer';
|
||||||
|
expect(await tools.addComposer(data)).toContain(
|
||||||
'https://getcomposer.org/composer-stable.phar'
|
'https://getcomposer.org/composer-stable.phar'
|
||||||
);
|
);
|
||||||
expect(await tools.getComposerUrl('stable')).toContain(
|
data['version'] = 'stable';
|
||||||
|
expect(await tools.addComposer(data)).toContain(
|
||||||
'https://getcomposer.org/composer-stable.phar'
|
'https://getcomposer.org/composer-stable.phar'
|
||||||
);
|
);
|
||||||
expect(await tools.getComposerUrl('snapshot')).toContain(
|
data['version'] = 'snapshot';
|
||||||
|
expect(await tools.addComposer(data)).toContain(
|
||||||
'https://getcomposer.org/composer.phar'
|
'https://getcomposer.org/composer.phar'
|
||||||
);
|
);
|
||||||
expect(await tools.getComposerUrl('preview')).toContain(
|
data['version'] = 'preview';
|
||||||
|
expect(await tools.addComposer(data)).toContain(
|
||||||
'https://getcomposer.org/composer-preview.phar'
|
'https://getcomposer.org/composer-preview.phar'
|
||||||
);
|
);
|
||||||
expect(await tools.getComposerUrl('1')).toContain(
|
data['version'] = '1';
|
||||||
|
expect(await tools.addComposer(data)).toContain(
|
||||||
'https://getcomposer.org/composer-1.phar'
|
'https://getcomposer.org/composer-1.phar'
|
||||||
);
|
);
|
||||||
expect(await tools.getComposerUrl('2')).toContain(
|
data['version'] = '2';
|
||||||
|
expect(await tools.addComposer(data)).toContain(
|
||||||
'https://getcomposer.org/composer-2.phar'
|
'https://getcomposer.org/composer-2.phar'
|
||||||
);
|
);
|
||||||
expect(await tools.getComposerUrl('1.7.2')).toContain(
|
data['version'] = '1.7.2';
|
||||||
|
expect(await tools.addComposer(data)).toContain(
|
||||||
'https://github.com/composer/composer/releases/download/1.7.2/composer.phar'
|
'https://github.com/composer/composer/releases/download/1.7.2/composer.phar'
|
||||||
);
|
);
|
||||||
expect(await tools.getComposerUrl('1.7.2')).toContain(
|
expect(await tools.addComposer(data)).toContain(
|
||||||
'https://getcomposer.org/composer-1.7.2.phar'
|
'https://getcomposer.org/composer-1.7.2.phar'
|
||||||
);
|
);
|
||||||
expect(await tools.getComposerUrl('2.0.0-RC2')).toContain(
|
data['version'] = '2.0.0-RC2';
|
||||||
|
expect(await tools.addComposer(data)).toContain(
|
||||||
'https://github.com/composer/composer/releases/download/2.0.0-RC2/composer.phar'
|
'https://github.com/composer/composer/releases/download/2.0.0-RC2/composer.phar'
|
||||||
);
|
);
|
||||||
expect(await tools.getComposerUrl('2.0.0-RC2')).toContain(
|
expect(await tools.addComposer(data)).toContain(
|
||||||
'https://getcomposer.org/composer-2.0.0-RC2.phar'
|
'https://getcomposer.org/composer-2.0.0-RC2.phar'
|
||||||
);
|
);
|
||||||
expect(await tools.getComposerUrl('wrong')).toContain(
|
data['version'] = 'wrong';
|
||||||
|
expect(await tools.addComposer(data)).toContain(
|
||||||
'https://getcomposer.org/composer-stable.phar'
|
'https://getcomposer.org/composer-stable.phar'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checking getSymfonyUri', async () => {
|
it('checking addSymfony', async () => {
|
||||||
expect(await tools.getSymfonyUri('latest', 'linux')).toContain(
|
const data = getData('symfony', 'latest', '7.4', 'linux');
|
||||||
|
expect(await tools.addSymfony(data)).toContain(
|
||||||
'releases/latest/download/symfony_linux_amd64'
|
'releases/latest/download/symfony_linux_amd64'
|
||||||
);
|
);
|
||||||
expect(await tools.getSymfonyUri('1.2.3', 'linux')).toContain(
|
data['version'] = '1.2.3';
|
||||||
|
expect(await tools.addSymfony(data)).toContain(
|
||||||
'releases/download/v1.2.3/symfony_linux_amd64'
|
'releases/download/v1.2.3/symfony_linux_amd64'
|
||||||
);
|
);
|
||||||
expect(await tools.getSymfonyUri('latest', 'darwin')).toContain(
|
data['version'] = 'latest';
|
||||||
|
data['os_version'] = 'darwin';
|
||||||
|
expect(await tools.addSymfony(data)).toContain(
|
||||||
'releases/latest/download/symfony_darwin_amd64'
|
'releases/latest/download/symfony_darwin_amd64'
|
||||||
);
|
);
|
||||||
expect(await tools.getSymfonyUri('1.2.3', 'darwin')).toContain(
|
data['version'] = '1.2.3';
|
||||||
|
expect(await tools.addSymfony(data)).toContain(
|
||||||
'releases/download/v1.2.3/symfony_darwin_amd64'
|
'releases/download/v1.2.3/symfony_darwin_amd64'
|
||||||
);
|
);
|
||||||
expect(await tools.getSymfonyUri('latest', 'win32')).toContain(
|
data['version'] = 'latest';
|
||||||
|
data['os_version'] = 'win32';
|
||||||
|
expect(await tools.addSymfony(data)).toContain(
|
||||||
'releases/latest/download/symfony_windows_amd64'
|
'releases/latest/download/symfony_windows_amd64'
|
||||||
);
|
);
|
||||||
expect(await tools.getSymfonyUri('1.2.3', 'win32')).toContain(
|
data['version'] = '1.2.3';
|
||||||
|
expect(await tools.addSymfony(data)).toContain(
|
||||||
'releases/download/v1.2.3/symfony_windows_amd64'
|
'releases/download/v1.2.3/symfony_windows_amd64'
|
||||||
);
|
);
|
||||||
expect(await tools.getSymfonyUri('1.2.3', 'openbsd')).toContain(
|
data['os_version'] = 'openbsd';
|
||||||
|
expect(await tools.addSymfony(data)).toContain(
|
||||||
'Platform openbsd is not supported'
|
'Platform openbsd is not supported'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checking getWpCliUri', async () => {
|
it('checking addWPCLI', async () => {
|
||||||
expect(await tools.getWpCliUrl('latest')).toBe(
|
const data = getData('wp-cli', 'latest', '7.4', 'linux');
|
||||||
|
data['repository'] = 'wp-cli/wp-cli';
|
||||||
|
data['version_prefix'] = 'v';
|
||||||
|
expect(await tools.addWPCLI(data)).toContain(
|
||||||
'wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true'
|
'wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true'
|
||||||
);
|
);
|
||||||
expect(await tools.getWpCliUrl('2.4.0')).toBe(
|
data['version'] = '2.4.0';
|
||||||
|
expect(await tools.addWPCLI(data)).toContain(
|
||||||
'wp-cli/wp-cli/releases/download/v2.4.0/wp-cli-2.4.0.phar'
|
'wp-cli/wp-cli/releases/download/v2.4.0/wp-cli-2.4.0.phar'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checking addArchive', async () => {
|
it('checking addArchive', async () => {
|
||||||
let script: string = await tools.addArchive(
|
const data = getData('tool', 'latest', '7.4', 'linux');
|
||||||
'tool',
|
data['url'] = 'https://example.com/tool.phar';
|
||||||
'https://tool.com/tool.phar',
|
data['version_parameter'] = JSON.stringify('-v');
|
||||||
'linux',
|
let script: string = await tools.addArchive(data);
|
||||||
'-v'
|
expect(script).toContain(
|
||||||
|
'add_tool https://example.com/tool.phar tool "-v"'
|
||||||
);
|
);
|
||||||
expect(script).toContain('add_tool https://tool.com/tool.phar tool');
|
data['os_version'] = 'darwin';
|
||||||
script = await tools.addArchive(
|
script = await tools.addArchive(data);
|
||||||
'tool',
|
expect(script).toContain(
|
||||||
'https://tool.com/tool.phar',
|
'add_tool https://example.com/tool.phar tool "-v"'
|
||||||
'darwin',
|
|
||||||
'-v'
|
|
||||||
);
|
);
|
||||||
expect(script).toContain('add_tool https://tool.com/tool.phar tool');
|
data['os_version'] = 'win32';
|
||||||
script = await tools.addArchive(
|
script = await tools.addArchive(data);
|
||||||
'tool',
|
expect(script).toContain(
|
||||||
'https://tool.com/tool.phar',
|
'Add-Tool https://example.com/tool.phar tool "-v"'
|
||||||
'win32',
|
|
||||||
'-v'
|
|
||||||
);
|
);
|
||||||
expect(script).toContain('Add-Tool https://tool.com/tool.phar tool');
|
|
||||||
|
|
||||||
script = await tools.addArchive(
|
data['os_version'] = 'openbsd';
|
||||||
'tool',
|
script = await tools.addArchive(data);
|
||||||
'https://tool.com/tool.phar',
|
|
||||||
'openbsd',
|
|
||||||
'-v'
|
|
||||||
);
|
|
||||||
expect(script).toContain('Platform openbsd is not supported');
|
expect(script).toContain('Platform openbsd is not supported');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checking addDevTools', async () => {
|
it('checking addDevTools', async () => {
|
||||||
let script: string = await tools.addDevTools('phpize', 'linux');
|
const data = getData('phpize', 'latest', '7.4', 'linux');
|
||||||
|
let script: string = await tools.addDevTools(data);
|
||||||
expect(script).toContain('add_devtools phpize');
|
expect(script).toContain('add_devtools phpize');
|
||||||
|
|
||||||
script = await tools.addDevTools('php-config', 'linux');
|
data['tool'] = 'php-config';
|
||||||
|
script = await tools.addDevTools(data);
|
||||||
expect(script).toContain('add_devtools php-config');
|
expect(script).toContain('add_devtools php-config');
|
||||||
|
|
||||||
script = await tools.addDevTools('phpize', 'darwin');
|
data['tool'] = 'phpize';
|
||||||
|
data['os_version'] = 'darwin';
|
||||||
|
script = await tools.addDevTools(data);
|
||||||
expect(script).toContain('add_devtools phpize');
|
expect(script).toContain('add_devtools phpize');
|
||||||
|
|
||||||
script = await tools.addDevTools('php-config', 'darwin');
|
data['tool'] = 'php-config';
|
||||||
|
script = await tools.addDevTools(data);
|
||||||
expect(script).toContain('add_devtools php-config');
|
expect(script).toContain('add_devtools php-config');
|
||||||
|
|
||||||
script = await tools.addDevTools('phpize', 'win32');
|
data['tool'] = 'phpize';
|
||||||
|
data['os_version'] = 'win32';
|
||||||
|
script = await tools.addDevTools(data);
|
||||||
expect(script).toContain(
|
expect(script).toContain(
|
||||||
'Add-Log "$tick" "phpize" "phpize is not a windows tool"'
|
'Add-Log "$tick" "phpize" "phpize is not a windows tool"'
|
||||||
);
|
);
|
||||||
|
|
||||||
script = await tools.addDevTools('php-config', 'win32');
|
data['tool'] = 'php-config';
|
||||||
|
script = await tools.addDevTools(data);
|
||||||
expect(script).toContain(
|
expect(script).toContain(
|
||||||
'Add-Log "$tick" "php-config" "php-config is not a windows tool"'
|
'Add-Log "$tick" "php-config" "php-config is not a windows tool"'
|
||||||
);
|
);
|
||||||
|
|
||||||
script = await tools.addDevTools('tool', 'openbsd');
|
data['os_version'] = 'openbsd';
|
||||||
|
script = await tools.addDevTools(data);
|
||||||
expect(script).toContain('Platform openbsd is not supported');
|
expect(script).toContain('Platform openbsd is not supported');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checking addPackage', async () => {
|
it('checking addPackage', async () => {
|
||||||
let script: string = await tools.addPackage(
|
const data = getData('tool', '1.2.3', '7.4', 'linux');
|
||||||
'tool',
|
data['release'] = 'tool:1.2.3';
|
||||||
'tool:1.2.3',
|
let script: string = await tools.addPackage(data);
|
||||||
'user/',
|
|
||||||
'linux'
|
|
||||||
);
|
|
||||||
expect(script).toContain('add_composertool tool tool:1.2.3 user/');
|
expect(script).toContain('add_composertool tool tool:1.2.3 user/');
|
||||||
|
|
||||||
script = await tools.addPackage('tool', 'tool:1.2.3', 'user/', 'darwin');
|
data['os_version'] = 'darwin';
|
||||||
|
script = await tools.addPackage(data);
|
||||||
expect(script).toContain('add_composertool tool tool:1.2.3 user/');
|
expect(script).toContain('add_composertool tool tool:1.2.3 user/');
|
||||||
|
|
||||||
script = await tools.addPackage('tool', 'tool:1.2.3', 'user/', 'win32');
|
data['os_version'] = 'win32';
|
||||||
|
script = await tools.addPackage(data);
|
||||||
expect(script).toContain('Add-Composertool tool tool:1.2.3 user/');
|
expect(script).toContain('Add-Composertool tool tool:1.2.3 user/');
|
||||||
|
|
||||||
script = await tools.addPackage('tool', 'tool:1.2.3', 'user/', 'openbsd');
|
data['os_version'] = 'openbsd';
|
||||||
|
script = await tools.addPackage(data);
|
||||||
expect(script).toContain('Platform openbsd is not supported');
|
expect(script).toContain('Platform openbsd is not supported');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checking addTools on linux', async () => {
|
it('checking addTools on linux', async () => {
|
||||||
const script: string = await tools.addTools(
|
const script: string = await tools.addTools(
|
||||||
'blackfire, blackfire-player, cs2pr, flex, grpc_php_plugin, php-cs-fixer, phplint, phpstan, phpunit, pecl, phing, phinx, phinx:1.2.3, phive, php-config, phpize, protoc, symfony, wp-cli',
|
'blackfire, blackfire-player, cs2pr, flex, grpc_php_plugin, php-cs-fixer, phplint, phpstan, phpunit, pecl, phing, phinx, phinx:1.2.3, phive, php-config, phpize, protoc, symfony, vapor, wp',
|
||||||
'7.4',
|
'7.4',
|
||||||
'linux'
|
'linux'
|
||||||
);
|
);
|
||||||
@ -351,13 +433,13 @@ describe('Tools tests', () => {
|
|||||||
'add_tool https://www.phing.info/get/phing-latest.phar phing "-v"'
|
'add_tool https://www.phing.info/get/phing-latest.phar phing "-v"'
|
||||||
);
|
);
|
||||||
expect(script).toContain(
|
expect(script).toContain(
|
||||||
'add_tool https://phar.io/releases/phive.phar phive status'
|
'add_tool https://phar.io/releases/phive.phar phive "status"'
|
||||||
);
|
);
|
||||||
expect(script).toContain(
|
expect(script).toContain(
|
||||||
'add_tool https://phar.phpunit.de/phpunit.phar phpunit "--version"'
|
'add_tool https://phar.phpunit.de/phpunit.phar phpunit "--version"'
|
||||||
);
|
);
|
||||||
expect(script).toContain(
|
expect(script).toContain(
|
||||||
'add_tool https://github.com/symfony/cli/releases/latest/download/symfony_linux_amd64 symfony version'
|
'add_tool https://github.com/symfony/cli/releases/latest/download/symfony_linux_amd64 symfony-cli "version"'
|
||||||
);
|
);
|
||||||
expect(script).toContain(
|
expect(script).toContain(
|
||||||
'add_tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli "--version"'
|
'add_tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli "--version"'
|
||||||
@ -369,6 +451,7 @@ describe('Tools tests', () => {
|
|||||||
expect(script).toContain('add_composertool phinx phinx robmorgan/');
|
expect(script).toContain('add_composertool phinx phinx robmorgan/');
|
||||||
expect(script).toContain('add_composertool phplint phplint overtrue/');
|
expect(script).toContain('add_composertool phplint phplint overtrue/');
|
||||||
expect(script).toContain('add_composertool phinx phinx:1.2.3 robmorgan/');
|
expect(script).toContain('add_composertool phinx phinx:1.2.3 robmorgan/');
|
||||||
|
expect(script).toContain('add_composertool vapor-cli vapor-cli laravel/');
|
||||||
expect(script).toContain('add_devtools php-config');
|
expect(script).toContain('add_devtools php-config');
|
||||||
expect(script).toContain('add_devtools phpize');
|
expect(script).toContain('add_devtools phpize');
|
||||||
});
|
});
|
||||||
@ -467,10 +550,10 @@ describe('Tools tests', () => {
|
|||||||
'add_composertool composer-unused composer-unused icanhazstring/'
|
'add_composertool composer-unused composer-unused icanhazstring/'
|
||||||
);
|
);
|
||||||
expect(script).toContain(
|
expect(script).toContain(
|
||||||
'add_tool https://github.com/symfony/cli/releases/latest/download/symfony_darwin_amd64 symfony version'
|
'add_tool https://github.com/symfony/cli/releases/latest/download/symfony_darwin_amd64 symfony-cli "version"'
|
||||||
);
|
);
|
||||||
expect(script).toContain(
|
expect(script).toContain(
|
||||||
'add_tool https://github.com/symfony/cli/releases/download/v1.2.3/symfony_darwin_amd64 symfony version'
|
'add_tool https://github.com/symfony/cli/releases/download/v1.2.3/symfony_darwin_amd64 symfony-cli "version"'
|
||||||
);
|
);
|
||||||
expect(script).toContain(
|
expect(script).toContain(
|
||||||
'add_tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli "--version"'
|
'add_tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli "--version"'
|
||||||
@ -520,10 +603,10 @@ describe('Tools tests', () => {
|
|||||||
);
|
);
|
||||||
expect(script).toContain('Add-Composertool phinx phinx robmorgan/');
|
expect(script).toContain('Add-Composertool phinx phinx robmorgan/');
|
||||||
expect(script).toContain(
|
expect(script).toContain(
|
||||||
'Add-Tool https://github.com/phar-io/phive/releases/download/0.13.2/phive-0.13.2.phar phive status'
|
'Add-Tool https://github.com/phar-io/phive/releases/download/0.13.2/phive-0.13.2.phar phive "status"'
|
||||||
);
|
);
|
||||||
expect(script).toContain(
|
expect(script).toContain(
|
||||||
'Add-Tool https://github.com/symfony/cli/releases/latest/download/symfony_windows_amd64.exe symfony version'
|
'Add-Tool https://github.com/symfony/cli/releases/latest/download/symfony_windows_amd64.exe symfony-cli "version"'
|
||||||
);
|
);
|
||||||
expect(script).toContain(
|
expect(script).toContain(
|
||||||
'Add-Tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli "--version"'
|
'Add-Tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli "--version"'
|
||||||
|
@ -32,7 +32,7 @@ describe('Utils tests', () => {
|
|||||||
expect(await utils.getInput('test', false)).toBe('setup-php');
|
expect(await utils.getInput('test', false)).toBe('setup-php');
|
||||||
expect(await utils.getInput('setup-php', false)).toBe('setup-php');
|
expect(await utils.getInput('setup-php', false)).toBe('setup-php');
|
||||||
expect(await utils.getInput('DoesNotExist', false)).toBe('');
|
expect(await utils.getInput('DoesNotExist', false)).toBe('');
|
||||||
expect(async () => {
|
await expect(async () => {
|
||||||
await utils.getInput('DoesNotExist', true);
|
await utils.getInput('DoesNotExist', true);
|
||||||
}).rejects.toThrow('Input required and not supplied: DoesNotExist');
|
}).rejects.toThrow('Input required and not supplied: DoesNotExist');
|
||||||
});
|
});
|
||||||
@ -70,7 +70,7 @@ describe('Utils tests', () => {
|
|||||||
expect(await utils.color('warning')).toBe('33');
|
expect(await utils.color('warning')).toBe('33');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checking readScripts', async () => {
|
it('checking readFile', async () => {
|
||||||
const darwin: string = fs.readFileSync(
|
const darwin: string = fs.readFileSync(
|
||||||
path.join(__dirname, '../src/scripts/darwin.sh'),
|
path.join(__dirname, '../src/scripts/darwin.sh'),
|
||||||
'utf8'
|
'utf8'
|
||||||
@ -83,12 +83,12 @@ describe('Utils tests', () => {
|
|||||||
path.join(__dirname, '../src/scripts/win32.ps1'),
|
path.join(__dirname, '../src/scripts/win32.ps1'),
|
||||||
'utf8'
|
'utf8'
|
||||||
);
|
);
|
||||||
expect(await utils.readScript('darwin.sh')).toBe(darwin);
|
expect(await utils.readFile('darwin.sh', 'src/scripts')).toBe(darwin);
|
||||||
expect(await utils.readScript('darwin.sh')).toBe(darwin);
|
expect(await utils.readFile('darwin.sh', 'src/scripts')).toBe(darwin);
|
||||||
expect(await utils.readScript('linux.sh')).toBe(linux);
|
expect(await utils.readFile('linux.sh', 'src/scripts')).toBe(linux);
|
||||||
expect(await utils.readScript('linux.sh')).toBe(linux);
|
expect(await utils.readFile('linux.sh', 'src/scripts')).toBe(linux);
|
||||||
expect(await utils.readScript('win32.ps1')).toBe(win32);
|
expect(await utils.readFile('win32.ps1', 'src/scripts')).toBe(win32);
|
||||||
expect(await utils.readScript('win32.ps1')).toBe(win32);
|
expect(await utils.readFile('win32.ps1', 'src/scripts')).toBe(win32);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checking writeScripts', async () => {
|
it('checking writeScripts', async () => {
|
||||||
|
518
dist/index.js
vendored
518
dist/index.js
vendored
@ -421,7 +421,7 @@ async function getScript(filename, version, os_version) {
|
|||||||
const ini_values_csv = await utils.getInput('ini-values', false);
|
const ini_values_csv = await utils.getInput('ini-values', false);
|
||||||
const coverage_driver = await utils.getInput('coverage', false);
|
const coverage_driver = await utils.getInput('coverage', false);
|
||||||
const tools_csv = await utils.getInput('tools', false);
|
const tools_csv = await utils.getInput('tools', false);
|
||||||
let script = await utils.readScript(filename);
|
let script = await utils.readFile(filename, 'src/scripts');
|
||||||
script += await tools.addTools(tools_csv, version, os_version);
|
script += await tools.addTools(tools_csv, version, os_version);
|
||||||
if (extension_csv) {
|
if (extension_csv) {
|
||||||
script += await extensions.addExtension(extension_csv, version, os_version);
|
script += await extensions.addExtension(extension_csv, version, os_version);
|
||||||
@ -492,9 +492,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.addTools = exports.addPackage = exports.addDevTools = exports.addArchive = exports.getComposerUrl = exports.addComposer = exports.getWpCliUrl = exports.getSymfonyUri = exports.getDeployerUrl = exports.getBlackfirePlayerUrl = exports.getPharUrl = exports.addPhive = exports.getUri = exports.parseTool = exports.getToolVersion = void 0;
|
exports.addTools = exports.initToolData = exports.functionRecord = exports.addWPCLI = exports.addSymfony = exports.addPHPUnitTools = exports.addPhive = exports.addPhing = exports.addPECL = exports.addDevTools = exports.addDeployer = exports.addComposer = exports.addBlackfirePlayer = exports.addPackage = exports.addArchive = exports.getPharUrl = exports.getUrl = exports.filterList = exports.parseRelease = exports.getToolVersion = void 0;
|
||||||
const utils = __importStar(__nccwpck_require__(918));
|
const utils = __importStar(__nccwpck_require__(918));
|
||||||
async function getToolVersion(version) {
|
async function getToolVersion(tool, version) {
|
||||||
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-]+)*))?$/;
|
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-]+)*))?$/;
|
||||||
const composer_regex = /^stable$|^preview$|^snapshot$|^v?[1|2]$/;
|
const composer_regex = /^stable$|^preview$|^snapshot$|^v?[1|2]$/;
|
||||||
version = version.replace(/[><=^]*/, '').replace(/^v(\d)/, '$1');
|
version = version.replace(/[><=^]*/, '').replace(/^v(\d)/, '$1');
|
||||||
@ -507,128 +507,36 @@ async function getToolVersion(version) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.getToolVersion = getToolVersion;
|
exports.getToolVersion = getToolVersion;
|
||||||
async function parseTool(release) {
|
async function parseRelease(release, data) {
|
||||||
const parts = release.split(':');
|
const parts = release.split(':');
|
||||||
const tool = parts[0];
|
const tool = parts[0];
|
||||||
const version = parts[1];
|
const version = parts[1];
|
||||||
|
release = release.includes('/')
|
||||||
|
? release.split('/')[1].replace(/\s+/, '')
|
||||||
|
: release;
|
||||||
|
release = release.includes(':')
|
||||||
|
? [data['tool'], release.split(':')[1]].join(':')
|
||||||
|
: data['tool'];
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case version === undefined:
|
case version === undefined:
|
||||||
return {
|
return {
|
||||||
name: tool,
|
release: release,
|
||||||
version: 'latest'
|
version: 'latest'
|
||||||
};
|
};
|
||||||
case /^[\w.-]+\/[\w.-]+$/.test(tool):
|
case /^[\w.-]+\/[\w.-]+$/.test(tool):
|
||||||
return {
|
return {
|
||||||
name: tool,
|
release: release,
|
||||||
version: version
|
version: version
|
||||||
};
|
};
|
||||||
default:
|
default:
|
||||||
return {
|
return {
|
||||||
name: tool,
|
release: release,
|
||||||
version: await getToolVersion(parts[1])
|
version: await getToolVersion(parts[0], parts[1])
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.parseTool = parseTool;
|
exports.parseRelease = parseRelease;
|
||||||
async function getUri(tool, extension, version, prefix, version_prefix, verb) {
|
async function filterList(tools_list) {
|
||||||
switch (version) {
|
|
||||||
case 'latest':
|
|
||||||
return [prefix, version, verb, tool + extension]
|
|
||||||
.filter(Boolean)
|
|
||||||
.join('/');
|
|
||||||
default:
|
|
||||||
return [prefix, verb, version_prefix + version, tool + extension]
|
|
||||||
.filter(Boolean)
|
|
||||||
.join('/');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.getUri = getUri;
|
|
||||||
async function addPhive(version, php_version, os_version) {
|
|
||||||
switch (true) {
|
|
||||||
case /5\.[3-5]/.test(php_version):
|
|
||||||
return await utils.addLog('$cross', 'phive', 'Phive is not supported on PHP ' + php_version, os_version);
|
|
||||||
case /5\.6|7\.0/.test(php_version):
|
|
||||||
version = version.replace('latest', '0.12.1');
|
|
||||||
break;
|
|
||||||
case /7\.1/.test(php_version):
|
|
||||||
version = version.replace('latest', '0.13.5');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
switch (version) {
|
|
||||||
case 'latest':
|
|
||||||
return ((await utils.getCommand(os_version, 'tool')) +
|
|
||||||
'https://phar.io/releases/phive.phar phive status');
|
|
||||||
default:
|
|
||||||
return ((await utils.getCommand(os_version, 'tool')) +
|
|
||||||
'https://github.com/phar-io/phive/releases/download/' +
|
|
||||||
version +
|
|
||||||
'/phive-' +
|
|
||||||
version +
|
|
||||||
'.phar phive status');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.addPhive = addPhive;
|
|
||||||
async function getPharUrl(domain, tool, prefix, version) {
|
|
||||||
switch (version) {
|
|
||||||
case 'latest':
|
|
||||||
return domain + '/' + tool + '.phar';
|
|
||||||
default:
|
|
||||||
return domain + '/' + tool + '-' + prefix + version + '.phar';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.getPharUrl = getPharUrl;
|
|
||||||
async function getBlackfirePlayerUrl(version, php_version) {
|
|
||||||
switch (true) {
|
|
||||||
case /5\.[5-6]|7\.0/.test(php_version) && version == 'latest':
|
|
||||||
version = '1.9.3';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return await getPharUrl('https://get.blackfire.io', 'blackfire-player', 'v', version);
|
|
||||||
}
|
|
||||||
exports.getBlackfirePlayerUrl = getBlackfirePlayerUrl;
|
|
||||||
async function getDeployerUrl(version) {
|
|
||||||
const deployer = 'https://deployer.org';
|
|
||||||
switch (version) {
|
|
||||||
case 'latest':
|
|
||||||
return deployer + '/deployer.phar';
|
|
||||||
default:
|
|
||||||
return deployer + '/releases/v' + version + '/deployer.phar';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.getDeployerUrl = getDeployerUrl;
|
|
||||||
async function getSymfonyUri(version, os_version) {
|
|
||||||
let filename = '';
|
|
||||||
switch (os_version) {
|
|
||||||
case 'linux':
|
|
||||||
case 'darwin':
|
|
||||||
filename = 'symfony_' + os_version + '_amd64';
|
|
||||||
break;
|
|
||||||
case 'win32':
|
|
||||||
filename = 'symfony_windows_amd64.exe';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return await utils.log('Platform ' + os_version + ' is not supported', os_version, 'error');
|
|
||||||
}
|
|
||||||
switch (version) {
|
|
||||||
case 'latest':
|
|
||||||
return 'releases/latest/download/' + filename;
|
|
||||||
default:
|
|
||||||
return 'releases/download/v' + version + '/' + filename;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.getSymfonyUri = getSymfonyUri;
|
|
||||||
async function getWpCliUrl(version) {
|
|
||||||
switch (version) {
|
|
||||||
case 'latest':
|
|
||||||
return 'wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true';
|
|
||||||
default:
|
|
||||||
return await getUri('wp-cli', '-' + version + '.phar', version, 'wp-cli/wp-cli/releases', 'v', 'download');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.getWpCliUrl = getWpCliUrl;
|
|
||||||
async function addComposer(tools_list) {
|
|
||||||
const regex_any = /^composer($|:.*)/;
|
const regex_any = /^composer($|:.*)/;
|
||||||
const regex_valid = /^composer:?($|preview$|snapshot$|v?[1-2]$|v?\d+\.\d+\.\d+[\w-]*$)/;
|
const regex_valid = /^composer:?($|preview$|snapshot$|v?[1-2]$|v?\d+\.\d+\.\d+[\w-]*$)/;
|
||||||
const matches = tools_list.filter(tool => regex_valid.test(tool));
|
const matches = tools_list.filter(tool => regex_valid.test(tool));
|
||||||
@ -644,44 +552,219 @@ async function addComposer(tools_list) {
|
|||||||
tools_list.unshift(composer);
|
tools_list.unshift(composer);
|
||||||
return tools_list;
|
return tools_list;
|
||||||
}
|
}
|
||||||
exports.addComposer = addComposer;
|
exports.filterList = filterList;
|
||||||
async function getComposerUrl(version) {
|
async function getUrl(data) {
|
||||||
let cache_url = `https://github.com/shivammathur/composer-cache/releases/latest/download/composer-${version.replace('latest', 'stable')}.phar`;
|
if (data['version'] === 'latest') {
|
||||||
switch (true) {
|
return [
|
||||||
case /^snapshot$/.test(version):
|
data['domain'],
|
||||||
return `${cache_url},https://getcomposer.org/composer.phar`;
|
data['repository'],
|
||||||
case /^preview$|^[1-2]$/.test(version):
|
data['prefix'],
|
||||||
return `${cache_url},https://getcomposer.org/composer-${version}.phar`;
|
data['version'],
|
||||||
case /^\d+\.\d+\.\d+[\w-]*$/.test(version):
|
data['verb'],
|
||||||
cache_url = `https://github.com/composer/composer/releases/download/${version}/composer.phar`;
|
data['tool'] + data['extension']
|
||||||
return `${cache_url},https://getcomposer.org/composer-${version}.phar`;
|
]
|
||||||
default:
|
.filter(Boolean)
|
||||||
return `${cache_url},https://getcomposer.org/composer-stable.phar`;
|
.join('/');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return [
|
||||||
|
data['domain'],
|
||||||
|
data['repository'],
|
||||||
|
data['prefix'],
|
||||||
|
data['verb'],
|
||||||
|
data['version_prefix'] + data['version'],
|
||||||
|
data['tool'] + data['extension']
|
||||||
|
]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join('/');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.getComposerUrl = getComposerUrl;
|
exports.getUrl = getUrl;
|
||||||
async function addArchive(tool, url, os_version, ver_param) {
|
async function getPharUrl(data) {
|
||||||
return ((await utils.getCommand(os_version, 'tool')) +
|
if (data['version'] === 'latest') {
|
||||||
(await utils.joins(url, tool, ver_param)));
|
return data['domain'] + '/' + data['tool'] + '.phar';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return (data['domain'] +
|
||||||
|
'/' +
|
||||||
|
data['tool'] +
|
||||||
|
'-' +
|
||||||
|
data['version_prefix'] +
|
||||||
|
data['version'] +
|
||||||
|
'.phar');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.getPharUrl = getPharUrl;
|
||||||
|
async function addArchive(data) {
|
||||||
|
return ((await utils.getCommand(data['os_version'], 'tool')) +
|
||||||
|
(await utils.joins(data['url'], data['tool'], data['version_parameter'])));
|
||||||
}
|
}
|
||||||
exports.addArchive = addArchive;
|
exports.addArchive = addArchive;
|
||||||
async function addDevTools(tool, os_version) {
|
async function addPackage(data) {
|
||||||
switch (os_version) {
|
const command = await utils.getCommand(data['os_version'], 'composertool');
|
||||||
|
const parts = data['repository'].split('/');
|
||||||
|
return command + parts[1] + ' ' + data['release'] + ' ' + parts[0] + '/';
|
||||||
|
}
|
||||||
|
exports.addPackage = addPackage;
|
||||||
|
async function addBlackfirePlayer(data) {
|
||||||
|
if (/5\.[5-6]|7\.0/.test(data['php_version']) &&
|
||||||
|
data['version'] == 'latest') {
|
||||||
|
data['version'] = '1.9.3';
|
||||||
|
}
|
||||||
|
data['url'] = await getPharUrl(data);
|
||||||
|
return addArchive(data);
|
||||||
|
}
|
||||||
|
exports.addBlackfirePlayer = addBlackfirePlayer;
|
||||||
|
async function addComposer(data) {
|
||||||
|
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`;
|
||||||
|
switch (true) {
|
||||||
|
case /^snapshot$/.test(data['version']):
|
||||||
|
break;
|
||||||
|
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`;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
source_url = `${getcomposer}/composer-stable.phar`;
|
||||||
|
}
|
||||||
|
data['url'] = `${cache_url},${source_url}`;
|
||||||
|
data['version_parameter'] = data['version'];
|
||||||
|
return await addArchive(data);
|
||||||
|
}
|
||||||
|
exports.addComposer = addComposer;
|
||||||
|
async function addDeployer(data) {
|
||||||
|
if (data['version'] === 'latest') {
|
||||||
|
data['url'] = data['domain'] + '/deployer.phar';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
data['url'] =
|
||||||
|
data['domain'] + '/releases/v' + data['version'] + '/deployer.phar';
|
||||||
|
}
|
||||||
|
return await addArchive(data);
|
||||||
|
}
|
||||||
|
exports.addDeployer = addDeployer;
|
||||||
|
async function addDevTools(data) {
|
||||||
|
switch (data['os_version']) {
|
||||||
case 'linux':
|
case 'linux':
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
return 'add_devtools ' + tool;
|
return 'add_devtools ' + data['tool'];
|
||||||
case 'win32':
|
case 'win32':
|
||||||
return await utils.addLog('$tick', tool, tool + ' is not a windows tool', 'win32');
|
return await utils.addLog('$tick', data['tool'], data['tool'] + ' is not a windows tool', 'win32');
|
||||||
default:
|
default:
|
||||||
return await utils.log('Platform ' + os_version + ' is not supported', os_version, 'error');
|
return await utils.log('Platform ' + data['os_version'] + ' is not supported', data['os_version'], 'error');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.addDevTools = addDevTools;
|
exports.addDevTools = addDevTools;
|
||||||
async function addPackage(tool, release, prefix, os_version) {
|
async function addPECL(data) {
|
||||||
const tool_command = await utils.getCommand(os_version, 'composertool');
|
return await utils.getCommand(data['os_version'], 'pecl');
|
||||||
return tool_command + tool + ' ' + release + ' ' + prefix;
|
|
||||||
}
|
}
|
||||||
exports.addPackage = addPackage;
|
exports.addPECL = addPECL;
|
||||||
|
async function addPhing(data) {
|
||||||
|
data['url'] =
|
||||||
|
data['domain'] + '/get/phing-' + data['version'] + data['extension'];
|
||||||
|
return await addArchive(data);
|
||||||
|
}
|
||||||
|
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']);
|
||||||
|
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('/');
|
||||||
|
}
|
||||||
|
data['url'] = await getPharUrl(data);
|
||||||
|
return await addArchive(data);
|
||||||
|
}
|
||||||
|
exports.addPhive = addPhive;
|
||||||
|
async function addPHPUnitTools(data) {
|
||||||
|
data['url'] = await getPharUrl(data);
|
||||||
|
return await addArchive(data);
|
||||||
|
}
|
||||||
|
exports.addPHPUnitTools = addPHPUnitTools;
|
||||||
|
async function addSymfony(data) {
|
||||||
|
let filename;
|
||||||
|
switch (data['os_version']) {
|
||||||
|
case 'linux':
|
||||||
|
case 'darwin':
|
||||||
|
filename = 'symfony_' + data['os_version'] + '_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');
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
exports.addSymfony = addSymfony;
|
||||||
|
async function addWPCLI(data) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
exports.addWPCLI = addWPCLI;
|
||||||
|
exports.functionRecord = {
|
||||||
|
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
|
||||||
|
};
|
||||||
|
async function initToolData(data, release, php_version, os_version) {
|
||||||
|
const release_data = 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;
|
||||||
|
}
|
||||||
|
exports.initToolData = initToolData;
|
||||||
async function addTools(tools_csv, php_version, os_version) {
|
async function addTools(tools_csv, php_version, os_version) {
|
||||||
let script = '\n';
|
let script = '\n';
|
||||||
if (tools_csv === 'none') {
|
if (tools_csv === 'none') {
|
||||||
@ -690,135 +773,29 @@ async function addTools(tools_csv, php_version, os_version) {
|
|||||||
else {
|
else {
|
||||||
script += await utils.stepLog('Setup Tools', os_version);
|
script += await utils.stepLog('Setup Tools', os_version);
|
||||||
}
|
}
|
||||||
const tools_list = await addComposer(await utils.CSVArray(tools_csv));
|
const tools_list = await filterList(await utils.CSVArray(tools_csv));
|
||||||
await utils.asyncForEach(tools_list, async function (release) {
|
await utils.asyncForEach(tools_list, async function (release) {
|
||||||
const tool_data = await parseTool(release);
|
const data = await initToolData(await utils.getToolData(release.split(':')[0]), release, php_version, os_version);
|
||||||
const tool = tool_data.name;
|
|
||||||
const version = tool_data.version;
|
|
||||||
const github = 'https://github.com/';
|
|
||||||
let uri = await getUri(tool, '.phar', version, 'releases', '', 'download');
|
|
||||||
script += '\n';
|
script += '\n';
|
||||||
let url = '';
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case /^blackfire(-agent)?$/.test(tool):
|
case 'phar' === data['type']:
|
||||||
script += await utils.customPackage('blackfire', 'tools', version, os_version);
|
data['url'] = await getUrl(data);
|
||||||
|
script += await addArchive(data);
|
||||||
break;
|
break;
|
||||||
case /^grpc_php_plugin$|^protoc$/.test(tool):
|
case 'composer' === data['type']:
|
||||||
script += await utils.customPackage(tool, 'tools', version, os_version);
|
case /^[\w.-]+\/[\w.-]+$/.test(data['tool']):
|
||||||
|
script += await addPackage(data);
|
||||||
break;
|
break;
|
||||||
case /^behat$|^codeception$|^phpspec$/.test(tool):
|
case 'custom-package' === data['type']:
|
||||||
script += await addPackage(tool, release, tool + '/', os_version);
|
script += await utils.customPackage(data['tool'].split('-')[0], 'tools', data['version'], data['os_version']);
|
||||||
break;
|
break;
|
||||||
case /^blackfire-player$/.test(tool):
|
case 'custom-function' === data['type']:
|
||||||
url = await getBlackfirePlayerUrl(version, php_version);
|
script += await exports.functionRecord[data['function']](data);
|
||||||
script += await addArchive(tool, url, os_version, '"-V"');
|
|
||||||
break;
|
break;
|
||||||
case /^composer$/.test(tool):
|
case /^none$/.test(data['tool']):
|
||||||
url = await getComposerUrl(version);
|
|
||||||
script += await addArchive('composer', url, os_version, version);
|
|
||||||
break;
|
|
||||||
case /^composer-normalize$/.test(tool):
|
|
||||||
uri = await getUri(tool, '.phar', version, 'releases', '', 'download');
|
|
||||||
url = github + 'ergebnis/composer-normalize/' + uri;
|
|
||||||
script += await addArchive(tool, url, os_version, '"-V"');
|
|
||||||
break;
|
|
||||||
case /^composer-prefetcher$/.test(tool):
|
|
||||||
script += await addPackage('automatic-' + tool, release, 'narrowspark/', os_version);
|
|
||||||
break;
|
|
||||||
case /^composer-require-checker$/.test(tool):
|
|
||||||
uri = await getUri(tool, '.phar', version, 'releases', '', 'download');
|
|
||||||
url = github + 'maglnet/ComposerRequireChecker/' + uri;
|
|
||||||
script += await addArchive(tool, url, os_version, '"-V"');
|
|
||||||
break;
|
|
||||||
case /^composer-unused$/.test(tool):
|
|
||||||
script += await addPackage(tool, release, 'icanhazstring/', os_version);
|
|
||||||
break;
|
|
||||||
case /^cs2pr$/.test(tool):
|
|
||||||
uri = await getUri(tool, '', version, 'releases', '', 'download');
|
|
||||||
url = github + 'staabm/annotate-pull-request-from-checkstyle/' + uri;
|
|
||||||
script += await addArchive(tool, url, os_version, '"-V"');
|
|
||||||
break;
|
|
||||||
case /^deployer$/.test(tool):
|
|
||||||
url = await getDeployerUrl(version);
|
|
||||||
script += await addArchive(tool, url, os_version, '"-V"');
|
|
||||||
break;
|
|
||||||
case /^flex$/.test(tool):
|
|
||||||
script += await addPackage(tool, release, 'symfony/', os_version);
|
|
||||||
break;
|
|
||||||
case /^infection$/.test(tool):
|
|
||||||
url = github + 'infection/infection/' + uri;
|
|
||||||
script += await addArchive(tool, url, os_version, '"-V"');
|
|
||||||
break;
|
|
||||||
case /^pecl/.test(tool):
|
|
||||||
script += await utils.getCommand(os_version, 'pecl');
|
|
||||||
break;
|
|
||||||
case /^phan$/.test(tool):
|
|
||||||
url = github + 'phan/phan/' + uri;
|
|
||||||
script += await addArchive(tool, url, os_version, '"-v"');
|
|
||||||
break;
|
|
||||||
case /^phing$/.test(tool):
|
|
||||||
url = 'https://www.phing.info/get/phing-' + version + '.phar';
|
|
||||||
script += await addArchive(tool, url, os_version, '"-v"');
|
|
||||||
break;
|
|
||||||
case /^phinx$/.test(tool):
|
|
||||||
script += await addPackage(tool, release, 'robmorgan/', os_version);
|
|
||||||
break;
|
|
||||||
case /^phive$/.test(tool):
|
|
||||||
script += await addPhive(version, php_version, os_version);
|
|
||||||
break;
|
|
||||||
case /^php(-config|ize)$/.test(tool):
|
|
||||||
script += await addDevTools(tool, os_version);
|
|
||||||
break;
|
|
||||||
case /^php-cs-fixer$/.test(tool):
|
|
||||||
uri = await getUri(tool, '.phar', version, 'releases', 'v', 'download');
|
|
||||||
url = github + 'FriendsOfPHP/PHP-CS-Fixer/' + uri;
|
|
||||||
script += await addArchive(tool, url, os_version, '"-V"');
|
|
||||||
break;
|
|
||||||
case /^php(cbf|cs)$/.test(tool):
|
|
||||||
url = github + 'squizlabs/PHP_CodeSniffer/' + uri;
|
|
||||||
script += await addArchive(tool, url, os_version, '"--version"');
|
|
||||||
break;
|
|
||||||
case /^php(cpd|unit)$/.test(tool):
|
|
||||||
url = await getPharUrl('https://phar.phpunit.de', tool, '', version);
|
|
||||||
script += await addArchive(tool, url, os_version, '"--version"');
|
|
||||||
break;
|
|
||||||
case /^phplint$/.test(tool):
|
|
||||||
script += await addPackage(tool, release, 'overtrue/', os_version);
|
|
||||||
break;
|
|
||||||
case /^phpmd$/.test(tool):
|
|
||||||
url = github + 'phpmd/phpmd/' + uri;
|
|
||||||
script += await addArchive(tool, url, os_version, '"--version"');
|
|
||||||
break;
|
|
||||||
case /^phpstan$/.test(tool):
|
|
||||||
url = github + 'phpstan/phpstan/' + uri;
|
|
||||||
script += await addArchive(tool, url, os_version, '"-V"');
|
|
||||||
break;
|
|
||||||
case /^prestissimo$/.test(tool):
|
|
||||||
script += await addPackage(tool, release, 'hirak/', os_version);
|
|
||||||
break;
|
|
||||||
case /^psalm$/.test(tool):
|
|
||||||
url = github + 'vimeo/psalm/' + uri;
|
|
||||||
script += await addArchive(tool, url, os_version, '"-v"');
|
|
||||||
break;
|
|
||||||
case /^symfony(-cli)?$/.test(tool):
|
|
||||||
uri = await getSymfonyUri(version, os_version);
|
|
||||||
url = github + 'symfony/cli/' + uri;
|
|
||||||
script += await addArchive('symfony', url, os_version, 'version');
|
|
||||||
break;
|
|
||||||
case /^vapor(-cli)?$/.test(tool):
|
|
||||||
script += await addPackage('vapor-cli', release, 'laravel/', os_version);
|
|
||||||
break;
|
|
||||||
case /^wp(-cli)?$/.test(tool):
|
|
||||||
url = github + (await getWpCliUrl(version));
|
|
||||||
script += await addArchive('wp-cli', url, os_version, '"--version"');
|
|
||||||
break;
|
|
||||||
case /^none$/.test(tool):
|
|
||||||
break;
|
|
||||||
case /^[\w.-]+\/[\w.-]+$/.test(tool):
|
|
||||||
script += await addPackage(tool.split('/')[1], release.split('/')[1].replace(/\s+/, ''), tool.split('/')[0] + '/', os_version);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
script += await utils.addLog('$cross', tool, 'Tool ' + tool + ' is not supported', os_version);
|
script += await utils.addLog('$cross', data['tool'], 'Tool ' + data['tool'] + ' is not supported', os_version);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -853,7 +830,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.parseExtensionSource = exports.customPackage = exports.scriptTool = 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.fetch = exports.getInput = exports.readEnv = void 0;
|
exports.parseExtensionSource = exports.customPackage = exports.scriptTool = exports.scriptExtension = exports.joins = exports.getCommand = exports.getUnsupportedLog = exports.suppressOutput = exports.getExtensionPrefix = exports.CSVArray = exports.extensionArray = exports.getToolData = exports.writeScript = exports.readFile = exports.addLog = exports.stepLog = exports.log = exports.color = exports.asyncForEach = exports.parseVersion = exports.fetch = exports.getInput = exports.readEnv = void 0;
|
||||||
const fs = __importStar(__nccwpck_require__(747));
|
const fs = __importStar(__nccwpck_require__(747));
|
||||||
const https = __importStar(__nccwpck_require__(211));
|
const https = __importStar(__nccwpck_require__(211));
|
||||||
const path = __importStar(__nccwpck_require__(622));
|
const path = __importStar(__nccwpck_require__(622));
|
||||||
@ -968,10 +945,10 @@ async function addLog(mark, subject, message, os_version) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.addLog = addLog;
|
exports.addLog = addLog;
|
||||||
async function readScript(filename) {
|
async function readFile(filename, directory) {
|
||||||
return fs.readFileSync(path.join(__dirname, '../src/scripts/' + filename), 'utf8');
|
return fs.readFileSync(path.join(__dirname, '../' + directory, filename), 'utf8');
|
||||||
}
|
}
|
||||||
exports.readScript = readScript;
|
exports.readFile = readFile;
|
||||||
async function writeScript(filename, script) {
|
async function writeScript(filename, script) {
|
||||||
const runner_dir = await getInput('RUNNER_TOOL_CACHE', false);
|
const runner_dir = await getInput('RUNNER_TOOL_CACHE', false);
|
||||||
const script_path = path.join(runner_dir, filename);
|
const script_path = path.join(runner_dir, filename);
|
||||||
@ -979,6 +956,31 @@ async function writeScript(filename, script) {
|
|||||||
return script_path;
|
return script_path;
|
||||||
}
|
}
|
||||||
exports.writeScript = writeScript;
|
exports.writeScript = writeScript;
|
||||||
|
async function getToolData(tool) {
|
||||||
|
const tools_json = await readFile('tools.json', 'src/configs');
|
||||||
|
const json_data = JSON.parse(tools_json);
|
||||||
|
let tool_data;
|
||||||
|
const tools = Object.keys(json_data);
|
||||||
|
if (tools.includes(tool)) {
|
||||||
|
tool_data = json_data[tool];
|
||||||
|
tool_data['tool'] = tool;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const tool_key = Object.keys(json_data).find((key) => {
|
||||||
|
return (json_data[key]['alias'] == tool ||
|
||||||
|
json_data[key]['repository'] == tool);
|
||||||
|
});
|
||||||
|
if (tool_key) {
|
||||||
|
tool_data = json_data[tool_key];
|
||||||
|
tool_data['tool'] = tool_key;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tool_data = { tool: tool };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tool_data;
|
||||||
|
}
|
||||||
|
exports.getToolData = getToolData;
|
||||||
async function extensionArray(extension_csv) {
|
async function extensionArray(extension_csv) {
|
||||||
switch (extension_csv) {
|
switch (extension_csv) {
|
||||||
case '':
|
case '':
|
||||||
|
234
src/configs/tools.json
Normal file
234
src/configs/tools.json
Normal file
@ -0,0 +1,234 @@
|
|||||||
|
{
|
||||||
|
"composer-normalize": {
|
||||||
|
"type": "phar",
|
||||||
|
"repository": "ergebnis/composer-normalize",
|
||||||
|
"extension": ".phar",
|
||||||
|
"domain": "https://github.com",
|
||||||
|
"version_prefix": "",
|
||||||
|
"version_parameter": "-V"
|
||||||
|
},
|
||||||
|
"composer-require-checker": {
|
||||||
|
"type": "phar",
|
||||||
|
"repository": "maglnet/ComposerRequireChecker",
|
||||||
|
"extension": ".phar",
|
||||||
|
"domain": "https://github.com",
|
||||||
|
"version_prefix": "",
|
||||||
|
"version_parameter": "-V"
|
||||||
|
},
|
||||||
|
"cs2pr": {
|
||||||
|
"type": "phar",
|
||||||
|
"repository": "staabm/annotate-pull-request-from-checkstyle",
|
||||||
|
"extension": "",
|
||||||
|
"domain": "https://github.com",
|
||||||
|
"version_prefix": "",
|
||||||
|
"version_parameter": "-V"
|
||||||
|
},
|
||||||
|
"infection": {
|
||||||
|
"type": "phar",
|
||||||
|
"repository": "infection/infection",
|
||||||
|
"extension": ".phar",
|
||||||
|
"domain": "https://github.com",
|
||||||
|
"version_prefix": "",
|
||||||
|
"version_parameter": "-V"
|
||||||
|
},
|
||||||
|
"phan": {
|
||||||
|
"type": "phar",
|
||||||
|
"repository": "phan/phan",
|
||||||
|
"extension": ".phar",
|
||||||
|
"domain": "https://github.com",
|
||||||
|
"version_prefix": "",
|
||||||
|
"version_parameter": "-v"
|
||||||
|
},
|
||||||
|
"php-cs-fixer": {
|
||||||
|
"type": "phar",
|
||||||
|
"repository": "FriendsOfPHP/PHP-CS-Fixer",
|
||||||
|
"extension": ".phar",
|
||||||
|
"domain": "https://github.com",
|
||||||
|
"version_prefix": "v",
|
||||||
|
"version_parameter": "-V"
|
||||||
|
},
|
||||||
|
"phpcbf": {
|
||||||
|
"type": "phar",
|
||||||
|
"repository": "squizlabs/PHP_CodeSniffer",
|
||||||
|
"extension": ".phar",
|
||||||
|
"domain": "https://github.com",
|
||||||
|
"version_prefix": "",
|
||||||
|
"version_parameter": "--version"
|
||||||
|
},
|
||||||
|
"phpcs": {
|
||||||
|
"type": "phar",
|
||||||
|
"repository": "squizlabs/PHP_CodeSniffer",
|
||||||
|
"extension": ".phar",
|
||||||
|
"domain": "https://github.com",
|
||||||
|
"version_prefix": "",
|
||||||
|
"version_parameter": "--version"
|
||||||
|
},
|
||||||
|
"phpmd": {
|
||||||
|
"type": "phar",
|
||||||
|
"repository": "phpmd/phpmd",
|
||||||
|
"extension": ".phar",
|
||||||
|
"domain": "https://github.com",
|
||||||
|
"version_prefix": "",
|
||||||
|
"version_parameter": "--version"
|
||||||
|
},
|
||||||
|
"phpstan": {
|
||||||
|
"type": "phar",
|
||||||
|
"repository": "phpstan/phpstan",
|
||||||
|
"extension": ".phar",
|
||||||
|
"domain": "https://github.com",
|
||||||
|
"version_prefix": "",
|
||||||
|
"version_parameter": "-V"
|
||||||
|
},
|
||||||
|
"psalm": {
|
||||||
|
"type": "phar",
|
||||||
|
"repository": "vimeo/psalm",
|
||||||
|
"extension": ".phar",
|
||||||
|
"domain": "https://github.com",
|
||||||
|
"version_prefix": "",
|
||||||
|
"version_parameter": "-v"
|
||||||
|
},
|
||||||
|
"behat": {
|
||||||
|
"type": "composer",
|
||||||
|
"repository": "behat/behat"
|
||||||
|
},
|
||||||
|
"codeception": {
|
||||||
|
"type": "composer",
|
||||||
|
"repository": "codeception/codeception"
|
||||||
|
},
|
||||||
|
"automatic-composer-prefetcher": {
|
||||||
|
"type": "composer",
|
||||||
|
"alias": "composer-prefetcher",
|
||||||
|
"repository": "narrowspark/automatic-composer-prefetcher"
|
||||||
|
},
|
||||||
|
"composer-unused": {
|
||||||
|
"type": "composer",
|
||||||
|
"repository": "icanhazstring/composer-unused"
|
||||||
|
},
|
||||||
|
"flex": {
|
||||||
|
"type": "composer",
|
||||||
|
"repository": "symfony/flex"
|
||||||
|
},
|
||||||
|
"phinx": {
|
||||||
|
"type": "composer",
|
||||||
|
"repository": "robmorgan/phinx"
|
||||||
|
},
|
||||||
|
"phplint": {
|
||||||
|
"type": "composer",
|
||||||
|
"repository": "overtrue/phplint"
|
||||||
|
},
|
||||||
|
"phpspec": {
|
||||||
|
"type": "composer",
|
||||||
|
"repository": "phpspec/phpspec"
|
||||||
|
},
|
||||||
|
"prestissimo": {
|
||||||
|
"type": "composer",
|
||||||
|
"repository": "hirak/prestissimo"
|
||||||
|
},
|
||||||
|
"vapor-cli": {
|
||||||
|
"type": "composer",
|
||||||
|
"alias": "vapor",
|
||||||
|
"repository": "laravel/vapor-cli"
|
||||||
|
},
|
||||||
|
"blackfire": {
|
||||||
|
"type": "custom-package",
|
||||||
|
"alias": "blackfire-agent"
|
||||||
|
},
|
||||||
|
"grpc_php_plugin": {
|
||||||
|
"type": "custom-package",
|
||||||
|
"repository": "grpc/grpc",
|
||||||
|
"domain": "https://github.com",
|
||||||
|
"version_prefix": "v"
|
||||||
|
},
|
||||||
|
"protoc": {
|
||||||
|
"type": "custom-package",
|
||||||
|
"repository": "protocolbuffers/protobuf",
|
||||||
|
"domain": "https://github.com",
|
||||||
|
"version_prefix": "v"
|
||||||
|
},
|
||||||
|
"blackfire-player": {
|
||||||
|
"type": "custom-function",
|
||||||
|
"domain": "https://get.blackfire.io",
|
||||||
|
"function": "blackfire_player",
|
||||||
|
"version_prefix": "v",
|
||||||
|
"version_parameter": "-V"
|
||||||
|
},
|
||||||
|
"composer": {
|
||||||
|
"type": "custom-function",
|
||||||
|
"domain": "https://getcomposer.org",
|
||||||
|
"repository": "composer/composer",
|
||||||
|
"function": "composer"
|
||||||
|
},
|
||||||
|
"deployer": {
|
||||||
|
"type": "custom-function",
|
||||||
|
"domain": "https://deployer.org",
|
||||||
|
"repository": "deployphp/deployer",
|
||||||
|
"function": "deployer",
|
||||||
|
"version_prefix": "v",
|
||||||
|
"version_parameter": "-V"
|
||||||
|
},
|
||||||
|
"pecl": {
|
||||||
|
"type": "custom-function",
|
||||||
|
"function": "pecl"
|
||||||
|
},
|
||||||
|
"phing": {
|
||||||
|
"type": "custom-function",
|
||||||
|
"domain": "https://www.phing.info",
|
||||||
|
"repository": "phingofficial/phing",
|
||||||
|
"function": "phing",
|
||||||
|
"extension": ".phar",
|
||||||
|
"version_prefix": "",
|
||||||
|
"version_parameter": "-v"
|
||||||
|
},
|
||||||
|
"phive": {
|
||||||
|
"type": "custom-function",
|
||||||
|
"repository": "phar-io/phive",
|
||||||
|
"domain": "https://phar.io",
|
||||||
|
"function": "phive",
|
||||||
|
"version_prefix": "",
|
||||||
|
"version_parameter": "status"
|
||||||
|
},
|
||||||
|
"phpcpd": {
|
||||||
|
"type": "custom-function",
|
||||||
|
"repository": "sebastianbergmann/phpcpd",
|
||||||
|
"domain": "https://phar.phpunit.de",
|
||||||
|
"function": "phpcpd",
|
||||||
|
"version_prefix": "",
|
||||||
|
"version_parameter": "--version"
|
||||||
|
},
|
||||||
|
"phpunit": {
|
||||||
|
"type": "custom-function",
|
||||||
|
"repository": "sebastianbergmann/phpunit",
|
||||||
|
"domain": "https://phar.phpunit.de",
|
||||||
|
"function": "phpcpd",
|
||||||
|
"version_prefix": "",
|
||||||
|
"version_parameter": "--version"
|
||||||
|
},
|
||||||
|
"phpize": {
|
||||||
|
"type": "custom-function",
|
||||||
|
"function": "dev_tools",
|
||||||
|
"alias": "php-config"
|
||||||
|
},
|
||||||
|
"php-config": {
|
||||||
|
"type": "custom-function",
|
||||||
|
"function": "dev_tools"
|
||||||
|
},
|
||||||
|
"symfony-cli": {
|
||||||
|
"type": "custom-function",
|
||||||
|
"function": "symfony",
|
||||||
|
"alias": "symfony",
|
||||||
|
"domain": "https://github.com",
|
||||||
|
"repository": "symfony/cli",
|
||||||
|
"version_prefix": "v",
|
||||||
|
"version_parameter": "version"
|
||||||
|
},
|
||||||
|
"wp-cli": {
|
||||||
|
"type": "custom-function",
|
||||||
|
"function": "wp_cli",
|
||||||
|
"repository": "wp-cli/wp-cli",
|
||||||
|
"domain": "https://github.com",
|
||||||
|
"alias": "wp",
|
||||||
|
"extension": ".phar",
|
||||||
|
"version_parameter": "--version",
|
||||||
|
"version_prefix": "v"
|
||||||
|
}
|
||||||
|
}
|
104
src/configs/tools_schema.json
Normal file
104
src/configs/tools_schema.json
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||||
|
"$id": "https://raw.githubusercontent.com/shivammathur/setup-php/develop/src/configs/tools_schema.json",
|
||||||
|
"type": "object",
|
||||||
|
"title": "Tools",
|
||||||
|
"default": {},
|
||||||
|
"examples": [
|
||||||
|
{
|
||||||
|
"tool": {
|
||||||
|
"alias": "tool_alias",
|
||||||
|
"domain": "https://example.com",
|
||||||
|
"extension": ".ext",
|
||||||
|
"function": "function_name",
|
||||||
|
"repository": "user/tool",
|
||||||
|
"type": "phar, composer, custom-package or custom-function",
|
||||||
|
"version_parameter": "--version",
|
||||||
|
"version_prefix": "v"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"items": {
|
||||||
|
"properties": {
|
||||||
|
"alias": {
|
||||||
|
"$id": "#/items/properties/alias",
|
||||||
|
"type": "string",
|
||||||
|
"title": "The alias schema",
|
||||||
|
"description": "Alias for a tool.",
|
||||||
|
"examples": [
|
||||||
|
"tool_alias"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"domain": {
|
||||||
|
"$id": "#/items/properties/domain",
|
||||||
|
"type": "string",
|
||||||
|
"title": "The domain schema",
|
||||||
|
"description": "Domain URL of the tool.",
|
||||||
|
"examples": [
|
||||||
|
"https://example.com"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"extension": {
|
||||||
|
"$id": "#/items/properties/extension",
|
||||||
|
"type": "string",
|
||||||
|
"title": "The extension schema",
|
||||||
|
"description": "File extension of the tool.",
|
||||||
|
"examples": [
|
||||||
|
".ext"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"function": {
|
||||||
|
"$id": "#/items/properties/function",
|
||||||
|
"type": "string",
|
||||||
|
"title": "The function schema",
|
||||||
|
"description": "Function name in tools.ts which returns the script to setup the tool.",
|
||||||
|
"examples": [
|
||||||
|
"function_name"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"$id": "#/items/properties/repository",
|
||||||
|
"type": "string",
|
||||||
|
"title": "The repository schema",
|
||||||
|
"description": "GitHub repository of the tool.",
|
||||||
|
"examples": [
|
||||||
|
"user/tool"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"$id": "#/items/properties/type",
|
||||||
|
"type": "string",
|
||||||
|
"title": "The type schema",
|
||||||
|
"description": "Type of tool: phar, composer, custom-package or custom-function.",
|
||||||
|
"enum": [
|
||||||
|
"phar",
|
||||||
|
"composer",
|
||||||
|
"custom-package",
|
||||||
|
"custom-function"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"version_parameter": {
|
||||||
|
"$id": "#/items/properties/version_parameter",
|
||||||
|
"type": "string",
|
||||||
|
"title": "The version_parameter schema",
|
||||||
|
"description": "Parameter to get the tool version.",
|
||||||
|
"examples": [
|
||||||
|
"--version"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"version_prefix": {
|
||||||
|
"$id": "#/items/properties/version_prefix",
|
||||||
|
"type": "string",
|
||||||
|
"title": "The version_prefix schema",
|
||||||
|
"description": "Prefix of the version in the download URL.",
|
||||||
|
"examples": [
|
||||||
|
"v"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"type"
|
||||||
|
],
|
||||||
|
"additionalProperties": true
|
||||||
|
}
|
||||||
|
}
|
@ -27,7 +27,7 @@ export async function getScript(
|
|||||||
const coverage_driver: string = await utils.getInput('coverage', false);
|
const coverage_driver: string = await utils.getInput('coverage', false);
|
||||||
const tools_csv: string = await utils.getInput('tools', false);
|
const tools_csv: string = await utils.getInput('tools', false);
|
||||||
|
|
||||||
let script: string = await utils.readScript(filename);
|
let script: string = await utils.readFile(filename, 'src/scripts');
|
||||||
script += await tools.addTools(tools_csv, version, os_version);
|
script += await tools.addTools(tools_csv, version, os_version);
|
||||||
|
|
||||||
if (extension_csv) {
|
if (extension_csv) {
|
||||||
|
@ -15,10 +15,10 @@ Function Add-ToolsHelper() {
|
|||||||
Add-Extension ast >$null 2>&1
|
Add-Extension ast >$null 2>&1
|
||||||
} elseif($tool -eq "phive") {
|
} elseif($tool -eq "phive") {
|
||||||
Add-Extension xml >$null 2>&1
|
Add-Extension xml >$null 2>&1
|
||||||
} elseif($tool -eq "symfony") {
|
} elseif($tool -eq "symfony-cli") {
|
||||||
Add-ToProfile $current_profile "symfony" "New-Alias symfony $bin_dir\$tool.exe"
|
Add-ToProfile $current_profile "symfony" "New-Alias symfony $bin_dir\symfony-cli.exe"
|
||||||
Add-ToProfile $current_profile "symfony-cli" "New-Alias symfony-cli $bin_dir\$tool.exe"
|
Add-ToProfile $current_profile "symfony_cli" "New-Alias symfony-cli $bin_dir\symfony-cli.exe"
|
||||||
} elseif($tool -eq "vapor-cli") {
|
} elseif($tool -match "vapor-cli") {
|
||||||
Copy-Item $composer_bin\vapor.bat -Destination $composer_bin\vapor-cli.bat
|
Copy-Item $composer_bin\vapor.bat -Destination $composer_bin\vapor-cli.bat
|
||||||
} elseif($tool -eq "wp-cli") {
|
} elseif($tool -eq "wp-cli") {
|
||||||
Copy-Item $bin_dir\wp-cli.bat -Destination $bin_dir\wp.bat
|
Copy-Item $bin_dir\wp-cli.bat -Destination $bin_dir\wp.bat
|
||||||
|
@ -14,11 +14,7 @@ add_tools_helper() {
|
|||||||
add_extension curl extension >/dev/null 2>&1
|
add_extension curl extension >/dev/null 2>&1
|
||||||
add_extension mbstring extension >/dev/null 2>&1
|
add_extension mbstring extension >/dev/null 2>&1
|
||||||
add_extension xml extension >/dev/null 2>&1
|
add_extension xml extension >/dev/null 2>&1
|
||||||
elif [ "$tool" = "symfony" ]; then
|
elif [[ "$tool" =~ (symfony|vapor|wp)-cli ]]; then
|
||||||
sudo ln -s "${tool_path:?}" "${tool_path_dir:?}"/symfony-cli
|
sudo ln -s "${tool_path:?}" "${tool_path_dir:?}"/${tool%-*}
|
||||||
elif [ "$tool" = "vapor-cli" ]; then
|
|
||||||
sudo ln -s "${tool_path:?}" "${tool_path_dir:?}"/vapor-cli
|
|
||||||
elif [ "$tool" = "wp-cli" ]; then
|
|
||||||
sudo ln -s "${tool_path:?}" "${tool_path_dir:?}"/wp
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
@ -302,8 +302,8 @@ Function Add-Tool() {
|
|||||||
$bat_content += "SET BIN_TARGET=%~dp0/" + $tool
|
$bat_content += "SET BIN_TARGET=%~dp0/" + $tool
|
||||||
$bat_content += "php %BIN_TARGET% %*"
|
$bat_content += "php %BIN_TARGET% %*"
|
||||||
Set-Content -Path $bin_dir\$tool.bat -Value $bat_content
|
Set-Content -Path $bin_dir\$tool.bat -Value $bat_content
|
||||||
Add-ToProfile $current_profile $tool "New-Alias $tool $bin_dir\$tool.bat" >$null 2>&1
|
|
||||||
Add-ToolsHelper $tool
|
Add-ToolsHelper $tool
|
||||||
|
Add-ToProfile $current_profile $tool "New-Alias $tool $bin_dir\$tool.bat" >$null 2>&1
|
||||||
$tool_version = Get-ToolVersion $tool $ver_param
|
$tool_version = Get-ToolVersion $tool $ver_param
|
||||||
Add-Log $tick $tool "Added $tool $tool_version"
|
Add-Log $tick $tool "Added $tool $tool_version"
|
||||||
} else {
|
} else {
|
||||||
|
738
src/tools.ts
738
src/tools.ts
@ -3,9 +3,13 @@ import * as utils from './utils';
|
|||||||
/**
|
/**
|
||||||
* Function to get tool version
|
* Function to get tool version
|
||||||
*
|
*
|
||||||
|
* @param tool
|
||||||
* @param version
|
* @param version
|
||||||
*/
|
*/
|
||||||
export async function getToolVersion(version: string): Promise<string> {
|
export async function getToolVersion(
|
||||||
|
tool: string,
|
||||||
|
version: string
|
||||||
|
): Promise<string> {
|
||||||
// semver_regex - https://semver.org/
|
// semver_regex - https://semver.org/
|
||||||
const semver_regex =
|
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-]+)*))?$/;
|
/^(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-]+)*))?$/;
|
||||||
@ -21,233 +25,49 @@ export async function getToolVersion(version: string): Promise<string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to parse tool:version
|
* Function to parse the release tool:version
|
||||||
*
|
*
|
||||||
* @param release
|
* @param release
|
||||||
|
* @param data
|
||||||
*/
|
*/
|
||||||
export async function parseTool(
|
export async function parseRelease(
|
||||||
release: string
|
release: string,
|
||||||
): Promise<{name: string; version: string}> {
|
data: Record<string, string>
|
||||||
|
): Promise<{version: string; release: string}> {
|
||||||
const parts: string[] = release.split(':');
|
const parts: string[] = release.split(':');
|
||||||
const tool: string = parts[0];
|
const tool: string = parts[0];
|
||||||
const version: string | undefined = parts[1];
|
const version: string | undefined = parts[1];
|
||||||
|
release = release.includes('/')
|
||||||
|
? release.split('/')[1].replace(/\s+/, '')
|
||||||
|
: release;
|
||||||
|
release = release.includes(':')
|
||||||
|
? [data['tool'], release.split(':')[1]].join(':')
|
||||||
|
: data['tool'];
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case version === undefined:
|
case version === undefined:
|
||||||
return {
|
return {
|
||||||
name: tool,
|
release: release,
|
||||||
version: 'latest'
|
version: 'latest'
|
||||||
};
|
};
|
||||||
case /^[\w.-]+\/[\w.-]+$/.test(tool):
|
case /^[\w.-]+\/[\w.-]+$/.test(tool):
|
||||||
return {
|
return {
|
||||||
name: tool,
|
release: release,
|
||||||
version: version
|
version: version
|
||||||
};
|
};
|
||||||
default:
|
default:
|
||||||
return {
|
return {
|
||||||
name: tool,
|
release: release,
|
||||||
version: await getToolVersion(parts[1])
|
version: await getToolVersion(parts[0], parts[1])
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Function to get the url of tool with the given version
|
|
||||||
*
|
|
||||||
* @param tool
|
|
||||||
* @param extension
|
|
||||||
* @param version
|
|
||||||
* @param prefix
|
|
||||||
* @param version_prefix
|
|
||||||
* @param verb
|
|
||||||
*/
|
|
||||||
export async function getUri(
|
|
||||||
tool: string,
|
|
||||||
extension: string,
|
|
||||||
version: string,
|
|
||||||
prefix: string,
|
|
||||||
version_prefix: string,
|
|
||||||
verb: string
|
|
||||||
): Promise<string> {
|
|
||||||
switch (version) {
|
|
||||||
case 'latest':
|
|
||||||
return [prefix, version, verb, tool + extension]
|
|
||||||
.filter(Boolean)
|
|
||||||
.join('/');
|
|
||||||
default:
|
|
||||||
return [prefix, verb, version_prefix + version, tool + extension]
|
|
||||||
.filter(Boolean)
|
|
||||||
.join('/');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function to get script to setup phive
|
|
||||||
*
|
|
||||||
* @param version
|
|
||||||
* @param php_version
|
|
||||||
* @param os_version
|
|
||||||
*/
|
|
||||||
export async function addPhive(
|
|
||||||
version: string,
|
|
||||||
php_version: string,
|
|
||||||
os_version: string
|
|
||||||
): Promise<string> {
|
|
||||||
switch (true) {
|
|
||||||
case /5\.[3-5]/.test(php_version):
|
|
||||||
return await utils.addLog(
|
|
||||||
'$cross',
|
|
||||||
'phive',
|
|
||||||
'Phive is not supported on PHP ' + php_version,
|
|
||||||
os_version
|
|
||||||
);
|
|
||||||
case /5\.6|7\.0/.test(php_version):
|
|
||||||
version = version.replace('latest', '0.12.1');
|
|
||||||
break;
|
|
||||||
case /7\.1/.test(php_version):
|
|
||||||
version = version.replace('latest', '0.13.5');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
switch (version) {
|
|
||||||
case 'latest':
|
|
||||||
return (
|
|
||||||
(await utils.getCommand(os_version, 'tool')) +
|
|
||||||
'https://phar.io/releases/phive.phar phive status'
|
|
||||||
);
|
|
||||||
default:
|
|
||||||
return (
|
|
||||||
(await utils.getCommand(os_version, 'tool')) +
|
|
||||||
'https://github.com/phar-io/phive/releases/download/' +
|
|
||||||
version +
|
|
||||||
'/phive-' +
|
|
||||||
version +
|
|
||||||
'.phar phive status'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function to get the phar url in domain/tool-version.phar format
|
|
||||||
*
|
|
||||||
* @param domain
|
|
||||||
* @param tool
|
|
||||||
* @param prefix
|
|
||||||
* @param version
|
|
||||||
*/
|
|
||||||
export async function getPharUrl(
|
|
||||||
domain: string,
|
|
||||||
tool: string,
|
|
||||||
prefix: string,
|
|
||||||
version: string
|
|
||||||
): Promise<string> {
|
|
||||||
switch (version) {
|
|
||||||
case 'latest':
|
|
||||||
return domain + '/' + tool + '.phar';
|
|
||||||
default:
|
|
||||||
return domain + '/' + tool + '-' + prefix + version + '.phar';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function to get blackfire player url for a PHP version.
|
|
||||||
*
|
|
||||||
* @param version
|
|
||||||
* @param php_version
|
|
||||||
*/
|
|
||||||
export async function getBlackfirePlayerUrl(
|
|
||||||
version: string,
|
|
||||||
php_version: string
|
|
||||||
): Promise<string> {
|
|
||||||
switch (true) {
|
|
||||||
case /5\.[5-6]|7\.0/.test(php_version) && version == 'latest':
|
|
||||||
version = '1.9.3';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return await getPharUrl(
|
|
||||||
'https://get.blackfire.io',
|
|
||||||
'blackfire-player',
|
|
||||||
'v',
|
|
||||||
version
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function to get the Deployer url
|
|
||||||
*
|
|
||||||
* @param version
|
|
||||||
*/
|
|
||||||
export async function getDeployerUrl(version: string): Promise<string> {
|
|
||||||
const deployer = 'https://deployer.org';
|
|
||||||
switch (version) {
|
|
||||||
case 'latest':
|
|
||||||
return deployer + '/deployer.phar';
|
|
||||||
default:
|
|
||||||
return deployer + '/releases/v' + version + '/deployer.phar';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function to get the Deployer url
|
|
||||||
*
|
|
||||||
* @param version
|
|
||||||
* @param os_version
|
|
||||||
*/
|
|
||||||
export async function getSymfonyUri(
|
|
||||||
version: string,
|
|
||||||
os_version: string
|
|
||||||
): Promise<string> {
|
|
||||||
let filename = '';
|
|
||||||
switch (os_version) {
|
|
||||||
case 'linux':
|
|
||||||
case 'darwin':
|
|
||||||
filename = 'symfony_' + os_version + '_amd64';
|
|
||||||
break;
|
|
||||||
case 'win32':
|
|
||||||
filename = 'symfony_windows_amd64.exe';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return await utils.log(
|
|
||||||
'Platform ' + os_version + ' is not supported',
|
|
||||||
os_version,
|
|
||||||
'error'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
switch (version) {
|
|
||||||
case 'latest':
|
|
||||||
return 'releases/latest/download/' + filename;
|
|
||||||
default:
|
|
||||||
return 'releases/download/v' + version + '/' + filename;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function to get the WP-CLI url
|
|
||||||
*
|
|
||||||
* @param version
|
|
||||||
*/
|
|
||||||
export async function getWpCliUrl(version: string): Promise<string> {
|
|
||||||
switch (version) {
|
|
||||||
case 'latest':
|
|
||||||
return 'wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true';
|
|
||||||
default:
|
|
||||||
return await getUri(
|
|
||||||
'wp-cli',
|
|
||||||
'-' + version + '.phar',
|
|
||||||
version,
|
|
||||||
'wp-cli/wp-cli/releases',
|
|
||||||
'v',
|
|
||||||
'download'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to add/move composer in the tools list
|
* Function to add/move composer in the tools list
|
||||||
*
|
*
|
||||||
* @param tools_list
|
* @param tools_list
|
||||||
*/
|
*/
|
||||||
export async function addComposer(tools_list: string[]): Promise<string[]> {
|
export async function filterList(tools_list: string[]): Promise<string[]> {
|
||||||
const regex_any = /^composer($|:.*)/;
|
const regex_any = /^composer($|:.*)/;
|
||||||
const regex_valid =
|
const regex_valid =
|
||||||
/^composer:?($|preview$|snapshot$|v?[1-2]$|v?\d+\.\d+\.\d+[\w-]*$)/;
|
/^composer:?($|preview$|snapshot$|v?[1-2]$|v?\d+\.\d+\.\d+[\w-]*$)/;
|
||||||
@ -266,94 +86,345 @@ export async function addComposer(tools_list: string[]): Promise<string[]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to get composer URL for a given version
|
* Function to get the url of tool with the given version
|
||||||
*
|
*
|
||||||
* @param version
|
* @param data
|
||||||
*/
|
*/
|
||||||
export async function getComposerUrl(version: string): Promise<string> {
|
export async function getUrl(data: Record<string, string>): Promise<string> {
|
||||||
let cache_url = `https://github.com/shivammathur/composer-cache/releases/latest/download/composer-${version.replace(
|
if (data['version'] === 'latest') {
|
||||||
'latest',
|
return [
|
||||||
'stable'
|
data['domain'],
|
||||||
)}.phar`;
|
data['repository'],
|
||||||
switch (true) {
|
data['prefix'],
|
||||||
case /^snapshot$/.test(version):
|
data['version'],
|
||||||
return `${cache_url},https://getcomposer.org/composer.phar`;
|
data['verb'],
|
||||||
case /^preview$|^[1-2]$/.test(version):
|
data['tool'] + data['extension']
|
||||||
return `${cache_url},https://getcomposer.org/composer-${version}.phar`;
|
]
|
||||||
case /^\d+\.\d+\.\d+[\w-]*$/.test(version):
|
.filter(Boolean)
|
||||||
cache_url = `https://github.com/composer/composer/releases/download/${version}/composer.phar`;
|
.join('/');
|
||||||
return `${cache_url},https://getcomposer.org/composer-${version}.phar`;
|
} else {
|
||||||
default:
|
return [
|
||||||
return `${cache_url},https://getcomposer.org/composer-stable.phar`;
|
data['domain'],
|
||||||
|
data['repository'],
|
||||||
|
data['prefix'],
|
||||||
|
data['verb'],
|
||||||
|
data['version_prefix'] + data['version'],
|
||||||
|
data['tool'] + data['extension']
|
||||||
|
]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join('/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to get the phar url in domain/tool-version.phar format
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
export async function getPharUrl(
|
||||||
|
data: Record<string, string>
|
||||||
|
): Promise<string> {
|
||||||
|
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
|
* Helper function to get script to setup a tool using a phar url
|
||||||
*
|
*
|
||||||
* @param tool
|
* @param data
|
||||||
* @param url
|
|
||||||
* @param os_version
|
|
||||||
* @param ver_param
|
|
||||||
*/
|
*/
|
||||||
export async function addArchive(
|
export async function addArchive(
|
||||||
tool: string,
|
data: Record<string, string>
|
||||||
url: string,
|
|
||||||
os_version: string,
|
|
||||||
ver_param: string
|
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
return (
|
return (
|
||||||
(await utils.getCommand(os_version, 'tool')) +
|
(await utils.getCommand(data['os_version'], 'tool')) +
|
||||||
(await utils.joins(url, tool, ver_param))
|
(await utils.joins(data['url'], data['tool'], data['version_parameter']))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to get the script to setup php-config and phpize
|
* Helper function to get script to setup a tool using composer
|
||||||
*
|
*
|
||||||
* @param tool
|
* @param data
|
||||||
* @param os_version
|
*/
|
||||||
|
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';
|
||||||
|
}
|
||||||
|
data['url'] = await getPharUrl(data);
|
||||||
|
return addArchive(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to add composer
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
export async function addComposer(
|
||||||
|
data: Record<string, string>
|
||||||
|
): Promise<string> {
|
||||||
|
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`;
|
||||||
|
switch (true) {
|
||||||
|
case /^snapshot$/.test(data['version']):
|
||||||
|
break;
|
||||||
|
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`;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
source_url = `${getcomposer}/composer-stable.phar`;
|
||||||
|
}
|
||||||
|
data['url'] = `${cache_url},${source_url}`;
|
||||||
|
data['version_parameter'] = data['version'];
|
||||||
|
return await addArchive(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to add Deployer
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
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';
|
||||||
|
}
|
||||||
|
return await addArchive(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to add php-config and phpize
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
*/
|
*/
|
||||||
export async function addDevTools(
|
export async function addDevTools(
|
||||||
tool: string,
|
data: Record<string, string>
|
||||||
os_version: string
|
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
switch (os_version) {
|
switch (data['os_version']) {
|
||||||
case 'linux':
|
case 'linux':
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
return 'add_devtools ' + tool;
|
return 'add_devtools ' + data['tool'];
|
||||||
case 'win32':
|
case 'win32':
|
||||||
return await utils.addLog(
|
return await utils.addLog(
|
||||||
'$tick',
|
'$tick',
|
||||||
tool,
|
data['tool'],
|
||||||
tool + ' is not a windows tool',
|
data['tool'] + ' is not a windows tool',
|
||||||
'win32'
|
'win32'
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
return await utils.log(
|
return await utils.log(
|
||||||
'Platform ' + os_version + ' is not supported',
|
'Platform ' + data['os_version'] + ' is not supported',
|
||||||
os_version,
|
data['os_version'],
|
||||||
'error'
|
'error'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to get script to setup a tool using composer
|
* Function to add PECL
|
||||||
*
|
*
|
||||||
* @param tool
|
* @param data
|
||||||
|
*/
|
||||||
|
export async function addPECL(data: Record<string, string>): Promise<string> {
|
||||||
|
return await utils.getCommand(data['os_version'], 'pecl');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to add Phing
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
export async function addPhing(data: Record<string, string>): Promise<string> {
|
||||||
|
data['url'] =
|
||||||
|
data['domain'] + '/get/phing-' + data['version'] + data['extension'];
|
||||||
|
return await addArchive(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to add Phive
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
export async function addPhive(data: Record<string, string>): Promise<string> {
|
||||||
|
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']
|
||||||
|
);
|
||||||
|
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('/');
|
||||||
|
}
|
||||||
|
data['url'] = await getPharUrl(data);
|
||||||
|
return await addArchive(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to add PHPUnit and related tools
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
export async function addPHPUnitTools(
|
||||||
|
data: Record<string, string>
|
||||||
|
): Promise<string> {
|
||||||
|
data['url'] = await getPharUrl(data);
|
||||||
|
return await addArchive(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to add Symfony
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
export async function addSymfony(
|
||||||
|
data: Record<string, string>
|
||||||
|
): Promise<string> {
|
||||||
|
let filename: string;
|
||||||
|
switch (data['os_version']) {
|
||||||
|
case 'linux':
|
||||||
|
case 'darwin':
|
||||||
|
filename = 'symfony_' + data['os_version'] + '_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'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to add WP-CLI
|
||||||
|
*
|
||||||
|
* @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
|
||||||
* @param release
|
* @param release
|
||||||
* @param prefix
|
* @param php_version
|
||||||
* @param os_version
|
* @param os_version
|
||||||
*/
|
*/
|
||||||
export async function addPackage(
|
export async function initToolData(
|
||||||
tool: string,
|
data: Record<string, string>,
|
||||||
release: string,
|
release: string,
|
||||||
prefix: string,
|
php_version: string,
|
||||||
os_version: string
|
os_version: string
|
||||||
): Promise<string> {
|
): Promise<Record<string, string>> {
|
||||||
const tool_command = await utils.getCommand(os_version, 'composertool');
|
const release_data: {release: string; version: string} = await parseRelease(
|
||||||
return tool_command + tool + ' ' + release + ' ' + prefix;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -374,165 +445,42 @@ export async function addTools(
|
|||||||
} else {
|
} else {
|
||||||
script += await utils.stepLog('Setup Tools', os_version);
|
script += await utils.stepLog('Setup Tools', os_version);
|
||||||
}
|
}
|
||||||
const tools_list = await addComposer(await utils.CSVArray(tools_csv));
|
const tools_list = await filterList(await utils.CSVArray(tools_csv));
|
||||||
await utils.asyncForEach(tools_list, async function (release: string) {
|
await utils.asyncForEach(tools_list, async function (release: string) {
|
||||||
const tool_data: {name: string; version: string} = await parseTool(release);
|
const data: Record<string, string> = await initToolData(
|
||||||
const tool: string = tool_data.name;
|
await utils.getToolData(release.split(':')[0]),
|
||||||
const version: string = tool_data.version;
|
release,
|
||||||
const github = 'https://github.com/';
|
php_version,
|
||||||
let uri: string = await getUri(
|
os_version
|
||||||
tool,
|
|
||||||
'.phar',
|
|
||||||
version,
|
|
||||||
'releases',
|
|
||||||
'',
|
|
||||||
'download'
|
|
||||||
);
|
);
|
||||||
script += '\n';
|
script += '\n';
|
||||||
let url = '';
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case /^blackfire(-agent)?$/.test(tool):
|
case 'phar' === data['type']:
|
||||||
|
data['url'] = await getUrl(data);
|
||||||
|
script += await addArchive(data);
|
||||||
|
break;
|
||||||
|
case 'composer' === data['type']:
|
||||||
|
case /^[\w.-]+\/[\w.-]+$/.test(data['tool']):
|
||||||
|
script += await addPackage(data);
|
||||||
|
break;
|
||||||
|
case 'custom-package' === data['type']:
|
||||||
script += await utils.customPackage(
|
script += await utils.customPackage(
|
||||||
'blackfire',
|
data['tool'].split('-')[0],
|
||||||
'tools',
|
'tools',
|
||||||
version,
|
data['version'],
|
||||||
os_version
|
data['os_version']
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case /^grpc_php_plugin$|^protoc$/.test(tool):
|
case 'custom-function' === data['type']:
|
||||||
script += await utils.customPackage(tool, 'tools', version, os_version);
|
script += await functionRecord[data['function']](data);
|
||||||
break;
|
break;
|
||||||
case /^behat$|^codeception$|^phpspec$/.test(tool):
|
case /^none$/.test(data['tool']):
|
||||||
script += await addPackage(tool, release, tool + '/', os_version);
|
|
||||||
break;
|
|
||||||
case /^blackfire-player$/.test(tool):
|
|
||||||
url = await getBlackfirePlayerUrl(version, php_version);
|
|
||||||
script += await addArchive(tool, url, os_version, '"-V"');
|
|
||||||
break;
|
|
||||||
case /^composer$/.test(tool):
|
|
||||||
url = await getComposerUrl(version);
|
|
||||||
script += await addArchive('composer', url, os_version, version);
|
|
||||||
break;
|
|
||||||
case /^composer-normalize$/.test(tool):
|
|
||||||
uri = await getUri(tool, '.phar', version, 'releases', '', 'download');
|
|
||||||
url = github + 'ergebnis/composer-normalize/' + uri;
|
|
||||||
script += await addArchive(tool, url, os_version, '"-V"');
|
|
||||||
break;
|
|
||||||
case /^composer-prefetcher$/.test(tool):
|
|
||||||
script += await addPackage(
|
|
||||||
'automatic-' + tool,
|
|
||||||
release,
|
|
||||||
'narrowspark/',
|
|
||||||
os_version
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case /^composer-require-checker$/.test(tool):
|
|
||||||
uri = await getUri(tool, '.phar', version, 'releases', '', 'download');
|
|
||||||
url = github + 'maglnet/ComposerRequireChecker/' + uri;
|
|
||||||
script += await addArchive(tool, url, os_version, '"-V"');
|
|
||||||
break;
|
|
||||||
case /^composer-unused$/.test(tool):
|
|
||||||
script += await addPackage(tool, release, 'icanhazstring/', os_version);
|
|
||||||
break;
|
|
||||||
case /^cs2pr$/.test(tool):
|
|
||||||
uri = await getUri(tool, '', version, 'releases', '', 'download');
|
|
||||||
url = github + 'staabm/annotate-pull-request-from-checkstyle/' + uri;
|
|
||||||
script += await addArchive(tool, url, os_version, '"-V"');
|
|
||||||
break;
|
|
||||||
case /^deployer$/.test(tool):
|
|
||||||
url = await getDeployerUrl(version);
|
|
||||||
script += await addArchive(tool, url, os_version, '"-V"');
|
|
||||||
break;
|
|
||||||
case /^flex$/.test(tool):
|
|
||||||
script += await addPackage(tool, release, 'symfony/', os_version);
|
|
||||||
break;
|
|
||||||
case /^infection$/.test(tool):
|
|
||||||
url = github + 'infection/infection/' + uri;
|
|
||||||
script += await addArchive(tool, url, os_version, '"-V"');
|
|
||||||
break;
|
|
||||||
case /^pecl/.test(tool):
|
|
||||||
script += await utils.getCommand(os_version, 'pecl');
|
|
||||||
break;
|
|
||||||
case /^phan$/.test(tool):
|
|
||||||
url = github + 'phan/phan/' + uri;
|
|
||||||
script += await addArchive(tool, url, os_version, '"-v"');
|
|
||||||
break;
|
|
||||||
case /^phing$/.test(tool):
|
|
||||||
url = 'https://www.phing.info/get/phing-' + version + '.phar';
|
|
||||||
script += await addArchive(tool, url, os_version, '"-v"');
|
|
||||||
break;
|
|
||||||
case /^phinx$/.test(tool):
|
|
||||||
script += await addPackage(tool, release, 'robmorgan/', os_version);
|
|
||||||
break;
|
|
||||||
case /^phive$/.test(tool):
|
|
||||||
script += await addPhive(version, php_version, os_version);
|
|
||||||
break;
|
|
||||||
case /^php(-config|ize)$/.test(tool):
|
|
||||||
script += await addDevTools(tool, os_version);
|
|
||||||
break;
|
|
||||||
case /^php-cs-fixer$/.test(tool):
|
|
||||||
uri = await getUri(tool, '.phar', version, 'releases', 'v', 'download');
|
|
||||||
url = github + 'FriendsOfPHP/PHP-CS-Fixer/' + uri;
|
|
||||||
script += await addArchive(tool, url, os_version, '"-V"');
|
|
||||||
break;
|
|
||||||
case /^php(cbf|cs)$/.test(tool):
|
|
||||||
url = github + 'squizlabs/PHP_CodeSniffer/' + uri;
|
|
||||||
script += await addArchive(tool, url, os_version, '"--version"');
|
|
||||||
break;
|
|
||||||
case /^php(cpd|unit)$/.test(tool):
|
|
||||||
url = await getPharUrl('https://phar.phpunit.de', tool, '', version);
|
|
||||||
script += await addArchive(tool, url, os_version, '"--version"');
|
|
||||||
break;
|
|
||||||
case /^phplint$/.test(tool):
|
|
||||||
script += await addPackage(tool, release, 'overtrue/', os_version);
|
|
||||||
break;
|
|
||||||
case /^phpmd$/.test(tool):
|
|
||||||
url = github + 'phpmd/phpmd/' + uri;
|
|
||||||
script += await addArchive(tool, url, os_version, '"--version"');
|
|
||||||
break;
|
|
||||||
case /^phpstan$/.test(tool):
|
|
||||||
url = github + 'phpstan/phpstan/' + uri;
|
|
||||||
script += await addArchive(tool, url, os_version, '"-V"');
|
|
||||||
break;
|
|
||||||
case /^prestissimo$/.test(tool):
|
|
||||||
script += await addPackage(tool, release, 'hirak/', os_version);
|
|
||||||
break;
|
|
||||||
case /^psalm$/.test(tool):
|
|
||||||
url = github + 'vimeo/psalm/' + uri;
|
|
||||||
script += await addArchive(tool, url, os_version, '"-v"');
|
|
||||||
break;
|
|
||||||
case /^symfony(-cli)?$/.test(tool):
|
|
||||||
uri = await getSymfonyUri(version, os_version);
|
|
||||||
url = github + 'symfony/cli/' + uri;
|
|
||||||
script += await addArchive('symfony', url, os_version, 'version');
|
|
||||||
break;
|
|
||||||
case /^vapor(-cli)?$/.test(tool):
|
|
||||||
script += await addPackage(
|
|
||||||
'vapor-cli',
|
|
||||||
release,
|
|
||||||
'laravel/',
|
|
||||||
os_version
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case /^wp(-cli)?$/.test(tool):
|
|
||||||
url = github + (await getWpCliUrl(version));
|
|
||||||
script += await addArchive('wp-cli', url, os_version, '"--version"');
|
|
||||||
break;
|
|
||||||
case /^none$/.test(tool):
|
|
||||||
break;
|
|
||||||
case /^[\w.-]+\/[\w.-]+$/.test(tool):
|
|
||||||
script += await addPackage(
|
|
||||||
tool.split('/')[1],
|
|
||||||
release.split('/')[1].replace(/\s+/, ''),
|
|
||||||
tool.split('/')[0] + '/',
|
|
||||||
os_version
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
script += await utils.addLog(
|
script += await utils.addLog(
|
||||||
'$cross',
|
'$cross',
|
||||||
tool,
|
data['tool'],
|
||||||
'Tool ' + tool + ' is not supported',
|
'Tool ' + data['tool'] + ' is not supported',
|
||||||
os_version
|
os_version
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
43
src/utils.ts
43
src/utils.ts
@ -207,10 +207,14 @@ export async function addLog(
|
|||||||
* Read the scripts
|
* Read the scripts
|
||||||
*
|
*
|
||||||
* @param filename
|
* @param filename
|
||||||
|
* @param directory
|
||||||
*/
|
*/
|
||||||
export async function readScript(filename: string): Promise<string> {
|
export async function readFile(
|
||||||
|
filename: string,
|
||||||
|
directory: string
|
||||||
|
): Promise<string> {
|
||||||
return fs.readFileSync(
|
return fs.readFileSync(
|
||||||
path.join(__dirname, '../src/scripts/' + filename),
|
path.join(__dirname, '../' + directory, filename),
|
||||||
'utf8'
|
'utf8'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -231,6 +235,41 @@ export async function writeScript(
|
|||||||
return script_path;
|
return script_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to get information about a tool
|
||||||
|
*
|
||||||
|
* @param tool
|
||||||
|
*/
|
||||||
|
export async function getToolData(
|
||||||
|
tool: string
|
||||||
|
): Promise<Record<string, string>> {
|
||||||
|
const tools_json: string = await readFile('tools.json', 'src/configs');
|
||||||
|
const json_data: Record<string, Record<string, string>> =
|
||||||
|
JSON.parse(tools_json);
|
||||||
|
let tool_data: Record<string, string>;
|
||||||
|
const tools: string[] = Object.keys(json_data);
|
||||||
|
if (tools.includes(tool)) {
|
||||||
|
tool_data = json_data[tool];
|
||||||
|
tool_data['tool'] = tool;
|
||||||
|
} else {
|
||||||
|
const tool_key: string | undefined = Object.keys(json_data).find(
|
||||||
|
(key: string) => {
|
||||||
|
return (
|
||||||
|
json_data[key]['alias'] == tool ||
|
||||||
|
json_data[key]['repository'] == tool
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (tool_key) {
|
||||||
|
tool_data = json_data[tool_key];
|
||||||
|
tool_data['tool'] = tool_key;
|
||||||
|
} else {
|
||||||
|
tool_data = {tool: tool};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tool_data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to break extension csv into an array
|
* Function to break extension csv into an array
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user