8
0

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

123456789101112131415161718192021
  1. #!/usr/bin/env node
  2. /**
  3. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  4. * For licensing, see LICENSE.md.
  5. */
  6. 'use strict';
  7. const fs = require( 'fs' );
  8. const path = require( 'path' );
  9. const glob = require( 'glob' );
  10. const srcPath = path.join( process.cwd(), '@(src|tests)', '**', '*.js' );
  11. for ( const filePath of glob.sync( srcPath ) ) {
  12. const fileContent = fs.readFileSync( filePath, 'utf-8' )
  13. .replace( /\nimport([^;]+)\.js';/g, '\nimport$1\';' );
  14. fs.writeFileSync( filePath, fileContent , 'utf-8' );
  15. }