bump-year.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 -am "Internal: Bumped the year. [skip ci]" && git push' && git commit -am "Internal: Bumped the year." && git push
  15. */
  16. const glob = require( 'glob' );
  17. const minimatch = require( 'minimatch' );
  18. const fs = require( 'fs' );
  19. glob( '!(node_modules|build|coverage|packages)/**/*', ( err, fileNames ) => {
  20. const filteredFileNames = fileNames.filter( fileName => {
  21. // Filter out stuff from ckeditor5-utils/src/lib.
  22. if ( minimatch( fileName, '**/src/lib/**' ) ) {
  23. return false;
  24. }
  25. if ( fs.statSync( fileName ).isDirectory() ) {
  26. return false;
  27. }
  28. return true;
  29. } );
  30. filteredFileNames.forEach( fileName => {
  31. fs.readFile( fileName, ( err, data ) => {
  32. data = data.toString();
  33. const year = new Date().getFullYear();
  34. const regexp = /Copyright \(c\) 2003-\d{4}/;
  35. const updatedData = data.replace( regexp, 'Copyright (c) 2003-' + year );
  36. if ( data == updatedData ) {
  37. // License headers are only required in JS files.
  38. // Also, the file might have already been updated.
  39. if ( fileName.endsWith( '.js' ) && !data.match( regexp ) ) {
  40. console.warn( `The file "${ fileName }" misses a license header.` );
  41. }
  42. } else {
  43. fs.writeFile( fileName, updatedData );
  44. }
  45. } );
  46. } );
  47. } );