Skip to content

Commit bbc65d9

Browse files
committed
Fix extension logs
Refactor utils.addCommand
1 parent 6db1a06 commit bbc65d9

File tree

10 files changed

+94
-69
lines changed

10 files changed

+94
-69
lines changed

__tests__/tools.test.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,11 @@ describe('Tools tests', () => {
222222
});
223223

224224
it.each`
225-
os | script | scope
226-
${'linux'} | ${'add_composertool tool tool:1.2.3 user/ global'} | ${'global'}
227-
${'darwin'} | ${'add_composertool tool tool:1.2.3 user/ scoped'} | ${'scoped'}
228-
${'win32'} | ${'Add-Composertool tool tool:1.2.3 user/ scoped'} | ${'scoped'}
229-
${'openbsd'} | ${'Platform openbsd is not supported'} | ${'global'}
225+
os | script | scope
226+
${'linux'} | ${'add_composer_tool tool tool:1.2.3 user/ global'} | ${'global'}
227+
${'darwin'} | ${'add_composer_tool tool tool:1.2.3 user/ scoped'} | ${'scoped'}
228+
${'win32'} | ${'Add-ComposerTool tool tool:1.2.3 user/ scoped'} | ${'scoped'}
229+
${'openbsd'} | ${'Platform openbsd is not supported'} | ${'global'}
230230
`('checking addPackage: $os, $scope', async ({os, script, scope}) => {
231231
const data = getData({
232232
tool: 'tool',
@@ -380,27 +380,27 @@ describe('Tools tests', () => {
380380
'add_tool https://get.blackfire.io/blackfire-player-v1.22.0.phar blackfire-player "-V"',
381381
'add_tool https://github.com/bmitch/churn-php/releases/latest/download/churn.phar churn "-V"',
382382
'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr "-V"',
383-
'add_composertool flex flex symfony/ global',
383+
'add_composer_tool flex flex symfony/ global',
384384
'add_grpc_php_plugin latest',
385385
'add_tool https://github.com/php-parallel-lint/PHP-Parallel-Lint/releases/latest/download/parallel-lint.phar parallel-lint "--version"',
386386
'add_tool https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v3.2.1/php-cs-fixer.phar php-cs-fixer "-V"',
387387
'add_tool https://github.com/phpDocumentor/phpDocumentor/releases/latest/download/phpDocumentor.phar phpDocumentor "--version"',
388-
'add_composertool phplint phplint overtrue/',
388+
'add_composer_tool phplint phplint overtrue/',
389389
'add_tool https://github.com/phpstan/phpstan/releases/latest/download/phpstan.phar phpstan "-V"',
390390
'add_tool https://phar.phpunit.de/phpunit.phar phpunit "--version"',
391391
'add_pecl',
392392
'add_tool https://www.phing.info/get/phing-latest.phar phing "-v"',
393-
'add_composertool phinx phinx robmorgan/ scoped',
394-
'add_composertool phinx phinx:1.2.3 robmorgan/ scoped',
393+
'add_composer_tool phinx phinx robmorgan/ scoped',
394+
'add_composer_tool phinx phinx:1.2.3 robmorgan/ scoped',
395395
'add_tool https://github.com/phar-io/phive/releases/download/3.2.1/phive-3.2.1.phar phive "status"',
396-
'add_composertool phpunit-bridge phpunit-bridge symfony/ global',
397-
'add_composertool phpunit-polyfills phpunit-polyfills yoast/ global',
396+
'add_composer_tool phpunit-bridge phpunit-bridge symfony/ global',
397+
'add_composer_tool phpunit-polyfills phpunit-polyfills yoast/ global',
398398
'add_tool https://github.com/laravel/pint/releases/latest/download/pint.phar pint "-V"',
399399
'add_devtools php-config',
400400
'add_devtools phpize',
401401
'add_protoc latest',
402402
'add_symfony latest',
403-
'add_composertool vapor-cli vapor-cli laravel/ scoped',
403+
'add_composer_tool vapor-cli vapor-cli laravel/ scoped',
404404
'add_tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli "--version"'
405405
]
406406
]
@@ -416,21 +416,21 @@ describe('Tools tests', () => {
416416
'behat, blackfire, blackfire-player, churn, composer-normalize, composer-require-checker, composer-unused, cs2pr:1.2.3, flex, grpc_php_plugin:1.2.3, infection, phan, phan:1.2.3, phing:1.2.3, phinx, phive:1.2.3, php-config, phpcbf, phpcpd, phpcs, phpdoc, phpize, phpmd, phpspec, phpunit-bridge:5.6, phpunit-polyfills:1.0.1, protoc:v1.2.3, psalm, rector, symfony-cli, vapor-cli, wp-cli',
417417
[
418418
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-stable.phar,https://dl.cloudsmith.io/public/shivammathur/composer-cache/raw/files/composer-7.4-stable.phar,https://getcomposer.org/composer-stable.phar composer',
419-
'add_composertool behat behat behat/ scoped',
419+
'add_composer_tool behat behat behat/ scoped',
420420
'add_blackfire',
421421
'add_tool https://get.blackfire.io/blackfire-player-v1.22.0.phar blackfire-player "-V"',
422422
'add_tool https://github.com/bmitch/churn-php/releases/latest/download/churn.phar churn "-V"',
423423
'add_tool https://github.com/ergebnis/composer-normalize/releases/latest/download/composer-normalize.phar composer-normalize "-V"',
424-
'add_composertool composer-require-checker composer-require-checker maglnet/ scoped',
424+
'add_composer_tool composer-require-checker composer-require-checker maglnet/ scoped',
425425
'add_tool https://github.com/composer-unused/composer-unused/releases/latest/download/composer-unused.phar composer-unused "-V"',
426426
'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/download/1.2.3/cs2pr cs2pr "-V"',
427-
'add_composertool flex flex symfony/ global',
427+
'add_composer_tool flex flex symfony/ global',
428428
'add_grpc_php_plugin 1.2.3',
429429
'add_tool https://github.com/infection/infection/releases/latest/download/infection.phar infection "-V"',
430430
'add_tool https://github.com/phan/phan/releases/latest/download/phan.phar phan "-v"',
431431
'add_tool https://github.com/phan/phan/releases/download/1.2.3/phan.phar phan "-v"',
432432
'add_tool https://www.phing.info/get/phing-1.2.3.phar,https://github.com/phingofficial/phing/releases/download/1.2.3/phing-1.2.3.phar phing "-v"',
433-
'add_composertool phinx phinx robmorgan/ scoped',
433+
'add_composer_tool phinx phinx robmorgan/ scoped',
434434
'add_tool https://github.com/phar-io/phive/releases/download/1.2.3/phive-1.2.3.phar phive',
435435
'add_devtools php-config',
436436
'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcbf.phar phpcbf "--version"',
@@ -440,13 +440,13 @@ describe('Tools tests', () => {
440440
'add_devtools phpize',
441441
'add_tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar phpmd "--version"',
442442
'add_tool https://github.com/phpspec/phpspec/releases/latest/download/phpspec.phar phpspec "-V"',
443-
'add_composertool phpunit-bridge phpunit-bridge:5.6.* symfony/ global',
444-
'add_composertool phpunit-polyfills phpunit-polyfills:1.0.1 yoast/ global',
443+
'add_composer_tool phpunit-bridge phpunit-bridge:5.6.* symfony/ global',
444+
'add_composer_tool phpunit-polyfills phpunit-polyfills:1.0.1 yoast/ global',
445445
'add_protoc 1.2.3',
446446
'add_tool https://github.com/vimeo/psalm/releases/latest/download/psalm.phar psalm "-v"',
447-
'add_composertool rector rector rector/ scoped',
447+
'add_composer_tool rector rector rector/ scoped',
448448
'add_symfony latest',
449-
'add_composertool vapor-cli vapor-cli laravel/ scoped',
449+
'add_composer_tool vapor-cli vapor-cli laravel/ scoped',
450450
'add_tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli "--version"'
451451
]
452452
]
@@ -468,13 +468,13 @@ describe('Tools tests', () => {
468468
'Add-Tool https://github.com/bmitch/churn-php/releases/latest/download/churn.phar churn "-V"',
469469
'Add-Tool https://deployer.org/deployer.phar deployer "-V"',
470470
'Tool does_not_exist is not supported',
471-
'Add-Composertool flex flex symfony/ global',
472-
'Add-Composertool phinx phinx robmorgan/ scoped',
471+
'Add-ComposerTool flex flex symfony/ global',
472+
'Add-ComposerTool phinx phinx robmorgan/ scoped',
473473
'Add-Tool https://github.com/phar-io/phive/releases/download/0.13.2/phive-0.13.2.phar phive "status"',
474474
'php-config is not a windows tool',
475475
'phpize is not a windows tool',
476476
'Add-Tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar phpmd "--version"',
477-
'Add-Composertool phpunit-bridge phpunit-bridge symfony/ global',
477+
'Add-ComposerTool phpunit-bridge phpunit-bridge symfony/ global',
478478
'Add-Symfony',
479479
'Add-Tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli "--version"'
480480
]
@@ -491,13 +491,13 @@ describe('Tools tests', () => {
491491
'composer:v1, codeception/codeception, prestissimo, hirak/prestissimo, composer-prefetcher, narrowspark/automatic-composer-prefetcher, phinx: 1.2, robmorgan/phinx: ^1.2, user/tool:1.2.3, user/tool:~1.2',
492492
[
493493
'Add-Tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-1.phar,https://dl.cloudsmith.io/public/shivammathur/composer-cache/raw/files/composer-7.4-1.phar,https://getcomposer.org/composer-1.phar composer',
494-
'Add-Composertool codeception codeception codeception/ global',
495-
'Add-Composertool prestissimo prestissimo hirak/ global',
496-
'Add-Composertool automatic-composer-prefetcher automatic-composer-prefetcher narrowspark/ global',
497-
'Add-Composertool phinx phinx:1.2.* robmorgan/ scoped',
498-
'Add-Composertool phinx phinx:^1.2 robmorgan/ global',
499-
'Add-Composertool tool tool:1.2.3 user/ global',
500-
'Add-Composertool tool tool:~1.2 user/ global'
494+
'Add-ComposerTool codeception codeception codeception/ global',
495+
'Add-ComposerTool prestissimo prestissimo hirak/ global',
496+
'Add-ComposerTool automatic-composer-prefetcher automatic-composer-prefetcher narrowspark/ global',
497+
'Add-ComposerTool phinx phinx:1.2.* robmorgan/ scoped',
498+
'Add-ComposerTool phinx phinx:^1.2 robmorgan/ global',
499+
'Add-ComposerTool tool tool:1.2.3 user/ global',
500+
'Add-ComposerTool tool tool:~1.2 user/ global'
501501
]
502502
]
503503
])(

__tests__/utils.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ describe('Utils tests', () => {
193193
expect(await utils.getCommand('linux', 'tool')).toBe('add_tool ');
194194
expect(await utils.getCommand('darwin', 'tool')).toBe('add_tool ');
195195
expect(await utils.getCommand('win32', 'tool')).toBe('Add-Tool ');
196+
expect(await utils.getCommand('win32', 'tool_name')).toBe('Add-ToolName ');
196197
expect(await utils.getCommand('openbsd', 'tool')).toContain(
197198
'Platform openbsd is not supported'
198199
);

dist/index.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,21 @@ async function checkXdebugError(extension, version) {
127127
exports.checkXdebugError = checkXdebugError;
128128
async function addCoverageXdebug(extension, version, os, pipe) {
129129
let script = '\n';
130-
let message = await checkXdebugError(extension, version);
131-
let status = '$cross';
132-
if (!message) {
130+
const error = await checkXdebugError(extension, version);
131+
if (!error) {
133132
script +=
134133
(await extensions.addExtension(':pcov:false', version, os, true)) + pipe;
135134
extension = extension == 'xdebug3' ? 'xdebug' : extension;
136135
script +=
137136
(await extensions.addExtension(extension, version, os, true)) + pipe;
138137
script += await utils.setVariable('xdebug_version', 'php -r "echo phpversion(\'xdebug\');"', os);
139-
message = 'Xdebug $xdebug_version enabled as coverage driver';
140-
status = '$tick';
138+
script +=
139+
(await utils.getCommand(os, 'extension_log')) +
140+
'xdebug "Xdebug $xdebug_version enabled as coverage driver"';
141+
}
142+
else {
143+
script += await utils.addLog('$cross', extension, error, os);
141144
}
142-
script += await utils.addLog(status, extension, message, os);
143145
return script;
144146
}
145147
exports.addCoverageXdebug = addCoverageXdebug;
@@ -154,7 +156,9 @@ async function addCoveragePCOV(version, os, pipe) {
154156
(await extensions.addExtension('pcov', version, os, true)) + pipe;
155157
script += (await config.addINIValues('pcov.enabled=1', os, true)) + '\n';
156158
script += await utils.setVariable('pcov_version', 'php -r "echo phpversion(\'pcov\');"', os);
157-
script += await utils.addLog('$tick', 'coverage: pcov', 'PCOV $pcov_version enabled as coverage driver', os);
159+
script +=
160+
(await utils.getCommand(os, 'extension_log')) +
161+
'pcov "PCOV $pcov_version enabled as coverage driver"';
158162
break;
159163
case /5\.[3-6]|7\.0/.test(version):
160164
script += await utils.addLog('$cross', 'pcov', 'PHP 7.1 or newer is required', os);
@@ -752,7 +756,7 @@ async function addArchive(data) {
752756
}
753757
exports.addArchive = addArchive;
754758
async function addPackage(data) {
755-
const command = await utils.getCommand(data['os'], 'composertool');
759+
const command = await utils.getCommand(data['os'], 'composer_tool');
756760
const parts = data['repository'].split('/');
757761
const args = await utils.joins(parts[1], data['release'], parts[0] + '/', data['scope']);
758762
return command + args;
@@ -1218,7 +1222,12 @@ async function getCommand(os, suffix) {
12181222
case 'darwin':
12191223
return 'add_' + suffix + ' ';
12201224
case 'win32':
1221-
return 'Add-' + suffix.charAt(0).toUpperCase() + suffix.slice(1) + ' ';
1225+
return ('Add-' +
1226+
suffix
1227+
.split('_')
1228+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
1229+
.join('') +
1230+
' ');
12221231
default:
12231232
return await log('Platform ' + os + ' is not supported', os, 'error');
12241233
}

src/coverage.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export async function checkXdebugError(
1616
}
1717

1818
/**
19-
* Function to setup Xdebug
19+
* Function to set up Xdebug
2020
*
2121
* @param extension
2222
* @param version
@@ -30,9 +30,8 @@ export async function addCoverageXdebug(
3030
pipe: string
3131
): Promise<string> {
3232
let script = '\n';
33-
let message: string = await checkXdebugError(extension, version);
34-
let status = '$cross';
35-
if (!message) {
33+
const error: string = await checkXdebugError(extension, version);
34+
if (!error) {
3635
script +=
3736
(await extensions.addExtension(':pcov:false', version, os, true)) + pipe;
3837
extension = extension == 'xdebug3' ? 'xdebug' : extension;
@@ -43,15 +42,17 @@ export async function addCoverageXdebug(
4342
'php -r "echo phpversion(\'xdebug\');"',
4443
os
4544
);
46-
message = 'Xdebug $xdebug_version enabled as coverage driver';
47-
status = '$tick';
45+
script +=
46+
(await utils.getCommand(os, 'extension_log')) +
47+
'xdebug "Xdebug $xdebug_version enabled as coverage driver"';
48+
} else {
49+
script += await utils.addLog('$cross', extension, error, os);
4850
}
49-
script += await utils.addLog(status, extension, message, os);
5051
return script;
5152
}
5253

5354
/**
54-
* Function to setup PCOV
55+
* Function to set up PCOV
5556
*
5657
* @param version
5758
* @param os
@@ -76,14 +77,9 @@ export async function addCoveragePCOV(
7677
'php -r "echo phpversion(\'pcov\');"',
7778
os
7879
);
79-
// success
80-
script += await utils.addLog(
81-
'$tick',
82-
'coverage: pcov',
83-
'PCOV $pcov_version enabled as coverage driver',
84-
os
85-
);
86-
// version is not supported
80+
script +=
81+
(await utils.getCommand(os, 'extension_log')) +
82+
'pcov "PCOV $pcov_version enabled as coverage driver"';
8783
break;
8884

8985
case /5\.[3-6]|7\.0/.test(version):

src/scripts/extensions/add_extensions.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
Function Add-ExtensionLog() {
2+
Param (
3+
[Parameter(Position = 0, Mandatory = $true)]
4+
[ValidateNotNull()]
5+
$extension,
6+
[Parameter(Position = 1, Mandatory = $true)]
7+
[ValidateNotNull()]
8+
$message
9+
)
10+
$extension_info = Get-PhpExtension -Path $php_dir | Where-Object { $_.Name -eq $extension -or $_.Handle -eq $extension }
11+
if ($null -ne $extension_info -and ($extension_info.State -eq 'Enabled' -or $extension_info.State -eq 'Builtin')) {
12+
Add-Log $tick $extension $message
13+
} else {
14+
Add-Log $cross $extension "Could not install $extension on PHP $( $installed.FullVersion )"
15+
}
16+
}
17+
118
# Function to link dependencies to PHP directory.
219
Function Set-ExtensionPrerequisites
320
{

src/scripts/extensions/http.ps1

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,5 @@ Function Add-Http() {
4747
}
4848
Add-Extension pecl_http >$null 2>&1
4949
Repair-ICU
50-
try {
51-
php --ri "http" 2> $null | Out-Null
52-
Add-Log $tick "http" "Installed and enabled"
53-
} catch {
54-
Add-Log $cross "http" "Could not install http on PHP $( $installed.FullVersion )"
55-
}
50+
Add-ExtensionLog http "Installed and enabled"
5651
}

src/scripts/tools/add_tools.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ Function Add-Tool() {
183183
}
184184
}
185185

186-
Function Add-ComposertoolHelper() {
186+
Function Add-ComposerToolHelper() {
187187
Param (
188188
[Parameter(Position = 0, Mandatory = $true)]
189189
[string]
@@ -234,7 +234,7 @@ Function Add-ComposertoolHelper() {
234234
}
235235

236236
# Function to setup a tool using composer.
237-
Function Add-Composertool() {
237+
Function Add-ComposerTool() {
238238
Param (
239239
[Parameter(Position = 0, Mandatory = $true)]
240240
[ValidateNotNull()]
@@ -267,7 +267,7 @@ Function Add-Composertool() {
267267
}
268268
}
269269
Enable-PhpExtension -Extension curl, mbstring, openssl -Path $php_dir
270-
$log = Add-ComposertoolHelper $tool $release $prefix $scope $composer_args
270+
$log = Add-ComposerToolHelper $tool $release $prefix $scope $composer_args
271271
if(Test-Path $composer_bin\composer) {
272272
Copy-Item -Path "$bin_dir\composer" -Destination "$composer_bin\composer" -Force
273273
}

src/scripts/tools/add_tools.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ add_tool() {
153153
}
154154

155155
# Function to setup a tool using composer in a different scope.
156-
add_composertool_helper() {
156+
add_composer_tool_helper() {
157157
tool=$1
158158
release=$2
159159
prefix=$3
@@ -184,7 +184,7 @@ add_composertool_helper() {
184184
}
185185

186186
# Function to setup a tool using composer.
187-
add_composertool() {
187+
add_composer_tool() {
188188
tool=$1
189189
release=$2
190190
prefix=$3
@@ -199,7 +199,7 @@ add_composertool() {
199199
return
200200
fi
201201
fi
202-
add_composertool_helper "$tool" "$release" "$prefix" "$scope" "$composer_args"
202+
add_composer_tool_helper "$tool" "$release" "$prefix" "$scope" "$composer_args"
203203
tool_version=$(get_tool_version cat /tmp/composer.log)
204204
([ -s /tmp/composer.log ] && add_log "$tick" "$tool" "Added $tool $tool_version"
205205
) || add_log "$cross" "$tool" "Could not setup $tool"

src/tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export async function addArchive(data: RS): Promise<string> {
201201
* @param data
202202
*/
203203
export async function addPackage(data: RS): Promise<string> {
204-
const command = await utils.getCommand(data['os'], 'composertool');
204+
const command = await utils.getCommand(data['os'], 'composer_tool');
205205
const parts: string[] = data['repository'].split('/');
206206
const args: string = await utils.joins(
207207
parts[1],

src/utils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,14 @@ export async function getCommand(os: string, suffix: string): Promise<string> {
320320
case 'darwin':
321321
return 'add_' + suffix + ' ';
322322
case 'win32':
323-
return 'Add-' + suffix.charAt(0).toUpperCase() + suffix.slice(1) + ' ';
323+
return (
324+
'Add-' +
325+
suffix
326+
.split('_')
327+
.map((part: string) => part.charAt(0).toUpperCase() + part.slice(1))
328+
.join('') +
329+
' '
330+
);
324331
default:
325332
return await log('Platform ' + os + ' is not supported', os, 'error');
326333
}

0 commit comments

Comments
 (0)