bump-year.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env node
  2. /**
  3. * @license Copyright (c) 2003-2019, 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 sync && mgit exec 'node ../../scripts/bump-year.js' && node scripts/bump-year.js
  13. And after reviewing the changes:
  14. mgit commit -m "Internal: Bumped the year. [skip ci]" && mgit 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. const includeDotFiles = {
  20. dot: true
  21. };
  22. glob( '!(build|coverage|node_modules|packages)/**', updateYear );
  23. // LICENSE.md, .eslintrc.js, etc.
  24. glob( '*', includeDotFiles, updateYear );
  25. function updateYear( err, fileNames ) {
  26. const filteredFileNames = fileNames.filter( fileName => {
  27. // Filter out stuff from ckeditor5-utils/src/lib.
  28. if ( minimatch( fileName, '**/src/lib/**' ) ) {
  29. return false;
  30. }
  31. if ( fs.statSync( fileName ).isDirectory() ) {
  32. return false;
  33. }
  34. return true;
  35. } );
  36. filteredFileNames.forEach( fileName => {
  37. fs.readFile( fileName, ( err, data ) => {
  38. data = data.toString();
  39. const year = new Date().getFullYear();
  40. const regexp = /Copyright \(c\) 2003-\d{4}/g;
  41. const updatedData = data.replace( regexp, 'Copyright (c) 2003-' + year );
  42. if ( data == updatedData ) {
  43. // License headers are only required in JS files.
  44. // Also, the file might have already been updated.
  45. if ( fileName.endsWith( '.js' ) && !data.match( regexp ) ) {
  46. console.warn( `The file "${ process.cwd() }/${ fileName }" misses a license header.` );
  47. }
  48. } else {
  49. fs.writeFile( fileName, updatedData, err => {
  50. if ( err ) {
  51. throw err;
  52. }
  53. } );
  54. }
  55. } );
  56. } );
  57. }