Skip to content

Commit

Permalink
FIX prepare script to delete tests & snapshots etc from dist (#7358)
Browse files Browse the repository at this point in the history
FIX prepare script to delete tests & snapshots etc from dist
  • Loading branch information
ndelangen authored and shilman committed Jul 31, 2019
1 parent 4b98d59 commit 40f2980
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
14 changes: 1 addition & 13 deletions scripts/compile-babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,11 @@ const shell = require('shelljs');
function getCommand(watch) {
const babel = path.join(__dirname, '..', 'node_modules', '.bin', 'babel');

const ignore = [
'**/__mocks__/',
'**/tests/',
'**/__tests__/',
'**/*.test.*',
'**/stories/',
'**/*.story.*',
'**/*.stories.*',
'**/__snapshots__',
'**/*.d.ts',
];

const args = [
'./src',
'--out-dir ./dist',
`--config-file ${path.resolve(__dirname, '../.babelrc.js')}`,
`--copy-files`,
`--ignore "${ignore.join('","')}"`,
];

/*
Expand Down Expand Up @@ -68,6 +55,7 @@ function babelify(options = {}) {
}

const command = getCommand(watch);

const { code, stderr } = shell.exec(command, { silent });

handleExit(code, stderr, errorCallback);
Expand Down
32 changes: 25 additions & 7 deletions scripts/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,32 @@ function removeDist() {
shell.rm('-rf', 'dist');
}

const ignore = [
'__mocks__',
'__snapshots__',
'__tests__',
'/tests/',
// '/stories/',
/.+\.test\..+/,
// /\/.+\.story\..+/,
// /\/.+\.stories\..+/,
];

function cleanup() {
// add .ts filtering to babel args and remove after babel - 7 is adopted
// remove files after babel --copy-files output
// --copy-files option doesn't work with --ignore
// https://github.com/babel/babel/issues/5404
// https://github.com/babel/babel/issues/6226
if (fs.existsSync(path.join(process.cwd(), 'dist'))) {
// ^(?!.*\.d\.ts$).*\.(ts|tsx)$ => Remove everything except .d.ts files https://regex101.com/r/gEBQ0U/16
const files = shell.find('dist').filter(tsFile => tsFile.match(/^(?!.*\.d\.ts$).*\.(ts|tsx)$/));
const files = shell.find('dist').filter(filePath => {
if (fs.lstatSync(filePath).isDirectory()) {
return false;
}
return ignore.reduce((acc, pattern) => {
return acc || !!filePath.match(pattern);
}, false);
});
if (files.length) {
shell.rm(files);
shell.rm('-f', ...files);
}
}
}
Expand All @@ -42,9 +59,10 @@ function logError(type, packageJson, errorLogs) {
const packageJson = getPackageJson();

removeDist();
babelify({ errorCallback: errorLogs => logError('js', packageJson, errorLogs) });
cleanup();

babelify({ errorCallback: errorLogs => logError('js', packageJson, errorLogs) });
tscfy({ errorCallback: errorLogs => logError('ts', packageJson, errorLogs) });

cleanup();

console.log(chalk.gray(`Built: ${chalk.bold(`${packageJson.name}@${packageJson.version}`)}`));

0 comments on commit 40f2980

Please sign in to comment.