Socket
Socket
Sign inDemoInstall

@alleyinteractive/create-release

Package Overview
Dependencies
50
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.2 to 0.1.3

28

dist/index.js

@@ -10,3 +10,3 @@ #!/usr/bin/env node

import entryArgs from './src/entryArgs.js';
import { bumpVersion, exitError, getCurrentVersion, getReleaseType, upgradeComposerVersion, upgradePluginVersion, upgradeReadmeVersion, } from './src/helpers.js';
import { bumpVersion, exitError, getCurrentVersion, getReleaseType, upgradeComposerVersion, upgradeNpmPackageVersion, upgradePluginVersion, upgradeReadmeVersion, } from './src/helpers.js';
/**

@@ -26,3 +26,3 @@ * Prompts the user to create a release.

}
const { 'dry-run': dryRun = false, } = entryArgs;
const { 'dry-run': dryRun = false, composer: updateComposer = false, npm: updateNpm = false, } = entryArgs;
if (dryRun) {

@@ -104,9 +104,21 @@ console.log(chalk.yellow('Dry Run: No changes will be made.'));

}
// Update the version in Composer.json.
if (dryRun) {
console.log(`Would be updating "version" in ${chalk.yellow('composer.json')} to ${chalk.yellow(releaseVersion)}`);
// Update the version in composer.json.
if (updateComposer) {
if (dryRun) {
console.log(`Would be updating "version" in ${chalk.yellow('composer.json')} to ${chalk.yellow(releaseVersion)}`);
}
else {
upgradeComposerVersion(basePath, releaseVersion);
console.log(`Updated "version" in ${chalk.yellow('composer.json')} to ${chalk.yellow(releaseVersion)}`);
}
}
else {
upgradeComposerVersion(basePath, releaseVersion);
console.log(`Updated "version" in ${chalk.yellow('composer.json')} to ${chalk.yellow(releaseVersion)}`);
// Update the version in package.json.
if (updateNpm) {
if (dryRun) {
console.log(`Would be updating "version" in ${chalk.yellow('package.json')} to ${chalk.yellow(releaseVersion)}`);
}
else {
upgradeNpmPackageVersion(basePath, releaseVersion);
console.log(`Updated "version" in ${chalk.yellow('package.json')} to ${chalk.yellow(releaseVersion)}`);
}
}

@@ -113,0 +125,0 @@ // Update the version in the plugin header.

@@ -10,2 +10,4 @@ /**

path?: string;
composer?: boolean;
npm?: boolean;
'dry-run'?: boolean;

@@ -12,0 +14,0 @@ help?: boolean;

@@ -33,2 +33,12 @@ import { parse } from 'ts-command-line-args';

},
composer: {
type: Boolean,
description: 'Update the composer.json file version.',
optional: true,
},
npm: {
type: Boolean,
description: 'Update the package.json file version.',
optional: true,
},
'dry-run': {

@@ -35,0 +45,0 @@ type: Boolean,

@@ -27,2 +27,6 @@ import { ReleaseType } from './options';

/**
* Upgrade the version number in the package.json file.
*/
declare function upgradeNpmPackageVersion(basePath: string, version: string): void;
/**
* Upgrade the version number in the plugin header.

@@ -35,3 +39,3 @@ */

declare function upgradeReadmeVersion(basePath: string, version: string): void;
export { exitError, getCurrentVersion, getReleaseType, bumpVersion, upgradeComposerVersion, upgradePluginVersion, upgradeReadmeVersion, };
export { exitError, getCurrentVersion, getReleaseType, bumpVersion, upgradeComposerVersion, upgradeNpmPackageVersion, upgradePluginVersion, upgradeReadmeVersion, };
//# sourceMappingURL=helpers.d.ts.map

@@ -54,17 +54,2 @@ import fs from 'fs';

