@wp-playground/blueprints 0.1.40 → 0.1.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +140 -0
- package/index.d.ts +7 -0
- package/index.js +2106 -0
- package/lib/blueprint.d.ts +27 -0
- package/lib/compile.d.ts +37 -0
- package/lib/resources.d.ts +211 -0
- package/lib/steps/activate-plugin.d.ts +12 -0
- package/lib/steps/apply-wordpress-patches/index.d.ts +12 -0
- package/lib/steps/client-methods.d.ts +56 -0
- package/lib/steps/common.d.ts +9 -0
- package/lib/steps/define-site-url.d.ts +12 -0
- package/lib/steps/define-virtual-wp-config-consts.d.ts +19 -0
- package/lib/steps/define-wp-config-consts.d.ts +16 -0
- package/{src/lib/steps/handlers.ts → lib/steps/handlers.d.ts} +2 -12
- package/lib/steps/import-export.d.ts +67 -0
- package/lib/steps/index.d.ts +28 -0
- package/lib/steps/install-plugin.d.ts +46 -0
- package/lib/steps/install-theme.d.ts +22 -0
- package/lib/steps/login.d.ts +16 -0
- package/lib/steps/migration.d.ts +2 -0
- package/lib/steps/run-wp-installation-wizard.d.ts +16 -0
- package/lib/steps/site-data.d.ts +12 -0
- package/package.json +4 -3
- package/.eslintrc.json +0 -18
- package/LICENSE +0 -339
- package/README.md +0 -11
- package/project.json +0 -58
- package/src/index.ts +0 -31
- package/src/lib/blueprint.ts +0 -28
- package/src/lib/compile.spec.ts +0 -34
- package/src/lib/compile.ts +0 -262
- package/src/lib/resources.ts +0 -417
- package/src/lib/steps/activate-plugin.ts +0 -35
- package/src/lib/steps/apply-wordpress-patches/index.ts +0 -113
- package/src/lib/steps/apply-wordpress-patches/wp-content/mu-plugins/1-show-admin-credentials-on-wp-login.php +0 -15
- package/src/lib/steps/client-methods.ts +0 -121
- package/src/lib/steps/common.ts +0 -30
- package/src/lib/steps/define-site-url.ts +0 -25
- package/src/lib/steps/define-wp-config-consts.ts +0 -45
- package/src/lib/steps/import-export.ts +0 -225
- package/src/lib/steps/index.ts +0 -67
- package/src/lib/steps/install-plugin.ts +0 -145
- package/src/lib/steps/install-theme.ts +0 -99
- package/src/lib/steps/login.ts +0 -37
- package/src/lib/steps/migration.ts +0 -63
- package/src/lib/steps/run-wp-installation-wizard.ts +0 -38
- package/src/lib/steps/site-data.ts +0 -58
- package/tsconfig.json +0 -23
- package/tsconfig.lib.json +0 -10
- package/tsconfig.spec.json +0 -19
- package/vite.config.ts +0 -58
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SupportedPHPVersion } from '@php-wasm/universal';
|
|
2
|
+
import { StepDefinition } from './steps';
|
|
3
|
+
export interface Blueprint {
|
|
4
|
+
/**
|
|
5
|
+
* The URL to navigate to after the blueprint has been run.
|
|
6
|
+
*/
|
|
7
|
+
landingPage?: string;
|
|
8
|
+
/**
|
|
9
|
+
* The preferred PHP and WordPress versions to use.
|
|
10
|
+
*/
|
|
11
|
+
preferredVersions?: {
|
|
12
|
+
/**
|
|
13
|
+
* The preferred PHP version to use.
|
|
14
|
+
* If not specified, the latest supported version will be used
|
|
15
|
+
*/
|
|
16
|
+
php: SupportedPHPVersion | 'latest';
|
|
17
|
+
/**
|
|
18
|
+
* The preferred WordPress version to use.
|
|
19
|
+
* If not specified, the latest supported version will be used
|
|
20
|
+
*/
|
|
21
|
+
wp: string | 'latest';
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The steps to run.
|
|
25
|
+
*/
|
|
26
|
+
steps?: Array<StepDefinition | string | undefined | false | null>;
|
|
27
|
+
}
|
package/lib/compile.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ProgressTracker } from '@php-wasm/progress';
|
|
2
|
+
import { Semaphore } from '@php-wasm/util';
|
|
3
|
+
import { SupportedPHPVersion, UniversalPHP } from '@php-wasm/universal';
|
|
4
|
+
import { StepDefinition } from './steps';
|
|
5
|
+
import { Blueprint } from './blueprint';
|
|
6
|
+
export type CompiledStep = (php: UniversalPHP) => Promise<void> | void;
|
|
7
|
+
declare const supportedWordPressVersions: readonly ["6.2", "6.1", "6.0", "5.9"];
|
|
8
|
+
type supportedWordPressVersion = (typeof supportedWordPressVersions)[number];
|
|
9
|
+
export interface CompiledBlueprint {
|
|
10
|
+
/** The requested versions of PHP and WordPress for the blueprint */
|
|
11
|
+
versions: {
|
|
12
|
+
php: SupportedPHPVersion;
|
|
13
|
+
wp: supportedWordPressVersion;
|
|
14
|
+
};
|
|
15
|
+
/** The compiled steps for the blueprint */
|
|
16
|
+
run: (playground: UniversalPHP) => Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export type OnStepCompleted = (output: any, step: StepDefinition) => any;
|
|
19
|
+
export interface CompileBlueprintOptions {
|
|
20
|
+
/** Optional progress tracker to monitor progress */
|
|
21
|
+
progress?: ProgressTracker;
|
|
22
|
+
/** Optional semaphore to control access to a shared resource */
|
|
23
|
+
semaphore?: Semaphore;
|
|
24
|
+
/** Optional callback with step output */
|
|
25
|
+
onStepCompleted?: OnStepCompleted;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Compiles Blueprint into a form that can be executed.
|
|
29
|
+
*
|
|
30
|
+
* @param playground The PlaygroundClient to use for the compilation
|
|
31
|
+
* @param blueprint The bBueprint to compile
|
|
32
|
+
* @param options Additional options for the compilation
|
|
33
|
+
* @returns The compiled blueprint
|
|
34
|
+
*/
|
|
35
|
+
export declare function compileBlueprint(blueprint: Blueprint, { progress, semaphore, onStepCompleted, }?: CompileBlueprintOptions): CompiledBlueprint;
|
|
36
|
+
export declare function runBlueprintSteps(compiledBlueprint: CompiledBlueprint, playground: UniversalPHP): Promise<void>;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { ProgressTracker } from '@php-wasm/progress';
|
|
2
|
+
import { UniversalPHP } from '@php-wasm/universal';
|
|
3
|
+
import { Semaphore } from '@php-wasm/util';
|
|
4
|
+
export declare const ResourceTypes: readonly ["vfs", "literal", "wordpress.org/themes", "wordpress.org/plugins", "url"];
|
|
5
|
+
export type VFSReference = {
|
|
6
|
+
/** Identifies the file resource as Virtual File System (VFS) */
|
|
7
|
+
resource: 'vfs';
|
|
8
|
+
/** The path to the file in the VFS */
|
|
9
|
+
path: string;
|
|
10
|
+
};
|
|
11
|
+
export type LiteralReference = {
|
|
12
|
+
/** Identifies the file resource as a literal file */
|
|
13
|
+
resource: 'literal';
|
|
14
|
+
/** The name of the file */
|
|
15
|
+
name: string;
|
|
16
|
+
/** The contents of the file */
|
|
17
|
+
contents: string | Uint8Array;
|
|
18
|
+
};
|
|
19
|
+
export type CoreThemeReference = {
|
|
20
|
+
/** Identifies the file resource as a WordPress Core theme */
|
|
21
|
+
resource: 'wordpress.org/themes';
|
|
22
|
+
/** The slug of the WordPress Core theme */
|
|
23
|
+
slug: string;
|
|
24
|
+
};
|
|
25
|
+
export type CorePluginReference = {
|
|
26
|
+
/** Identifies the file resource as a WordPress Core plugin */
|
|
27
|
+
resource: 'wordpress.org/plugins';
|
|
28
|
+
/** The slug of the WordPress Core plugin */
|
|
29
|
+
slug: string;
|
|
30
|
+
};
|
|
31
|
+
export type UrlReference = {
|
|
32
|
+
/** Identifies the file resource as a URL */
|
|
33
|
+
resource: 'url';
|
|
34
|
+
/** The URL of the file */
|
|
35
|
+
url: string;
|
|
36
|
+
/** Optional caption for displaying a progress message */
|
|
37
|
+
caption?: string;
|
|
38
|
+
};
|
|
39
|
+
export type FileReference = VFSReference | LiteralReference | CoreThemeReference | CorePluginReference | UrlReference;
|
|
40
|
+
export declare function isFileReference(ref: any): ref is FileReference;
|
|
41
|
+
export interface ResourceOptions {
|
|
42
|
+
/** Optional semaphore to limit concurrent downloads */
|
|
43
|
+
semaphore?: Semaphore;
|
|
44
|
+
progress?: ProgressTracker;
|
|
45
|
+
}
|
|
46
|
+
export declare abstract class Resource {
|
|
47
|
+
/** Optional progress tracker to monitor progress */
|
|
48
|
+
abstract progress?: ProgressTracker;
|
|
49
|
+
/** A Promise that resolves to the file contents */
|
|
50
|
+
protected promise?: Promise<File>;
|
|
51
|
+
protected playground?: UniversalPHP;
|
|
52
|
+
/**
|
|
53
|
+
* Creates a new Resource based on the given file reference
|
|
54
|
+
*
|
|
55
|
+
* @param ref The file reference to create the Resource for
|
|
56
|
+
* @param options Additional options for the Resource
|
|
57
|
+
* @returns A new Resource instance
|
|
58
|
+
*/
|
|
59
|
+
static create(ref: FileReference, { semaphore, progress }: ResourceOptions): Resource;
|
|
60
|
+
setPlayground(playground: UniversalPHP): void;
|
|
61
|
+
/**
|
|
62
|
+
* Resolves the file contents
|
|
63
|
+
* @returns The resolved file.
|
|
64
|
+
*/
|
|
65
|
+
abstract resolve(): Promise<File>;
|
|
66
|
+
/** The name of the referenced file */
|
|
67
|
+
abstract get name(): string;
|
|
68
|
+
/** Whether this Resource is loaded asynchronously */
|
|
69
|
+
get isAsync(): boolean;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A `Resource` that represents a file in the VFS (virtual file system) of the playground.
|
|
73
|
+
*/
|
|
74
|
+
export declare class VFSResource extends Resource {
|
|
75
|
+
private resource;
|
|
76
|
+
progress?: ProgressTracker | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Creates a new instance of `VFSResource`.
|
|
79
|
+
* @param playground The playground client.
|
|
80
|
+
* @param resource The VFS reference.
|
|
81
|
+
* @param progress The progress tracker.
|
|
82
|
+
*/
|
|
83
|
+
constructor(resource: VFSReference, progress?: ProgressTracker | undefined);
|
|
84
|
+
/** @inheritDoc */
|
|
85
|
+
resolve(): Promise<File>;
|
|
86
|
+
/** @inheritDoc */
|
|
87
|
+
get name(): string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* A `Resource` that represents a literal file.
|
|
91
|
+
*/
|
|
92
|
+
export declare class LiteralResource extends Resource {
|
|
93
|
+
private resource;
|
|
94
|
+
progress?: ProgressTracker | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Creates a new instance of `LiteralResource`.
|
|
97
|
+
* @param resource The literal reference.
|
|
98
|
+
* @param progress The progress tracker.
|
|
99
|
+
*/
|
|
100
|
+
constructor(resource: LiteralReference, progress?: ProgressTracker | undefined);
|
|
101
|
+
/** @inheritDoc */
|
|
102
|
+
resolve(): Promise<File>;
|
|
103
|
+
/** @inheritDoc */
|
|
104
|
+
get name(): string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A base class for `Resource`s that require fetching data from a remote URL.
|
|
108
|
+
*/
|
|
109
|
+
export declare abstract class FetchResource extends Resource {
|
|
110
|
+
progress?: ProgressTracker | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Creates a new instance of `FetchResource`.
|
|
113
|
+
* @param progress The progress tracker.
|
|
114
|
+
*/
|
|
115
|
+
constructor(progress?: ProgressTracker | undefined);
|
|
116
|
+
/** @inheritDoc */
|
|
117
|
+
resolve(): Promise<File>;
|
|
118
|
+
/**
|
|
119
|
+
* Gets the URL to fetch the data from.
|
|
120
|
+
* @returns The URL.
|
|
121
|
+
*/
|
|
122
|
+
protected abstract getURL(): string;
|
|
123
|
+
/**
|
|
124
|
+
* Gets the caption for the progress tracker.
|
|
125
|
+
* @returns The caption.
|
|
126
|
+
*/
|
|
127
|
+
protected get caption(): string;
|
|
128
|
+
/** @inheritDoc */
|
|
129
|
+
get name(): string;
|
|
130
|
+
/** @inheritDoc */
|
|
131
|
+
get isAsync(): boolean;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* A `Resource` that represents a file available from a URL.
|
|
135
|
+
*/
|
|
136
|
+
export declare class UrlResource extends FetchResource {
|
|
137
|
+
private resource;
|
|
138
|
+
/**
|
|
139
|
+
* Creates a new instance of `UrlResource`.
|
|
140
|
+
* @param resource The URL reference.
|
|
141
|
+
* @param progress The progress tracker.
|
|
142
|
+
*/
|
|
143
|
+
constructor(resource: UrlReference, progress?: ProgressTracker);
|
|
144
|
+
/** @inheritDoc */
|
|
145
|
+
getURL(): string;
|
|
146
|
+
/** @inheritDoc */
|
|
147
|
+
protected get caption(): string;
|
|
148
|
+
}
|
|
149
|
+
export declare function setPluginProxyURL(url: string): void;
|
|
150
|
+
/**
|
|
151
|
+
* A `Resource` that represents a WordPress core theme.
|
|
152
|
+
*/
|
|
153
|
+
export declare class CoreThemeResource extends FetchResource {
|
|
154
|
+
private resource;
|
|
155
|
+
constructor(resource: CoreThemeReference, progress?: ProgressTracker);
|
|
156
|
+
get name(): string;
|
|
157
|
+
getURL(): string;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* A resource that fetches a WordPress plugin from wordpress.org.
|
|
161
|
+
*/
|
|
162
|
+
export declare class CorePluginResource extends FetchResource {
|
|
163
|
+
private resource;
|
|
164
|
+
constructor(resource: CorePluginReference, progress?: ProgressTracker);
|
|
165
|
+
/** @inheritDoc */
|
|
166
|
+
get name(): string;
|
|
167
|
+
/** @inheritDoc */
|
|
168
|
+
getURL(): string;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Transforms a plugin slug into a directory zip name.
|
|
172
|
+
* If the input already ends with ".zip", returns it unchanged.
|
|
173
|
+
* Otherwise, appends ".latest-stable.zip".
|
|
174
|
+
*/
|
|
175
|
+
export declare function toDirectoryZipName(rawInput: string): string;
|
|
176
|
+
/**
|
|
177
|
+
* A decorator for a resource that adds functionality such as progress tracking and caching.
|
|
178
|
+
*/
|
|
179
|
+
export declare class DecoratedResource<T extends Resource> extends Resource {
|
|
180
|
+
private resource;
|
|
181
|
+
constructor(resource: T);
|
|
182
|
+
/** @inheritDoc */
|
|
183
|
+
resolve(): Promise<File>;
|
|
184
|
+
/** @inheritDoc */
|
|
185
|
+
setPlayground(playground: UniversalPHP): Promise<void>;
|
|
186
|
+
/** @inheritDoc */
|
|
187
|
+
get progress(): ProgressTracker | undefined;
|
|
188
|
+
/** @inheritDoc */
|
|
189
|
+
set progress(value: ProgressTracker | undefined);
|
|
190
|
+
/** @inheritDoc */
|
|
191
|
+
get name(): string;
|
|
192
|
+
/** @inheritDoc */
|
|
193
|
+
get isAsync(): boolean;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* A decorator for a resource that adds caching functionality.
|
|
197
|
+
*/
|
|
198
|
+
export declare class CachedResource<T extends Resource> extends DecoratedResource<T> {
|
|
199
|
+
protected promise?: Promise<File>;
|
|
200
|
+
/** @inheritDoc */
|
|
201
|
+
resolve(): Promise<File>;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* A decorator for a resource that adds concurrency control functionality through a semaphore.
|
|
205
|
+
*/
|
|
206
|
+
export declare class SemaphoreResource<T extends Resource> extends DecoratedResource<T> {
|
|
207
|
+
private readonly semaphore;
|
|
208
|
+
constructor(resource: T, semaphore: Semaphore);
|
|
209
|
+
/** @inheritDoc */
|
|
210
|
+
resolve(): Promise<File>;
|
|
211
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StepHandler } from '.';
|
|
2
|
+
export interface ActivatePluginStep {
|
|
3
|
+
step: 'activatePlugin';
|
|
4
|
+
plugin: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Activates a WordPress plugin in the Playground.
|
|
8
|
+
*
|
|
9
|
+
* @param playground The playground client.
|
|
10
|
+
* @param plugin The plugin slug.
|
|
11
|
+
*/
|
|
12
|
+
export declare const activatePlugin: StepHandler<ActivatePluginStep>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StepHandler } from '..';
|
|
2
|
+
export interface ApplyWordPressPatchesStep {
|
|
3
|
+
step: 'applyWordPressPatches';
|
|
4
|
+
siteUrl: string;
|
|
5
|
+
wordpressPath?: string;
|
|
6
|
+
patchSqlitePlugin?: boolean;
|
|
7
|
+
addPhpInfo?: boolean;
|
|
8
|
+
patchSiteUrl?: boolean;
|
|
9
|
+
disableSiteHealth?: boolean;
|
|
10
|
+
disableWpNewBlogNotification?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare const applyWordPressPatches: StepHandler<ApplyWordPressPatchesStep>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { PHPRunOptions, PHPRequest } from '@php-wasm/universal';
|
|
2
|
+
import { StepHandler } from '.';
|
|
3
|
+
export interface RunPHPStep {
|
|
4
|
+
step: 'runPHP';
|
|
5
|
+
code: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const runPHP: StepHandler<RunPHPStep>;
|
|
8
|
+
export interface RunPHPWithOptionsStep {
|
|
9
|
+
step: 'runPHPWithOptions';
|
|
10
|
+
options: PHPRunOptions;
|
|
11
|
+
}
|
|
12
|
+
export declare const runPHPWithOptions: StepHandler<RunPHPWithOptionsStep>;
|
|
13
|
+
export interface SetPhpIniEntryStep {
|
|
14
|
+
step: 'setPhpIniEntry';
|
|
15
|
+
key: string;
|
|
16
|
+
value: string;
|
|
17
|
+
}
|
|
18
|
+
export declare const setPhpIniEntry: StepHandler<SetPhpIniEntryStep>;
|
|
19
|
+
export interface RequestStep {
|
|
20
|
+
step: 'request';
|
|
21
|
+
request: PHPRequest;
|
|
22
|
+
}
|
|
23
|
+
export declare const request: StepHandler<RequestStep>;
|
|
24
|
+
export interface CpStep {
|
|
25
|
+
step: 'cp';
|
|
26
|
+
fromPath: string;
|
|
27
|
+
toPath: string;
|
|
28
|
+
}
|
|
29
|
+
export declare const cp: StepHandler<CpStep>;
|
|
30
|
+
export interface MvStep {
|
|
31
|
+
step: 'mv';
|
|
32
|
+
fromPath: string;
|
|
33
|
+
toPath: string;
|
|
34
|
+
}
|
|
35
|
+
export declare const mv: StepHandler<MvStep>;
|
|
36
|
+
export interface MkdirStep {
|
|
37
|
+
step: 'mkdir';
|
|
38
|
+
path: string;
|
|
39
|
+
}
|
|
40
|
+
export declare const mkdir: StepHandler<MkdirStep>;
|
|
41
|
+
export interface RmStep {
|
|
42
|
+
step: 'rm';
|
|
43
|
+
path: string;
|
|
44
|
+
}
|
|
45
|
+
export declare const rm: StepHandler<RmStep>;
|
|
46
|
+
export interface RmdirStep {
|
|
47
|
+
step: 'rmdir';
|
|
48
|
+
path: string;
|
|
49
|
+
}
|
|
50
|
+
export declare const rmdir: StepHandler<RmdirStep>;
|
|
51
|
+
export interface WriteFileStep<ResourceType> {
|
|
52
|
+
step: 'writeFile';
|
|
53
|
+
path: string;
|
|
54
|
+
data: ResourceType | string | Uint8Array;
|
|
55
|
+
}
|
|
56
|
+
export declare const writeFile: StepHandler<WriteFileStep<File>>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PHPResponse, UniversalPHP } from '@php-wasm/universal';
|
|
2
|
+
export declare function asDOM(response: PHPResponse): Document;
|
|
3
|
+
export declare function zipNameToHumanName(zipName: string): string;
|
|
4
|
+
type PatchFileCallback = (contents: string) => string | Uint8Array;
|
|
5
|
+
export declare function updateFile(php: UniversalPHP, path: string, callback: PatchFileCallback): Promise<void>;
|
|
6
|
+
export declare function fileToUint8Array(file: File): Promise<Uint8Array>;
|
|
7
|
+
export declare const VFS_CONFIG_FILE_BASENAME = "/vfs-blueprints";
|
|
8
|
+
export declare const VFS_CONFIG_FILE_PATH = "/vfs-blueprints/wp-config-consts.php";
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StepHandler } from '.';
|
|
2
|
+
export interface DefineSiteUrlStep {
|
|
3
|
+
step: 'defineSiteUrl';
|
|
4
|
+
siteUrl: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Sets site URL of the WordPress installation.
|
|
8
|
+
*
|
|
9
|
+
* @param playground The playground client.
|
|
10
|
+
* @param siteUrl
|
|
11
|
+
*/
|
|
12
|
+
export declare const defineSiteUrl: StepHandler<DefineSiteUrlStep>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { StepHandler } from '.';
|
|
2
|
+
/**
|
|
3
|
+
* The step object for defining constants in the VFS_CONFIG_FILE_PATH php file and loaded using the auto_prepend_file php.ini directive.
|
|
4
|
+
*/
|
|
5
|
+
export interface DefineVirtualWpConfigConstsStep {
|
|
6
|
+
step: 'defineVirtualWpConfigConsts';
|
|
7
|
+
/** The constants to define */
|
|
8
|
+
consts: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Function to define constants in the virtual VFS_CONFIG_FILE_PATH php file of a WordPress installation.
|
|
12
|
+
* The file should be dynamically loaded using the auto_prepend_file php.ini directive after this step.
|
|
13
|
+
*
|
|
14
|
+
* @param playground The playground client.
|
|
15
|
+
* @param wpConfigConst An object containing the constants to be defined and the optional virtual file system configuration file path.
|
|
16
|
+
* @returns Returns the virtual file system configuration file path.
|
|
17
|
+
* @see {@link https://www.php.net/manual/en/ini.core.php#ini.auto-prepend-file}
|
|
18
|
+
*/
|
|
19
|
+
export declare const defineVirtualWpConfigConsts: StepHandler<DefineVirtualWpConfigConstsStep>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { StepHandler } from '.';
|
|
2
|
+
/**
|
|
3
|
+
* The step object for defining constants in the wp-config.php file of a WordPress installation.
|
|
4
|
+
*/
|
|
5
|
+
export interface DefineWpConfigConstsStep {
|
|
6
|
+
step: 'defineWpConfigConsts';
|
|
7
|
+
/** The constants to define */
|
|
8
|
+
consts: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Sets site URL of the WordPress installation.
|
|
12
|
+
*
|
|
13
|
+
* @param playground The playground client.
|
|
14
|
+
* @param wpConfigConst
|
|
15
|
+
*/
|
|
16
|
+
export declare const defineWpConfigConsts: StepHandler<DefineWpConfigConstsStep>;
|
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
export { activatePlugin } from './activate-plugin';
|
|
2
2
|
export { applyWordPressPatches } from './apply-wordpress-patches';
|
|
3
|
-
export {
|
|
4
|
-
rm,
|
|
5
|
-
cp,
|
|
6
|
-
mkdir,
|
|
7
|
-
rmdir,
|
|
8
|
-
mv,
|
|
9
|
-
setPhpIniEntry,
|
|
10
|
-
runPHP,
|
|
11
|
-
runPHPWithOptions,
|
|
12
|
-
request,
|
|
13
|
-
writeFile,
|
|
14
|
-
} from './client-methods';
|
|
3
|
+
export { rm, cp, mkdir, rmdir, mv, setPhpIniEntry, runPHP, runPHPWithOptions, request, writeFile, } from './client-methods';
|
|
15
4
|
export { defineSiteUrl } from './define-site-url';
|
|
16
5
|
export { importFile, unzip, replaceSite, zipEntireSite } from './import-export';
|
|
17
6
|
export { installPlugin } from './install-plugin';
|
|
@@ -20,3 +9,4 @@ export { login } from './login';
|
|
|
20
9
|
export { runWpInstallationWizard } from './run-wp-installation-wizard';
|
|
21
10
|
export { setSiteOptions, updateUserMeta } from './site-data';
|
|
22
11
|
export { defineWpConfigConsts } from './define-wp-config-consts';
|
|
12
|
+
export { defineVirtualWpConfigConsts } from './define-virtual-wp-config-consts';
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { UniversalPHP } from '@php-wasm/universal';
|
|
2
|
+
import { StepHandler } from '.';
|
|
3
|
+
/**
|
|
4
|
+
* Full site export support:
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Export the current site as a zip file.
|
|
8
|
+
*
|
|
9
|
+
* @param playground Playground client.
|
|
10
|
+
*/
|
|
11
|
+
export declare function zipEntireSite(playground: UniversalPHP): Promise<File>;
|
|
12
|
+
export interface ReplaceSiteStep<ResourceType> {
|
|
13
|
+
step: 'replaceSite';
|
|
14
|
+
fullSiteZip: ResourceType;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Replace the current site with the contents of a full site zip file.
|
|
18
|
+
*
|
|
19
|
+
* @param playground Playground client.
|
|
20
|
+
* @param fullSiteZip Zipped WordPress site.
|
|
21
|
+
*/
|
|
22
|
+
export declare const replaceSite: StepHandler<ReplaceSiteStep<File>>;
|
|
23
|
+
export interface UnzipStep {
|
|
24
|
+
step: 'unzip';
|
|
25
|
+
zipPath: string;
|
|
26
|
+
extractToPath: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Unzip a zip file.
|
|
30
|
+
*
|
|
31
|
+
* @param playground Playground client.
|
|
32
|
+
* @param zipPath The zip file to unzip.
|
|
33
|
+
* @param extractTo The directory to extract the zip file to.
|
|
34
|
+
*/
|
|
35
|
+
export declare const unzip: StepHandler<UnzipStep>;
|
|
36
|
+
/**
|
|
37
|
+
* WXR and WXZ files support:
|
|
38
|
+
*/
|
|
39
|
+
/**
|
|
40
|
+
* Exports the WordPress database as a WXR file using
|
|
41
|
+
* the core WordPress export tool.
|
|
42
|
+
*
|
|
43
|
+
* @param playground Playground client
|
|
44
|
+
* @returns WXR file
|
|
45
|
+
*/
|
|
46
|
+
export declare function exportWXR(playground: UniversalPHP): Promise<File>;
|
|
47
|
+
/**
|
|
48
|
+
* Exports the WordPress database as a WXZ file using
|
|
49
|
+
* the export-wxz plugin from https://github.com/akirk/export-wxz.
|
|
50
|
+
*
|
|
51
|
+
* @param playground Playground client
|
|
52
|
+
* @returns WXZ file
|
|
53
|
+
*/
|
|
54
|
+
export declare function exportWXZ(playground: UniversalPHP): Promise<File>;
|
|
55
|
+
export interface ImportFileStep<ResourceType> {
|
|
56
|
+
step: 'importFile';
|
|
57
|
+
file: ResourceType;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Uploads a file to the WordPress importer and returns the response.
|
|
61
|
+
* Supports both WXR and WXZ files.
|
|
62
|
+
*
|
|
63
|
+
* @see https://github.com/WordPress/wordpress-importer/compare/master...akirk:wordpress-importer:import-wxz.patch
|
|
64
|
+
* @param playground Playground client.
|
|
65
|
+
* @param file The file to import.
|
|
66
|
+
*/
|
|
67
|
+
export declare const importFile: StepHandler<ImportFileStep<File>>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ProgressTracker } from '@php-wasm/progress';
|
|
2
|
+
import { UniversalPHP } from '@php-wasm/universal';
|
|
3
|
+
import { FileReference } from '../resources';
|
|
4
|
+
import { ActivatePluginStep } from './activate-plugin';
|
|
5
|
+
import { ApplyWordPressPatchesStep } from './apply-wordpress-patches';
|
|
6
|
+
import { DefineSiteUrlStep } from './define-site-url';
|
|
7
|
+
import { ImportFileStep, ReplaceSiteStep, UnzipStep } from './import-export';
|
|
8
|
+
import { InstallPluginStep, InstallPluginOptions } from './install-plugin';
|
|
9
|
+
import { InstallThemeStep, InstallThemeOptions } from './install-theme';
|
|
10
|
+
import { LoginStep } from './login';
|
|
11
|
+
import { RunWpInstallationWizardStep, WordPressInstallationOptions } from './run-wp-installation-wizard';
|
|
12
|
+
import { SetSiteOptionsStep, UpdateUserMetaStep } from './site-data';
|
|
13
|
+
import { RmStep, CpStep, MkdirStep, RmdirStep, MvStep, SetPhpIniEntryStep, RunPHPStep, RunPHPWithOptionsStep, RequestStep, WriteFileStep } from './client-methods';
|
|
14
|
+
import { DefineWpConfigConstsStep } from './define-wp-config-consts';
|
|
15
|
+
import { DefineVirtualWpConfigConstsStep } from './define-virtual-wp-config-consts';
|
|
16
|
+
export type Step = GenericStep<FileReference>;
|
|
17
|
+
export type StepDefinition = Step & {
|
|
18
|
+
progress?: {
|
|
19
|
+
weight?: number;
|
|
20
|
+
caption?: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export type GenericStep<Resource> = ActivatePluginStep | ApplyWordPressPatchesStep | CpStep | DefineWpConfigConstsStep | DefineVirtualWpConfigConstsStep | DefineSiteUrlStep | ImportFileStep<Resource> | InstallPluginStep<Resource> | InstallThemeStep<Resource> | LoginStep | MkdirStep | MvStep | RequestStep | ReplaceSiteStep<Resource> | RmStep | RmdirStep | RunPHPStep | RunPHPWithOptionsStep | RunWpInstallationWizardStep | SetPhpIniEntryStep | SetSiteOptionsStep | UnzipStep | UpdateUserMetaStep | WriteFileStep<Resource>;
|
|
24
|
+
export type { ActivatePluginStep, ApplyWordPressPatchesStep, CpStep, DefineWpConfigConstsStep, DefineSiteUrlStep, ImportFileStep, InstallPluginStep, InstallPluginOptions, InstallThemeStep, InstallThemeOptions, LoginStep, MkdirStep, MvStep, RequestStep, ReplaceSiteStep, RmStep, RmdirStep, RunPHPStep, RunPHPWithOptionsStep, RunWpInstallationWizardStep, WordPressInstallationOptions, SetPhpIniEntryStep, SetSiteOptionsStep, UnzipStep, UpdateUserMetaStep, WriteFileStep, };
|
|
25
|
+
export type StepHandler<S extends GenericStep<File>> = (php: UniversalPHP, args: Omit<S, 'step'>, progressArgs?: {
|
|
26
|
+
tracker: ProgressTracker;
|
|
27
|
+
initialCaption?: string;
|
|
28
|
+
}) => any;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { StepHandler } from '.';
|
|
2
|
+
/**
|
|
3
|
+
* The step to install a WordPress plugin in the Playground.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
*
|
|
7
|
+
* <code>
|
|
8
|
+
* {
|
|
9
|
+
* "step": "installPlugin",
|
|
10
|
+
* "pluginZipFile": "http://example.com/plugin.zip",
|
|
11
|
+
* "options": {
|
|
12
|
+
* "activate": true
|
|
13
|
+
* }
|
|
14
|
+
* }
|
|
15
|
+
* </code>
|
|
16
|
+
*/
|
|
17
|
+
export interface InstallPluginStep<ResourceType> {
|
|
18
|
+
/**
|
|
19
|
+
* The step identifier.
|
|
20
|
+
*/
|
|
21
|
+
step: 'installPlugin';
|
|
22
|
+
/**
|
|
23
|
+
* The plugin zip file to install.
|
|
24
|
+
*/
|
|
25
|
+
pluginZipFile: ResourceType;
|
|
26
|
+
/**
|
|
27
|
+
* Optional installation options.
|
|
28
|
+
*/
|
|
29
|
+
options?: InstallPluginOptions;
|
|
30
|
+
}
|
|
31
|
+
export interface InstallPluginOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Whether to activate the plugin after installing it.
|
|
34
|
+
*/
|
|
35
|
+
activate?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Installs a WordPress plugin in the Playground.
|
|
39
|
+
* Technically, it uses the same plugin upload form as a WordPress user
|
|
40
|
+
* would, and then activates the plugin if needed.
|
|
41
|
+
*
|
|
42
|
+
* @param playground The playground client.
|
|
43
|
+
* @param pluginZipFile The plugin zip file.
|
|
44
|
+
* @param options Optional. Set `activate` to false if you don't want to activate the plugin.
|
|
45
|
+
*/
|
|
46
|
+
export declare const installPlugin: StepHandler<InstallPluginStep<File>>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { StepHandler } from '.';
|
|
2
|
+
export interface InstallThemeStep<ResourceType> {
|
|
3
|
+
step: 'installTheme';
|
|
4
|
+
themeZipFile: ResourceType;
|
|
5
|
+
options?: InstallThemeOptions;
|
|
6
|
+
}
|
|
7
|
+
export interface InstallThemeOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Whether to activate the theme after installing it.
|
|
10
|
+
*/
|
|
11
|
+
activate?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Installs a WordPress theme in the Playground.
|
|
15
|
+
* Technically, it uses the same theme upload form as a WordPress user
|
|
16
|
+
* would, and then activates the theme if needed.
|
|
17
|
+
*
|
|
18
|
+
* @param playground The playground client.
|
|
19
|
+
* @param themeZipFile The theme zip file.
|
|
20
|
+
* @param options Optional. Set `activate` to false if you don't want to activate the theme.
|
|
21
|
+
*/
|
|
22
|
+
export declare const installTheme: StepHandler<InstallThemeStep<File>>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { StepHandler } from '.';
|
|
2
|
+
export type LoginStep = {
|
|
3
|
+
step: 'login';
|
|
4
|
+
username?: string;
|
|
5
|
+
password?: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Logs in to the Playground.
|
|
9
|
+
* Under the hood, this function submits the wp-login.php form
|
|
10
|
+
* just like a user would.
|
|
11
|
+
*
|
|
12
|
+
* @param playground The playground client.
|
|
13
|
+
* @param user The user to log in as. Defaults to 'admin'.
|
|
14
|
+
* @param password The password to log in with. Defaults to 'password'.
|
|
15
|
+
*/
|
|
16
|
+
export declare const login: StepHandler<LoginStep>;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: "<?php\n\nfunction zipDir($dir, $output, $additionalFiles = array())\n{\n $zip = new ZipArchive;\n $res = $zip->open($output, ZipArchive::CREATE);\n if ($res === TRUE) {\n foreach ($additionalFiles as $file) {\n $zip->addFile($file);\n }\n $directories = array(\n rtrim($dir, '/') . '/'\n );\n while (sizeof($directories)) {\n $dir = array_pop($directories);\n\n if ($handle = opendir($dir)) {\n while (false !== ($entry = readdir($handle))) {\n if ($entry == '.' || $entry == '..') {\n continue;\n }\n\n $entry = $dir . $entry;\n\n if (is_dir($entry)) {\n $directory_path = $entry . '/';\n array_push($directories, $directory_path);\n } else if (is_file($entry)) {\n $zip->addFile($entry);\n }\n }\n closedir($handle);\n }\n }\n $zip->close();\n chmod($output, 0777);\n }\n}\n\nfunction unzip($zipPath, $extractTo, $overwrite = true)\n{\n if(!is_dir($extractTo)) {\n mkdir($extractTo, 0777, true);\n }\n $zip = new ZipArchive;\n $res = $zip->open($zipPath);\n if ($res === TRUE) {\n $zip->extractTo($extractTo);\n $zip->close();\n chmod($extractTo, 0777);\n }\n}\n\n\nfunction delTree($dir)\n{\n $files = array_diff(scandir($dir), array('.', '..'));\n foreach ($files as $file) {\n (is_dir(\"$dir/$file\")) ? delTree(\"$dir/$file\") : unlink(\"$dir/$file\");\n }\n return rmdir($dir);\n}\n";
|
|
2
|
+
export default _default;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { StepHandler } from '.';
|
|
2
|
+
export interface RunWpInstallationWizardStep {
|
|
3
|
+
step: 'runWpInstallationWizard';
|
|
4
|
+
options: WordPressInstallationOptions;
|
|
5
|
+
}
|
|
6
|
+
export interface WordPressInstallationOptions {
|
|
7
|
+
adminUsername?: string;
|
|
8
|
+
adminPassword?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Installs WordPress
|
|
12
|
+
*
|
|
13
|
+
* @param playground The playground client.
|
|
14
|
+
* @param options Installation options.
|
|
15
|
+
*/
|
|
16
|
+
export declare const runWpInstallationWizard: StepHandler<RunWpInstallationWizardStep>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StepHandler } from '.';
|
|
2
|
+
export type SetSiteOptionsStep = {
|
|
3
|
+
step: 'setSiteOptions';
|
|
4
|
+
options: Record<string, unknown>;
|
|
5
|
+
};
|
|
6
|
+
export declare const setSiteOptions: StepHandler<SetSiteOptionsStep>;
|
|
7
|
+
export interface UpdateUserMetaStep {
|
|
8
|
+
step: 'updateUserMeta';
|
|
9
|
+
meta: Record<string, unknown>;
|
|
10
|
+
userId: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const updateUserMeta: StepHandler<UpdateUserMetaStep>;
|