Skip to content

Commit a38fa9a

Browse files
wp-now: Allow plugins, themes or wp-content for 'wp-content' mode (#377)
Fixes #376 ## What? Allows the existence of `plugins`, `themes`, or `mu-plugins` to trigger 'wp-content' mode. Previously, 'wp-content' mode required both `themes` and `plugins`. ## Why? Some 'wp-content' projects may only have a `themes` or `plugins` directory at the beginning. ## Testing Instructions 1. Tests should pass. 2. Run `nx preview wp-now start --path=/path/to/wp-content-project` and verify the server starts as expected. 3. Run `nx preview wp-now start --path=/path/to/plugin-project` and verify the server starts as expected. 4. Run `nx preview wp-now start --path=/path/to/wordpress-project` and verify the server starts as expected.
1 parent f5e1654 commit a38fa9a

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

packages/wp-now/src/tests/mode-examples/wp-content-only-themes/themes/.gitkeep

Whitespace-only changes.

packages/wp-now/src/tests/wp-now.spec.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,22 @@ test('isWpContentDirectory detects a WordPress wp-content directory and infer WP
126126
test('isWpContentDirectory returns false for wp-content parent directory', () => {
127127
const projectPath = exampleDir + '/index';
128128
expect(isWpContentDirectory(projectPath)).toBe(false);
129+
expect(isWordPressDirectory(projectPath)).toBe(false);
129130
expect(inferMode(projectPath)).toBe(WPNowMode.INDEX);
130131
});
131132

132-
test.skip('isWpContentDirectory returns false for a directory with only one directory of plugins or themes', () => {
133-
const projectPath = exampleDir + '/not-wp-content';
134-
expect(isWpContentDirectory(projectPath)).toBe(false);
135-
expect(inferMode(projectPath)).toBe(WPNowMode.INDEX);
133+
test('isWpContentDirectory returns true for a directory with only themes directory', () => {
134+
const projectPath = exampleDir + '/wp-content-only-themes';
135+
expect(isWpContentDirectory(projectPath)).toBe(true);
136+
expect(isWordPressDirectory(projectPath)).toBe(false);
137+
expect(inferMode(projectPath)).toBe(WPNowMode.WP_CONTENT);
138+
});
139+
140+
test('isWpContentDirectory returns true for a directory with only mu-plugins directory', () => {
141+
const projectPath = exampleDir + '/wp-content-only-mu-plugins';
142+
expect(isWpContentDirectory(projectPath)).toBe(true);
143+
expect(isWordPressDirectory(projectPath)).toBe(false);
144+
expect(inferMode(projectPath)).toBe(WPNowMode.WP_CONTENT);
136145
});
137146

138147
// WordPress mode

packages/wp-now/src/wp-playground-wordpress/is-wp-content-directory.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import path from 'path';
88
* @returns A boolean value indicating whether the project is a WordPress wp-content directory.
99
*/
1010
export function isWpContentDirectory(projectPath: string): Boolean {
11+
const muPluginsExists = fs.existsSync(path.join(projectPath, 'mu-plugins'));
1112
const pluginsExists = fs.existsSync(path.join(projectPath, 'plugins'));
1213
const themesExists = fs.existsSync(path.join(projectPath, 'themes'));
13-
if (!pluginsExists || !themesExists) {
14-
return false;
14+
if (muPluginsExists || pluginsExists || themesExists) {
15+
return true;
1516
}
16-
return true;
17+
return false;
1718
}

0 commit comments

Comments
 (0)