@wp-playground/blueprints 0.9.19 → 0.9.20

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.
@@ -0,0 +1,89 @@
1
+ import { SupportedPHPExtensionBundle, SupportedPHPVersion } from '../../../../php-wasm/universal/src/index.ts';
2
+ import { StepDefinition } from './steps';
3
+ import { FileReference } from './resources';
4
+ export interface Blueprint {
5
+ /**
6
+ * The URL to navigate to after the blueprint has been run.
7
+ */
8
+ landingPage?: string;
9
+ /**
10
+ * Optional description. It doesn't do anything but is exposed as
11
+ * a courtesy to developers who may want to document which blueprint
12
+ * file does what.
13
+ *
14
+ * @deprecated Use meta.description instead.
15
+ */
16
+ description?: string;
17
+ /**
18
+ * Optional metadata. Used by the Blueprints gallery at https://github.com/WordPress/blueprints
19
+ */
20
+ meta?: {
21
+ /**
22
+ * A clear and concise name for your Blueprint.
23
+ */
24
+ title: string;
25
+ /**
26
+ * A brief explanation of what your Blueprint offers.
27
+ */
28
+ description?: string;
29
+ /**
30
+ * A GitHub username of the author of this Blueprint.
31
+ */
32
+ author: string;
33
+ /**
34
+ * Relevant categories to help users find your Blueprint in the future Blueprints section on WordPress.org.
35
+ */
36
+ categories?: string[];
37
+ };
38
+ /**
39
+ * The preferred PHP and WordPress versions to use.
40
+ */
41
+ preferredVersions?: {
42
+ /**
43
+ * The preferred PHP version to use.
44
+ * If not specified, the latest supported version will be used
45
+ */
46
+ php: SupportedPHPVersion | 'latest';
47
+ /**
48
+ * The preferred WordPress version to use.
49
+ * If not specified, the latest supported version will be used
50
+ */
51
+ wp: string | 'latest';
52
+ };
53
+ features?: {
54
+ /** Should boot with support for network request via wp_safe_remote_get? */
55
+ networking?: boolean;
56
+ };
57
+ /**
58
+ * PHP Constants to define on every request
59
+ */
60
+ constants?: Record<string, string>;
61
+ /**
62
+ * WordPress plugins to install and activate
63
+ */
64
+ plugins?: Array<string | FileReference>;
65
+ /**
66
+ * WordPress site options to define
67
+ */
68
+ siteOptions?: Record<string, string> & {
69
+ /** The site title */
70
+ blogname?: string;
71
+ };
72
+ /**
73
+ * User to log in as.
74
+ * If true, logs the user in as admin/password.
75
+ */
76
+ login?: boolean | {
77
+ username: string;
78
+ password: string;
79
+ };
80
+ /**
81
+ * The PHP extensions to use.
82
+ */
83
+ phpExtensionBundles?: SupportedPHPExtensionBundle[];
84
+ /**
85
+ * The steps to run after every other operation in this Blueprint was
86
+ * executed.
87
+ */
88
+ steps?: Array<StepDefinition | string | undefined | false | null>;
89
+ }
@@ -0,0 +1,47 @@
1
+ import { ProgressTracker } from '../../../../php-wasm/progress/src/index.ts';
2
+ import { Semaphore } from '../../../../php-wasm/util/src/index.ts';
3
+ import { SupportedPHPExtension, SupportedPHPVersion, UniversalPHP } from '../../../../php-wasm/universal/src/index.ts';
4
+ import { StepDefinition } from './steps';
5
+ import { Blueprint } from './blueprint';
6
+ export type CompiledStep = (php: UniversalPHP) => Promise<void> | void;
7
+ export interface CompiledBlueprint {
8
+ /** The requested versions of PHP and WordPress for the blueprint */
9
+ versions: {
10
+ php: SupportedPHPVersion;
11
+ wp: string;
12
+ };
13
+ /** The requested PHP extensions to load */
14
+ phpExtensions: SupportedPHPExtension[];
15
+ features: {
16
+ /** Should boot with support for network request via wp_safe_remote_get? */
17
+ networking: boolean;
18
+ };
19
+ /** The compiled steps for the blueprint */
20
+ run: (playground: UniversalPHP) => Promise<void>;
21
+ }
22
+ export type OnStepCompleted = (output: any, step: StepDefinition) => any;
23
+ export interface CompileBlueprintOptions {
24
+ /** Optional progress tracker to monitor progress */
25
+ progress?: ProgressTracker;
26
+ /** Optional semaphore to control access to a shared resource */
27
+ semaphore?: Semaphore;
28
+ /** Optional callback with step output */
29
+ onStepCompleted?: OnStepCompleted;
30
+ }
31
+ /**
32
+ * Compiles Blueprint into a form that can be executed.
33
+ *
34
+ * @param playground The PlaygroundClient to use for the compilation
35
+ * @param blueprint The bBueprint to compile
36
+ * @param options Additional options for the compilation
37
+ * @returns The compiled blueprint
38
+ */
39
+ export declare function compileBlueprint(blueprint: Blueprint, { progress, semaphore, onStepCompleted, }?: CompileBlueprintOptions): CompiledBlueprint;
40
+ export declare function validateBlueprint(blueprintMaybe: object): {
41
+ valid: true;
42
+ errors?: undefined;
43
+ } | {
44
+ valid: false;
45
+ errors: import("ajv").ErrorObject<string, Record<string, any>, unknown>[] | undefined;
46
+ };
47
+ export declare function runBlueprintSteps(compiledBlueprint: CompiledBlueprint, playground: UniversalPHP): Promise<void>;
@@ -0,0 +1,210 @@
1
+ import { ProgressTracker } from '../../../../php-wasm/progress/src/index.ts';
2
+ import { UniversalPHP } from '../../../../php-wasm/universal/src/index.ts';
3
+ import { Semaphore } from '../../../../php-wasm/util/src/index.ts';
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
+ /**
150
+ * A `Resource` that represents a WordPress core theme.
151
+ */
152
+ export declare class CoreThemeResource extends FetchResource {
153
+ private resource;
154
+ constructor(resource: CoreThemeReference, progress?: ProgressTracker);
155
+ get name(): string;
156
+ getURL(): string;
157
+ }
158
+ /**
159
+ * A resource that fetches a WordPress plugin from wordpress.org.
160
+ */
161
+ export declare class CorePluginResource extends FetchResource {
162
+ private resource;
163
+ constructor(resource: CorePluginReference, progress?: ProgressTracker);
164
+ /** @inheritDoc */
165
+ get name(): string;
166
+ /** @inheritDoc */
167
+ getURL(): string;
168
+ }
169
+ /**
170
+ * Transforms a plugin slug into a directory zip name.
171
+ * If the input already ends with ".zip", returns it unchanged.
172
+ * Otherwise, appends ".latest-stable.zip".
173
+ */
174
+ export declare function toDirectoryZipName(rawInput: string): string;
175
+ /**
176
+ * A decorator for a resource that adds functionality such as progress tracking and caching.
177
+ */
178
+ export declare class DecoratedResource<T extends Resource> extends Resource {
179
+ private resource;
180
+ constructor(resource: T);
181
+ /** @inheritDoc */
182
+ resolve(): Promise<File>;
183
+ /** @inheritDoc */
184
+ setPlayground(playground: UniversalPHP): Promise<void>;
185
+ /** @inheritDoc */
186
+ get progress(): ProgressTracker | undefined;
187
+ /** @inheritDoc */
188
+ set progress(value: ProgressTracker | undefined);
189
+ /** @inheritDoc */
190
+ get name(): string;
191
+ /** @inheritDoc */
192
+ get isAsync(): boolean;
193
+ }
194
+ /**
195
+ * A decorator for a resource that adds caching functionality.
196
+ */
197
+ export declare class CachedResource<T extends Resource> extends DecoratedResource<T> {
198
+ protected promise?: Promise<File>;
199
+ /** @inheritDoc */
200
+ resolve(): Promise<File>;
201
+ }
202
+ /**
203
+ * A decorator for a resource that adds concurrency control functionality through a semaphore.
204
+ */
205
+ export declare class SemaphoreResource<T extends Resource> extends DecoratedResource<T> {
206
+ private readonly semaphore;
207
+ constructor(resource: T, semaphore: Semaphore);
208
+ /** @inheritDoc */
209
+ resolve(): Promise<File>;
210
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-playground/blueprints",
3
- "version": "0.9.19",
3
+ "version": "0.9.20",
4
4
  "exports": {
5
5
  ".": {
6
6
  "import": "./index.js",
@@ -21,7 +21,7 @@
21
21
  "access": "public",
22
22
  "directory": "../../../dist/packages/playground/blueprints"
23
23
  },
24
- "gitHead": "aafbbcdc4b0644885bd55d0ed67381952f0b16b6",
24
+ "gitHead": "f619fcb719128d247bec296b9339aff52101e948",
25
25
  "engines": {
26
26
  "node": ">=18.18.0",
27
27
  "npm": ">=8.11.0"
File without changes