Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/node_modules
.idea
31 changes: 31 additions & 0 deletions hooks/commitlint/commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
rules: {
'body-leading-blank': [1, 'always'],
'body-tense': [1, 'always', ['present-imperative']],
'footer-leading-blank': [1, 'always'],
'footer-tense': [1, 'always', ['present-imperative']],
'header-max-length': [2, 'always', 72],
'scope-case': [2, 'always', 'lowerCase'],
'subject-empty': [2, 'never'],
'subject-full-stop': [2, 'never', '.'],
'subject-tense': [1, 'always', ['present-imperative']],
'type-case': [2, 'always', 'lowerCase'],
'type-empty': [2, 'never'],
'type-enum': [
2,
'always',
[
'build',
'chore',
'docs',
'feat',
'fix',
'perf',
'refactor',
'revert',
'style',
'test',
],
],
},
};
50 changes: 50 additions & 0 deletions hooks/commitlint/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const emoji = require('node-emoji')
const chalk = require('chalk')
const spawn = require('./../../utils/spawnHelper')
const fs = require('fs-extra')
const packageJsonHelper = require('./../../utils/packageJsonHelper')
const loadPackageJsonFromPath = packageJsonHelper.loadPackageJsonFromPath
const savePackageJsonIn = packageJsonHelper.savePackageJsonIn

const question = {
name: 'commitlint',
type: 'confirm',
message: 'Would you like to add commit message linting?'
}


function func (cwd, folderName) {

console.log('\n\n')
console.log(`${emoji.get('fire')} ${chalk.cyan('Adding commitlint')} ${emoji.get('fire')}`)
console.log('\n\n')

return fs.copy(`${__dirname}/commitlint.config.js`, `${cwd}/${folderName}/commitlint.config.js`)
.then(() => {
const commitlintDependencies = [
'husky',
'@commitlint/cli'
]
const command = `npm i ${commitlintDependencies.join(' ')} --save-dev`
const terminalOpts = {
cwd: `${cwd}/${folderName}`,
shell: true,
stdio:'inherit',
}

return spawn(command, [], terminalOpts)
})
.then(() => loadPackageJsonFromPath(`${cwd}/${folderName}/package.json`))
.then((data => {
data.scripts.commitmsg = 'commitlint -e'
return savePackageJsonIn(`${cwd}/${folderName}/package.json`, data)
}))
}

module.exports = {
action: {
type: 'git',
func,
},
question: question,
}
19 changes: 18 additions & 1 deletion hooks/eslint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,18 @@ const func = (cwd, folderName) => {
}

const addEslintFileSuccess = (cwd, folderName) => {
const command = `npm i eslint eslint-config-airbnb babel-eslint --save-dev`
const eslintDependencies = [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice Refactor mate

'eslint',
'eslint-config-airbnb',
'eslint-plugin-jsx-a11y',
'eslint-plugin-import',
'eslint-plugin-react',
'babel-eslint',
'lint-staged',
'husky'
]

const command = `npm i ${eslintDependencies.join(' ')} --save-dev`

const terminalOpts = {
cwd: `${cwd}/${folderName}`,
Expand All @@ -38,6 +49,12 @@ const installPackagesSuccess = (cwd, folderName) => {
return loadPackageJsonFromPath(`${cwd}/${folderName}/package.json`)
.then( data => {
data.scripts.eslint = 'eslint .'
data.scripts.precommit = 'lint-staged'
data['lint-staged'] = {
'*.js': [
'eslint --cache --max-warnings 0'
]
}

return savePackageJsonIn(`${cwd}/${folderName}/package.json`, data)
})
Expand Down
41 changes: 41 additions & 0 deletions hooks/git/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const emoji = require('node-emoji')
const chalk = require('chalk')
const spawn = require('./../../utils/spawnHelper')
const fs = require('fs-extra')

const question = {
name: 'git',
type: 'confirm',
message: 'Would you like to initialize a git repository?'
}


function func (cwd, folderName) {
const gitExists = fs.pathExistsSync(`${cwd}/${folderName}/.git`)
const command = 'git init'
const terminalOpts = {
cwd: `${cwd}/${folderName}`,
shell: true,
stdio:'inherit',
}

if (gitExists) {
console.log('\n\n')
console.log(chalk.cyan('Git repository already initialized. Skipping...'))
console.log('\n\n')
return Promise.resolve(true)
} else {
console.log('\n\n')
console.log(`${emoji.get('fire')} ${chalk.cyan('Initializing git repository')} ${emoji.get('fire')}`)
console.log('\n\n')
return spawn(command, [], terminalOpts)
}
}

module.exports = {
action: {
type: 'git',
func,
},
question: question,
}
4 changes: 3 additions & 1 deletion hooks/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const hooks = [
require('./git'),
require('./eslint'),
require('./commitlint'),
require('./editorconfig'),
]

module.exports = {
questions: hooks.map(hook => hook.question),
actions: hooks.map(hook => hook.action),
}
}