Skip to content

Commit 11173e4

Browse files
committed
up: upgrade dependencies and devDependencies
1 parent 3a68ade commit 11173e4

10 files changed

Lines changed: 1016 additions & 1481 deletions

File tree

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"plugin:prettier/recommended"
1010
],
1111
"parserOptions": {
12-
"ecmaVersion": 2017
12+
"ecmaVersion": "latest",
13+
"sourceType": "module"
1314
},
1415
"rules": {
1516
"no-console": "off",

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ $ export EDITOR='subl -w'
3939
### Init
4040

4141
```sh
42-
$ git consistent init
42+
$ git consistent --init
4343
Use Type? (Y/n): Y
4444
Use Emoji? (y/N): N
4545
Does the subject start with lower case? (Y/n): Y
@@ -311,6 +311,7 @@ Date: Sat Feb 10 15:13:40 2018 +0900
311311
| `-D, --dry-run` | run dry-run mode |
312312
| `-i, --interactive` | run interactive mode |
313313
| `-S, --silent` | don't show commit command |
314+
| `-I, --init` | generate config files |
314315
| `-V, --version` | output the version number |
315316
316317
## Badges

lib/colors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const _cyan = '\u001b[36m'
88
const _white = '\u001b[37m'
99
const reset = '\u001b[0m'
1010

11-
module.exports = {
11+
export default {
1212
success: green,
1313
warning: yellow,
1414
info: magenta,

lib/gen-config.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
const path = require('path')
2-
const fs = require('fs')
3-
const _ = require('lodash')
4-
const prompt = require('prompt-sync')()
5-
const inquirer = require('inquirer')
6-
const csvParse = require('csv-parse/lib/sync')
7-
const yaml = require('js-yaml')
1+
import path from 'path'
2+
import fs from 'fs'
3+
import _ from 'lodash'
4+
import promptSync from 'prompt-sync'
5+
import inquirer from 'inquirer'
6+
import yaml from 'js-yaml'
7+
import url from 'url'
8+
import { parse as csvParse } from 'csv-parse/sync'
89

9-
const colors = require('./colors')
10+
import colors from './colors.js'
11+
12+
const prompt = promptSync()
13+
14+
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
1015

1116
const getMaxLength = (types, headName) => {
1217
return _(types)
@@ -149,7 +154,7 @@ const generateDefinitionsFile = (definitionsFileName, answers, dryRun = false) =
149154
},
150155
}
151156

152-
writeFile(path.join('.', definitionsFileName), yaml.safeDump(content), dryRun)
157+
writeFile(path.join('.', definitionsFileName), yaml.dump(content), dryRun)
153158
}
154159

155160
const promptBool = (text, defaultValue = true) => {
@@ -198,10 +203,12 @@ const writeFile = (path, text, dryRun = false) => {
198203
//
199204
// Main
200205
//
201-
module.exports = async (program, templateFileName, definitionsFileName) => {
206+
export default async (program, templateFileName, definitionsFileName) => {
207+
const options = program.opts()
208+
202209
await inquirer.prompt(createQuestions()).then((answers) => {
203-
generateTemplateFile(templateFileName, answers, program.dryRun)
204-
generateDefinitionsFile(definitionsFileName, answers, program.dryRun)
210+
generateTemplateFile(templateFileName, answers, options.dryRun)
211+
generateDefinitionsFile(definitionsFileName, answers, options.dryRun)
205212

206213
console.log()
207214
console.log(`${colors.success}Generated '${templateFileName}' and '${definitionsFileName}'.${colors.reset}`)

lib/index.js

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
#!/usr/bin/env node
22

3-
const program = require('commander')
4-
const path = require('path')
5-
const fs = require('fs')
6-
const _ = require('lodash')
7-
const execSync = require('child_process').execSync
8-
const yaml = require('js-yaml')
9-
10-
const colors = require('./colors')
11-
const main = require('./main')
12-
const genConfig = require('./gen-config')
13-
const pk = require('../package.json')
3+
import path from 'path'
4+
import fs from 'fs'
5+
import _ from 'lodash'
6+
import yaml from 'js-yaml'
7+
import { Command } from 'commander'
8+
import { execSync } from 'child_process'
9+
10+
import colors from './colors.js'
11+
import main from './main.js'
12+
import genConfig from './gen-config.js'
1413

1514
const templateFileName = '.gitcommit_template'
1615
const definitionsFileName = '.git_consistent'
1716

17+
const program = new Command()
18+
const pk = JSON.parse(fs.readFileSync('./package.json'))
1819
const version = pk.version
1920

2021
//
@@ -35,18 +36,16 @@ const getFilePath = (filePaths, fileName) => {
3536
}
3637

3738
const loadYaml = (path) => {
38-
return yaml.safeLoad(fs.readFileSync(path, 'utf8'))
39+
return yaml.load(fs.readFileSync(path, 'utf8'))
3940
}
4041

4142
const setCustomOptions = (program, definitions) => {
42-
program.option('', '---- custom options ----')
4343
_.forEach(definitions, (definition, term) => {
4444
const optionName = term == 'subject' ? `-m, --${term}` : `--${term}`
4545
const valueStr = definition.required ? `<${term}>` : `[${term}]`
4646
const defaultValue = definition.default
4747
if (!['variable', 'branch'].includes(definition.type)) program.option(`${optionName} ${valueStr}`, definition.description, defaultValue)
4848
})
49-
program.option('', '---- custom options ----')
5049
}
5150

5251
const showErrorMessageAndExit = (e) => {
@@ -92,6 +91,7 @@ program
9291
.option('-D, --dry-run', 'run dry-run mode')
9392
.option('-i, --interactive', 'run interactive mode')
9493
.option('-S, --silent', "don't show commit command")
94+
.option('-I, --init', 'generate config files')
9595
.on('--help', () => {
9696
console.log('')
9797
console.log('File Paths:')
@@ -100,15 +100,7 @@ program
100100
})
101101
.version(version)
102102

103-
program
104-
.command('init')
105-
.description('generate config files')
106-
.option('-D, --dry-run', 'run dry-run mode')
107-
.action(() => {
108-
/* no-op */
109-
})
110-
111-
if (process.argv[2] === 'init') {
103+
if (['-I', '--init'].includes(process.argv[2])) {
112104
runInit(program)
113105
} else if (['-h', '--help'].includes(process.argv[2])) {
114106
runHelp(program, definitionsFilePath)

lib/main.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const _ = require('lodash')
2-
const execSync = require('child_process').execSync
3-
const inquirer = require('inquirer')
4-
const emoji = require('node-emoji')
1+
import _ from 'lodash'
2+
import inquirer from 'inquirer'
3+
import emoji from 'node-emoji'
4+
import { execSync } from 'child_process'
55

6-
const colors = require('./colors')
6+
import colors from './colors.js'
77

88
//
99
// Functions
@@ -171,29 +171,29 @@ const createQuestion = (definition, term) => {
171171
}
172172
}
173173

174-
const createQuestions = (program, definitions) => {
174+
const createQuestions = (options, definitions) => {
175175
return _(definitions)
176176
.map((definition, term) => {
177-
if (!_.isUndefined(program[term]) || !_.isUndefined(definition.default)) return
177+
if (!_.isUndefined(options[term]) || !_.isUndefined(definition.default)) return
178178
return createQuestion(definitions[term], term)
179179
})
180180
.compact()
181181
.value()
182182
}
183183

184-
const getValue = (program, definition, answer, term) => {
184+
const getValue = (options, definition, answer, term) => {
185185
const val = branchText(definition)
186186

187187
switch (definition.type) {
188188
case 'enum':
189189
case 'string':
190190
case 'text':
191-
if (!_.isUndefined(program[term])) return program[term]
191+
if (!_.isUndefined(options[term])) return options[term]
192192
if (!_.isUndefined(answer)) return answer
193193
if (!_.isUndefined(definition.default)) return definition.default
194194
return ''
195195
case 'variable':
196-
if (!_.isUndefined(program[definition.origin])) return program[definition.origin]
196+
if (!_.isUndefined(options[definition.origin])) return options[definition.origin]
197197
return ''
198198
case 'branch':
199199
if (!_.isUndefined(val)) return val
@@ -203,17 +203,16 @@ const getValue = (program, definition, answer, term) => {
203203
}
204204
}
205205

206-
const replaceTerms = async (program, template, definitions, callback) => {
206+
const replaceTerms = async (options, template, definitions, callback) => {
207207
await inquirer
208-
.prompt(createQuestions(program, definitions))
208+
.prompt(createQuestions(options, definitions))
209209
.then((answers) => {
210210
let result = template
211211
_.forEach(definitions, (definition, term) => {
212212
const answer = answers[term]
213-
const value = getValue(program, definition, answer, term).trim()
214-
215-
program[term] = value
213+
const value = getValue(options, definition, answer, term).trim()
216214

215+
options[term] = value
217216
const errorMessages = checkValue(term, value, definition)
218217
if (!_.isEmpty(errorMessages)) throw new Error(errorMessages)
219218

@@ -256,10 +255,12 @@ const gitCommit = (commitMessage, duet = false, silent = false, dryRun = false)
256255
//
257256
// Main
258257
//
259-
module.exports = async (program, template, definitions) => {
260-
if (!program.dryRun) checkAddedFile()
258+
export default async (program, template, definitions) => {
259+
const options = program.opts()
260+
261+
if (!options.dryRun) checkAddedFile()
261262

262-
await replaceTerms(program, template, definitions, (commitMessage) => {
263-
gitCommit(commitMessage.trim(), program.duet, program.silent, program.dryRun)
263+
await replaceTerms(options, template, definitions, (commitMessage) => {
264+
gitCommit(commitMessage.trim(), options.duet, options.silent, options.dryRun)
264265
})
265266
}

package.json

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"engines": {
1717
"node": "<=12"
1818
},
19+
"type": "module",
1920
"bin": {
2021
"git-consistent": "./lib/index.js"
2122
},
@@ -26,21 +27,21 @@
2627
"test": "ava --verbose"
2728
},
2829
"dependencies": {
29-
"commander": "4.1.1",
30-
"csv-parse": "4.11.1",
31-
"inquirer": "7.3.2",
32-
"js-yaml": "3.14.0",
33-
"lodash": "4.17.19",
34-
"node-emoji": "1.10.0",
30+
"commander": "9.4.1",
31+
"csv-parse": "5.3.1",
32+
"inquirer": "9.1.4",
33+
"js-yaml": "4.1.0",
34+
"lodash": "4.17.21",
35+
"node-emoji": "1.11.0",
3536
"prompt-sync": "4.2.0"
3637
},
3738
"devDependencies": {
38-
"ava": "3.10.1",
39-
"eslint": "7.4.0",
40-
"eslint-config-prettier": "6.11.0",
41-
"eslint-plugin-prettier": "3.1.4",
42-
"outdent": "0.7.1",
43-
"prettier": "2.0.5",
44-
"sinon": "9.0.2"
39+
"ava": "4.3.3",
40+
"eslint": "8.26.0",
41+
"eslint-config-prettier": "8.5.0",
42+
"eslint-plugin-prettier": "4.2.1",
43+
"outdent": "0.8.0",
44+
"prettier": "2.7.1",
45+
"sinon": "14.0.1"
4546
}
4647
}

test/index.test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
const test = require('ava')
2-
const execSync = require('child_process').execSync
3-
const path = require('path')
1+
import test from 'ava'
2+
import path from 'path'
3+
import url from 'url'
4+
import { execSync } from 'child_process'
5+
6+
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
47

58
test('--version', (t) => {
69
const output = execSync(`${path.join(__dirname, '../lib/index.js')} --version`)

test/main.test.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const test = require('ava')
2-
const sinon = require('sinon')
3-
const outdent = require('outdent')
1+
import test from 'ava'
2+
import sinon from './../node_modules/sinon/pkg/sinon-esm.js'
3+
import outdent from 'outdent'
44

5-
const main = require('../lib/main')
5+
import main from './../lib/main.js'
66

77
test.beforeEach((t) => {
88
t.context.consoleStub = sinon.stub(console, 'log')
@@ -16,12 +16,15 @@ test('main : simple case', async (t) => {
1616
const type = 'feat'
1717
const subject = 'first commit'
1818
const body = `this is body`
19-
const program = {
20-
type: type,
21-
subject: subject,
22-
body: body,
23-
dryRun: true,
24-
silent: true,
19+
const program = {}
20+
program.opts = function () {
21+
return {
22+
type: type,
23+
subject: subject,
24+
body: body,
25+
dryRun: true,
26+
silent: true,
27+
}
2528
}
2629
const template = outdent`
2730
<type>: <subject>

0 commit comments

Comments
 (0)