Skip to content

Commit

Permalink
fix(lock-file): allow adding lock files during release commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera committed Mar 21, 2024
1 parent a0ef71a commit 841741f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ or Yarn
commit [boolean] [default: true]
-d, --date [CHANGELOG.md] release date in the form of a valid date
string. Uses system new Date([your date])
[string] [default: "2024-01-29T07:40:54.615Z"]
[string] [default: "2024-03-21T13:20:45.593Z"]
-n, --non-cc Allow non-conventional commits to apply a semver weight
and appear in [CHANGELOG.md] under a general type
description. [boolean] [default: false]
Expand All @@ -65,6 +65,11 @@ or Yarn
This should start with "http". Attempts to use "$ git
remote get-url origin", if it starts with "http"
[string]
--lock-file Lock file read and relative path. Will attempt to
determine "package-lock.json" or "yarn.lock" use and
updates during release. Use if a "lock-like" file
outside of "package" and "yarn" lock is customized or
used. [string]
--package package.json read, output and relative path
[string] [default: "./package.json"]
--pr-path [CHANGELOG.md] path used for PRs/MRs. This will be
Expand Down
23 changes: 23 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node

const { existsSync } = require('fs');
const { join } = require('path');
const yargs = require('yargs');
const packageJson = require('../package');
Expand All @@ -17,6 +18,7 @@ const {
'compare-path': comparePath,
date,
'dry-run': isDryRun,
'lock-file': lockFile,
'non-cc': isAllowNonConventionalCommits,
override: overrideVersion,
package: packageFile,
Expand Down Expand Up @@ -94,6 +96,11 @@ const {
'Url override for updating all [CHANGELOG.md] base urls. This should start with "http". Attempts to use "$ git remote get-url origin", if it starts with "http"',
type: 'string'
})
.option('lock-file', {
describe:
'Lock file read and relative path. Will attempt to determine "package-lock.json" or "yarn.lock" use and updates during release. Use if a "lock-like" file outside of "package" and "yarn" lock is customized or used.',
type: 'string'
})
.option('package', {
default: './package.json',
describe: 'package.json read, output and relative path',
Expand Down Expand Up @@ -141,6 +148,22 @@ OPTIONS._set = {
isCommit,
isOverrideVersion: overrideVersion !== undefined,
linkUrl,
lockFile,
lockFilePath: function () {
if (lockFile) {
return join(this.contextPath, lockFile);
}

const foundLockFile = [join(this.contextPath, 'package-lock.json'), join(this.contextPath, 'yarn.lock')].find(
fileAndPath => existsSync(fileAndPath)
);

if (foundLockFile) {
return foundLockFile;
}

return undefined;
},
overrideVersion,
packageFile,
packagePath: function () {
Expand Down
6 changes: 4 additions & 2 deletions src/cmds.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ const runCmd = (cmd, { errorMessage = 'Skipping... {0}' } = {}) => {
* @param {object} options
* @param {string} options.changelogPath
* @param {string} options.packagePath
* @param {string} options.lockFilePath
* @param {string[]|string} options.releaseTypeScope
* @returns {string}
*/
const commitFiles = (version, { changelogPath, packagePath, releaseTypeScope } = OPTIONS) => {
const commitFiles = (version, { changelogPath, packagePath, lockFilePath, releaseTypeScope } = OPTIONS) => {
const isArray = Array.isArray(releaseTypeScope);
const updatedLockFilePath = (lockFilePath && ` ${lockFilePath}`) || '';

return runCmd(
`git add ${packagePath} ${changelogPath} && git commit ${packagePath} ${changelogPath} -m "${
`git add ${packagePath} ${changelogPath}${updatedLockFilePath} && git commit ${packagePath} ${changelogPath}${updatedLockFilePath} -m "${
(isArray && releaseTypeScope?.[0]) || releaseTypeScope
}: ${version}"`,
'Skipping release commit... {0}'
Expand Down

0 comments on commit 841741f

Please sign in to comment.