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

Add rename script #278

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

seothemes
Copy link
Contributor

@seothemes seothemes commented Jul 3, 2019

I've created a node package to rename strings in the theme based on the theme claim package mentioned here.

Installation:

Save as a dev dependency:

npm install [email protected] --save-dev

Usage:

Run the following command and follow the CLI instructions:

npm run rename

I've probably missed a few strings but the bulk of it is working. Some of the things it renames:

  • Theme name
  • Package name
  • Puthor name
  • Author URI
  • Function prefixes
  • Text domains

Things to consider adding:

  • Version number

@nickcernis
Copy link
Collaborator

nickcernis commented Jul 10, 2019

Thanks for this, @seothemes. I like the interactive approach:

Screen Shot 2019-07-10 at 12 27 52

As you predicted, there are still several “sample” strings left after running npm run rename.

Screen Shot 2019-07-10 at 12 24 05

Do you think the theme-claim/genesis-theme-claim packages are flexible enough to allow us to process those too (and potentially reset version numbers and @since comments as you suggest)? Or would we be better off writing our own script? I can foresee us wanting to offer more Genesis specific options in the future (layouts available, default layout to use, templates available, number and type of widget areas etc.), which is why I wondered about going down a custom route here.

@seothemes
Copy link
Contributor Author

@nickcernis it will definitely handle all of the string replacements. I’ll get it updated tomorrow to include those files that it missed.

I’m not sure about version numbers though, maybe it would be better to use something like bump-regex to allow the version to be bumped independently.

@nickcernis
Copy link
Collaborator

nickcernis commented Jul 10, 2019

maybe it would be better to use something like bump-regex to allow the version to be bumped independently.

I was thinking more that, if someone's using Genesis Sample as a new theme for a project, it's undesirable to have all version numbers reading 3.0.1 (instead of 0.1.0 or 1.0.0), and all @since documentation comments reading different values that may exceed the project's first version (all existing @since should use the first version of the theme, ideally).

@seothemes
Copy link
Contributor Author

@nickcernis ok, I've bumped Genesis Theme Claim to version 0.3.0 which replaces all strings and resets the version number. Ready for you to take a look.

@nickcernis
Copy link
Collaborator

Nice work, @seothemes! Resetting versions to 1.0.0 is a great touch.

I found a few tiny 'Sample' strings still remaining in file/function names (ignore the package.json):

Screen Shot 2019-07-18 at 21 52 32

Should we delete the genesis-sample.pot file too? (An alternative might be to delete all existing *.pot files in the makepot script before creating a new one, which would recreate it with the correct filename the next time npm run makepot is run.)

I suppose someone might expect the changelog to be wiped for a new theme too, but they can update this themselves pretty easily.

Apart from that, it looks great. Thank you again for all the work that went into this.

@seothemes
Copy link
Contributor Author

@nickcernis updated to 0.4.0 which adds a new function to rename the POT file and WooCommerce CSS file. I wasn't able to find any "sample" strings after running the latest script.

Have also added a changelog reset function which should reset it to something like this:

# My Theme Changelog

## [1.0.0] - (current date)
* Initial commit.

Is there anything else you can think of to improve it further?

@nickcernis
Copy link
Collaborator

nickcernis commented Jul 19, 2019

Great job! The only two things I found with a new theme string of “Genesis NewTheme” were:

  1. The WooCommerce script is renamed to new-theme:

genesis-new-theme-woocommerce.css

But it's enqueued as (newtheme):

'src' => get_stylesheet_directory_uri() . '/lib/woocommerce/genesis-newtheme-woocommerce.css',

We should probably just change the src to use genesis_get_theme_handle()

'src' => get_stylesheet_directory_uri() . '/lib/woocommerce/' . genesis_get_theme_handle() . '-woocommerce.css',
de

  1. The pot file is renamed to genesis-newtheme.pot, which should be genesis-new-theme.pot, which is what you'll see created if you run npm run makepot.

Both are probably edge cases to do with the “NewTheme” string.

I'm otherwise happy to merge this pending approval from one more reviewer.

@seothemes
Copy link
Contributor Author

Would it be better to just rename the stylesheet to woocommerce.css? Having the theme name there is not really necessary since it's already in the handle. Can add to this PR.

For the POT file, that is expected. To have genesis-new-theme.pot you would need to enter "Genesis New Theme" as the theme name. This will need to be documented somewhere. Should I add some basic info to the readme?

@nickcernis
Copy link
Collaborator

nickcernis commented Jul 20, 2019

Would it be better to just rename the stylesheet to woocommerce.css? Having the theme name there is not really necessary since it's already in the handle. Can add to this PR.

Good idea.

For the POT file, that is expected. To have genesis-new-theme.pot you would need to enter "Genesis New Theme" as the theme name. This will need to be documented somewhere. Should I add some basic info to the readme?

If you run npm run makepot, you do get genesis-newtheme.pot (one dash) from the “Genesis NewTheme” name. The issue is that the existing lang file that was renamed during npm run rename is named genesis-new-theme.pot (two dashes) using a “Genesis NewTheme” name. So when someone runs npm run makepot, they'll have two files in the languages folder:

  • genesis-newtheme.pot
  • genesis-new-theme.pot

There's also an inconsistency between the Theme Name (“Genesis New Theme” in the stylesheet instead of the entered “Genesis NewTheme”), and the text domain (“genesis-newtheme”). It likely relates to the UpperCamelCase, so it's an edge case we could log and don't have to solve for immediately.

@bharath
Copy link

bharath commented Jul 20, 2019

@seothemes, @nickcernis

  1. landing-page.php header contains 'Genesis sample' instead of 'Genesis Sample' and the script is ignoring it instead of renaming.

Screenshot 2019-07-20 at 2 02 13 PM

  1. when I use the new theme string of "BK Child", The theme name is changed to 'B K Child' in style.css header

Screenshot 2019-07-20 at 2 02 34 PM

and in woocommerce stylesheet header

Screenshot 2019-07-20 at 5 38 11 PM

  1. woocommerce stylesheet is renamed to b-k-child-woocommerce.css instead of bk-child-woocommerce.css which throws an error.

Screenshot 2019-07-20 at 5 45 13 PM

Thanks,
Bharath.

@seothemes
Copy link
Contributor Author

seothemes commented Jul 21, 2019

Ok, 0.5.0 is ready for testing. I've fixed the file renaming issue - the strings are no longer split by capital letters. Only spaces are used as delimiters now. For example:

The string "BK Theme" will create a bk-theme.pot file. "Genesis NewTheme" will create genesis-newtheme.pot.

I've also added a new function to rename the actual theme directory. It follows the same rules as above.

@bharath 1 & 3 are fixed with ea5241b and 8ce5656. Make sure you test with this branch to get the latest commits.

@bharath
Copy link

bharath commented Jul 21, 2019

@seothemes

I am using new theme string of "BK Child" for testing.

  1. Capitalizing theme name string in landing-page.php fixed it.

  2. style.css header still says "B K Child" instead of "BK Child"

Screenshot 2019-07-21 at 12 09 30 PM

and in woocommerce stylesheet comment

Screenshot 2019-07-21 at 12 09 41 PM

  1. Renaming genesis-sample-woocommerce.css file to woocommerce.css works and no longer throws an error.

  2. Renaming actual theme directory works good.

@seothemes
Copy link
Contributor Author

@bharath 2 should be fixed with 0.6.0 ^

@bharath
Copy link

bharath commented Jul 30, 2019

Everything works good. Great work @seothemes

@sparkbold
Copy link

Have these conflicts ever got resolved and merged to current develop? I do need the feature to rename the theme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants