|
| 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}`); |
0 commit comments