Skip to content

Commit

Permalink
cli: generate command should ask for plugin versioning method (#29078)
Browse files Browse the repository at this point in the history
* cli: `generate` command should ask for plugin versioning method

We've been defaulting to semver like we do for all other project types,
but it seems this may be confusing teams working on the plugins who may
be expecting WordPress-style versioning. Instead let's ask when the
plugin is being created.
  • Loading branch information
anomiex authored Feb 27, 2023
1 parent a2631f9 commit a80af64
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion tools/cli/commands/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,39 @@ export function getQuestions( type ) {
const packageQuestions = [];
const jsPackageQuestions = [];
const pluginQuestions = [
{
type: 'list',
name: 'versioningMethod',
message: 'How do you want versioning to work for your plugin?',
choices: [
// Note: There's no actual reason for recommending either option. Neither method is
// objectively better. We're not going to actually have consistency, tooling is
// already pretty simple in this respect (and without mandatory consistency it can't
// be simplified anyway), cognitive load would need research to determine the extent
// to which it's an issue, and WordPress core explicitly doesn't take a side on it.
// It comes down to which way the developers actually working on the plugin think
// about versioning for it.
//
// But everyone else wants to make an arbitrary recommendation anyway, so 🤷.
{
name:
'WordPress-style ("recommended"): Like 1.2, with each non-bugfix release always incrementing by 0.1.',
checked: true,
value: 'wordpress',
},
{
name:
'Semver: Like 1.2.3, with the next version depending on what kinds of changes are included.',
checked: true,
value: 'semver',
},
],
},
{
type: 'input',
name: 'version',
message: "What is the plugin's starting version?:",
default: '0.1.0-alpha',
default: answers => ( answers.versioningMethod === 'semver' ? '0.1.0-alpha' : '0.0-alpha' ),
},
{
type: 'list',
Expand Down Expand Up @@ -243,6 +271,8 @@ export async function generateProject(
fileURLToPath( new URL( './', import.meta.url ) ),
`../../../projects/${ type }/${ answers.name }`
);
answers.project = project;
answers.projDir = projDir;

if ( 'plugin' === answers.type && 'starter' === answers.pluginTemplate ) {
return generatePluginFromStarter( projDir, answers );
Expand Down Expand Up @@ -356,6 +386,13 @@ async function generatePluginFromStarter( projDir, answers ) {
path.join( projDir, 'src/class-jetpack-starter-plugin.php' ),
path.join( projDir, 'src/class-jetpack-' + answers.name + '.php' )
);

// Update composer.json.
const composerJson = readComposerJson( answers.project );
composerJson.extra ||= {};
composerJson.extra.changelogger ||= {};
composerJson.extra.changelogger.versioning = answers.versioningMethod;
writeComposerJson( answers.project, composerJson, answers.projDir );
}

/**
Expand Down Expand Up @@ -526,6 +563,8 @@ async function createComposerJson( composerJson, answers ) {
composerJson.extra = composerJson.extra || {};
composerJson.extra[ 'release-branch-prefix' ] = answers.name;
composerJson.type = 'wordpress-plugin';
composerJson.extra.changelogger ||= {};
composerJson.extra.changelogger.versioning = answers.versioningMethod;
break;
case 'js-package':
composerJson.scripts = {
Expand Down

0 comments on commit a80af64

Please sign in to comment.