Skip to content

Commit a63fa2d

Browse files
devversionandrewseguin
authored andcommitted
build: create script for building docs-content (#20198)
Creates a script that builds the docs-content. We also use that script in the our CI setup to reduce duplication. The script will not pack the package by default, as that is up to the consumer of the script. It's totally fine just adding a package directory to a project (similar to a tarball). (cherry picked from commit 53c9441)
1 parent c8585f3 commit a63fa2d

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ jobs:
440440
# The components examples package is not a release package, but we publish it
441441
# as part of this job to the docs-content repository. It's not contained in the
442442
# attached release output, so we need to build it here.
443-
- run: bazel build src/components-examples:npm_package --config=snapshot-build
443+
- run: yarn build-docs-content
444444

445445
# Ensures that we do not push the snapshot artifacts upstream until all previous
446446
# snapshot build jobs have completed. This helps avoiding conflicts when multiple

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"scripts": {
1616
"postinstall": "node tools/postinstall/apply-patches.js && ngcc --properties module main --create-ivy-entry-points && node tools/postinstall/update-ngcc-main-fields.js",
1717
"build": "node ./scripts/build-packages-dist.js",
18+
"build-docs-content": "node ./scripts/build-docs-content.js",
1819
"dev-app": "ibazel run //src/dev-app:devserver",
1920
"test": "node ./scripts/run-component-tests.js",
2021
"test-local": "yarn -s test --local",

scripts/build-docs-content.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Script that builds the docs content NPM package and moves it into an conveniently
5+
* accessible distribution directory (the project `dist/` directory).
6+
*/
7+
8+
const {join} = require('path');
9+
const {chmod, cd, cp, mkdir, rm, set, exec} = require('shelljs');
10+
11+
/** Path to the project directory. */
12+
const projectDir = join(__dirname, '../');
13+
14+
/** Path to the distribution directory. */
15+
const distDir = join(projectDir, 'dist/');
16+
17+
/**
18+
* Path to the directory where the docs-content package is copied to. Note: When
19+
* changing the path, also change the path in the docs-content deploy script.
20+
*/
21+
const outputDir = join(distDir, 'docs-content-pkg');
22+
23+
/** Command that runs Bazel. */
24+
const bazelCmd = process.env.BAZEL_COMMAND || `yarn -s bazel`;
25+
26+
// ShellJS should exit if a command fails.
27+
set('-e');
28+
29+
// Go to project directory.
30+
cd(projectDir);
31+
32+
/** Path to the bazel bin output directory. */
33+
const bazelBinPath = exec(`${bazelCmd} info bazel-bin`).stdout.trim();
34+
35+
/** Path where the NPM package is built into by Bazel. */
36+
const bazelBinOutDir = join(bazelBinPath, 'src/components-examples/npm_package');
37+
38+
// Build the docs-content package with the snapshot-build mode. That will help
39+
// determining which commit is associated with the built docs-content.
40+
exec(`${bazelCmd} build src/components-examples:npm_package --config=snapshot-build`);
41+
42+
// Clean the output directory to ensure that the docs-content package
43+
// will not contain outdated files from previous builds.
44+
rm('-rf', outputDir);
45+
mkdir('-p', distDir);
46+
47+
// Copy the package output into the dist path. Also update the permissions
48+
// as Bazel by default marks files in the bazel-out as readonly.
49+
cp('-R', bazelBinOutDir, outputDir);
50+
chmod('-R', 'u+w', outputDir);
51+
52+
console.info(`Built docs-content into: ${outputDir}`);

scripts/deploy/publish-docs-content.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ docsDistPath="${projectPath}/dist/docs"
2323
# Path to the cloned docs-content repository.
2424
docsContentPath="${projectPath}/tmp/material2-docs-content"
2525

26-
# Path to the release output of the Bazel "@angular/components-examples" NPM package.
27-
examplesPackagePath="$(bazel info bazel-bin)/src/components-examples/npm_package"
26+
# Path to the build output of the Bazel "@angular/components-examples" NPM package.
27+
# Note: When changing this, also change the path in `scripts/build-docs-content.js`.
28+
examplesPackagePath="${projectPath}/dist/docs-content-pkg/"
2829

2930
# Git clone URL for the material2-docs-content repository.
3031
docsContentRepoUrl="https://github.com/angular/material2-docs-content"

0 commit comments

Comments
 (0)