ソースを参照

Ported the script from ckeditor5-dev-docs.

Piotrek Koszuliński 8 年 前
コミット
6c2a666c7a

+ 1 - 1
.travis.yml

@@ -22,7 +22,7 @@ script:
   - npm t -- --reporter=dots
   - npm run docs:api -- --validate-only
 after_success:
-  - travis_wait ./node_modules/.bin/ckeditor5-dev-docs-publish-nightly
+  - travis_wait npm t docs:build-and-publish-nightly
 notifications:
   slack:
     rooms:

+ 2 - 0
package.json

@@ -49,6 +49,7 @@
     "@ckeditor/ckeditor5-dev-docs": "^8.0.0",
     "@ckeditor/ckeditor5-dev-env": "^8.0.4",
     "@ckeditor/ckeditor5-dev-tests": "^10.2.0",
+    "@ckeditor/ckeditor5-dev-utils": "^7.0.3",
     "@ckeditor/ckeditor5-dev-webpack-plugin": "^3.0.4",
     "babel-minify-webpack-plugin": "^0.2.0",
     "eslint": "^4.15.0",
@@ -87,6 +88,7 @@
     "docs": "node ./scripts/docs/build-docs.js",
     "docs:api": "node ./scripts/docs/build-api-docs.js",
     "docs:build-and-publish": "node ./scripts/docs/build-and-publish.js",
+    "docs:build-and-publish-nightly": "node ./scripts/docs/build-and-publish-nightly.js",
     "translations:collect": "ckeditor5-dev-env-translations collect",
     "translations:download": "ckeditor5-dev-env-translations download",
     "translations:upload": "ckeditor5-dev-env-translations upload",

+ 77 - 0
scripts/docs/build-and-publish-nightly.js

@@ -0,0 +1,77 @@
+#!/usr/bin/env node
+
+/**
+ * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* eslint-env node */
+
+'use strict';
+
+/*
+
+This script is to be used on CI to automatically update https://ckeditor5.github.io/docs/nightly/ckeditor5/latest/.
+
+*/
+
+// Build the documentation only when master branch is updated.
+// if ( process.env.TRAVIS_BRANCH !== 'master' ) {
+// 	process.exit();
+// }
+
+// Build the documentation only when a cron task triggered the CI.
+// if ( process.env.TRAVIS_EVENT_TYPE !== 'cron' ) {
+// 	process.exit();
+// }
+
+const path = require( 'path' );
+const { tools } = require( '@ckeditor/ckeditor5-dev-utils' );
+
+const mainRepoUrl = 'https://github.com/CKEditor5/ckeditor5.github.io';
+
+// The assumption here is that the script is called from ckeditor5/.
+const projectVersion = require( path.join( process.cwd(), 'package.json' ) ).version;
+
+// Clone the CKEditor 5 page.
+console.log( 'Cloning ckeditor5.github.io repository...' );
+exec( `git clone ${ mainRepoUrl }.git` );
+
+// Build the documentation.
+console.log( 'Building documentation...' );
+exec( 'npm run docs -- --production' );
+
+console.log( 'Copying files...' );
+
+// Remove existing documentation.
+exec( `rm -rf ckeditor5.github.io/docs/nightly/ckeditor5/${ projectVersion }` );
+exec( 'rm -rf ckeditor5.github.io/docs/nightly/ckeditor5/latest' );
+
+// Copy built documentation to the new destination.
+exec( 'cp -R build/docs/* ckeditor5.github.io/docs/nightly/' );
+
+// Copy the versioned documentation to latest/.
+exec( 'mkdir ckeditor5.github.io/docs/nightly/ckeditor5/latest' );
+exec( `cp -R ckeditor5.github.io/docs/nightly/ckeditor5/${ projectVersion }/* ckeditor5.github.io/docs/nightly/ckeditor5/latest` );
+
+// Change work directory in order to make a commit in CKEditor 5 page's repository.
+process.chdir( path.join( process.cwd(), 'ckeditor5.github.io' ) );
+
+exec( `echo "https://${ process.env.GITHUB_TOKEN }:@github.com" > .git/credentials 2> /dev/null` );
+exec( 'git config credential.helper "store --file=.git/credentials"' );
+
+// Commit the documentation.
+if ( exec( 'git diff --name-only docs/' ).trim().length ) {
+	exec( 'git add docs/' );
+	exec( 'git commit -m "Documentation build."' );
+	exec( 'git push origin master --quiet' );
+
+	const lastCommit = exec( 'git log -1 --format="%h"' );
+	console.log( `Successfully published the documentation under ${ mainRepoUrl }/commit/${ lastCommit }` );
+} else {
+	console.log( 'Nothing to commit. Documentation is up to date.' );
+}
+
+function exec( command ) {
+	return tools.shExec( command, { verbosity: 'error' } );
+}

+ 8 - 0
scripts/docs/build-and-publish.js

@@ -7,6 +7,14 @@
 
 /* eslint-env node */
 
+/*
+
+This script allows manually publishing docs on https://ckeditor5.github.io/docs/nightly/ckeditor5/latest/.
+
+It assumes that ckeditor5.github.io is cloned next to ckeditor5.
+
+*/
+
 'use strict';
 
 const path = require( 'path' );