Created
November 23, 2020 15:57
-
-
Save ernestofreyreg/8a7f4e912effbe262e7bbe882e825773 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { ActionConfig, NodePlopAPI } from 'plop' | |
import globby from 'globby' | |
import fse from 'fs-extra' | |
import replaceInFiles from 'replace-in-files' | |
export const copyFiles = async (answers: object, config: ActionConfig, plop: NodePlopAPI) => { | |
const configData = config.data as any | |
const allFiles = await globby([configData.source], { | |
gitignore: true, | |
dot: true | |
}) | |
for (let fileName of allFiles) { | |
const destFileName = fileName.replace(configData.source, configData.dest) | |
console.log(`- ${destFileName}`) | |
await fse.copy(fileName, destFileName) | |
} | |
for (let key in configData.replaceInFiles) { | |
await replaceInFiles({ | |
files: [`${configData.dest}/**/*`, `${configData.dest}/*`], | |
from: new RegExp(key, 'g'), | |
to: configData.replaceInFiles[key] | |
}) | |
} | |
return await Promise.resolve('success') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment