bigbite / build-tools

MIT License
6 stars 1 forks source link

[88] Add version script to build tools #119

Open jordanharris-6 opened 5 months ago

jordanharris-6 commented 5 months ago

88 - This PR adds a new command to the build tools package so you can increase the increment the project version in all files without updating them manually.

The command is build-tools version <version type> <project>

The versions currently are

The project command can be left blank which will search the whole directory or you can list projects for example theme,plugin1, plugin2 etc

This will then go through and update the files in those directories.

It currently updates the version in package.json, plugin.php and style.css

To test: Once you have build-tools and yalc added to your test project Run build-tools version minor for example and this will go through all the files and folders in the directory your in and increment the version. It will also return which files it found and inform you of the old version and the version it has been upgraded too.

Video -> http://bigbite.im/v/tf2VBx

Change Log

ampersarnie commented 5 months ago

Not able to update from project directory.

When working from a theme or plugin directory, I am not able to increment the version of that project. I should be able to increment a project version on an individual basis.

Example

cd example-site/themes/test-theme
node ../../../src/cli.js version minor

Output

No Projects Found

[!NOTE] Edit: Issue has been addressed.

ampersarnie commented 5 months ago

Short version numbers not updated.

When updating a theme or plugin, if there is an assignment of a version such as 1.0 rather than 1.0.0. As 1.0 or similar is still valid when it comes to semver standards, these should also be accepted and incremented appropriately. Here's a list of some expectations around that.

Example If I change the version to 1.3 in example-site/themes/test-theme/styles.css and run the blow command.

cd example-site/themes/test-theme
node ../../../src/cli.js version minor

The blow is output, where it can be seen that it does not pick up the changed styles.css and opening the file itself will show that it remains 1.3.

searching all projects.....
Error incrementing version in client-mu-plugins/test-client-plugin/package.json: Invalid version: undefined
Error incrementing version in plugins/standards/package.json: Invalid version: undefined
#plugins/test-plugin/package.json: 1.4.0 -> 1.5.0
#plugins/test-plugin/src/plugin.php: 1.4.0 -> 1.5.0
#themes/test-theme/package.json: 1.3.0 -> 1.4.0

[!NOTE] Edit: Issue has been addressed.

ampersarnie commented 5 months ago

package-lock.json file not incremented

When updating a version, the package-lock.json also needs incrementing to keep it consistent with the package.json increase. Its also worth bearing in mind that this file may not exist, in which case it should be allowed to be skipped, so we're not forcing this file to exist even when required.

[!NOTE] Edit: Issue has been addressed.

ampersarnie commented 5 months ago

There are no options for a Release Candidate

Not in the original ticket but it would be nice to be able pass an rc sub command through to the script to create a Release Candidate version. This should work in the same way that has been implemented for Beta releases with the *:beta subcommand.

Example

build-tools version minor:rc

Output

#plugins/test-plugin/package.json: 1.8.0 -> 1.9.0-rc.1
#plugins/test-plugin/src/plugin.php: 1.8.0 -> 1.9.0-rc.1

[!NOTE] Edit: Issue has been addressed.

ampersarnie commented 5 months ago

Messaging inconsistencies

Terminal output doesn't have consistent approaches and language. The following changes should be made:

[!NOTE] Edit: Issue has been addressed.

ampersarnie commented 5 months ago

non-lowercase subcommands fail

Using subcommands that are not lowercase will fail, causing the same null assignment that happens without a subcommand.

Example

cd example-site/themes/test-theme
node ../../../src/cli.js version MINOR

Output

Error incrementing version in client-mu-plugins/test-client-plugin/package.json: Invalid version: undefined
Error incrementing version in plugins/standards/package.json: Invalid version: undefined
Error incrementing version in plugins/test-plugin/package.json: Invalid version: null
#themes/test-theme/package.json: 1.8.0 -> null
#themes/test-theme/style.css: 1.2.0 -> null

You have two options on how to approach this:

  1. Force all subcommands to be treated as lowercase so they're always actionable when used, or
  2. Check for non-valid subcommands and throw an error, preventing the process from going further and creating null versions.

[!NOTE] Edit: Issue has been addressed.

ampersarnie commented 5 months ago

Spacing inconsistencies

There's a fair amount of spacing consistencies between variable, and logical declarations. There are some indentation issues across files that would need addressing also.

const example = 'value';

if (logicCheck !== 123) {
    // ... 
}

Keeping some separation will help readability overall for others.

ampersarnie commented 5 months ago

Terminal Output Colours

It would be nice to be able to have some additional styling and formatting with the terminal output that takes advantage of ANSI escape codes and colours. See how it is done here for example.

[!NOTE] Edit: Issue has been addressed.

jordanharris-6 commented 4 months ago

@ampersarnie on this comment https://github.com/bigbite/build-tools/pull/119#issuecomment-2148227042

Could you let me know what im missing here please? when I add a RC to the command it adds a rc release number http://bigbite.im/i/qcTpJF

Also I added the 1 to the prerelease to semver inc as requested however it still comes out as .0 I wondered if you know where im going wrong with this?

Thanks 😄

ampersarnie commented 4 months ago

@jordanharris-6

Could you let me know what im missing here please? when I add a RC to the command it adds a rc release number http://bigbite.im/i/qcTpJF

When I'm looking at it, its increasing the wrong version. So if I have a current version of 10.0.0 and run a major:rc version increase, what I'm not left with is 10.0.1-rc.1. It's increasing the patch number, not the major. I would expect to get 11.0.0-rc.1.

Also I added the 1 to the prerelease to semver inc as requested however it still comes out as .0 I wondered if you know where im going wrong with this?

I changed it on your previous version to a 1 and it comes out as expected. But I'm not able to test with your latest changes as I'm getting the following error:

example-site git:(feat/88-version-increment) ✗ node ../src/cli.js version major:beta
Incrementing All Projects...
ReferenceError: path is not defined%
jordanharris-6 commented 4 months ago

@ampersarnie I think I have solved this by removing an if statement and adding in another command http://bigbite.im/v/ZIup9l

You can now do build-tools version prerelease:beta << this will change the last value in the version after -beta

jordanharris-6 commented 3 months ago

@ampersarnie I've refactored this now to re-use the existing functions