8
0

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

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