| | #!/usr/bin/env node |
| |
|
| | |
| | const { execSync } = require( 'child_process' ); |
| | const path = require( 'path' ); |
| |
|
| | const dir = process.cwd(); |
| | const root = path.dirname( __dirname ); |
| | const babelPresetFile = require.resolve( '@automattic/calypso-babel-config/presets/default.js' ); |
| |
|
| | const inputDir = path.join( dir, 'src' ); |
| | const outputDirESM = path.join( dir, 'dist', 'esm' ); |
| | const outputDirCJS = path.join( dir, 'dist', 'cjs' ); |
| |
|
| | let transpileAll = true; |
| | let transpileESM = false; |
| | let transpileCJS = false; |
| |
|
| | for ( const arg of process.argv.slice( 2 ) ) { |
| | if ( arg === '--esm' ) { |
| | transpileAll = false; |
| | transpileESM = true; |
| | } |
| |
|
| | if ( arg === '--cjs' ) { |
| | transpileAll = false; |
| | transpileCJS = true; |
| | } |
| | } |
| |
|
| | |
| | |
| | const testIgnorePattern = path.join( dir, '**/test/**' ); |
| |
|
| | console.log( 'Building %s', dir ); |
| | const baseCommand = `npx --no-install babel --presets="${ babelPresetFile }" --ignore "${ testIgnorePattern }" --extensions='.js,.jsx,.ts,.tsx'`; |
| |
|
| | if ( transpileAll || transpileESM ) { |
| | execSync( `${ baseCommand } -d "${ outputDirESM }" "${ inputDir }"`, { |
| | cwd: root, |
| | } ); |
| | } |
| |
|
| | if ( transpileAll || transpileCJS ) { |
| | execSync( `${ baseCommand } -d "${ outputDirCJS }" "${ inputDir }"`, { |
| | env: Object.assign( {}, process.env, { MODULES: 'commonjs' } ), |
| | cwd: root, |
| | } ); |
| | } |
| |
|