cz-cli icon indicating copy to clipboard operation
cz-cli copied to clipboard

Can I pass the adapter config from node but not read from then package.json

Open fancyboynet opened this issue 5 years ago • 3 comments

Hi, thanks you for the great work. I am trying write a new command to call the cz-cli like the doc said. However, I will get some error as below when I run the command if the pakcage.json does not have the config propery.

\node_modules\commitizen\node_modules\cz-conventional-changelog\index.js:10
defaultType: process.env.CZ_TYPE || config.defaultType,
                                             ^
TypeError: Cannot read property 'defaultType' of undefined

I want the user can just run a commit command and do not need to add package.json config. Is that possible?Someways like:

const bootstrap = require('commitizen/dist/cli/git-cz').bootstrap
const path = require('path')
bootstrap({
      cliPath: path.join(__dirname, '../node_modules/commitizen'),
      config: {
        "path": 'cz-conventional-changelog'
      },
      adapter: {
       "commitizen": {
          "path": "cz-conventional-changelog"
        }
      }
    })

fancyboynet avatar Aug 16 '19 06:08 fancyboynet

I had same problem, I solve like this:

const bootstrap = require('commitizen/dist/cli/git-cz').bootstrap
// Set the global constant
Object.assign(process.env, {
	'CZ_TYPE': ' ',
	'CZ_SCOPE': ' ',
	'CZ_SUBJECT': ' ',
	'CZ_BODY': ' ',
	'CZ_ISSUES': ' ',
	'CZ_MAX_HEADER_WIDTH': 100,
	'CZ_MAX_LINE_WIDTH': 100
})

bootstrap({
	cliPath: path.join(__dirname, '../../node_modules/commitizen'),
	// this is new
	config: {
		path: 'cz-conventional-changelog'
	}
})

Hope to help you

yuersen avatar Oct 16 '19 08:10 yuersen

@yuerbaby Thanks very much. After set the global constant, the prompt show,but it will throw a new error as below after I complete all the questions

error: pathspec 'commit' did not match any file(s) known to git.

Do you have any ideas?Thank you again.

fancyboynet avatar Nov 01 '19 07:11 fancyboynet

@fancyboynet I have the same error, Do you have any fix?

oscles avatar Sep 16 '22 20:09 oscles