diff --git a/README.md b/README.md index 55ecd73..c9610e0 100644 --- a/README.md +++ b/README.md @@ -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] @@ -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 diff --git a/bin/cli.js b/bin/cli.js index 84dd622..d24e72f 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -1,5 +1,6 @@ #!/usr/bin/env node +const { existsSync } = require('fs'); const { join } = require('path'); const yargs = require('yargs'); const packageJson = require('../package'); @@ -17,6 +18,7 @@ const { 'compare-path': comparePath, date, 'dry-run': isDryRun, + 'lock-file': lockFile, 'non-cc': isAllowNonConventionalCommits, override: overrideVersion, package: packageFile, @@ -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', @@ -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 () { diff --git a/src/cmds.js b/src/cmds.js index eca2d35..6c5885f 100644 --- a/src/cmds.js +++ b/src/cmds.js @@ -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}'