Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5eafe60
commit 0160ae5
Showing
15 changed files
with
406 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.snap] | ||
trim_trailing_whitespace = false |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "seek", | ||
"rules": { | ||
"no-console": 0, | ||
"no-sync": 0 | ||
} | ||
} |
Validating CODEOWNERS rules …
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# See https://help.github.com/articles/about-codeowners/ for more info | ||
# Each line is a file pattern followed by one or more owners. | ||
|
||
# These owners will be the default owners for everything in the repo. | ||
* @front-end-contributors |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
lts/* |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"singleQuote": true | ||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
language: node_js | ||
notifications: | ||
email: false | ||
before_script: | ||
- npm prune | ||
after_success: | ||
- npm run semantic-release | ||
branches: | ||
except: | ||
- /^v\d+\.\d+\.\d+$/ |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 SEEK | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 |
---|---|---|
@@ -1,3 +1,67 @@ | ||
[![Build Status](https://img.shields.io/travis/seek-oss/gitignore-ensure/master.svg?style=flat-square)](http://travis-ci.org/seek-oss/gitignore-ensure) [![npm](https://img.shields.io/npm/v/gitignore-ensure.svg?style=flat-square)](https://www.npmjs.com/package/gitignore-ensure) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square)](http://commitizen.github.io/cz-cli/) | ||
|
||
# gitignore-ensure | ||
|
||
Ensure the presence of paths within a project's gitignore | ||
Ensure the presence of patterns within a project's gitignore. | ||
|
||
## Usage | ||
|
||
```js | ||
const gitignoreEnsure = require('gitignore-ensure'); | ||
|
||
await gitignoreEnsure({ | ||
patterns: ['node_modules', 'output'] | ||
}); | ||
``` | ||
|
||
### Options | ||
|
||
#### filepath (string, default: '<cwd>/.gitignore') | ||
|
||
Path to the `.gitignore` file to be used. | ||
|
||
#### patterns (?Array\<string>) | ||
|
||
An array of patterns to ensure are present in the specified `.gitignore` file. Any pattern that already exists in the file will be appended with the [comment](#comment). All new patterns will be appended to the bottom of the file. | ||
|
||
<a id="comment"> | ||
|
||
#### comment (?string) | ||
|
||
Appended to each pattern that is being ensured to indicate what is programmatically being controlled. | ||
|
||
```js | ||
const gitignoreEnsure = require('gitignore-ensure'); | ||
|
||
await gitignoreEnsure({ | ||
patterns: ['node_modules', 'output'], | ||
comment: 'managed' | ||
}); | ||
|
||
// => | ||
// node_modules # managed | ||
// output # managed | ||
// | ||
``` | ||
|
||
#### dryRun (?boolean, default: false) | ||
|
||
The file at the input path will not be updated, instead the intended output will be returned. | ||
|
||
```js | ||
const gitignoreEnsure = require('gitignore-ensure'); | ||
|
||
const result = await gitignoreEnsure({ | ||
patterns: ['node_modules', 'output'], | ||
dryRun: true | ||
}); | ||
|
||
// result: | ||
// node_modules | ||
// output | ||
// | ||
``` | ||
|
||
## License | ||
|
||
MIT. |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { promisify } = require('util'); | ||
|
||
const writeFile = promisify(fs.writeFile); | ||
const readFile = promisify(fs.readFile); | ||
|
||
const write = async (filepath, output, dryRun) => { | ||
if (!dryRun) { | ||
await writeFile(filepath, output); | ||
} | ||
return output; | ||
}; | ||
|
||
module.exports = async ({ | ||
patterns = [], | ||
comment = '', | ||
filepath = path.resolve(process.cwd(), '.gitignore'), | ||
dryRun = false | ||
}) => { | ||
const commented = str => (comment ? `${str} # ${comment}` : str); | ||
|
||
const managed = patterns.sort(); | ||
const contents = await readFile(filepath, 'utf-8'); | ||
const current = contents.split(/\r?\n/); | ||
|
||
const corrected = current.map( | ||
pattern => (managed.includes(pattern) ? commented(pattern) : pattern) | ||
); | ||
|
||
const additions = managed | ||
.filter(pattern => !corrected.includes(commented(pattern))) | ||
.map(commented); | ||
|
||
const outputPatterns = corrected.concat(additions); | ||
const output = `${outputPatterns.join('\n')}${ | ||
outputPatterns[outputPatterns.length - 1] === '' ? '' : '\n' | ||
}`; | ||
|
||
return current.join('\n') !== output | ||
? write(filepath, output, dryRun) | ||
: current.join('\n'); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"name": "gitignore-ensure", | ||
"version": "0.0.0-development", | ||
"description": "Ensure the presence of patterns within a project's gitignore", | ||
"main": "index.js", | ||
"scripts": { | ||
"commit": "git-cz", | ||
"semantic-release": "semantic-release", | ||
"pretest": "eslint .", | ||
"test": "jest" | ||
}, | ||
"jest": { | ||
"testEnvironment": "node" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"commit-msg": "commitlint --edit --extends seek", | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.js": [ | ||
"prettier --write", | ||
"git add" | ||
] | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/seek-oss/gitignore-ensure.git" | ||
}, | ||
"author": "SEEK", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/seek-oss/gitignore-ensure/issues" | ||
}, | ||
"homepage": "https://github.com/seek-oss/gitignore-ensure#readme", | ||
"devDependencies": { | ||
"@commitlint/cli": "^7.2.1", | ||
"commitizen": "^3.0.2", | ||
"commitlint-config-seek": "^1.0.0", | ||
"cz-conventional-changelog": "^2.1.0", | ||
"eslint": "^5.7.0", | ||
"eslint-config-seek": "^3.2.1", | ||
"husky": "^1.1.2", | ||
"jest": "^23.6.0", | ||
"lint-staged": "^7.3.0", | ||
"prettier": "^1.14.3", | ||
"semantic-release": "^15.10.3" | ||
}, | ||
"release": { | ||
"success": false | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
} | ||
} |
Oops, something went wrong.