Skip to content

Commit

Permalink
✨ Add option to exclude certain files when syncing directories #26
Browse files Browse the repository at this point in the history
  • Loading branch information
BetaHuhn committed Apr 16, 2021
1 parent 9dc51bf commit b557527
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const core = require('@actions/core')
const yaml = require('js-yaml')
const fs = require('fs-extra')
const path = require('path')

require('dotenv').config()

Expand Down Expand Up @@ -126,6 +127,14 @@ const parseRepoName = (fullRepo) => {
}
}

const parseExclude = (text, src) => {
if (text === undefined || typeof text !== 'string') return undefined

const files = text.split('\n').filter((i) => i)

return files.map((file) => path.join(src, file))
}

const parseFiles = (files) => {
return files.map((item) => {

Expand All @@ -141,7 +150,8 @@ const parseFiles = (files) => {
return {
source: item.source,
dest: item.dest !== undefined ? item.dest : item.source,
replace: item.replace !== undefined ? item.replace : REPLACE_DEFAULT
replace: item.replace !== undefined ? item.replace : REPLACE_DEFAULT,
exclude: parseExclude(item.exclude, item.source)
}
}

Expand Down
14 changes: 12 additions & 2 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,21 @@ const pathIsDirectory = async (path) => {
return stat.isDirectory()
}

const copy = async (src, dest) => {
const copy = async (src, dest, exclude) => {

core.debug(`CP: ${ src } TO ${ dest }`)

return fs.copy(src, dest)
const filterFunc = (file) => {

if (exclude.includes(file)) {
core.debug(`Excluding file ${ file }`)
return false
}

return true
}

return fs.copy(src, dest, (exclude !== undefined && { filter: filterFunc }))
}

const remove = async (src) => {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const run = async () => {

if (isDirectory) core.warning(`Source is directory`)

await copy(source, localDestination)
await copy(source, localDestination, file.exclude)

await git.add(file.dest)

Expand Down

0 comments on commit b557527

Please sign in to comment.