build-and-publish.js 1.9 KB

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