1- const { isUndefined} = require ( 'lodash' ) ;
2- const parser = require ( 'conventional-commits-parser' ) . sync ;
3- const filter = require ( 'conventional-commits-filter' ) ;
4- const debug = require ( 'debug' ) ( 'semantic-release:commit-analyzer' ) ;
5- const loadParserConfig = require ( './lib/load-parser-config.js' ) ;
6- const loadReleaseRules = require ( './lib/load-release-rules.js' ) ;
7- const analyzeCommit = require ( './lib/analyze-commit.js' ) ;
8- const compareReleaseTypes = require ( './lib/compare-release-types.js' ) ;
9- const RELEASE_TYPES = require ( './lib/default-release-types.js' ) ;
10- const DEFAULT_RELEASE_RULES = require ( './lib/default-release-rules.js' ) ;
1+ import { isUndefined } from "lodash-es" ;
2+ import { sync as parser } from "conventional-commits-parser" ;
3+ import filter from "conventional-commits-filter" ;
4+ import debugFactory from "debug" ;
5+ import loadParserConfig from "./lib/load-parser-config.js" ;
6+ import loadReleaseRules from "./lib/load-release-rules.js" ;
7+ import analyzeCommit from "./lib/analyze-commit.js" ;
8+ import compareReleaseTypes from "./lib/compare-release-types.js" ;
9+ import RELEASE_TYPES from "./lib/default-release-types.js" ;
10+ import DEFAULT_RELEASE_RULES from "./lib/default-release-rules.js" ;
11+
12+ const debug = debugFactory ( "semantic-release:commit-analyzer" ) ;
1113
1214/**
1315 * Determine the type of release to create based on a list of commits.
1416 *
1517 * @param {Object } pluginConfig The plugin configuration.
1618 * @param {String } pluginConfig.preset conventional-changelog preset ('angular', 'atom', 'codemirror', 'ember', 'eslint', 'express', 'jquery', 'jscs', 'jshint')
17- * @param {String } pluginConfig.config Requirable npm package with a custom conventional-changelog preset
19+ * @param {String } pluginConfig.config Requireable npm package with a custom conventional-changelog preset
1820 * @param {String|Array } pluginConfig.releaseRules A `String` to load an external module or an `Array` of rules.
1921 * @param {Object } pluginConfig.parserOpts Additional `conventional-changelog-parser` options that will overwrite ones loaded by `preset` or `config`.
2022 * @param {Object } context The semantic-release context.
@@ -23,43 +25,43 @@ const DEFAULT_RELEASE_RULES = require('./lib/default-release-rules.js');
2325 *
2426 * @returns {String|null } the type of release to create based on the list of commits or `null` if no release has to be done.
2527 */
26- async function analyzeCommits ( pluginConfig , context ) {
27- const { commits, logger} = context ;
28+ export async function analyzeCommits ( pluginConfig , context ) {
29+ const { commits, logger } = context ;
2830 const releaseRules = loadReleaseRules ( pluginConfig , context ) ;
2931 const config = await loadParserConfig ( pluginConfig , context ) ;
3032 let releaseType = null ;
3133
3234 filter (
3335 commits
34- . filter ( ( { message, hash} ) => {
36+ . filter ( ( { message, hash } ) => {
3537 if ( ! message . trim ( ) ) {
36- debug ( ' Skip commit %s with empty message' , hash ) ;
38+ debug ( " Skip commit %s with empty message" , hash ) ;
3739 return false ;
3840 }
3941
4042 return true ;
4143 } )
42- . map ( ( { message, ...commitProps } ) => ( { rawMsg : message , message, ...commitProps , ...parser ( message , config ) } ) )
43- ) . every ( ( { rawMsg, ...commit } ) => {
44+ . map ( ( { message, ...commitProps } ) => ( { rawMsg : message , message, ...commitProps , ...parser ( message , config ) } ) )
45+ ) . every ( ( { rawMsg, ...commit } ) => {
4446 logger . log ( `Analyzing commit: %s` , rawMsg ) ;
4547 let commitReleaseType ;
4648
4749 // Determine release type based on custom releaseRules
4850 if ( releaseRules ) {
49- debug ( ' Analyzing with custom rules' ) ;
51+ debug ( " Analyzing with custom rules" ) ;
5052 commitReleaseType = analyzeCommit ( releaseRules , commit ) ;
5153 }
5254
5355 // If no custom releaseRules or none matched the commit, try with default releaseRules
5456 if ( isUndefined ( commitReleaseType ) ) {
55- debug ( ' Analyzing with default rules' ) ;
57+ debug ( " Analyzing with default rules" ) ;
5658 commitReleaseType = analyzeCommit ( DEFAULT_RELEASE_RULES , commit ) ;
5759 }
5860
5961 if ( commitReleaseType ) {
60- logger . log ( ' The release type for the commit is %s' , commitReleaseType ) ;
62+ logger . log ( " The release type for the commit is %s" , commitReleaseType ) ;
6163 } else {
62- logger . log ( ' The commit should not trigger a release' ) ;
64+ logger . log ( " The commit should not trigger a release" ) ;
6365 }
6466
6567 // Set releaseType if commit's release type is higher
@@ -74,9 +76,7 @@ async function analyzeCommits(pluginConfig, context) {
7476
7577 return true ;
7678 } ) ;
77- logger . log ( ' Analysis of %s commits complete: %s release' , commits . length , releaseType || 'no' ) ;
79+ logger . log ( " Analysis of %s commits complete: %s release" , commits . length , releaseType || "no" ) ;
7880
7981 return releaseType ;
8082}
81-
82- module . exports = { analyzeCommits} ;
0 commit comments