update-utils-version.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. 'use strict';
  8. // This script updates the version of CKEditor 5 in the `@ckeditor/ckeditor5-utils/src/version` module.
  9. // It should be called as a post hook, after generating changelogs.
  10. const fs = require( 'fs' );
  11. const path = require( 'path' );
  12. const { tools } = require( '@ckeditor/ckeditor5-dev-utils' );
  13. const versionUtils = require( '@ckeditor/ckeditor5-dev-env/lib/release-tools/utils/versions' );
  14. const CWD = process.cwd();
  15. const UTILS_PACKAGE_PATH = path.join( CWD, 'packages', 'ckeditor5-utils' );
  16. const UTILS_MODULE_PATH = path.join( UTILS_PACKAGE_PATH, 'src', 'version.js' );
  17. const version = versionUtils.getLastFromChangelog();
  18. const fileContent = fs.readFileSync( UTILS_MODULE_PATH, 'utf-8' )
  19. .replace( /const version = '\d+\.\d+\.\d+';/, `const version = '${ version }';` );
  20. fs.writeFileSync( UTILS_MODULE_PATH, fileContent );
  21. process.chdir( UTILS_PACKAGE_PATH );
  22. if ( exec( 'git status -s' ).trim().length ) {
  23. exec( 'git add src/version.js' );
  24. exec( 'git commit -m "Internal (utils): Updated version of CKEditor 5."' );
  25. console.log( `The hardcoded version in ckeditor5-utils has been updated to ${ version }.` );
  26. } else {
  27. console.log( `Nothing to commit. Version in ckeditor5-utils is up-to-date (${ version }).` );
  28. }
  29. process.chdir( CWD );
  30. function exec( command ) {
  31. return tools.shExec( command, { verbosity: 'error' } );
  32. }