mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 10:55:37 +00:00
copy folders that exist
This commit is contained in:
parent
aad0515764
commit
eec4aa2e56
@ -33,12 +33,17 @@ describe('generate:template command', () => {
|
||||
it.each(['api', 'components', 'config/functions/bootstrap.js', 'data'])(
|
||||
'copies folder %s',
|
||||
async item => {
|
||||
// Mock the empty directory arg
|
||||
fse.pathExists.mockReturnValueOnce(false);
|
||||
// Mock the folder exists
|
||||
fse.pathExists.mockReturnValue(true);
|
||||
const directory = '../test-dir';
|
||||
const rootPath = resolve(directory);
|
||||
const templatePath = join(rootPath, 'template');
|
||||
|
||||
await exportTemplate(directory);
|
||||
|
||||
expect(fse.pathExists).toHaveBeenCalledWith(join(process.cwd(), item));
|
||||
expect(fse.copy).toHaveBeenCalledWith(join(process.cwd(), item), join(templatePath, item));
|
||||
}
|
||||
);
|
||||
|
||||
@ -16,13 +16,17 @@ const TEMPLATE_CONTENT = ['api', 'components', 'config/functions/bootstrap.js',
|
||||
async function copyContent(templatePath, rootBase) {
|
||||
for (const item of TEMPLATE_CONTENT) {
|
||||
try {
|
||||
await fse.copy(join(process.cwd(), item), join(templatePath, item));
|
||||
const currentProjectBase = basename(process.cwd());
|
||||
console.log(
|
||||
`${chalk.green(
|
||||
'success'
|
||||
)}: copy ${currentProjectBase}/${item} => ${rootBase}/template/${item}`
|
||||
);
|
||||
const folderExists = await fse.pathExists(join(process.cwd(), item));
|
||||
|
||||
if (folderExists) {
|
||||
await fse.copy(join(process.cwd(), item), join(templatePath, item));
|
||||
const currentProjectBase = basename(process.cwd());
|
||||
console.log(
|
||||
`${chalk.green(
|
||||
'success'
|
||||
)}: copy ${currentProjectBase}/${item} => ${rootBase}/template/${item}`
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`${chalk.red('error')}: ${error.message}`);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user