Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ignore-sync

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ignore-sync - npm Package Compare versions

Comparing version 2.0.1 to 3.0.0

10

CHANGELOG.md

@@ -5,2 +5,12 @@ # Changelog

## [3.0.0](https://github.com/foray1010/ignore-sync/compare/v2.0.1...v3.0.0) (2020-11-04)
### ⚠ BREAKING CHANGES
- drop nodejs < 10.13
### Features
- append path to local files by [relative] ([#301](https://github.com/foray1010/ignore-sync/issues/301)) ([7e4a806](https://github.com/foray1010/ignore-sync/commit/7e4a80669e6f0b155630cbdf8f6a8f1c854a5cba))
### [2.0.1](https://github.com/foray1010/ignore-sync/compare/v2.0.0...v2.0.1) (2019-06-11)

@@ -7,0 +17,0 @@

46

package.json
{
"name": "ignore-sync",
"version": "2.0.1",
"engines": {
"node": ">=7.6"
},
"version": "3.0.0",
"description": "a CLI tool to build and sync *ignore files across files and repositories",

@@ -19,31 +16,40 @@ "keywords": [

],
"repository": "https://github.com/foray1010/ignore-sync",
"license": "MIT",
"author": "foray1010",
"repository": "https://github.com/foray1010/ignore-sync",
"bin": "src/bin.js",
"scripts": {
"lint": "eslint .",
"ci": "yarn lint:js && yarn lint:md && yarn test",
"eslint": "eslint --ext=cjs,js,mjs,ts,tsx --ignore-path=node_modules/@foray1010/eslint-config/eslintignore",
"lint:js": "yarn eslint .",
"lint:md": "yarn remark .",
"mermaid": "glob-exec --foreach 'docs/**/*.mmd' -- 'mmdc -i {{file}} -o {{file}}.png'",
"prettier": "prettier --ignore-path=node_modules/@foray1010/prettier-config/prettierignore",
"remark": "remark --frail --ignore-path=node_modules/@foray1010/remark-preset/remarkignore --ignore-path-resolve-from=cwd",
"test": "cross-env NODE_ENV=test jest --config .jestrc.json"
},
"dependencies": {
"axios": "^0.19.0",
"fs-extra": "^8.0.1",
"ignore": "^5.1.2",
"ramda": "^0.26.1"
"axios": "0.21.0",
"ignore": "5.1.8",
"ramda": "0.27.1"
},
"devDependencies": {
"@commitlint/cli": "8.0.0",
"@commitlint/config-conventional": "8.0.0",
"cross-env": "5.2.0",
"eslint": "5.16.0",
"eslint-config-foray1010": "7.3.0",
"@commitlint/cli": "11.0.0",
"@commitlint/config-conventional": "11.0.0",
"@foray1010/eslint-config": "4.1.0",
"@foray1010/prettier-config": "4.1.1",
"@foray1010/remark-preset": "3.4.0",
"cross-env": "7.0.2",
"eslint": "7.12.1",
"glob-exec": "0.1.1",
"husky": "2.4.0",
"jest": "24.8.0",
"lint-staged": "8.2.0",
"markdownlint-cli": "0.16.0",
"husky": "4.3.0",
"jest": "26.6.1",
"lint-staged": "10.5.1",
"mermaid.cli": "0.5.1",
"prettier-eslint-cli": "4.7.1"
"prettier": "2.1.2",
"remark-cli": "9.0.0"
},
"engines": {
"node": ">=10.13"
}
}
# ignore-sync
a cli tool to build and sync *ignore files across files and repositories
a cli tool to build and sync \*ignore files across files and repositories

@@ -31,9 +31,11 @@ ## why

1. update `package.json`
```diff json
{
"scripts": {
+ "ignore-sync": "ignore-sync ."
}
}
```
```diff json
{
"scripts": {
+ "ignore-sync": "ignore-sync ."
}
}
```
1. now follow [how to use](#how-to-use) to create `*ignore-sync` files, then `npm run ignore-sync`, all corresponding ignore files will be generated.

@@ -45,22 +47,41 @@

example: `.gitignore-sync` -> `.gitignore`
example: `.gitignore-sync` -> `.gitignore`
1. create a source tag in your `*ignore-sync` file to identify the source of ignore patterns
```ini
[put_source_tag_here]
```
```ini
[put_source_tag_here]
```
different source tag identifies different source of ignore patterns
different source tag identifies different source of ignore patterns
- `[inline]`
- ignore patterns under this tag will be copied to generated ignore file directly
- `[local]`
- local file paths under this tag will be read and the content of these files will be copied to generated ignore file
- file paths are relative to the location of the `*ignore-sync` file
- `[$username/$repo]`
- github file paths under this tag will be read and the content of these files will be copied to generated ignore file
- file paths are relative to the root of the github repository
- recommend using ignore patterns from [[github/gitignore]](https://github.com/github/gitignore)
- `[inline]`
- the ignore patterns will be copied directly to generated ignore file
- `[local]`
- the content of these local files will be copied directly to generated ignore file
- `[relative]`
- the content of these local files will be copied with **relative path prefix** to generated ignore file
- example
```ini
# input: /packages/a/.prettierignore
ignored.md
```
```ini
# input: /.prettierignore-sync
[relative]
packages/a/.prettierignore
```
```ini
# output: /.prettierignore
packages/a/ignored.md
```
- `[$username/$repo]`
- the content of these github files will be downloaded and appended to generated ignore file
- recommend using ignore patterns from [[github/gitignore]](https://github.com/github/gitignore)
1. `npm run ignore-sync`
'use strict'
const path = require('path')
const R = require('ramda')

@@ -9,4 +8,4 @@ const isIgnoreSyncFile = require('./isIgnoreSyncFile')

const processIgnoreSyncFile = require('./processIgnoreSyncFile')
const {isDirectory} = require('./utils/fsHelper')
const {promiseMap} = require('./utils/ramdaHelper')
const { isDirectory } = require('./utils/fsHelper')
const { promiseMap } = require('./utils/ramdaHelper')

@@ -23,3 +22,3 @@ const validateInputs = async (absolutePath) => {

const startApp = async (cwd, relativePaths) => {
const absolutePaths = R.map((p) => path.join(cwd, p), relativePaths)
const absolutePaths = relativePaths.map((p) => path.join(cwd, p))

@@ -26,0 +25,0 @@ await promiseMap(validateInputs, absolutePaths)

@@ -5,6 +5,9 @@ 'use strict'

const {COMMENT_CHAR, LINE_BREAK} = require('./constants')
const { COMMENT_CHAR, LINE_BREAK } = require('./constants')
const removeEmptyLines = R.reject((line) => line === '')
const removeTrailingSpacesAndComment = R.replace(RegExp(`\\s*(${COMMENT_CHAR}.*)?$`), '')
const removeTrailingSpacesAndComment = R.replace(
RegExp(`\\s*(${COMMENT_CHAR}.*)?$`),
'',
)

@@ -15,4 +18,4 @@ const cleanupIgnoreSyncFile = R.compose(

R.map(removeTrailingSpacesAndComment),
R.split(LINE_BREAK)
R.split(LINE_BREAK),
)
module.exports = cleanupIgnoreSyncFile
{
"COMMENT_CHAR": "#",
"COMMENT_HEADER_ALERT":
"GENERATED BY IGNORE-SYNC, DO NOT EDIT!!!\nhttps://github.com/foray1010/ignore-sync",
"COMMENT_HEADER_ALERT": "GENERATED BY IGNORE-SYNC, DO NOT EDIT!!!\nhttps://github.com/foray1010/ignore-sync",
"LINE_BREAK": "\n"
}

@@ -6,7 +6,7 @@ 'use strict'

const cleanupIgnoreSyncFile = require('./cleanupIgnoreSyncFile')
const {LINE_BREAK} = require('./constants')
const { LINE_BREAK } = require('./constants')
const appendToLastData = (blocks, datum) => [
...R.init(blocks),
R.compose(R.over(R.lensProp('data'), R.append(datum)), R.last)(blocks)
R.compose(R.over(R.lensProp('data'), R.append(datum)), R.last)(blocks),
]

@@ -22,8 +22,9 @@

source: RegExp.$1,
data: []
}
data: [],
},
]
}
if (!acc.length) throw new Error('source `[]` not found before ignore pattern is found')
if (!acc.length)
throw new Error('source `[]` not found before ignore pattern is found')

@@ -33,4 +34,4 @@ return appendToLastData(acc, line)

R.split(LINE_BREAK),
cleanupIgnoreSyncFile
cleanupIgnoreSyncFile,
)(ignoreSyncFile)
module.exports = decodeIgnoreSyncFile

@@ -10,5 +10,5 @@ 'use strict'

const joinLinesWithEOF = require('./utils/joinLinesWithEOF')
const {COMMENT_HEADER_ALERT} = require('./constants')
const {dynamicComposeP, promiseMap} = require('./utils/ramdaHelper')
const {readFile} = require('./utils/fsHelper')
const { COMMENT_HEADER_ALERT, LINE_BREAK } = require('./constants')
const { dynamicComposeP, promiseMap } = require('./utils/ramdaHelper')
const { readFile } = require('./utils/fsHelper')

@@ -23,4 +23,5 @@ const isGithubSource = R.test(/^(\w+\/\w+)$/i)

const files = await promiseMap(
(relativePath) => github.getContentFile({owner, repo, path: relativePath}),
block.data
(relativePath) =>
github.getContentFile({ owner, repo, path: relativePath }),
block.data,
)

@@ -32,7 +33,32 @@ return joinLinesWithEOF(files)

(relativeFilePath) => readFile(path.join(directory, relativeFilePath)),
block.data
block.data,
)
return joinLinesWithEOF(files)
}
const relativeSourceFetcher = async (block, directory) => {
const files = await promiseMap(async (relativeFilePath) => {
const filePath = path.dirname(relativeFilePath)
const fileContent = await readFile(path.join(directory, relativeFilePath))
const splittedFileContent = fileContent.split(LINE_BREAK)
const edittedFileContent = splittedFileContent.map((line) => {
if (!line) {
return line
}
if (line.startsWith('#')) {
return line
}
if (line.startsWith('!')) {
return '!' + path.join(filePath, line.substring(1))
}
return path.join(filePath, line)
})
return edittedFileContent.join(LINE_BREAK)
}, block.data)
return joinLinesWithEOF(files)
}
const generateIgnoreFile = (ignoreSyncFile, directory) => {

@@ -42,3 +68,10 @@ const fetchIgnorePatternsBySource = promiseMap(

[sourceIs(R.equals('inline')), inlineSourceFetcher],
[sourceIs(R.equals('local')), (block) => localSourceFetcher(block, directory)],
[
sourceIs(R.equals('local')),
(block) => localSourceFetcher(block, directory),
],
[
sourceIs(R.equals('relative')),
(block) => relativeSourceFetcher(block, directory),
],
[sourceIs(isGithubSource), githubSourceFetcher],

@@ -49,5 +82,5 @@ [

throw new Error(`unknown source: ${block.source}`)
}
]
])
},
],
]),
)

