diff --git a/__tests__/tools.test.ts b/__tests__/tools.test.ts index 2add3b35..5904e05e 100644 --- a/__tests__/tools.test.ts +++ b/__tests__/tools.test.ts @@ -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'); }); }); diff --git a/dist/index.js b/dist/index.js index f91b8883..3e440052 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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); diff --git a/src/tools.ts b/src/tools.ts index dfc3aa1d..7a3e97d0 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -32,6 +32,38 @@ export async function getPECLCommand(os_version: string): Promise { } } +export async function linkTool( + tool: string, + os_version: string +): Promise { + 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);