Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add export-template command to cli #10331

Merged
merged 10 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
);
Expand Down
18 changes: 11 additions & 7 deletions packages/strapi/lib/commands/generate-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
);
}
alexandrebodin marked this conversation as resolved.
Show resolved Hide resolved
} catch (error) {
console.error(`${chalk.red('error')}: ${error.message}`);
}
Expand Down