Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
✨ isEnabled checks (config.)enabled; developer bypass .env
Browse files Browse the repository at this point in the history
This allows for developers to override a repo with a `.env` process flag that
the team can agree to put in `changelog.config.js`

.env => GIT_CZ = false

Then in `changelog.config.js` can pass `enabled: process.env.GIT_CZ || true`
  • Loading branch information
JeromeFitz authored and kodiakhq[bot] committed May 19, 2021
1 parent 7b12e13 commit a699016
Show file tree
Hide file tree
Showing 16 changed files with 268 additions and 277 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const config = require('@jeromefitz/codestyle/.eslintrc.js')
const config = require('@jeromefitz/codestyle/.eslintrc')

module.exports = {
...config,
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const config = require('@jeromefitz/codestyle/.prettierrc.js')
const config = require('@jeromefitz/codestyle/.prettierrc')

module.exports = {
...config,
Expand Down
8 changes: 6 additions & 2 deletions changelog.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// @note(typescript) need to grab the built version for testing
const config = require('./dist/themes/gitmoji.js').default
const isCI = require('is-ci')
!isCI && require('dotenv').config({ path: './.env' })
const config = require('./dist/themes/gitmoji').default

const OVERRIDE_TEST = false

const enabled = (OVERRIDE_TEST && (process.env.GIT_CZ || !OVERRIDE_TEST)) || true

const typesCustom = {
override: {
branch: false,
Expand Down Expand Up @@ -40,6 +44,6 @@ const branch = OVERRIDE_TEST

const types = OVERRIDE_TEST ? { ...config.types, ...typesCustom } : config.types

const changelog = { ...config, branch, commit, types }
const changelog = { ...config, branch, commit, enabled, types }

module.exports = changelog
2 changes: 1 addition & 1 deletion lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const config = require('@jeromefitz/codestyle/lint-staged.config.js')
const config = require('@jeromefitz/codestyle/lint-staged.config')

module.exports = {
...config,
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
"pretty"
],
"scripts": {
"branch": "git-cz --branch --allow-empty",
"branch": "git-cz -m branch --allow-empty",
"build:binaries": "mkdirp binaries && pkg ./dist/cli.js --out-path binaries --targets node12-linux-x64,node12-macos-x64,node12-win-x64",
"build": "tsc",
"clean": "rimraf dist",
"dry:run": "yarn clean && tsc && node ./dist/cli",
"gitmoji": "./scripts/gitmoji/gitmojiInit.sh && yarn lint-fix",
"gitmoji": "./scripts/gitmoji/gitmojiInit.sh && yarn lint-eslint --fix && yarn prettier-fix && yarn typescript",
"lint-eslint": "eslint . --ext js,jsx,ts,tsx --max-warnings=0",
"lint-fix": "yarn prettier-fix && eslint . --ext js,jsx,ts,tsx,json --fix --max-warnings=0",
"lint-typescript": "yarn typescript",
Expand All @@ -60,8 +60,8 @@
"typescript": "tsc --noEmit --declaration -p tsconfig.json"
},
"devDependencies": {
"@jeromefitz/codestyle": "2.0.0-canary.5",
"@jeromefitz/semantic": "2.0.0-canary.5",
"@jeromefitz/codestyle": "2.0.5",
"@jeromefitz/semantic": "2.0.5",
"chai": "4.3.4",
"commitizen": "4.2.4",
"dotenv": "9.0.2",
Expand Down
2 changes: 1 addition & 1 deletion release.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @note This should not be run locally, only on CI/CD Environments.
* To work locally you will need SSH / Auth Tokens for GitHub.
*/
const release = require('@jeromefitz/semantic/release.config.js')
const release = require('@jeromefitz/semantic/release.config')
const isCI = require('is-ci')
!isCI && require('dotenv').config({ path: './.env' })

Expand Down
1 change: 1 addition & 0 deletions scripts/gitmoji/gitmojiTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const commit = {
const theme = {
branch,
commit,
enabled: true,
types,
}

Expand Down
3 changes: 3 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import chalkPipe from 'chalk-pipe'
import parseArgs from './utils/parseArgs'
import isEnabled from './utils/isEnabled'
import runInteractiveQuestions from './utils/runInteractiveQuestions'
import runNonInteractiveMode from './utils/runNonInteractiveMode'
import setBranch from './utils/setBranch'
Expand All @@ -12,6 +13,8 @@ const cli = async () => {

const state = setState(cliOptions)

await isEnabled(state)

Object.keys(cliAnswers).forEach((key) => {
state.answers[key] = cliAnswers[key]
})
Expand Down
5 changes: 4 additions & 1 deletion src/cz.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import runInteractiveQuestions from './utils/runInteractiveQuestions'
import parseArgs from './utils/parseArgs'
import isEnabled from './utils/isEnabled'
import setBranch from './utils/setBranch'
import setState from './utils/setState'
import { getCommitMessage } from './utils/setCommit'
Expand All @@ -10,6 +11,8 @@ const prompter = (cz, commit) => {
const { cliAnswers, cliOptions, passThroughParams } = parseArgs()
const state = setState(cliOptions)

await isEnabled(state)

const options = {
cliAnswers,
cliOptions,
Expand All @@ -19,13 +22,13 @@ const prompter = (cz, commit) => {

switch (cliOptions.mode) {
case TYPE_BRANCH:
await runInteractiveQuestions(state, cliAnswers, cliOptions)
return setBranch(options)
break
case TYPE_COMMIT:
default: {
await runInteractiveQuestions(state, cliAnswers, cliOptions)
const message = getCommitMessage(state)

return commit(message)
break
}
Expand Down
1 change: 1 addition & 0 deletions src/themes/gitmoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const gitmoji = {
],
scopes: [],
},
enabled: true,
types: {
access: {
branch: false,
Expand Down
2 changes: 2 additions & 0 deletions src/utils/findSource.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable import/default */
/* eslint-disable import/no-named-as-default-member */
import fuzzy from 'fuzzy'

const choiceToListItem = (choices, choice, _value) => {
Expand Down
13 changes: 13 additions & 0 deletions src/utils/isEnabled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @note Bounce if config overrides, double-check false string (process.env)
*/
const isEnabled = (state) => {
const _isEnabled =
state?.config?.enabled === 'false' ? false : state?.config?.enabled
if (!_isEnabled) {
process.exit(1)
}
return _isEnabled
}

export default isEnabled
1 change: 0 additions & 1 deletion src/utils/parseArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const parseArgs = () => {
...passThroughParams
} = minimist(process.argv.slice(2), {
alias: {
b: 'branch',
h: 'help',
m: 'mode',
v: 'version',
Expand Down
4 changes: 4 additions & 0 deletions src/utils/setBranch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const setBranch = ({
.replace(/\{branchName\}/g, branchNameReplace)
.replace(/\{branchType\}/g, '')

if (!branchName) {
throw new Error('No branchName provided.')
}

const commandArray = ['git', 'checkout', '-b', branchName]
const command = shellescape(commandArray)

Expand Down
1 change: 1 addition & 0 deletions src/utils/setState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const setState = (cliOptions) => {
// @todo(uhh) this cannot be right, haha
branch: { ...configDefault.branch, ...configOverride.branch },
commit: { ...configDefault.commit, ...configOverride.commit },
enabled: configOverride.enabled || configDefault.enabled,
types: { ...configDefault.types, ...configOverride.types },
},
types: { branch: {}, commit: {} },
Expand Down
Loading

0 comments on commit a699016

Please sign in to comment.