build(docs-infra): improve applying post-install patches (#37896)

In `aio/`, we have a mechanism to apply patches in a `postinstall` hook.
See `aio/tools/cli-patches/README.md` for more info.

Previously, we had to update `aio/tools/cli-patches/patch.js` to list
each `.patch` file separately. While working on #37688, I found it
helpful for the script to automatically pick up `.patch` files.

This commit updates the script to automatically pick up and apply
`.patch` files from the `aio/tools/cli-patches/` directory. If one wants
to keep a `.patch` file but not apply it, they can change the file's
extension or move it to a sub-directory (without having to update the
script).

PR Close #37896
This commit is contained in:
George Kalpakas 2020-07-02 20:00:24 +03:00 committed by Alex Rickabaugh
parent aed6b131bb
commit 596fbb3f06
1 changed files with 8 additions and 3 deletions

View File

@ -1,9 +1,14 @@
const fs = require('fs');
const sh = require('shelljs');
const PATCH_LOCK = 'node_modules/@angular/cli/.patched';
if (!fs.existsSync(PATCH_LOCK)) {
sh.set('-e');
sh.cd(`${__dirname}/../../`);
if (!sh.test('-f', PATCH_LOCK)) {
sh.ls('-l', __dirname)
.filter(stat => stat.isFile() && /\.patch$/i.test(stat.name))
.forEach(stat => sh.exec(`patch -p0 -i "${__dirname}/${stat.name}"`));
sh.touch(PATCH_LOCK);
}