From 594859db40a9afdf772ec9b20e1901bd044cd8d2 Mon Sep 17 00:00:00 2001 From: myxmaster Date: Sat, 25 Nov 2023 13:30:26 +0100 Subject: [PATCH] created test to ensure static styles don't contain themeColor() calls, use node 18 in workflows --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/prettier.yml | 2 +- .github/workflows/test.yml | 2 +- README.md | 3 +++ check-styles.test.ts | 38 ++++++++++++++++++++++++++++++++ package.json | 7 +++--- 7 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 check-styles.test.ts diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 6c970cbfcf..ab1ea5b1d4 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -11,7 +11,7 @@ This pull request is categorized as a: - [ ] Code refactor - [ ] Configuration change - [ ] Locales update -- [ ] Quality assurance +- [ ] Quality assurance - [ ] Other ## Checklist diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 30bee9903b..d6a5422e5c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -14,6 +14,6 @@ jobs: - name: Use Node.js uses: actions/setup-node@v3 with: - node-version: '16.x' + node-version: '18.x' - run: yarn install --frozen-lockfile - run: yarn run lint diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml index 7213000837..974f60e2c4 100644 --- a/.github/workflows/prettier.yml +++ b/.github/workflows/prettier.yml @@ -14,6 +14,6 @@ jobs: - name: Use Node.js uses: actions/setup-node@v3 with: - node-version: '16.x' + node-version: '18.x' - run: yarn install --frozen-lockfile - run: yarn run prettier diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1ceda17917..8f8400de8b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,6 +14,6 @@ jobs: - name: Use Node.js uses: actions/setup-node@v3 with: - node-version: '16.x' + node-version: '18.x' - run: yarn install --frozen-lockfile - run: yarn run test diff --git a/README.md b/README.md index 259a5c5925..6e04693e77 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,9 @@ ZEUS is proud to be integrated on the following platforms: **Don't trust, verify** the code with your own two eyes. Then when ready proceed to the steps below based on your platform. +### Prerequisites +1. Node.js (minimum version: 18.17) + ### Android 1. install and setup react-native and its related dependencies under **"Building Projects with Native Code"** on [react-native's Getting Started page](https://reactnative.dev/docs/environment-setup) diff --git a/check-styles.test.ts b/check-styles.test.ts new file mode 100644 index 0000000000..0620d99d4f --- /dev/null +++ b/check-styles.test.ts @@ -0,0 +1,38 @@ +import * as fs from 'fs'; +import * as path from 'path'; + +describe('static style sheets', () => { + it('must not contain themeColor() calls', () => { + const dirs = fs + .readdirSync('.', { withFileTypes: true }) + .filter((e) => e.isDirectory() && e.name !== 'node_modules') + .map((e) => e.name); + dirs.push('.'); + const tsxFiles = dirs.flatMap((dir) => + fs + .readdirSync(dir, { recursive: dir !== '.' }) + .filter( + (file) => + typeof file === 'string' && + !file.startsWith('node_modules/') && + file.toLowerCase().endsWith('.tsx') + ) + .map((file) => path.join(dir, file as string)) + ); + const regExp = new RegExp( + /\n[^\s][^\n]+StyleSheet\.create\(\{.*themeColor\(/, + 's' + ); + const invalidFiles = tsxFiles.filter((file) => + fs.readFileSync(file).toString('utf8').match(regExp) + ); + + if (invalidFiles.length > 0) { + throw new Error( + 'The following files contain static StyleSheets with themeColor() calls. ' + + 'This is not allowed because the color then will not be updated when theme is changed.\n' + + invalidFiles.join('\n') + ); + } + }); +}); diff --git a/package.json b/package.json index fc1100ee7e..11c229dac1 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ ], "transformIgnorePatterns": [ "node_modules/(?!(react-native|@react-native|react-native-blob-util|react-native-randombytes)/)" - ] + ], + "testPathIgnorePatterns": ["check-styles.test.ts"] }, "scripts": { "start": "react-native start", @@ -18,14 +19,14 @@ "postinstall": "rn-nodeify --install --hack & npx jetify & yarn run patch & react-native setup-ios-permissions & yarn run fetch-libraries & pod-install", "test": "jest", "tsc": "tsc", - "lint": "eslint --ext .js,.ts,.tsx \"*.@(js|ts|tsx)\" .", + "lint": "eslint --ext .js,.ts,.tsx \"*.@(js|ts|tsx)\" . && yarn run test check-styles.test.ts --testPathIgnorePatterns=", "prettier": "prettier --check \"**/*.ts*\"", "prettier-write": "prettier --check --write \"**/*.ts*\"", "patch": "git apply patches/react-native-camera-kit.patch && git apply patches/rnqli-build.gradle.patch", "gen-proto": "pbjs -t static-module --keep-case -w es6 --force-long -o proto/lightning.js proto/*.proto proto/*/*.proto && pbts -o proto/lightning.d.ts proto/lightning.js", "gradlew": "cd android && ./gradlew", "android:clean": "yarn gradlew clean", - "fetch-libraries": "bash fetch-libraries.sh" + "fetch-libraries": "bash fetch-libraries.sh", }, "dependencies": { "@keystonehq/bc-ur-registry": "0.4.2",