Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage language packs for all dependency types #224

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support for PHP 8
- `whippet generate plugin` to generate a plugin based on our template repo https://github.com/dxw/wordpress-plugin-template/
- Psalm compliance
- Support for managing WordPress language packs as a dependency

### Removed
- `whippet migrate` commands.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ sudo ln -s $PWD/bin/whippet /usr/local/bin/whippet

The main things you can use Whippet to do are:

* [Generating a Whippet application or theme](docs/generate.md)
* [Managing themes and plugins](docs/themesandplugins.md)
* [Generating a Whippet application, theme or plugin](docs/generate.md)
* [Managing themes, plugins and language packs](docs/managing-dependencies.md)
* [Deploying a Whippet application](docs/deploy.md)

## Support
Expand Down
12 changes: 6 additions & 6 deletions docs/generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Whippet can generate new Whippet-compliant applications and themes for you.

To create a new Whippet application, run:

```
```shell
$ whippet generate app
```

Expand All @@ -24,7 +24,7 @@ There are a few configuration steps you'll need to follow when you create a new

By default, Whippet uses the latest release of WordPress. To specify a version to develop against, you'll need to edit `config/application.json`:

```
```json
{
"wordpress": {
"repository": "https://github.com/WordPress/WordPress.git",
Expand All @@ -37,7 +37,7 @@ You can also change the WordPress repository used here by setting the `-r` optio

To change the version, replace the "revision" value with the version you'd like:

```
```json
"revision": "4.1.1"
```

