From a863fe8331de882db582892ed84eab41b678ef8b Mon Sep 17 00:00:00 2001
From: BetaHuhn <51766171+BetaHuhn@users.noreply.github.com>
Date: Fri, 8 Jan 2021 23:14:11 +0100
Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20support=20for=20directories?=
=?UTF-8?q?=20[skip=20ci]?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
dist/index.js | 29 ++++++++++++++++-------------
src/index.js | 29 ++++++++++++++++-------------
2 files changed, 32 insertions(+), 26 deletions(-)
diff --git a/dist/index.js b/dist/index.js
index 73b126aa..b29a16bf 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -30579,28 +30579,29 @@ const run = async () => {
const fileExists = fs.existsSync(file.source)
if (fileExists === false) {
- core.warning(`Source file ${ file.source } not found`)
+ core.warning(`Source ${ file.source } not found`)
return
}
const stat = await fs.promises.lstat(file.source)
const isFile = stat.isFile()
if (isFile === false) {
- core.warning(`Directory as source not supported yet`)
- // io.cp(file.source, dest, { recursive: false, force: false })
- return
+ core.warning(`Source is directory`)
}
const dest = `${ git.localPath }/${ file.dest }`
const destExists = fs.existsSync(dest)
if (destExists === true && file.replace === false) {
- core.warning(`File already exists in destination and 'replace' option is set to false`)
+ core.warning(`File(s) already exist(s) in destination and 'replace' option is set to false`)
return
}
- core.info(`Copying ${ file.source } to ${ dest }`)
- await io.cp(file.source, dest, { recursive: false, force: true }).catch((err) => {
- core.error(`Unable to copy file.`)
+ const addTrailingSlash = (str) => str.endsWith('/') ? str : str + '/'
+ const copySource = (isFile === false) ? `${ addTrailingSlash(file.source) }` : file.source
+
+ core.info(`Copying ${ copySource } to ${ dest }`)
+ await io.cp(copySource, dest, { recursive: true, force: true }).catch((err) => {
+ core.error(`Unable to copy file(s).`)
core.error(err)
}).then(async () => {
await git.add(file.dest)
@@ -30608,20 +30609,22 @@ const run = async () => {
if (COMMIT_EACH_FILE === true) {
const hasChange = await git.hasChange()
if (hasChange === false) {
- core.info('File already up to date')
+ core.info('File(s) already up to date')
return
}
- core.info(`Creating commit for file ${ file.dest }`)
+ core.info(`Creating commit for file(s) ${ file.dest }`)
let message
let prMessage
+ const directory = isFile === false ? 'directory' : ''
+ const otherFiles = isFile === false ? 'and copied all sub files/folders' : ''
if (destExists) {
message = `${ COMMIT_PREFIX } Synced local '${ file.dest }' with remote '${ file.source }'`
- prMessage = `Synced local ${ file.dest }
with remote ${ file.source }
`
+ prMessage = `Synced local ${ directory } ${ file.dest }
with remote ${ directory } ${ file.source }
`
} else {
message = `${ COMMIT_PREFIX } Created local '${ file.dest }' from remote '${ file.source }'`
- prMessage = `Created local ${ file.dest }
from remote ${ file.source }
`
+ prMessage = `Created local ${ directory } ${ file.dest }
${ otherFiles } from remote ${ directory } ${ file.source }
`
}
await git.commit(message)
@@ -30687,7 +30690,7 @@ const run = async () => {
repo: item.repo.name,
title: `${ COMMIT_PREFIX } Synced file(s) with ${ GITHUB_REPOSITORY }`,
body: dedent(`
- Synced file(s) with [${ GITHUB_REPOSITORY }](https://github.com/${ GITHUB_REPOSITORY }).
+ Synced local file(s) with [${ GITHUB_REPOSITORY }](https://github.com/${ GITHUB_REPOSITORY }).
${ changedFiles }
diff --git a/src/index.js b/src/index.js
index 252fa192..91c0a001 100644
--- a/src/index.js
+++ b/src/index.js
@@ -48,28 +48,29 @@ const run = async () => {
const fileExists = fs.existsSync(file.source)
if (fileExists === false) {
- core.warning(`Source file ${ file.source } not found`)
+ core.warning(`Source ${ file.source } not found`)
return
}
const stat = await fs.promises.lstat(file.source)
const isFile = stat.isFile()
if (isFile === false) {
- core.warning(`Directory as source not supported yet`)
- // io.cp(file.source, dest, { recursive: false, force: false })
- return
+ core.warning(`Source is directory`)
}
const dest = `${ git.localPath }/${ file.dest }`
const destExists = fs.existsSync(dest)
if (destExists === true && file.replace === false) {
- core.warning(`File already exists in destination and 'replace' option is set to false`)
+ core.warning(`File(s) already exist(s) in destination and 'replace' option is set to false`)
return
}
- core.info(`Copying ${ file.source } to ${ dest }`)
- await io.cp(file.source, dest, { recursive: false, force: true }).catch((err) => {
- core.error(`Unable to copy file.`)
+ const addTrailingSlash = (str) => str.endsWith('/') ? str : str + '/'
+ const copySource = (isFile === false) ? `${ addTrailingSlash(file.source) }` : file.source
+
+ core.info(`Copying ${ copySource } to ${ dest }`)
+ await io.cp(copySource, dest, { recursive: true, force: true }).catch((err) => {
+ core.error(`Unable to copy file(s).`)
core.error(err)
}).then(async () => {
await git.add(file.dest)
@@ -77,20 +78,22 @@ const run = async () => {
if (COMMIT_EACH_FILE === true) {
const hasChange = await git.hasChange()
if (hasChange === false) {
- core.info('File already up to date')
+ core.info('File(s) already up to date')
return
}
- core.info(`Creating commit for file ${ file.dest }`)
+ core.info(`Creating commit for file(s) ${ file.dest }`)
let message
let prMessage
+ const directory = isFile === false ? 'directory' : ''
+ const otherFiles = isFile === false ? 'and copied all sub files/folders' : ''
if (destExists) {
message = `${ COMMIT_PREFIX } Synced local '${ file.dest }' with remote '${ file.source }'`
- prMessage = `Synced local ${ file.dest }
with remote ${ file.source }
`
+ prMessage = `Synced local ${ directory } ${ file.dest }
with remote ${ directory } ${ file.source }
`
} else {
message = `${ COMMIT_PREFIX } Created local '${ file.dest }' from remote '${ file.source }'`
- prMessage = `Created local ${ file.dest }
from remote ${ file.source }
`
+ prMessage = `Created local ${ directory } ${ file.dest }
${ otherFiles } from remote ${ directory } ${ file.source }
`
}
await git.commit(message)
@@ -156,7 +159,7 @@ const run = async () => {
repo: item.repo.name,
title: `${ COMMIT_PREFIX } Synced file(s) with ${ GITHUB_REPOSITORY }`,
body: dedent(`
- Synced file(s) with [${ GITHUB_REPOSITORY }](https://github.com/${ GITHUB_REPOSITORY }).
+ Synced local file(s) with [${ GITHUB_REPOSITORY }](https://github.com/${ GITHUB_REPOSITORY }).
${ changedFiles }