Skip to content

Instantly share code, notes, and snippets.

@m-abs
Created March 28, 2018 12:06
Show Gist options
  • Save m-abs/7143d2b598091c577a57f6d0fe8948c8 to your computer and use it in GitHub Desktop.
Save m-abs/7143d2b598091c577a57f6d0fe8948c8 to your computer and use it in GitHub Desktop.
patch nrwl/nx formatter for nativescript projects
#!/bin/bash
realpath() {
[[ $1 = /* ]] && echo "$1" || (cd "$PWD/${1#./}" && echo $PWD);
}
apply_patch() {
PATCH=$1
patch -p0 -N --dry-run --silent -i $PATCH 2>&1 > /dev/null
if [[ $? -eq 0 ]]; then
patch -p0 -N --silent -i $PATCH
if [[ $? -eq 0 ]]; then
echo "APPLIED PATCH: ${PATCH}";
else
echo "COULDN'T APPLY THE PATCH: ${PATCH}";
exit 127
fi
else
patch -p0 -N -R --dry-run --silent -i $PATCH 2>&1 > /dev/null
if [[ $? -eq 0 ]]; then
echo "ALREADY APPLIED: ${PATCH}";
else
echo "CANNOT APPLY THE PATCH: ${PATCH}";
exit 127
fi
fi
}
PATCH_DIR=$(realpath $(dirname $0));
ROOT=$(git rev-parse --show-toplevel);
echo -e "Applying local patches from ${PATCH_DIR}\n";
cd $ROOT
for patch in $PATCH_DIR/*.patch; do
apply_patch $patch
done
echo -e "\nDONE - Applying local patches from ${PATCH_DIR}";
--- node_modules/@nrwl/schematics/src/command-line/format.js.orig 2018-03-28 13:15:08.107680784 +0200
+++ node_modules/@nrwl/schematics/src/command-line/format.js 2018-03-28 13:15:22.124751217 +0200
@@ -33,7 +33,7 @@ function getPatterns(args) {
return libsAndApp ? getPatternsFromApps(patterns) : patterns;
}
catch (e) {
- return ['"{apps,libs}/**/*.ts"'];
+ return ['"{apps,libs}/**/*.ts"', "!apps/**/platforms/{android,ios}/**/*.ts"];
}
}
function getPatternsFromApps(affectedFiles) {
@m-abs
Copy link
Author

m-abs commented Mar 28, 2018

When you generate lib/modules/etc in an nx+nativescript project, the nx format will crawl through all the *.ts-files in the platform folder.

This is a quick and very dirty fix to get around that.
apply-patches.sh is a shell script for applying patches to node_modules (which is very dirty -- but sometimes needed).
fix-nw-format-for-tns.patch is the patch itself, which tells the formatter to ignore the files under the platforms-folder

Put both files into the <gitroot>/patches-folder and mark apply-patches.sh as executable.

Edit package.json and change postinstall from

./node_modules/.bin/nx postinstall

To:

./patches/apply-patches.sh; ./node_modules/.bin/nx postinstall

Run npm install again or call patches/apply-patches.sh directly to apply the patch

Issue with template-nativescript-nx: NathanWalker/template-nativescript-nx#12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment