bump-year.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env node
  2. /**
  3. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  4. * For licensing, see LICENSE.md.
  5. */
  6. /* eslint-env node */
  7. /*
  8. Usage:
  9. mgit exec 'node ../../scripts/bump-year.js'
  10. node scripts/bump-year.js
  11. Full command to update the entire project:
  12. git pull && mgit update && mgit exec 'node ../../scripts/bump-year.js' && node scripts/bump-year.js
  13. And after reviewing the changes:
  14. mgit exec 'git commit -m "Internal: Bumped up the year. [skip ci]" && git push' &&
  15. git commit -m "Internal: Bumped up the year." && git push
  16. */
  17. const glob = require( 'glob' );
  18. const minimatch = require( 'minimatch' );
  19. const fs = require( 'fs' );
  20. glob( '!(node_modules|build|coverage|packages)/**/*', ( err, fileNames ) => {
  21. const filteredFileNames = fileNames.filter( fileName => {
  22. // Filter out stuff from ckeditor5-utils/src/lib.
  23. if ( minimatch( fileName, '**/src/lib/**' ) ) {
  24. return false;
  25. }
  26. if ( fs.statSync( fileName ).isDirectory() ) {
  27. return false;
  28. }
  29. return true;
  30. } );
  31. filteredFileNames.forEach( fileName => {
  32. fs.readFile( fileName, ( err, data ) => {
  33. data = data.toString();
  34. const year = new Date().getFullYear();
  35. const regexp = /Copyright \(c\) 2003-\d{4}/;
  36. const updatedData = data.replace( regexp, 'Copyright (c) 2003-' + year );
  37. if ( data == updatedData ) {
  38. // License headers are only required in JS files.
  39. // Also, the file might have already been updated.
  40. if ( fileName.endsWith( '.js' ) && !data.match( regexp ) ) {
  41. console.warn( `The file "${ fileName }" misses a license header.` );
  42. }
  43. } else {
  44. fs.writeFile( fileName, updatedData );
  45. }
  46. } );
  47. } );
  48. } );