-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Updater/refactor
Refactor
- Loading branch information
Showing
19 changed files
with
2,319 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
const { publish } = require('@semantic-release/github'); | ||
const withGitTag = require('./src/with-git-tag'); | ||
const versionToGitTag = require('./src/version-to-git-tag'); | ||
|
||
module.exports = withGitTag(publish); | ||
const { | ||
mapNextReleaseVersionToNextReleaseGitTag, | ||
} = require('./src/options-transforms'); | ||
|
||
module.exports = async (pluginConf, options) => | ||
publish( | ||
pluginConf, | ||
await mapNextReleaseVersionToNextReleaseGitTag(versionToGitTag)(options) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const commitAnalyzer = require('@semantic-release/commit-analyzer'); | ||
const { filterCommits } = require('./options-transforms'); | ||
const onlyPackageCommits = require('./only-package-commits'); | ||
|
||
async function analyzeCommits(pluginConf, options) { | ||
return commitAnalyzer( | ||
pluginConf, | ||
await filterCommits(onlyPackageCommits)(options) | ||
); | ||
} | ||
|
||
module.exports = analyzeCommits; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const { pipeP } = require('ramda'); | ||
const releaseNotesGenerator = require('@semantic-release/release-notes-generator'); | ||
const withPackageCommits = require('./only-package-commits'); | ||
const versionToGitTag = require('./version-to-git-tag'); | ||
|
||
const { | ||
filterCommits, | ||
mapNextReleaseVersion, | ||
mapLastReleaseVersionToLastReleaseGitTag, | ||
mapNextReleaseVersionToNextReleaseGitTag, | ||
} = require('./options-transforms'); | ||
|
||
async function generateNotes(pluginConf, options) { | ||
return releaseNotesGenerator( | ||
pluginConf, | ||
await pipeP( | ||
filterCommits(withPackageCommits), | ||
mapLastReleaseVersionToLastReleaseGitTag(versionToGitTag), | ||
mapNextReleaseVersionToNextReleaseGitTag(versionToGitTag), | ||
mapNextReleaseVersion(versionToGitTag) | ||
)(options) | ||
); | ||
} | ||
|
||
module.exports = generateNotes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const analyzeCommits = require('./analyze-commits'); | ||
const generateNotes = require('./generate-notes'); | ||
const getLastRelease = require('./get-last-release'); | ||
|
||
module.exports = { | ||
analyzeCommits, | ||
generateNotes, | ||
getLastRelease, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const { curry, set, view } = require('ramda'); | ||
|
||
/** | ||
* Async version of Ramda's `over` lens utility. | ||
*/ | ||
const overA = curry(async (lens, f, x) => { | ||
const value = await f(view(lens, x)); | ||
return set(lens, value, x); | ||
}); | ||
|
||
/** | ||
* Specialization of `overA`, using another lens as the source of the | ||
* data for the `over` transformation. | ||
*/ | ||
const overFromA = curry(async (lens1, lens2, f, x) => { | ||
const value = await f(view(lens2, x)); | ||
return set(lens1, value, x); | ||
}); | ||
|
||
module.exports = { | ||
overA, | ||
overFromA, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const debug = require('debug')('semantic-release:monorepo'); | ||
const pkgUp = require('pkg-up'); | ||
|
||
const { getCommitFiles, getGitRoot } = require('./git-utils'); | ||
|
||
const getPackagePath = async () => { | ||
const path = await pkgUp(); | ||
const gitRoot = await getGitRoot(); | ||
return path.replace('package.json', '').replace(`${gitRoot}/`, ''); | ||
}; | ||
|
||
const withFiles = async commits => { | ||
return Promise.all( | ||
commits.map(async commit => { | ||
const files = await getCommitFiles(commit.hash); | ||
return { ...commit, files }; | ||
}) | ||
); | ||
}; | ||
|
||
const onlyPackageCommits = async commits => { | ||
const packagePath = await getPackagePath(); | ||
debug('Filter commits by package path: "%s"', packagePath); | ||
const commitsWithFiles = await withFiles(commits); | ||
|
||
return commitsWithFiles.filter(({ files, subject }) => { | ||
const packageFile = files.find(path => path.indexOf(packagePath) === 0); | ||
|
||
if (packageFile) { | ||
debug( | ||
'Including commit "%s" because it modified package file "%s".', | ||
subject, | ||
packageFile | ||
); | ||
} | ||
|
||
return !!packageFile; | ||
}); | ||
}; | ||
|
||
module.exports = onlyPackageCommits; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const { compose, lensProp } = require('ramda'); | ||
const { overA, overFromA } = require('./lens-utils'); | ||
|
||
const commits = lensProp('commits'); | ||
const lastRelease = lensProp('lastRelease'); | ||
const nextRelease = lensProp('nextRelease'); | ||
const gitTag = lensProp('gitTag'); | ||
const version = lensProp('version'); | ||
|
||
const filterCommits = fn => overA(commits, async commits => await fn(commits)); | ||
|
||
const mapNextReleaseVersion = overA(compose(nextRelease, version)); | ||
|
||
const mapLastReleaseVersionToLastReleaseGitTag = overFromA( | ||
compose(lastRelease, gitTag), | ||
compose(lastRelease, version) | ||
); | ||
|
||
const mapNextReleaseVersionToNextReleaseGitTag = overFromA( | ||
compose(nextRelease, gitTag), | ||
compose(nextRelease, version) | ||
); | ||
|
||
module.exports = { | ||
filterCommits, | ||
mapNextReleaseVersion, | ||
mapLastReleaseVersionToLastReleaseGitTag, | ||
mapNextReleaseVersionToNextReleaseGitTag, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
const { | ||
filterCommits, | ||
mapNextReleaseVersion, | ||
mapLastReleaseVersionToLastReleaseGitTag, | ||
mapNextReleaseVersionToNextReleaseGitTag, | ||
} = require('./options-transforms'); | ||
|
||
const OPTIONS = { | ||
commits: [1, 2, 3, 4], | ||
lastRelease: { | ||
version: '1.2.3', | ||
}, | ||
nextRelease: { | ||
version: '4.5.6', | ||
}, | ||
}; | ||
|
||
const even = n => n % 2 === 0; | ||
const toTag = x => `tag-${x}`; | ||
|
||
describe('semantic-release plugin options transforms', () => { | ||
describe('#filterCommits', () => { | ||
it('allows transforming the "commits" option', async () => { | ||
const fn = commits => commits.filter(even); | ||
|
||
expect(await filterCommits(fn)(OPTIONS)).toEqual({ | ||
...OPTIONS, | ||
commits: [2, 4], | ||
}); | ||
}); | ||
}); | ||
|
||
describe('#mapNextReleaseVersion', () => { | ||
it('maps the nextRelease.version option', async () => { | ||
expect(await mapNextReleaseVersion(toTag)(OPTIONS)).toEqual({ | ||
...OPTIONS, | ||
nextRelease: { | ||
version: 'tag-4.5.6', | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('#mapLastReleaseVersionToLastReleaseGitTag', () => { | ||
it('maps the lastRelease.version option to lastRelease.gitTag', async () => { | ||
const fn = mapLastReleaseVersionToLastReleaseGitTag(toTag); | ||
|
||
expect(await fn(OPTIONS)).toEqual({ | ||
...OPTIONS, | ||
lastRelease: { | ||
gitTag: 'tag-1.2.3', | ||
version: '1.2.3', | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('#mapNextReleaseVersionToNextReleaseGitTag', () => { | ||
it('maps the nextRelease.version option to nextRelease.gitTag', async () => { | ||
const fn = mapNextReleaseVersionToNextReleaseGitTag(toTag); | ||
|
||
expect(await fn(OPTIONS)).toEqual({ | ||
...OPTIONS, | ||
nextRelease: { | ||
gitTag: 'tag-4.5.6', | ||
version: '4.5.6', | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.