-
Notifications
You must be signed in to change notification settings - Fork 211
/
install-theme.ts
84 lines (79 loc) · 1.9 KB
/
install-theme.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { StepHandler } from '.';
import { InstallAssetOptions, installAsset } from './install-asset';
import { activateTheme } from './activate-theme';
import { zipNameToHumanName } from '../utils/zip-name-to-human-name';
/**
* @inheritDoc installTheme
* @hasRunnableExample
* @needsLogin
* @example
*
* <code>
* {
* "step": "installTheme",
* "themeZipFile": {
* "resource": "wordpress.org/themes",
* "slug": "pendant"
* },
* "options": {
* "activate": true
* }
* }
* </code>
*/
export interface InstallThemeStep<ResourceType>
extends Pick<InstallAssetOptions, 'ifAlreadyInstalled'> {
/**
* The step identifier.
*/
step: 'installTheme';
/**
* The theme zip file to install.
*/
themeZipFile: ResourceType;
/**
* Optional installation options.
*/
options?: {
/**
* Whether to activate the theme after installing it.
*/
activate?: boolean;
};
}
export interface InstallThemeOptions {
/**
* Whether to activate the theme after installing it.
*/
activate?: boolean;
}
/**
* Installs a WordPress theme in the Playground.
*
* @param playground The playground client.
* @param themeZipFile The theme zip file.
* @param options Optional. Set `activate` to false if you don't want to activate the theme.
*/
export const installTheme: StepHandler<InstallThemeStep<File>> = async (
playground,
{ themeZipFile, ifAlreadyInstalled, options = {} },
progress
) => {
const zipNiceName = zipNameToHumanName(themeZipFile.name);
progress?.tracker.setCaption(`Installing the ${zipNiceName} theme`);
const { assetFolderName } = await installAsset(playground, {
ifAlreadyInstalled,
zipFile: themeZipFile,
targetPath: `${await playground.documentRoot}/wp-content/themes`,
});
const activate = 'activate' in options ? options.activate : true;
if (activate) {
await activateTheme(
playground,
{
themeFolderName: assetFolderName,
},
progress
);
}
};