bump-year.js 1.7 KB

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