WP-CLI tool support added

This commit is contained in:
Geoff Taylor 2020-02-21 23:36:14 -05:00 committed by Shivam Mathur
parent 03fd0b8719
commit d95ca49e8d
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
5 changed files with 73 additions and 3 deletions

View File

@ -276,6 +276,15 @@ describe('Tools tests', () => {
]);
});
it('checking getWpCliUri', async () => {
expect(await tools.getWpCliUrl('latest')).toBe(
'https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar'
);
expect(await tools.getWpCliUrl('2.4.0')).toBe(
'https://github.com/wp-cli/wp-cli/releases/download/v2.4.0/wp-cli-2.4.0.phar'
);
});
it('checking addArchive', async () => {
let script: string = await tools.addArchive(
'tool',
@ -358,7 +367,7 @@ describe('Tools tests', () => {
it('checking addTools on linux', async () => {
const script: string = await tools.addTools(
'cs2pr, php-cs-fixer, phpstan, phpunit, pecl, phinx, phinx:1.2.3, phive, php-config, phpize, symfony',
'cs2pr, php-cs-fixer, phpstan, phpunit, pecl, phinx, phinx:1.2.3, phive, php-config, phpize, symfony, wp-cli',
'7.4',
'linux'
);
@ -383,6 +392,9 @@ describe('Tools tests', () => {
expect(script).toContain(
'add_tool https://github.com/symfony/cli/releases/latest/download/symfony_linux_amd64 symfony'
);
expect(script).toContain(
'add_tool https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar wp-cli'
);
expect(script).toContain('add_pecl');
expect(script).toContain('add_composer_tool phinx phinx robmorgan/');
expect(script).toContain('add_composer_tool phinx phinx:1.2.3 robmorgan/');
@ -392,7 +404,7 @@ describe('Tools tests', () => {
});
it('checking addTools on darwin', async () => {
const script: string = await tools.addTools(
'phpcs, phpcbf, phpcpd, phpmd, psalm, phinx, phive:1.2.3, cs2pr:1.2.3, composer-prefetcher:1.2.3, phpize, php-config, symfony, symfony:1.2.3',
'phpcs, phpcbf, phpcpd, phpmd, psalm, phinx, phive:1.2.3, cs2pr:1.2.3, composer-prefetcher:1.2.3, phpize, php-config, symfony, symfony:1.2.3, wp-cli',
'7.4',
'darwin'
);
@ -430,12 +442,15 @@ describe('Tools tests', () => {
expect(script).toContain(
'add_tool https://github.com/symfony/cli/releases/download/v1.2.3/symfony_darwin_amd64 symfony'
);
expect(script).toContain(
'add_tool https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar wp-cli'
);
expect(script).toContain('add_log "$tick" "phpize" "Added"');
expect(script).toContain('add_log "$tick" "php-config" "Added"');
});
it('checking addTools on windows', async () => {
const script: string = await tools.addTools(
'codeception, cs2pr, deployer, prestissimo, phpmd, phinx, phive:0.13.2, php-config, phpize, symfony, does_not_exit',
'codeception, cs2pr, deployer, prestissimo, phpmd, phinx, phive:0.13.2, php-config, phpize, symfony, wp-cli, does_not_exit',
'7.4',
'win32'
);
@ -461,6 +476,9 @@ describe('Tools tests', () => {
expect(script).toContain(
'Add-Tool https://github.com/symfony/cli/releases/latest/download/symfony_windows_amd64.exe symfony'
);
expect(script).toContain(
'Add-Tool https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar wp-cli'
);
expect(script).toContain('phpize is not a windows tool');
expect(script).toContain('php-config is not a windows tool');
expect(script).toContain('Tool does_not_exit is not supported');

24
dist/index.js vendored
View File

@ -1863,6 +1863,26 @@ function getSymfonyUri(version, os_version) {
});
}
exports.getSymfonyUri = getSymfonyUri;
/**
* Function to get the WP-CLI url
*
* @param version
*/
function getWpCliUrl(version) {
return __awaiter(this, void 0, void 0, function* () {
switch (version) {
case 'latest':
return 'https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar';
default:
return ('https://github.com/wp-cli/wp-cli/releases/download/v' +
version +
'/wp-cli-' +
version +
'.phar');
}
});
}
exports.getWpCliUrl = getWpCliUrl;
/**
* Function to add/move composer in the tools list
*
@ -2048,6 +2068,10 @@ function addTools(tools_csv, php_version, os_version) {
url = github + 'symfony/cli/' + uri;
script += yield addArchive('symfony', version, url, os_version);
break;
case 'wp-cli':
url = yield getWpCliUrl(version);
script += yield addArchive(tool, version, url, os_version);
break;
default:
script += yield utils.addLog('$cross', tool, 'Tool ' + tool + ' is not supported', os_version);
break;

View File

@ -109,6 +109,8 @@ add_tool() {
sudo sed -i '' 's/exit(9)/exit(0)/' "$tool_path"
tr -d '\r' < "$tool_path" | sudo tee "$tool_path.tmp" >/dev/null 2>&1 && sudo mv "$tool_path.tmp" "$tool_path"
sudo chmod a+x "$tool_path"
elif [ "$tool" = "wp-cli" ]; then
sudo cp "$tool_path" /usr/local/bin/wp
fi
add_log "$tick" "$tool" "Added"
else

View File

@ -165,6 +165,8 @@ add_tool() {
add_extension curl "$apt_install php$version-curl" extension >/dev/null 2>&1
add_extension mbstring "$apt_install php$version-mbstring" extension >/dev/null 2>&1
add_extension xml "$apt_install php$version-xml" extension >/dev/null 2>&1
elif [ "$tool" = "wp-cli" ]; then
sudo cp "$tool_path" /usr/local/bin/wp
fi
add_log "$tick" "$tool" "Added"
else

View File

@ -308,6 +308,26 @@ export async function getSymfonyUri(
}
}
/**
* Function to get the WP-CLI url
*
* @param version
*/
export async function getWpCliUrl(version: string): Promise<string> {
switch (version) {
case 'latest':
return 'https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar';
default:
return (
'https://github.com/wp-cli/wp-cli/releases/download/v' +
version +
'/wp-cli-' +
version +
'.phar'
);
}
}
/**
* Function to add/move composer in the tools list
*
@ -523,6 +543,10 @@ export async function addTools(
url = github + 'symfony/cli/' + uri;
script += await addArchive('symfony', version, url, os_version);
break;
case 'wp-cli':
url = await getWpCliUrl(version);
script += await addArchive(tool, version, url, os_version);
break;
default:
script += await utils.addLog(
'$cross',