build-and-publish.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env node
  2. /**
  3. * @license Copyright (c) 2003-2019, 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( 'yarn 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. // Umberto makes a symlink between the latest version (`projectVersion`) and "latest/" directory.
  28. // The symlink must be deleted in order to copy a documentation for `projectVersion` as `latest`.
  29. exec( 'rm -rf ../ckeditor5.github.io/docs/nightly/ckeditor5/latest' );
  30. // Copy the versioned documentation to latest/.
  31. exec( `cp -R ../ckeditor5.github.io/docs/nightly/ckeditor5/${ projectVersion } ../ckeditor5.github.io/docs/nightly/ckeditor5/latest` );
  32. process.chdir( path.join( process.cwd(), '..', 'ckeditor5.github.io' ) );
  33. // Commit the documentation.
  34. if ( exec( 'git diff --name-only docs/' ).trim().length ) {
  35. exec( 'git add docs/' );
  36. exec( 'git commit -m "Documentation build."' );
  37. exec( 'git push origin master --quiet' );
  38. const lastCommit = exec( 'git log -1 --format="%h"' );
  39. console.log( `Successfully published the documentation under ${ mainRepoUrl }/commit/${ lastCommit }` );
  40. } else {
  41. console.log( 'Nothing to commit. Documentation is up to date.' );
  42. }
  43. process.chdir( path.join( process.cwd(), '..', 'ckeditor5' ) );
  44. function exec( command ) {
  45. try {
  46. return tools.shExec( command, { verbosity: 'error' } );
  47. }
  48. catch ( error ) {
  49. console.error( error );
  50. process.exit( 1 );
  51. }
  52. }