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 filter for files passed as parameter to not be ignored #313

Merged
merged 2 commits into from
Jan 4, 2019
Merged
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
13 changes: 10 additions & 3 deletions src/commands/apm_cmds/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,21 @@ async function prepareFilesForPublishing(
const filter = ignore().add(ignorePatterns)
const projectRoot = findProjectRoot()

function createFilter(files, ignorePath) {
let f = fs.readFileSync(ignorePath).toString()
files.forEach(file => {
f = f.concat(`!${file}\n`)
Copy link
Contributor

Choose a reason for hiding this comment

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

One small detail: are you assuming that ignore file will have a new line at the end? Would it work otherwise? Maybe you could add a \n before starting the concatenation for safety.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, it will not work on that case. I updated to concat the new line first.

})
return f
}

const ipfsignorePath = path.resolve(projectRoot, '.ipfsignore')
if (pathExistsSync(ipfsignorePath)) {
filter.add(fs.readFileSync(ipfsignorePath).toString())
filter.add(createFilter(files, ipfsignorePath))
} else {
const gitignorePath = path.resolve(projectRoot, '.gitignore')

if (pathExistsSync(gitignorePath)) {
filter.add(fs.readFileSync(gitignorePath).toString())
filter.add(createFilter(files, gitignorePath))
}
}

Expand Down