8
0

bump-year.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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|external)/**', 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 nested `node_modules`.
  27. if ( minimatch( fileName, '**/node_modules/**' ) ) {
  28. return false;
  29. }
  30. // Filter out stuff from `src/lib/`.
  31. if ( minimatch( fileName, '**/src/lib/**' ) ) {
  32. return false;
  33. }
  34. // Filter out builds.
  35. if ( minimatch( fileName, '**/ckeditor5-build-*/build/**' ) ) {
  36. return false;
  37. }
  38. // Filter out directories.
  39. if ( fs.statSync( fileName ).isDirectory() ) {
  40. return false;
  41. }
  42. return true;
  43. } );
  44. filteredFileNames.forEach( fileName => {
  45. fs.readFile( fileName, ( err, data ) => {
  46. data = data.toString();
  47. const year = new Date().getFullYear();
  48. const regexp = /Copyright \(c\) 2003-\d{4}/g;
  49. const updatedData = data.replace( regexp, 'Copyright (c) 2003-' + year );
  50. if ( data == updatedData ) {
  51. // License headers are only required in JS files.
  52. // Also, the file might have already been updated.
  53. if ( fileName.endsWith( '.js' ) && !data.match( regexp ) ) {
  54. console.warn( `The file "${ process.cwd() }/${ fileName }" misses a license header.` );
  55. }
  56. } else {
  57. fs.writeFile( fileName, updatedData, err => {
  58. if ( err ) {
  59. throw err;
  60. }
  61. } );
  62. }
  63. } );
  64. } );
  65. }