Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add git init and precommit hook for eslint #47

Merged
merged 3 commits into from
Oct 13, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
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
34 changes: 34 additions & 0 deletions hooks/git/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const emoji = require('node-emoji')
const chalk = require('chalk')
const spawn = require('./../../utils/spawnHelper')

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


function func (cwd, folderName) {

console.log('\n\n')
console.log(`${emoji.get('fire')} ${chalk.cyan('Initializing git repository')} ${emoji.get('fire')}`)
console.log('\n\n')

const command = 'git init'
const terminalOpts = {
cwd: `${cwd}/${folderName}`,
shell: true,
stdio:'inherit',
}

return spawn(command, [], terminalOpts)
Copy link
Contributor

Choose a reason for hiding this comment

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

So, We tried to find if has some issue on create-react-app related with that and I've found this PR facebook/create-react-app#1288

So, looks like that will be added at some moment, what do you think about test if already has a git started? maybe just test if exists .git folder.

}

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

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