diff --git a/.nvmrc b/.nvmrc index 0e9dc6b5..2a59cf43 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v18.13.0 +v20.0.0 diff --git a/packages/wp-now/README.md b/packages/wp-now/README.md index 28c1c39b..674a23f6 100644 --- a/packages/wp-now/README.md +++ b/packages/wp-now/README.md @@ -57,6 +57,7 @@ wp-now php my-file.php - `--php=`: the version of PHP to use. This is optional and if not provided, it will use a default version which is `8.0`(example usage: `--php=7.4`); - `--port=`: the port number on which the server will listen. This is optional and if not provided, it will pick an open port number automatically. The default port number is set to `8881`(example of usage: `--port=3000`); - `--wp=`: the version of WordPress to use. This is optional and if not provided, it will use a default version. The default version is set to the [latest WordPress version](https://wordpress.org/download/releases/)(example usage: `--wp=5.8`) +- `--blueprint=`: the path of a JSON file with the Blueprint steps. This is optional, if provided will execute the defined Blueprints. See [Using Blueprints](#using-blueprints) for more details. Of these, `wp-now php` currently supports the `--path=` and `--php=` arguments. @@ -65,6 +66,92 @@ Of these, `wp-now php` currently supports the `--path=` and `--php= { const spinner = startSpinner('Starting the server...'); @@ -76,6 +80,7 @@ export async function runCli() { php: argv.php as SupportedPHPVersion, wp: argv.wp as string, port: argv.port as number, + blueprint: argv.blueprint as string, }); portFinder.setPort(options.port as number); const { url } = await startServer(options); diff --git a/packages/wp-now/src/tests/blueprints/wp-config.json b/packages/wp-now/src/tests/blueprints/wp-config.json new file mode 100644 index 00000000..05ae3d22 --- /dev/null +++ b/packages/wp-now/src/tests/blueprints/wp-config.json @@ -0,0 +1,12 @@ +{ + "steps": [ + { + "step": "defineWpConfigConsts", + "consts": { + "WP_HOME": "http://127.0.0.1", + "WP_SITEURL": "http://127.0.0.1" + }, + "virtualize": true + } + ] +} diff --git a/packages/wp-now/src/tests/blueprints/wp-debug.json b/packages/wp-now/src/tests/blueprints/wp-debug.json new file mode 100644 index 00000000..f189ee3a --- /dev/null +++ b/packages/wp-now/src/tests/blueprints/wp-debug.json @@ -0,0 +1,11 @@ +{ + "steps": [ + { + "step": "defineWpConfigConsts", + "consts": { + "WP_DEBUG_LOG": "/var/www/html/wp-content/themes/fake/example.log" + }, + "virtualize": true + } + ] +} diff --git a/packages/wp-now/src/tests/wp-now.spec.ts b/packages/wp-now/src/tests/wp-now.spec.ts index 5b4babde..41babc2b 100644 --- a/packages/wp-now/src/tests/wp-now.spec.ts +++ b/packages/wp-now/src/tests/wp-now.spec.ts @@ -737,6 +737,59 @@ describe('Test starting different modes', () => { expect(req.headers.get('content-encoding')).toBe(null); }); }); + + /** + * Test blueprints execution. + */ + describe('blueprints', () => { + const blueprintExamplesPath = path.join(__dirname, 'blueprints'); + + afterEach(() => { + // Clean the custom url from the SQLite database + fs.rmSync( + path.join(getWpNowTmpPath(), 'wp-content', 'playground'), + { recursive: true } + ); + }); + + test('setting wp-config variable WP_DEBUG_LOG through blueprint', async () => { + const options = await getWpNowConfig({ + blueprint: path.join(blueprintExamplesPath, 'wp-debug.json'), + }); + const { php, stopServer } = await startServer(options); + php.writeFile( + `${php.documentRoot}/print-constants.php`, + ` { + const options = await getWpNowConfig({ + blueprint: path.join(blueprintExamplesPath, 'wp-config.json'), + }); + const { php, stopServer } = await startServer(options); + expect(options.absoluteUrl).toBe('http://127.0.0.1'); + + php.writeFile( + `${php.documentRoot}/print-constants.php`, + ` { + output?.log(`Blueprint step completed: ${step.step}`); + }, + }); + await runBlueprintSteps(compiled, php); + } + await installationStep2(php); await login(php, { username: 'admin',