Skip to content

Commit

Permalink
feat(scripts): push generated docs to material assets repo
Browse files Browse the repository at this point in the history
  • Loading branch information
riavalon committed Jan 25, 2017
1 parent 55b9224 commit ab8dd2d
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 5 deletions.
3 changes: 2 additions & 1 deletion scripts/ci/after-success.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
./scripts/release/publish-docs-content.sh
fi
77 changes: 77 additions & 0 deletions scripts/release/publish-docs-content.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tools/dgeni/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions tools/gulp/tasks/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import * as path from 'path';
// viewer.
const EXAMPLE_PATTERN = /<!--\W*example\(([^)]+)\)\W*-->/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
Expand All @@ -28,10 +30,10 @@ gulp.task('docs', () => {
.pipe(transform((content: string) =>
content.toString().replace(EXAMPLE_PATTERN, (match: string, name: string) =>
`<div material-docs-example="${name}"></div>`)))
.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]);
Expand Down

0 comments on commit ab8dd2d

Please sign in to comment.