@@ -59,5 +92,5 @@

fetchIgnorePatternsBySource,
decodeIgnoreSyncFile
decodeIgnoreSyncFile,
)(ignoreSyncFile)
}
module.exports = generateIgnoreFile
'use strict'
const R = require('ramda')
const isIgnoreSyncFile = require('./isIgnoreSyncFile')
const {readDir} = require('./utils/fsHelper')
const { readDir } = require('./utils/fsHelper')
const getIgnoreSyncFiles = async (absoluteDirPath) => {
const absoluteFilePaths = await readDir(absoluteDirPath)
return R.filter(isIgnoreSyncFile, absoluteFilePaths)
return absoluteFilePaths.filter((x) => isIgnoreSyncFile(x))
}
module.exports = getIgnoreSyncFiles

@@ -10,12 +10,18 @@ 'use strict'

const {
isDirectory, isReadable, readDir, readFile
isDirectory,
isReadable,
readDir,
readFile,
} = require('./utils/fsHelper')
const {promiseFilter, promiseMap} = require('./utils/ramdaHelper')
const { promiseFilter, promiseMap } = require('./utils/ramdaHelper')
const filterByGitIgnoreFilters = (absoluteDataPaths, gitIgnoreFilters) => {
if (gitIgnoreFilters.length === 0) return absoluteDataPaths
return R.filter(R.allPass(gitIgnoreFilters), absoluteDataPaths)
return absoluteDataPaths.filter(R.allPass(gitIgnoreFilters))
}
const filterDirPaths = R.composeP(R.map(R.concat(R.__, path.sep)), promiseFilter(isDirectory))
const filterDirPaths = R.composeP(
R.map(R.concat(R.__, path.sep)),
promiseFilter(isDirectory),
)