function getCurrentVersion(path) {
// Check if the composer.json file exists.
if (fs.existsSync(`${path}/composer.json`)) {
try {
const contents = JSON.parse(fs.readFileSync(`${path}/composer.json`, 'utf8'));
if (contents.version) {
if (valid(contents.version)) {
return contents.version;
}
exitError(`The version number in the composer.json file is not a valid semver version number: ${contents.version}`);
}
}
catch (error) {
// Do nothing.
}
}
// Retrieve the plugin file to read the headers from.

@@ -89,2 +74,17 @@ const files = [

}
// Check if the composer.json file exists.
if (fs.existsSync(`${path}/composer.json`)) {
try {
const contents = JSON.parse(fs.readFileSync(`${path}/composer.json`, 'utf8'));
if (contents.version) {
if (valid(contents.version)) {
return contents.version;
}
exitError(`The version number in the composer.json file is not a valid semver version number: ${contents.version}`);
}
}
catch (error) {
// Do nothing.
}
}
return undefined;

@@ -164,2 +164,31 @@ }

/**
* Upgrade the version number in the package.json file.
*/
function upgradeNpmPackageVersion(basePath, version) {
try {
const contents = JSON.parse(fs.readFileSync(`${basePath}/package.json`, 'utf8'));
// Insert the version after the description/name index if it doesn't exist.
if (!contents.version) {
const insertIndex = Object.keys(contents).indexOf('name');
contents.version = version;
const newContents = {};
Object.keys(contents).forEach((key, index) => {
if (index === insertIndex + 1) {
newContents.version = version;
}
newContents[key] = contents[key];
});
fs.writeFileSync(`${basePath}/package.json`, `${JSON.stringify(newContents, null, 4)}\n`);
}
else {
contents.version = version;
fs.writeFileSync(`${basePath}/package.json`, `${JSON.stringify(contents, null, 4)}\n`);
}
}
catch (error) {
console.error(error); // eslint-disable-line no-console
exitError('There was an error upgrading the version number in the package.json file.');
}
}
/**
* Upgrade the version number in the plugin header.

@@ -178,7 +207,10 @@ */

}
// Replace "* Version: " in the plugin header with "* Version: {version}".
const contents = fs.readFileSync(file, 'utf8');
const newContents = contents.replace(/(\* Version: )(.*)/g, `$1${version}`);
fs.writeFileSync(file, newContents);
if (contents !== newContents) {
fs.writeFileSync(file, newContents);
return;
}
}
exitError('Unable to upgrade the "Version" plugin header.');
}

@@ -202,6 +234,8 @@ /**

const newContents = contents.replace(/(Stable tag: )(.*)/g, `$1${version}`);
fs.writeFileSync(file, newContents);
if (contents !== newContents) {
fs.writeFileSync(file, newContents);
}
}
}
export { exitError, getCurrentVersion, getReleaseType, bumpVersion, upgradeComposerVersion, upgradePluginVersion, upgradeReadmeVersion, };
export { exitError, getCurrentVersion, getReleaseType, bumpVersion, upgradeComposerVersion, upgradeNpmPackageVersion, upgradePluginVersion, upgradeReadmeVersion, };
//# sourceMappingURL=helpers.js.map

@@ -6,3 +6,3 @@ {

"name": "@alleyinteractive/create-release",
"version": "0.1.2",
"version": "0.1.3",
"devDependencies": {

@@ -9,0 +9,0 @@ "@alleyinteractive/eslint-config": "*",

@@ -6,8 +6,14 @@ # Create Release

When run, it will trigger a new version to be set in the plugin's
`composer.json` and plugin's header. This sets up the [GitHub Action
workflow](https://github.com/alleyinteractive/create-wordpress-plugin/blob/HEAD/.github/workflows/built-release.yml)
When run, it will trigger a new version to be set in the plugin's header and
optionally in the plugin's `composer.json`/`package.json` files. This sets up
the [GitHub Action workflow](https://github.com/alleyinteractive/create-wordpress-plugin/blob/HEAD/.github/workflows/built-release.yml)
which listens for a new version to automatically build and publish to Git.
Running this package's command is optional and can be done manually by the user.
Running this package's command is optional and the work can still be done
manually by the user but does aim to make it easier to develop and release new
versions of a plugin. The command does not commit or push any changes to Git,
only changing the local files and deferring to the user to commit and push
changes to Git.
## Usage

@@ -30,2 +36,4 @@

-p, --path string The path to the plugin. Supports relative and absolute paths.
--composer Update the version in the plugin's composer.json file.
--npm Update the version in the plugin's package.json file.
--dry-run Run the command without making any changes.

@@ -32,0 +40,0 @@ -h, --help Prints help information.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc