Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: merge develop into main with plugin-permissions release #2732

Merged
merged 6 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@brandingbrand/code-plugin-asset": "2.0.0",
"@brandingbrand/code-plugin-example": "link:./coderc/plugins/plugin-example",
"@brandingbrand/code-plugin-native-navigation": "2.0.0",
"@brandingbrand/code-plugin-permissions": "2.0.0",
"@brandingbrand/code-plugin-permissions": "2.0.1",
"@brandingbrand/code-plugin-splash-screen": "2.0.0",
"@react-native/eslint-config": "^0.72.2",
"@react-native/metro-config": "^0.72.11",
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"types": "dist/index.d.ts",
"dependencies": {
"@brandingbrand/code-cli-kit": "13.0.0",
"ansi-align": "^3.0.1",
"bundle-require": "^4.0.2",
"chalk": "^4.1.2",
"ci-info": "^4.0.0",
Expand Down Expand Up @@ -51,6 +52,7 @@
"@brandingbrand/code-jest-config": "1.0.0",
"@repo/eslint-config": "*",
"@repo/typescript-config": "*",
"@types/ansi-align": "3.0.5",
"@types/eslint": "^8.56.1",
"@types/node": "^20.10.6",
"@types/react": "^18.2.55",
Expand Down
9 changes: 6 additions & 3 deletions packages/cli/src/actions/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {isWindows} from '@brandingbrand/code-cli-kit';
import pkg from '../../package.json';

import {config, defineAction, logger} from '@/lib';
import ansiAlign from 'ansi-align';

/**
* Executes the default action, providing detailed information and performing necessary checks.
Expand Down Expand Up @@ -40,11 +41,13 @@ export default defineAction(
▒▒▒▒

`);

logger.info(
chalk.bold
.blue`Welcome to Flagship Code ${chalk.bold.white`v${pkg.version}`}`,
ansiAlign([
chalk.bold.blue`Flagship Code ${chalk.bold.white`v${pkg.version}`}`,
chalk.dim`Configurable - Extensible - Toolkit`,
]).join('\n'),
);
logger.info(chalk.dim` Configurable - Extensible - Toolkit`);

// Check if the script is running on Windows, and throw an error if it is
if (isWindows) {
Expand Down
6 changes: 6 additions & 0 deletions packages/plugin-permissions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @brandingbrand/code-plugin-permissions

## 2.0.1

### Patch Changes

- c920f96: utilize react-native-permissions ios setup script.

## 2.0.0

### Major Changes
Expand Down
14 changes: 5 additions & 9 deletions packages/plugin-permissions/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import plugin from '../src';
import type {CodePluginPermissions} from '../src/types';

describe('plugin-permissions', () => {
jest.spyOn(fs, 'writeFile').mockImplementation(jest.fn());

it('ios', async () => {
const config: BuildConfig & CodePluginPermissions = {
ios: {
Expand Down Expand Up @@ -39,13 +37,11 @@ describe('plugin-permissions', () => {

await plugin.ios?.(config, {} as any);

expect(fs.writeFile).toHaveBeenCalledWith(
require.resolve('react-native-permissions/RNPermissions.podspec'),
expect.stringContaining(
'"ios/*.{h,m,mm}", "ios/AppTrackingTransparency/*.{h,m,mm}"',
),
'utf-8',
);
expect(await fs.readFile(path.ios.podfile, 'utf-8'))
.toContain(`setup_permissions([
'AppTrackingTransparency',
'LocationAccuracy'
])`);
expect(await fs.readFile(path.ios.infoPlist, 'utf-8'))
.toContain(`<key>NSUserTrackingUsageDescription</key>
<string>Let me use your ad identifier</string>`);
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-permissions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@brandingbrand/code-plugin-permissions",
"version": "2.0.0",
"version": "2.0.1",
"description": "plugin for Flagship Code for react-native-permissions",
"license": "MIT",
"main": "src/index.ts",
Expand Down
46 changes: 27 additions & 19 deletions packages/plugin-permissions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
string,
withInfoPlist,
withManifest,
path,
} from '@brandingbrand/code-cli-kit';

import * as permissions from './permissions';
Expand All @@ -36,29 +37,36 @@ export default definePlugin<CodePluginPermissions>({
// Check if the iOS plugin permissions are defined
if (!build.codePluginPermissions.plugin.ios) return;

// Resolve the path for RNPermissions.podspec file
const filePath = require.resolve(
'react-native-permissions/RNPermissions.podspec',
{
// eslint-disable-next-line turbo/no-undeclared-env-vars
...(!process.env.JEST_WORKER_ID && {paths: [process.cwd()]}),
},
);

// Update podspec file with appropriate permissions
await withUTF8(filePath, content => {
const pods = build.codePluginPermissions.plugin.ios!.reduce(
(acc, curr) => {
const pod = permissions.ios[curr.permission];
await withUTF8(path.ios.podfile, content => {
const pods = build.codePluginPermissions.plugin.ios?.map(
it => `'${it.permission}'`,
);

if (!pod?.pod) return acc;
if (!pods) return content;

return `${acc}, "ios/${pod?.pod}/*.{h,m,mm}"`;
},
'"ios/*.{h,m,mm}"',
);
const setupPodsString = `setup_permissions([
${pods.join(',\n ')}
])`;

return string.replace(content, /(source_files\s+=\s+).*/, `$1${pods}`);
return string.replace(
content,
/(.)/m,
`def node_require(script)
# Resolve script with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
"require.resolve(
'#{script}',
{paths: [process.argv[1]]},
)", __dir__]).strip
end

node_require('react-native-permissions/scripts/setup.rb')

${setupPodsString}

$1`,
);
});

// Update Info.plist with appropriate permissions and texts
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3181,6 +3181,11 @@
dependencies:
"@types/estree" "*"

"@types/[email protected]":
version "3.0.5"
resolved "https://registry.yarnpkg.com/@types/ansi-align/-/ansi-align-3.0.5.tgz#47302af78848bfcc2432b9050ce81e7c11a6d541"
integrity sha512-W6b8auzVjGP4JS2ejBl9OzwL1N3aBGqY7gamD28GymzcdNVeVGS+jfLeNWO/iknHLWa00hqGPaT3AcXhKax4aA==

"@types/babel__core@^7.1.14", "@types/babel__core@^7.20.4":
version "7.20.5"
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.20.5.tgz#3df15f27ba85319caa07ba08d0721889bb39c017"
Expand Down