@@ -47,7 +53,12 @@ const getGitIgnoreFilter = async (directory) => {

const gitIgnore = await getGitIgnoreFilter(directory)
const updatedGitIgnoreFilters = [...gitIgnoreFilters, gitIgnore].filter(Boolean)
const updatedGitIgnoreFilters = [...gitIgnoreFilters, gitIgnore].filter(
Boolean,
)
const absoluteDataPaths = await readDir(directory)
const absoluteDirPaths = await filterDirPaths(absoluteDataPaths)
const filteredDirPaths = filterByGitIgnoreFilters(absoluteDirPaths, updatedGitIgnoreFilters)
const filteredDirPaths = filterByGitIgnoreFilters(
absoluteDirPaths,
updatedGitIgnoreFilters,
)

@@ -54,0 +65,0 @@ processDirectory(filteredDirPaths, updatedGitIgnoreFilters)

@@ -7,3 +7,3 @@ 'use strict'

const renameIgnoreFile = require('./renameIgnoreFile')
const {overwriteFile, readFile} = require('./utils/fsHelper')
const { overwriteFile, readFile } = require('./utils/fsHelper')

@@ -13,3 +13,6 @@ const processIgnoreSyncFile = async (absoluteFilePath) => {

const ignoreFile = await generateIgnoreFile(ignoreSyncFile, path.dirname(absoluteFilePath))
const ignoreFile = await generateIgnoreFile(
ignoreSyncFile,
path.dirname(absoluteFilePath),
)
const ignoreFilePath = renameIgnoreFile(absoluteFilePath)

@@ -16,0 +19,0 @@

'use strict'
const fs = require('fs-extra')
const fs = require('fs')
const path = require('path')
const R = require('ramda')
const { promisify } = require('util')
const fsAccess = promisify(fs.access)
const fsStat = promisify(fs.stat)
const fsUnlink = promisify(fs.unlink)
const fsWriteFile = promisify(fs.writeFile)
const fsReaddir = promisify(fs.readdir)
const fsReadFile = promisify(fs.readFile)
const isReadable = async (dataPath) => {
try {
await fs.access(dataPath, fs.constants.R_OK)
await fsAccess(dataPath, fs.constants.R_OK)
return true

@@ -18,3 +25,3 @@ } catch (err) {

const isDirectory = async (dataPath) => {
const stats = await fs.stat(dataPath)
const stats = await fsStat(dataPath)
return stats.isDirectory()

@@ -25,4 +32,4 @@ }

const overwriteFile = async (filePath, fileStr) => {
await fs.unlink(filePath).catch(() => {})
await fs.writeFile(filePath, fileStr)
await fsUnlink(filePath).catch(() => {})
await fsWriteFile(filePath, fileStr)
}

@@ -32,7 +39,6 @@ exports.overwriteFile = overwriteFile

const readDir = async (absoluteDirPath) => {
const relativeDataPaths = await fs.readdir(absoluteDirPath)
return R.map(
(relativeDataPath) => path.join(absoluteDirPath, relativeDataPath),
relativeDataPaths
)
const relativeDataPaths = await fsReaddir(absoluteDirPath)
return relativeDataPaths.map((relativeDataPath) => {
return path.join(absoluteDirPath, relativeDataPath)
})
}

@@ -42,5 +48,5 @@ exports.readDir = readDir

const readFile = async (filePath) => {
const fileBuffer = await fs.readFile(filePath)
const fileBuffer = await fsReadFile(filePath)
return String(fileBuffer)
}
exports.readFile = readFile

@@ -9,6 +9,6 @@ 'use strict'

ref = 'master', // commit/branch/tag
repo
repo,
}) => {
const {data: file} = await axios.get(
`https://raw.githubusercontent.com/${owner}/${repo}/${ref}/${path}`
const { data: file } = await axios.get(
`https://raw.githubusercontent.com/${owner}/${repo}/${ref}/${path}`,
)

@@ -15,0 +15,0 @@ return file

@@ -5,3 +5,3 @@ 'use strict'

const {COMMENT_CHAR, LINE_BREAK} = require('../constants')
const { COMMENT_CHAR, LINE_BREAK } = require('../constants')

@@ -17,8 +17,7 @@ const spacing = ' '

const maxLen = Math.max(...R.map(R.length, comments))
const maxLen = Math.max(...comments.map(R.length))
const lineLen = leftPad.length + maxLen + rightPad.length
const paddedComments = R.map(
const paddedComments = comments.map(
(comment) => leftPad + comment.padEnd(maxLen, spacing) + rightPad,
comments
)

@@ -25,0 +24,0 @@ const verticalPad = COMMENT_CHAR.repeat(lineLen)

@@ -5,8 +5,8 @@ 'use strict'

const {LINE_BREAK} = require('../constants')
const { LINE_BREAK } = require('../constants')
const joinLinesWithEOF = R.compose(
R.replace(RegExp(LINE_BREAK + '*$'), LINE_BREAK),
R.join(LINE_BREAK)
R.join(LINE_BREAK),
)
module.exports = joinLinesWithEOF

@@ -7,6 +7,3 @@ 'use strict'

const dynamicComposeP = (...args) =>
R.composeP(
...args,
R.bind(Promise.resolve, Promise)
)
R.composeP(...args, R.bind(Promise.resolve, Promise))
exports.dynamicComposeP = dynamicComposeP

@@ -13,0 +10,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc