Skip to content

Commit

Permalink
fix: do not delete TS template files after building the CLI package
Browse files Browse the repository at this point in the history
I inverted the logic to check if we are in the SB CLI package as this
is the only package that require extra check on filenames.
  • Loading branch information
gaetanmaisse committed Jan 12, 2021
1 parent e823b54 commit bc93753
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions scripts/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,18 @@ function cleanup() {
// --copy-files option doesn't work with --ignore
// https://github.com/babel/babel/issues/6226
if (fs.existsSync(path.join(process.cwd(), 'dist'))) {
const inStoryshots = process.cwd().includes('storyshots'); // This is a helper the exclude storyshots folder from the regex
const files = shell.find('dist').filter((filePath) => {
const isInStorybookCLIPackage = process.cwd().includes(path.join('lib', 'cli'));
const filesToRemove = shell.find('dist').filter((filePath) => {
// Do not remove folder
// And do not clean anything for:
// - @storybook/cli/dist/generators/**/template*
// - @storybook/cli/dist/frameworks/*
// because these are the template files
// that will be copied to init SB on users' projects
// - @storybook/cli/dist/(esm|cjs)/generators/**/template*
// - @storybook/cli/dist/(esm|cjs)/frameworks/*
// because these are the template files that will be copied to init SB on users' projects

if (
fs.lstatSync(filePath).isDirectory() ||
/generators\/.+\/template.*/.test(filePath) ||
(/dist\/frameworks\/.*/.test(filePath) && !inStoryshots)
(isInStorybookCLIPackage &&
/\/(esm|cjs)\/(generators\/.+\/template|frameworks).*/.test(filePath))
) {
return false;
}
Expand All @@ -56,8 +55,8 @@ function cleanup() {
return acc || !!filePath.match(pattern);
}, false);
});
if (files.length) {
shell.rm('-f', ...files);
if (filesToRemove.length) {
shell.rm('-f', ...filesToRemove);
}
}
}
Expand Down

0 comments on commit bc93753

Please sign in to comment.