Skip to content

Commit

Permalink
perf(cmds,files): prep strings for cli options
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera committed Oct 13, 2022
1 parent a9147eb commit 974e795
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/cmds.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ const runCmd = (cmd, { errorMessage = 'Skipping... {0}' } = {}) => {
* @param {*|string} version
* @param {object} options
* @param {string} options.contextPath
* @param {string} options.releaseTypeScope
* @returns {string}
*/
const commitFiles = (version, { contextPath = CONTEXT_PATH } = {}) =>
const commitFiles = (version, { contextPath = CONTEXT_PATH, releaseTypeScope = 'chore(release)' } = {}) =>
runCmd(
`git add ${join(contextPath, 'package.json')} ${join(contextPath, 'CHANGELOG.md')} && git commit ${join(
contextPath,
'package.json'
)} ${join(contextPath, 'CHANGELOG.md')} -m "chore(release): ${version}"`,
)} ${join(contextPath, 'CHANGELOG.md')} -m "${releaseTypeScope}: ${version}"`,
'Skipping release commit... {0}'
);

Expand All @@ -56,10 +57,12 @@ const getCurrentVersion = ({ contextPath = CONTEXT_PATH } = {}) => {
/**
* Get last release commit hash
*
* @param {object} options
* @param {string} releaseTypeScope
* @returns {string}
*/
const getReleaseCommit = () =>
runCmd('git log --grep="chore(release)" --pretty=oneline -1', 'Skipping release commit check... {0}');
const getReleaseCommit = ({ releaseTypeScope = 'chore(release)' } = {}) =>
runCmd(`git log --grep="${releaseTypeScope}" --pretty=oneline -1`, 'Skipping release commit check... {0}');

/**
* Get the repositories remote
Expand Down
4 changes: 3 additions & 1 deletion src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const { _COMMIT_CHANGELOG_CONTEXT_PATH: CONTEXT_PATH } = global;
* @param {object} options
* @param {string} options.fallbackPackageVersion
* @param {string} options.filePath
* @param {string} options.headerMd
* @param {boolean} options.isDryRun
* @returns {string}
*/
Expand All @@ -21,13 +22,14 @@ const updateChangelog = (
date,
fallbackPackageVersion = '¯\\_(ツ)_/¯',
filePath = join(CONTEXT_PATH, `/CHANGELOG.md`),
headerMd = `# Changelog\nAll notable changes to this project will be documented in this file.`,
isDryRun = false
} = {}
) => {
const systemTimestamp = ((date && new Date(date)) || new Date()).toLocaleDateString('fr-CA', {
timeZone: 'UTC'
});
let header = `# Changelog\nAll notable changes to this project will be documented in this file.`;
let header = headerMd;
let body = '';

if (existsSync(filePath)) {
Expand Down
6 changes: 3 additions & 3 deletions tests/__snapshots__/code.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
exports[`General code checks should only have specific console.[warn|log|info|error] methods: console methods 1`] = `
[
"cmds.js:21: console.error(color.RED, errorMessage.replace('{0}', e.message), color.NOCOLOR)",
"cmds.js:122: console.error(color.RED, \`Semver: \${e.message}\`, color.NOCOLOR)",
"cmds.js:152: console.error(color.RED, \`Semver: \${e.message}\`, color.NOCOLOR)",
"files.js:48: console.info(\` \${output}\`)",
"cmds.js:125: console.error(color.RED, \`Semver: \${e.message}\`, color.NOCOLOR)",
"cmds.js:155: console.error(color.RED, \`Semver: \${e.message}\`, color.NOCOLOR)",
"files.js:50: console.info(\` \${output}\`)",
"global.js:64: console.error(color.RED, \`Conventional commit types: \${e.message}\`, color.NOCOLOR)",
"index.js:40: console.info( index.js:54: console.info(color.NOCOLOR)",
]
Expand Down

0 comments on commit 974e795

Please sign in to comment.