From ab8dd2d10c9064266fb924da271332121b21980d Mon Sep 17 00:00:00 2001 From: Raven Avalon Date: Thu, 19 Jan 2017 14:04:11 -0500 Subject: [PATCH] feat(scripts): push generated docs to material assets repo --- scripts/ci/after-success.sh | 3 +- scripts/release/publish-docs-content.sh | 77 +++++++++++++++++++++++++ tools/dgeni/index.js | 2 +- tools/gulp/tasks/docs.ts | 8 ++- 4 files changed, 85 insertions(+), 5 deletions(-) create mode 100755 scripts/release/publish-docs-content.sh diff --git a/scripts/ci/after-success.sh b/scripts/ci/after-success.sh index 37524389d1e3..599f097f2cec 100755 --- a/scripts/ci/after-success.sh +++ b/scripts/ci/after-success.sh @@ -10,4 +10,5 @@ cd $(dirname $0)/../.. if [ "$TRAVIS_PULL_REQUEST" = "false" ] && $(npm bin)/travis-after-modes; then echo "All travis modes passed. Publishing the build artifacts..." ./scripts/release/publish-build-artifacts.sh -fi \ No newline at end of file + ./scripts/release/publish-docs-content.sh +fi diff --git a/scripts/release/publish-docs-content.sh b/scripts/release/publish-docs-content.sh new file mode 100755 index 000000000000..e214b49e41ea --- /dev/null +++ b/scripts/release/publish-docs-content.sh @@ -0,0 +1,77 @@ +#!/bin/bash + +# Publish material2 docs assets to the material2-docs-content repo +# material.angular.io will pull from this assets repo to get the latest docs + +cd "$(dirname $0)/../../" + +docsPath="/dist/docs" +repoPath="/tmp/material2-docs-content" +repoUrl="https://github.com/DevVersion/material2-docs-content" + +# If the docs directory is not present, generate docs +if [ ! -d $docsPath ]; then + $(npm bin)/gulp docs +fi + +# Get git meta info for commit +commitSha="$(git rev-parse --short HEAD)" +commitAuthorName="$(git --no-pager show -s --format='%an' HEAD)" +commitAuthorEmail="$(git --no-pager show -s --format='%ae' HEAD)" +commitMessage="$(git log --oneline -n 1)" + +# create directory and clone test repo +rm -rf "/tmp/" +mkdir "/tmp/" $repoPath +git clone $repoUrl $repoPath + +# Clean out repo directory and copy contents of dist/docs into it +rm -rf $repoPath/* +mkdir $repoPath/overview +mkdir $repoPath/guides +mkdir $repoPath/api +# mkdir $repoPath/examples + +# Move api files over to $repoPath/api +cp -r $docsPath/api/* $repoPath/api + +# Move guide files over to $repoPath/guides +for filename in $overviewFiles* +do + if [ -f $filename ]; then + cp -r $filename $repoPath/guides + fi +done + +# Flatten the markdown docs structure and move it into $repoPath/overview +overviewFiles=$docsPath/markdown/ +targetFile="OVERVIEW.html" +for filename in $overviewFiles* +do + if [ -d $filename ]; then + for _ in $filename/* + do + if [ -f $filename/$targetFile ]; then + name=${filename#$overviewFiles} + cp -r $filename/$targetFile $repoPath/overview/ + mv $repoPath/overview/$targetFile $repoPath/overview/$name.html + fi + done + fi +done + +# src/examples should be added to the $repoPath after they have been moved into +# the material2 repo from material.angular.io + +# Push content to repo +cd $repoPath +git config user.name "$commitAuthorName" +git config user.email "$commitAuthorEmail" +git config credential.helper "store --file=.git/credentials" + +echo "https://${MATERIAL2_BUILDS_TOKEN}:@github.com" > .git/credentials + +git add -A +git commit -m "$commitMessage" +git tag "$commitSha" +git push origin master --tags diff --git a/tools/dgeni/index.js b/tools/dgeni/index.js index 8cd4795e2486..331fda75f63e 100644 --- a/tools/dgeni/index.js +++ b/tools/dgeni/index.js @@ -12,7 +12,7 @@ const typescriptPackage = require('dgeni-packages/typescript'); // Project configuration. const projectRootDir = path.resolve(__dirname, '../..'); const sourceDir = path.resolve(projectRootDir, 'src/lib'); -const outputDir = path.resolve(projectRootDir, 'dist/docs'); +const outputDir = path.resolve(projectRootDir, 'dist/docs/api'); const templateDir = path.resolve(__dirname, './templates'); // Package definition for material2 api docs. This only *defines* the package- it does not yet diff --git a/tools/gulp/tasks/docs.ts b/tools/gulp/tasks/docs.ts index e6b9fc5021a1..2c9f8387c3cb 100644 --- a/tools/gulp/tasks/docs.ts +++ b/tools/gulp/tasks/docs.ts @@ -11,7 +11,9 @@ import * as path from 'path'; // viewer. const EXAMPLE_PATTERN = //g; -gulp.task('docs', () => { +gulp.task('docs', ['markdown-docs', 'api-docs']) + +gulp.task('markdown-docs', () => { return gulp.src(['src/lib/**/*.md', 'guides/*.md']) .pipe(markdown({ // Add syntax highlight using highlight.js @@ -28,10 +30,10 @@ gulp.task('docs', () => { .pipe(transform((content: string) => content.toString().replace(EXAMPLE_PATTERN, (match: string, name: string) => `
`))) - .pipe(gulp.dest('dist/docs')); + .pipe(gulp.dest('dist/docs/markdown')); }); -task('api', () => { +task('api-docs', () => { const Dgeni = require('dgeni'); const docsPackage = require(path.resolve(__dirname, '../../dgeni')); const dgeni = new Dgeni([docsPackage]);