Link tools installed using composer

This commit is contained in:
Shivam Mathur 2019-12-31 04:26:18 +05:30
parent dd4f0db7bf
commit 3f42b7d5fb
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
3 changed files with 110 additions and 6 deletions

View File

@ -19,6 +19,24 @@ describe('Tools tests', () => {
);
});
it('checking linkTool', async () => {
expect(await tools.linkTool('tool', 'linux')).toContain(
'sudo ln -s "$(composer -q global config home)"/vendor/bin/tool /usr/local/bin/tool'
);
expect(await tools.linkTool('tool', 'darwin')).toContain(
'sudo ln -s "$(composer -q global config home)"/vendor/bin/tool /usr/local/bin/tool'
);
expect(await tools.linkTool('tool', 'win32')).toContain(
'$composer_dir = composer -q global config home | % {$_ -replace "/", "\\"}'
);
expect(await tools.linkTool('tool', 'win32')).toContain(
'Add-Content -Path $PsHome\\profile.ps1 -Value "New-Alias tool $composer_dir\\vendor\\bin\\tool.bat"'
);
expect(await tools.linkTool('tool', 'fedora')).toContain(
'Platform fedora is not supported'
);
});
it('checking addTools', async () => {
let script: string = await tools.addTools(
'php-cs-fixer, phpstan, phpunit, pecl, phinx',
@ -38,9 +56,12 @@ describe('Tools tests', () => {
);
expect(script).toContain('add_pecl');
expect(script).toContain('composer global require robmorgan/phinx');
expect(script).toContain(
'sudo ln -s "$(composer -q global config home)"/vendor/bin/phinx /usr/local/bin/phinx'
);
script = await tools.addTools(
'phpcs, phpcbf, phpcpd, phpmd, psalm',
'phpcs, phpcbf, phpcpd, phpmd, psalm, phinx',
'darwin'
);
expect(script).toContain(
@ -61,9 +82,13 @@ describe('Tools tests', () => {
expect(script).toContain(
'https://github.com/vimeo/psalm/releases/latest/download/psalm.phar psalm'
);
expect(script).toContain('composer global require robmorgan/phinx');
expect(script).toContain(
'sudo ln -s "$(composer -q global config home)"/vendor/bin/phinx /usr/local/bin/phinx'
);
script = await tools.addTools(
'codeception, deployer, prestissimo, phpmd, does_not_exit',
'codeception, deployer, prestissimo, phpmd, phinx, does_not_exit',
'win32'
);
expect(script).toContain(
@ -73,6 +98,13 @@ describe('Tools tests', () => {
'Add-Tool https://deployer.org/deployer.phar deployer'
);
expect(script).toContain('composer global require hirak/prestissimo');
expect(script).toContain('composer global require robmorgan/phinx');
expect(script).toContain(
'$composer_dir = composer -q global config home | % {$_ -replace "/", "\\"}'
);
expect(script).toContain(
'Add-Content -Path $PsHome\\profile.ps1 -Value "New-Alias phinx $composer_dir\\vendor\\bin\\phinx.bat"'
);
expect(script).toContain('Tool does_not_exit is not supported');
});
});

33
dist/index.js vendored
View File

@ -1583,6 +1583,29 @@ function getPECLCommand(os_version) {
});
}
exports.getPECLCommand = getPECLCommand;
function linkTool(tool, os_version) {
return __awaiter(this, void 0, void 0, function* () {
switch (os_version) {
case 'linux':
case 'darwin':
return ('sudo ln -s "$(composer -q global config home)"/vendor/bin/' +
tool +
' /usr/local/bin/' +
tool);
case 'win32':
return ('$composer_dir = composer -q global config home | % {$_ -replace "/", "\\"}' +
'\n' +
'Add-Content -Path $PsHome\\profile.ps1 -Value "New-Alias ' +
tool +
' $composer_dir\\vendor\\bin\\' +
tool +
'.bat"');
default:
return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error');
}
});
}
exports.linkTool = linkTool;
/**
* Setup tools
*
@ -1651,7 +1674,11 @@ function addTools(tools_csv, os_version) {
case 'phinx':
script +=
'composer global require robmorgan/phinx' +
(yield utils.suppressOutput(os_version));
(yield utils.suppressOutput(os_version)) +
'\n' +
(yield linkTool('phinx', os_version)) +
'\n' +
(yield utils.addLog('$tick', 'phinx', 'Added', os_version));
break;
case 'composer':
script +=
@ -1684,7 +1711,9 @@ function addTools(tools_csv, os_version) {
case 'prestissimo':
script +=
'composer global require hirak/prestissimo' +
(yield utils.suppressOutput(os_version));
(yield utils.suppressOutput(os_version)) +
'\n' +
(yield utils.addLog('$tick', 'hirak/prestissimo', 'Added', os_version));
break;
case 'pecl':
script += yield getPECLCommand(os_version);

View File

@ -32,6 +32,38 @@ export async function getPECLCommand(os_version: string): Promise<string> {
}
}
export async function linkTool(
tool: string,
os_version: string
): Promise<string> {
switch (os_version) {
case 'linux':
case 'darwin':
return (
'sudo ln -s "$(composer -q global config home)"/vendor/bin/' +
tool +
' /usr/local/bin/' +
tool
);
case 'win32':
return (
'$composer_dir = composer -q global config home | % {$_ -replace "/", "\\"}' +
'\n' +
'Add-Content -Path $PsHome\\profile.ps1 -Value "New-Alias ' +
tool +
' $composer_dir\\vendor\\bin\\' +
tool +
'.bat"'
);
default:
return await utils.log(
'Platform ' + os_version + ' is not supported',
os_version,
'error'
);
}
}
/**
* Setup tools
*
@ -101,7 +133,11 @@ export async function addTools(
case 'phinx':
script +=
'composer global require robmorgan/phinx' +
(await utils.suppressOutput(os_version));
(await utils.suppressOutput(os_version)) +
'\n' +
(await linkTool('phinx', os_version)) +
'\n' +
(await utils.addLog('$tick', 'phinx', 'Added', os_version));
break;
case 'composer':
script +=
@ -134,7 +170,14 @@ export async function addTools(
case 'prestissimo':
script +=
'composer global require hirak/prestissimo' +
(await utils.suppressOutput(os_version));
(await utils.suppressOutput(os_version)) +
'\n' +
(await utils.addLog(
'$tick',
'hirak/prestissimo',
'Added',
os_version
));
break;
case 'pecl':
script += await getPECLCommand(os_version);