-
-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use cosmiconfig for lint-staged config. Closes #64
- Loading branch information
Showing
2 changed files
with
45 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,38 +5,57 @@ | |
|
||
process.env.FORCE_COLOR = true // Force colors for packages that depend on https://www.npmjs.com/package/supports-color | ||
|
||
const path = require('path') | ||
const sgf = require('staged-git-files') | ||
const appRoot = require('app-root-path') | ||
const Listr = require('listr') | ||
const path = require('path') | ||
const cosmiconfig = require('cosmiconfig') | ||
|
||
const config = require(appRoot.resolve('package.json')) // eslint-disable-line | ||
const packageJson = require(appRoot.resolve('package.json')) // eslint-disable-line | ||
const runScript = require('./runScript') | ||
const resolvePaths = require('./resolvePaths') | ||
const generateTasks = require('./generateTasks') | ||
|
||
// If git root is defined -> Set git root as sgf's cwd | ||
if (config['lint-staged']['git-root'] !== undefined) { | ||
sgf.cwd = path.resolve(config['lint-staged']['git-root']) | ||
} | ||
|
||
sgf('ACM', (err, files) => { | ||
if (err) { | ||
console.error(err) | ||
} | ||
|
||
const tasks = generateTasks(config['lint-staged'], resolvePaths(files)) | ||
.map(task => ({ | ||
title: `Running tasks for ${ task.pattern }`, | ||
task: () => (new Listr(runScript(task.commands, task.fileList, config))) | ||
})) | ||
|
||
|
||
if (tasks.length) { | ||
new Listr(tasks).run().catch((error) => { | ||
console.error(error) | ||
process.exit(1) | ||
}) | ||
} | ||
cosmiconfig(packageJson.name, { | ||
rc: 'lintstaged' | ||
}) | ||
.then((result) => { | ||
// result.config is the parsed configuration object | ||
// result.filepath is the path to the config file that was found | ||
const config = result.config | ||
|
||
// If git-root is defined -> set git root as sgf's cwd | ||
if ('git-root' in config) { | ||
sgf.cwd = path.resolve(config['git-root']) | ||
} | ||
|
||
sgf('ACM', (err, files) => { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
okonet
Author
Collaborator
|
||
if (err) { | ||
console.error(err) | ||
} | ||
|
||
const tasks = generateTasks(config, resolvePaths(files)) | ||
.map(task => ({ | ||
title: `Running tasks for ${ task.pattern }`, | ||
task: () => (new Listr(runScript(task.commands, task.fileList, config))) | ||
})) | ||
|
||
|
||
if (tasks.length) { | ||
new Listr(tasks).run().catch((error) => { | ||
console.error(error) | ||
process.exit(1) | ||
}) | ||
} | ||
}) | ||
}) | ||
.catch((parsingError) => { | ||
// do something constructive | ||
console.error(`Could not parse lint-staged config. | ||
Make sure you have created it. See ${ packageJson.homepage }. | ||
${ parsingError } | ||
`) | ||
process.exit(1) | ||
}) | ||
|
If I am correct
ACM
meansadded
,created
andmodified
. Is it possible to make this configurable? Because sometimes we only want to commit some but not all of the files that are modified in one commit.