Skip to content
This repository was archived by the owner on Dec 24, 2021. It is now read-only.

Commit 9ce99e3

Browse files
committed
feat: 🌟 add commitlint config
1 parent f60190c commit 9ce99e3

File tree

4 files changed

+79
-12
lines changed

4 files changed

+79
-12
lines changed

bin/createEdoApp.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ program
1616
.option('--silent', 'do not show command prompts', true)
1717
.option('--with-fetch', 'include node-fetch', true)
1818
.option('--with-docker', 'include Docker', true)
19+
.option('--with-commitlint', 'include commitlint and standard-version', true)
1920
.action((d) => (directory = d))
2021
.parse()
2122

22-
const { silent, withFetch, withDocker } = program.opts()
23+
const { silent, withFetch, withDocker, withCommitlint } = program.opts()
2324

2425
// Run the app
25-
createEdoApp({ directory, silent, withFetch, withDocker })
26+
createEdoApp({ directory, silent, withFetch, withDocker, withCommitlint })

config.json

+21-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
"commands": {
33
"gitInit": "git init",
44
"gitAdd": "git add .",
5+
"gitCommit": "git commit -m 'init: :tada: initial commit'",
56
"createLocalEnv": "cp .env.example .env",
67
"huskyCommands": [
78
"npm set-script prepare 'husky install'",
8-
"npm run prepare",
9+
"npm run prepare --silent",
910
"npx husky add .husky/pre-commit 'npx lint-staged'"
10-
]
11+
],
12+
"huskyCommitlint": "npx husky add .husky/commit-msg 'npx commitlint --config .commitlintrc.cjs --edit'"
1113
},
1214
"dependencies": [
1315
"express",
@@ -29,7 +31,21 @@
2931
"husky"
3032
],
3133
"extraDeps": {
32-
"fetch": "node-fetch"
34+
"fetch": [
35+
"node-fetch"
36+
],
37+
"commitlint": [
38+
"standard-version",
39+
"@commitlint/cli",
40+
"@commitlint/config-conventional"
41+
]
42+
},
43+
"extraOptions": {
44+
"commitlint": {
45+
"scripts": {
46+
"release": "standard-version --no-verify --sign"
47+
}
48+
}
3349
},
3450
"options": {
3551
"author": "",
@@ -53,6 +69,8 @@
5369
"base": "Added basic source and configuration files",
5470
"fetch": "Added node-fetch utils",
5571
"docker": "Added Docker files",
72+
"commitlint": "Added commitlintrc",
73+
"commitlint_hook": "Added husky commit message hook",
5674
"npm": "Initialized npm package and installed dependencies",
5775
"git": "Initialized git repository",
5876
"env": "Created local .env file",

index.js

+16-7
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,22 @@ const runCommand = (command) => {
2121
}
2222
const runCommands = (commandList) => runCommand(commandList.join(' && '))
2323

24-
module.exports = async ({ directory, silent, withFetch, withDocker }) => {
24+
module.exports = async ({ directory, silent, withFetch, withDocker, withCommitlint }) => {
2525
const cd = `cd ${directory}`
2626

27+
console.log({ silent })
28+
2729
const packageOptions = {
2830
...config.options,
2931
prompt: !silent,
3032
directory,
3133
name: directory,
3234
description: `Project created with ${pkg.name}`,
33-
dependencies: [...dependencies, ...(withFetch ? [config.extraDeps.fetch] : [])],
34-
devDependencies,
35+
dependencies: [...dependencies, ...(withFetch ? config.extraDeps.fetch : [])],
36+
devDependencies: [...devDependencies, ...(withCommitlint ? config.extraDeps.commitlint : [])],
37+
scripts: withCommitlint
38+
? config.options.scripts
39+
: { ...config.options.scripts, ...config.extraOptions.commitlint.scripts },
3540
}
3641

3742
logStep('start', chalk.cyan(directory))
@@ -49,6 +54,11 @@ module.exports = async ({ directory, silent, withFetch, withDocker }) => {
4954
await fs.copy(path.join(__dirname, 'templates/docker'), directory)
5055
logStep('docker')
5156
}
57+
58+
if (withCommitlint) {
59+
await fs.copy(path.join(__dirname, 'templates/commitlint'), directory)
60+
logStep('commitlint')
61+
}
5262
} catch (err) {
5363
console.error(err)
5464
return
@@ -57,10 +67,9 @@ module.exports = async ({ directory, silent, withFetch, withDocker }) => {
5767
await createPackageJson(packageOptions)
5868
logStep('npm')
5969

60-
if (runCommands([cd, commands.gitInit])) logStep('git')
70+
if (runCommands([cd, `${commands.gitInit} ${silent ? '--quiet' : ''}`])) logStep('git')
6171
if (runCommands([cd, commands.createLocalEnv])) logStep('env')
6272
if (runCommands([cd, ...commands.huskyCommands])) logStep('husky')
63-
64-
const initialCommitCommand = `git commit ${silent ? '--quiet' : ''} -m "init: :tada: initial commit"`
65-
if (runCommands([cd, commands.gitAdd, initialCommitCommand])) logStep('commit')
73+
if (withCommitlint && runCommands([cd, commands.huskyCommitlint])) logStep('commitlint_hook')
74+
if (runCommands([cd, commands.gitAdd, `${commands.gitCommit} ${silent ? '--quiet' : ''}`])) logStep('commit')
6675
}
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module.exports = {
2+
extends: ['@commitlint/config-conventional'],
3+
rules: {
4+
'scope-enum': [
5+
2,
6+
'always',
7+
[
8+
'style',
9+
'lint',
10+
'review',
11+
'uiux',
12+
'deps',
13+
'build',
14+
'release',
15+
'flags',
16+
'logs',
17+
'db',
18+
'security',
19+
'perf',
20+
'a11y',
21+
'i18n',
22+
'typos',
23+
'literals',
24+
'analytics',
25+
'seo',
26+
'linux',
27+
'windows',
28+
'osx',
29+
'android',
30+
'ios',
31+
],
32+
],
33+
'type-enum': [
34+
2,
35+
'always',
36+
['wip', 'feat', 'fix', 'config', 'refactor', 'revert', 'chore', 'ci', 'assets', 'test', 'docs', 'init'],
37+
],
38+
},
39+
}

0 commit comments

Comments
 (0)