remove-js-extensions-from-imports.js 410 B

1234567891011121314
  1. #!/usr/bin/env node
  2. const fs = require( 'fs' );
  3. const path = require( 'path' );
  4. const glob = require( 'glob' );
  5. const srcPath = path.join( process.cwd(), '@(src|tests)', '**', '*.js' );
  6. for ( const filePath of glob.sync( srcPath ) ) {
  7. const fileContent = fs.readFileSync( filePath, 'utf-8' )
  8. .replace( /\nimport([^;]+)\.js';/g, '\nimport$1\';' );
  9. fs.writeFileSync( filePath, fileContent , 'utf-8' );
  10. }