From 596fbb3f066e36ec0c0245b2e36767d8ea267077 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Thu, 2 Jul 2020 20:00:24 +0300 Subject: [PATCH] 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 --- aio/tools/cli-patches/patch.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/aio/tools/cli-patches/patch.js b/aio/tools/cli-patches/patch.js index e7afdf43fa..a7e6407d7e 100644 --- a/aio/tools/cli-patches/patch.js +++ b/aio/tools/cli-patches/patch.js @@ -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); } -