Skip to content

Commit

Permalink
refactor(lock-file): optimize cli option (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera authored Mar 22, 2024
1 parent 4dbb795 commit 50eaf02
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ 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]
--lock-file Lock file read and relative path lookup. Defaults to
looking for git related updates to "package-lock.json"
and "yarn.lock" during release. You can pass your own
custom "lock" file if needed. To disable, pass a
falsely value.
[array] [default: ["./package-lock.json","./yarn.lock"]]
--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
21 changes: 8 additions & 13 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ const {
type: 'string'
})
.option('lock-file', {
default: ['./package-lock.json', './yarn.lock'],
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'
'Lock file read and relative path lookup. Defaults to looking for git related updates to "package-lock.json" and "yarn.lock" during release. You can pass your own custom "lock" file if needed. To disable, pass a falsely value.',
type: 'array',
coerce: args => args.flat().filter(value => !/null|undefined|false|0/.test(value) && value !== '')
})
.option('package', {
default: './package.json',
Expand Down Expand Up @@ -148,21 +150,14 @@ 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)
);
let foundLockFile;

if (foundLockFile) {
return foundLockFile;
if (Array.isArray(lockFile)) {
foundLockFile = lockFile.map(file => join(this.contextPath, file)).find(filePath => existsSync(filePath));
}

return undefined;
return foundLockFile;
},
overrideVersion,
packageFile,
Expand Down

0 comments on commit 50eaf02

Please sign in to comment.