Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install Theme no matter if the user run the npx create-wp-project command in the wrong folder #820

Closed
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions setup/create-wp-project/src/commands/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,39 @@ exports.handler = async (argv) => {
await clearConsole();
await writeIntro();

const fs = require('fs');

const findProjectRoot = (currentDir) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how will this work with the plugin flag?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Plugins to be in a separate task, but putting everything together into one PR can also work, especially when the changes are closely connected and won't get confusing. So, we can go ahead with that approach :).

if (!currentDir || currentDir === '/') {
// Reached the root without finding wp-config.php
return null;
}

const wpConfigPath = path.join(currentDir, 'wp-config.php');
const wpConfigExists = fs.existsSync(wpConfigPath);

if (wpConfigExists) {
// Found wp-config.php, return the current directory as the project root
return currentDir;
}

// Move up one directory level and continue the search
const parentDir = path.dirname(currentDir);
return findProjectRoot(parentDir);
};

// Find the root directory of the WordPress project
const rootDir = findProjectRoot(process.cwd());

if (!rootDir) {
console.error('Unable to find project root.');
process.exit(1);
}

// The root directory, navigate to the themes folder
const themesDir = path.join(rootDir, 'wp-content', 'themes');
process.chdir(themesDir);

// Trigger prompts if any of the required arguments was not set
const promptedInfo = await maybePrompt(scriptArguments, argv);

Expand Down
Loading