mirror of
https://github.com/strapi/strapi.git
synced 2025-11-12 16:22:10 +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'])(
|
it.each(['api', 'components', 'config/functions/bootstrap.js', 'data'])(
|
||||||
'copies folder %s',
|
'copies folder %s',
|
||||||
async item => {
|
async item => {
|
||||||
|
// Mock the empty directory arg
|
||||||
|
fse.pathExists.mockReturnValueOnce(false);
|
||||||
|
// Mock the folder exists
|
||||||
|
fse.pathExists.mockReturnValue(true);
|
||||||
const directory = '../test-dir';
|
const directory = '../test-dir';
|
||||||
const rootPath = resolve(directory);
|
const rootPath = resolve(directory);
|
||||||
const templatePath = join(rootPath, 'template');
|
const templatePath = join(rootPath, 'template');
|
||||||
|
|
||||||
await exportTemplate(directory);
|
await exportTemplate(directory);
|
||||||
|
|
||||||
|
expect(fse.pathExists).toHaveBeenCalledWith(join(process.cwd(), item));
|
||||||
expect(fse.copy).toHaveBeenCalledWith(join(process.cwd(), item), join(templatePath, 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) {
|
async function copyContent(templatePath, rootBase) {
|
||||||
for (const item of TEMPLATE_CONTENT) {
|
for (const item of TEMPLATE_CONTENT) {
|
||||||
try {
|
try {
|
||||||
await fse.copy(join(process.cwd(), item), join(templatePath, item));
|
const folderExists = await fse.pathExists(join(process.cwd(), item));
|
||||||
const currentProjectBase = basename(process.cwd());
|
|
||||||
console.log(
|
if (folderExists) {
|
||||||
`${chalk.green(
|
await fse.copy(join(process.cwd(), item), join(templatePath, item));
|
||||||
'success'
|
const currentProjectBase = basename(process.cwd());
|
||||||
)}: copy ${currentProjectBase}/${item} => ${rootBase}/template/${item}`
|
console.log(
|
||||||
);
|
`${chalk.green(
|
||||||
|
'success'
|
||||||
|
)}: copy ${currentProjectBase}/${item} => ${rootBase}/template/${item}`
|
||||||
|
);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`${chalk.red('error')}: ${error.message}`);
|
console.error(`${chalk.red('error')}: ${error.message}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user