Expand All @@ -62,7 +62,7 @@ The recommended method for running a Whippet application is to use the [wpc](htt

An application that uses Whippet must have the following directory structure, and must be a git repository:

```
```md
- config # Application configuration files
- public # Non-WordPress files that should be available via the web
- wp-content # Your application's wp-content directory
Expand All @@ -75,7 +75,7 @@ An application that uses Whippet must have the following directory structure, an

To create a new Whippet theme, run:

```
```shell
$ whippet generate theme
```

Expand All @@ -89,7 +89,7 @@ The generated theme is based on the theme in the [dxw WordPress template](https:

To create a new Whippet plugin, run:

```
```shell
$ whippet generate plugin
```

Expand Down
37 changes: 29 additions & 8 deletions docs/themesandplugins.md → docs/managing-dependencies.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
# Managing themes and plugins
# Managing themes, plugins and language packs

Note: At the moment, Whippet assumes it is running within dxw's infrastructure, and makes some assumptions accordingly. If you run into a problem where this may be the cause, please open an issue.

To manage plugins and themes using Whippet, you make entries in the `whippet.json` file in the root of the application.
To manage plugins, themes and language packs using Whippet, you make entries in the `whippet.json` file in the root of the application.

The file should specify a source for plugins and themes. The source should be a base url for a git repo.

If you are a dxw customer, the source will be `git@git.govpress.com:wordpress-plugins/`. If not, we suggest using `https://github.com/wp-plugins` for plugins.

The rest of the file should specify plugins and themes that you want to install. Example:
For language packs, Whippet will query `https://api.wordpress.org/translations/` and use the given URL for the
version of the language pack that you need. For any language you wish to install, Whippet will install the
relevant files for the themes and plugins in your `whippet.json` file, as well as the files for WordPress Core.

Note that if you do not have a file called `config/application.json` with an entry such as:

```json
{
"wordpress": {
"repository": "git@git.govpress.com:wordpress/snapshot",
"revision": "6.2.2"
}
}
```

Whippet will assume that you are using the current latest stable version of WordPress.

The rest of the file should specify plugins, themes and language packs that you want to install. Example:

```shell
{
"src": {
"plugins": "git@git.govpress.com:wordpress-plugins/",
Expand All @@ -23,19 +40,23 @@ The rest of the file should specify plugins and themes that you want to install.
{"name": "twentyfourteen"},
{"name": "twentysixteen"},
{"name": "twentyten"}
],
"languages": [
{"name": "en_GB"},
{"name": "ja"}
]
}
```

The `{"name": "akismet"}` instructs Whippet (on request) to install the most recent version of Akismet available in the repo. Whippet will determine a valid repo URL for the akismet plugin by appending the name to the source. In this example:

```
```shell
git@git.govpress.com:wordpress-plugins/akismet
```

You can also specify a particular label or branch that you want to use. Generally, this will either be master (the default) or a tag (for a specific version), but you can use any git reference. So you can do:

```
```shell
{
"name": "akismet",
"ref": "v1.1"
Expand All @@ -48,7 +69,7 @@ Finally, you can also specify a repo for an individual plugin or theme explicitl

- Pull version 3.0.0 from your own special repo:

```
```json
{
"name": "akismet",
"ref": "v3.0.0",
Expand All @@ -58,7 +79,7 @@ Finally, you can also specify a repo for an individual plugin or theme explicitl

- Or, pull master:

```
```json
{
"name": "akismet",
"ref": "master",
Expand All @@ -68,7 +89,7 @@ Finally, you can also specify a repo for an individual plugin or theme explicitl

- This works too:

```
```json
{
"name": "akismet",
"src": "git@my-git-server.com:akismet"
Expand Down
23 changes: 21 additions & 2 deletions docs/support.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ However, you may well need to use it as part of supporting WordPress sites we ho

## Common tasks

### Updating plugins & themes via Whippet
### Updating plugins, themes and language packs via Whippet

Run `whippet deps update` in the directory that contains the `whippet.lock` file.

Expand All @@ -31,6 +31,10 @@ Manually edit the `whippet.json` file to add an entry to the "plugins" section f
{"name": "twentyfourteen"},
{"name": "twentysixteen"},
{"name": "twentyten"}
],
"languages": [
{"name": "en_GB"},
{"name": "ja"}
]
}
```
Expand All @@ -51,6 +55,10 @@ And you want to add a plugin called "Foo", you would edit it to look like this:
{"name": "twentyfourteen"},
{"name": "twentysixteen"},
{"name": "twentyten"}
],
"languages": [
{"name": "en_GB"},
{"name": "ja"}
]
}
```
Expand All @@ -59,7 +67,18 @@ Then run `whippet deps update`.

Commit the updated `whippet.json`, `whippet.lock`, and `.gitignore`.

### Removing a plugin
### Adding a language pack

For language packs, note that you can add the language code for the pack (e.g. `nl_NL`) and
Whippet will automatically install any available language packs for themes and plugins that
are in the JSON file.

To find out which languages have translation support, please see
`https://api.wordpress.org/translations/core/1.0/?version={wp-version}` for the relevant
version of WordPress core. Other relevant APIs can be found
[in the codex](https://codex.wordpress.org/WordPress.org_API#Translations).

### Removing a plugin

Manually edit the `whippet.json` file to remove the entry for the plugin you want removed.

Expand Down
13 changes: 7 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<phpunit bootstrap="tests/Helpers.php" backupGlobals="false" colors="true">
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/Helpers.php" backupGlobals="false" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="unit_and_integration">
<directory suffix="_test.php">tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
44 changes: 44 additions & 0 deletions spec/dependencies/dependency_types.spec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

describe(\Dxw\Whippet\Dependencies\DependencyTypes::class, function () {
beforeAll(function () {
$this->plugins = \Dxw\Whippet\Dependencies\DependencyTypes::PLUGINS;
$this->themes = \Dxw\Whippet\Dependencies\DependencyTypes::THEMES;
$this->languages = \Dxw\Whippet\Dependencies\DependencyTypes::LANGUAGES;
$this->random_text = "lorem ipsum";
});

context("getDependencyTypes()", function () {
it('returns a list of dependencies as strings', function () {
expect(\Dxw\Whippet\Dependencies\DependencyTypes::getDependencyTypes())->toBe(['themes', 'plugins', 'languages']);
});
});

context("getThemeAndPluginTypes()", function () {
it('returns a list of dependencies as strings without languages', function () {
expect(\Dxw\Whippet\Dependencies\DependencyTypes::getThemeAndPluginTypes())->toBe(['themes', 'plugins']);
});
});

context("isLanguageType()", function () {
it('only returns true for language types', function () {
expect(\Dxw\Whippet\Dependencies\DependencyTypes::isLanguageType($this->plugins))->toBe(false);
expect(\Dxw\Whippet\Dependencies\DependencyTypes::isLanguageType($this->themes))->toBe(false);
expect(\Dxw\Whippet\Dependencies\DependencyTypes::isLanguageType($this->languages))->toBe(true);
expect(\Dxw\Whippet\Dependencies\DependencyTypes::isLanguageType($this->random_text))->toBe(false);
expect(\Dxw\Whippet\Dependencies\DependencyTypes::isLanguageType(""))->toBe(false);
expect(\Dxw\Whippet\Dependencies\DependencyTypes::isLanguageType(null))->toBe(false);
});
});

context("isNotLanguageType()", function () {
it('only returns false for language types', function () {
expect(\Dxw\Whippet\Dependencies\DependencyTypes::isNotLanguageType($this->plugins))->toBe(true);
expect(\Dxw\Whippet\Dependencies\DependencyTypes::isNotLanguageType($this->themes))->toBe(true);
expect(\Dxw\Whippet\Dependencies\DependencyTypes::isNotLanguageType($this->languages))->toBe(false);
expect(\Dxw\Whippet\Dependencies\DependencyTypes::isNotLanguageType($this->random_text))->toBe(true);
expect(\Dxw\Whippet\Dependencies\DependencyTypes::isNotLanguageType(""))->toBe(true);
expect(\Dxw\Whippet\Dependencies\DependencyTypes::isNotLanguageType(null))->toBe(true);
});
});
});
45 changes: 34 additions & 11 deletions spec/dependencies/describer.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
'magicMethods' => true
]);
allow(\Dxw\Whippet\Git\Git::class)->toBe($git);
allow($git)->toReceive('::tag_for_commit')->andReturn(\Result\Result::err('Error getting tag'));
allow($this->factory)->toReceive('callStatic')->andReturn(\Result\Result::err('Error getting tag'));

