8
0

update-utils-version.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env node
  2. /**
  3. * @license Copyright (c) 2003-2019, 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 scripts updates 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 CWD = process.cwd();
  14. const UTILS_PACKAGE_PATH = path.join( CWD, 'packages', 'ckeditor5-utils' );
  15. const UTILS_MODULE_PATH = path.join( UTILS_PACKAGE_PATH, 'src', 'version.js' );
  16. const { version } = require( path.join( CWD, 'package.json' ) );
  17. const fileContent = fs.readFileSync( UTILS_MODULE_PATH, 'utf-8' )
  18. .replace( /const version = '\d+\.\d+\.\d+';/, `const version = '${ version }';` );
  19. fs.writeFileSync( UTILS_MODULE_PATH, fileContent );
  20. process.chdir( UTILS_PACKAGE_PATH );
  21. if ( exec( 'git status -s' ).trim().length ) {
  22. exec( 'git add src/version.js' );
  23. exec( 'git commit -m "Internal: Updated version of CKEditor 5."' );
  24. console.log( 'The version has been updated and committed.' );
  25. } else {
  26. console.log( 'Nothing to commit. Version is up-to-date.' );
  27. }
  28. process.chdir( CWD );
  29. function exec( command ) {
  30. return tools.shExec( command, { verbosity: 'error' } );
  31. }