build-and-publish.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env node
  2. /**
  3. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  4. * For licensing, see LICENSE.md.
  5. */
  6. /* eslint-env node */
  7. /*
  8. This script allows manually publishing docs on https://ckeditor5.github.io/docs/nightly/ckeditor5/latest/.
  9. It assumes that ckeditor5.github.io is cloned next to ckeditor5.
  10. */
  11. 'use strict';
  12. const path = require( 'path' );
  13. const { tools } = require( '@ckeditor/ckeditor5-dev-utils' );
  14. const mainRepoUrl = 'https://github.com/CKEditor5/ckeditor5.github.io';
  15. // The assumption here is that the script is called from ckeditor5/.
  16. const projectVersion = require( path.join( process.cwd(), 'package.json' ) ).version;
  17. console.log( 'Updating your ckeditor5.github.io clone...' );
  18. exec( 'cd ../ckeditor5.github.io && git pull && cd -' );
  19. console.log( 'Building documentation...' );
  20. exec( 'npm run docs -- --production' );
  21. console.log( 'Copying files...' );
  22. // Remove existing documentation.
  23. exec( `rm -rf ../ckeditor5.github.io/docs/nightly/ckeditor5/${ projectVersion }` );
  24. exec( 'rm -rf ../ckeditor5.github.io/docs/nightly/ckeditor5/latest' );
  25. // Copy built documentation to the new destination.
  26. exec( 'cp -R build/docs/* ../ckeditor5.github.io/docs/nightly/' );
  27. // Copy the versioned documentation to latest/.
  28. exec( 'mkdir ../ckeditor5.github.io/docs/nightly/ckeditor5/latest' );
  29. exec( `cp -R ../ckeditor5.github.io/docs/nightly/ckeditor5/${ projectVersion }/* ../ckeditor5.github.io/docs/nightly/ckeditor5/latest` );
  30. process.chdir( path.join( process.cwd(), '..', 'ckeditor5.github.io' ) );
  31. // Commit the documentation.
  32. if ( exec( 'git diff --name-only docs/' ).trim().length ) {
  33. exec( 'git add docs/' );
  34. exec( 'git commit -m "Documentation build."' );
  35. exec( 'git push origin master --quiet' );
  36. const lastCommit = exec( 'git log -1 --format="%h"' );
  37. console.log( `Successfully published the documentation under ${ mainRepoUrl }/commit/${ lastCommit }` );
  38. } else {
  39. console.log( 'Nothing to commit. Documentation is up to date.' );
  40. }
  41. process.chdir( path.join( process.cwd(), '..', 'ckeditor5' ) );
  42. function exec( command ) {
  43. return tools.shExec( command, { verbosity: 'error' } );
  44. }