$result = $this->describer->describe();

Expand All @@ -60,26 +60,44 @@
'extends' => '\Dxw\Whippet\Files\WhippetLock',
'magicMethods' => true
]);
allow($whippetLock)->toReceive('getDependencies')->andReturn([
allow($whippetLock)->toReceive('getDependencies')->andReturn(
[
[
'name' => 'theme-one',
'src' => 'theme-one-src',
'revision' => 'commit-hash'
]
], [
],
[
[
'name' => 'plugin-one',
'src' => 'plugin-one-src',
'revision' => 'commit-hash'
],
]);
allow($this->factory)->toReceive('callStatic')->andReturn(\Result\Result::ok($whippetLock));
$git = Double::instance([
'extends' => '\Dxw\Whippet\Git\Git',
'magicMethods' => true
]);
allow(\Dxw\Whippet\Git\Git::class)->toBe($git);
allow($git)->toReceive('::tag_for_commit')->andReturn(\Result\Result::ok('v1.0.1'), \Result\Result::ok('v3.0'));
],
[
[
'name' => 'pt_BR',
'src' => 'lange-one-src-for-core',
'revision' => '6.3.3'
],
[
'name' => 'pt_BR/plugins/plugin-one',
'src' => 'lange-one-src-for-plugin-one',
'revision' => '1.2.3'
],
[
'name' => 'pt_BR/themes/theme-one',
'src' => 'lange-one-src-for-theme-one',
'revision' => '3.2.1'
]
]
);
allow($this->factory)->toReceive('callStatic')->andReturn(
\Result\Result::ok($whippetLock),
\Result\Result::ok('v1.0.1'),
\Result\Result::ok('v3.0')
);

ob_start();

Expand All @@ -93,6 +111,11 @@
],
'plugins' => [
'plugin-one' => 'v3.0'
],
'languages' => [
"pt_BR" => "6.3.3",
"pt_BR/plugins/plugin-one" => "1.2.3",
"pt_BR/themes/theme-one" => "3.2.1"
]
]);
expect($result->isErr())->toBe(false);
Expand Down
Loading