Skip to content

Commit bb3ab3d

Browse files
committed
remove react-native-config
1 parent aac8bbd commit bb3ab3d

12 files changed

Lines changed: 124 additions & 74 deletions

File tree

.github/workflows/build.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,12 @@ jobs:
4646
- name: Install Dependencies
4747
run: pnpm install --frozen-lockfile
4848

49-
- name: Create Environment File
49+
- name: Generate Environment Variables
5050
run: |
51-
cat > .env << EOF
52-
MYANIMELIST_CLIENT_ID=${{ vars.MYANIMELIST_CLIENT_ID }}
53-
ANILIST_CLIENT_ID=${{ vars.ANILIST_CLIENT_ID }}
54-
GIT_HASH=$(git rev-parse --short HEAD)
55-
RELEASE_DATE=$(date --utc +'%d/%m/%y %I:%M %p %Z')
56-
BUILD_TYPE=Github Action
57-
TEST="This is a test"
58-
EOF
51+
node scripts/generate-env.js \
52+
--build-type "Github Action" \
53+
--myanimelist-client-id "${{ vars.MYANIMELIST_CLIENT_ID }}" \
54+
--anilist-client-id "${{ vars.ANILIST_CLIENT_ID }}"
5955
6056
- name: Build Android Release with Rock
6157
uses: callstackincubator/android@v3

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ flake.lock
8989
# pnpm
9090
.pnpm-store
9191

92+
src/generated/**/*
93+
9294
.cursor/
9395
.agents/
9496
.claude/

babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default function (api) {
2727
'@type': './src/type',
2828
'@specs': './specs',
2929
'@test-utils': './__tests-modules__/test-utils',
30+
'@env': './src/generated/build-info',
3031
'react-native-vector-icons/MaterialCommunityIcons':
3132
'@react-native-vector-icons/material-design-icons',
3233
},

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const baseModuleNameMapper = {
1717
'^@type/(.*)$': '<rootDir>/src/type/$1',
1818
'^@specs/(.*)$': '<rootDir>/specs/$1',
1919
'^@test-utils$': '<rootDir>/__tests-modules__/test-utils',
20+
'^@env$': '<rootDir>/src/generated/build-info',
2021
// Mock static assets
2122
'\\.(jpg|jpeg|png|gif|webp|svg)$': '<rootDir>/__mocks__/fileMock.js',
2223
};

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"dev:clean-start": "pnpm run dev:start -- --reset-cache",
1111
"build:release:android": "pnpm run generate:env:release && rock build:android --variant \"release\"",
1212
"build:open-apk": "open ./android/app/build/outputs/apk/release/",
13-
"generate:env:debug": "node scripts/generate-env-file.cjs Debug",
14-
"generate:env:release": "node scripts/generate-env-file.cjs Release",
13+
"generate:env:debug": "node scripts/generate-env-file.cjs --build-type Debug",
14+
"generate:env:release": "node scripts/generate-env-file.cjs --build-type Release",
1515
"generate:string-types": "node scripts/generate-string-types.cjs",
1616
"generate:db-migration": "drizzle-kit generate",
1717
"upgrade:migration-format": "drizzle-kit up",
@@ -95,7 +95,6 @@
9595
"react": "^19.2.4",
9696
"react-native": "^0.83.4",
9797
"react-native-background-actions": "^4.0.1",
98-
"react-native-config": "^1.6.1",
9998
"react-native-device-info": "^15.0.2",
10099
"react-native-draggable-flatlist": "^4.0.3",
101100
"react-native-drawer-layout": "^4.2.2",

pnpm-lock.yaml

Lines changed: 0 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/generate-env-file.cjs

Lines changed: 108 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,127 @@
11
const fs = require('fs');
2-
const os = require('os');
32
const path = require('path');
43
const { execSync } = require('child_process');
54

6-
const formattedDate = new Date().getTime();
7-
const commitHash = execSync('git rev-parse --short HEAD').toString().trim();
8-
const buildType = process.argv[2] || 'Beta';
5+
function parseArgs(argv) {
6+
const out = {};
97

10-
const newEnvVars = [
11-
`BUILD_TYPE=${buildType}`,
12-
`GIT_HASH=${commitHash}`,
13-
`RELEASE_DATE=${formattedDate}`,
14-
`NODE_ENV=${buildType === 'Release' ? 'production' : 'development'}`,
15-
].join(os.EOL);
8+
for (let i = 2; i < argv.length; i += 1) {
9+
const token = argv[i];
1610

17-
const envFilePath = path.join(__dirname, '..', '.env');
18-
let existingEnvData = '';
11+
if (!token.startsWith('--')) {
12+
continue;
13+
}
1914

20-
try {
21-
if (fs.existsSync(envFilePath)) {
22-
const existingContent = fs.readFileSync(envFilePath, 'utf8');
23-
24-
existingEnvData = existingContent
25-
.split(os.EOL)
26-
.filter(line => {
27-
const trimmedLine = line.trim();
28-
return (
29-
trimmedLine &&
30-
!trimmedLine.startsWith('BUILD_TYPE=') &&
31-
!trimmedLine.startsWith('GIT_HASH=') &&
32-
!trimmedLine.startsWith('RELEASE_DATE=') &&
33-
!trimmedLine.startsWith('NODE_ENV=')
34-
);
35-
})
36-
.join(os.EOL);
15+
const eqIndex = token.indexOf('=');
16+
17+
if (eqIndex !== -1) {
18+
out[token.slice(2, eqIndex)] = token.slice(eqIndex + 1);
19+
continue;
20+
}
21+
22+
const key = token.slice(2);
23+
const next = argv[i + 1];
24+
25+
if (next && !next.startsWith('--')) {
26+
out[key] = next;
27+
i += 1;
28+
} else {
29+
out[key] = true;
30+
}
3731
}
38-
} catch (err) {
39-
console.warn('Warning: Could not read existing .env file:', err.message);
32+
33+
return out;
4034
}
4135

42-
const finalContent = existingEnvData
43-
? `${newEnvVars}${os.EOL}${existingEnvData}${os.EOL}`
44-
: `${newEnvVars}${os.EOL}`;
36+
function formatUtcDate(date) {
37+
const pad = n => String(n).padStart(2, '0');
38+
39+
const day = pad(date.getUTCDate());
40+
const month = pad(date.getUTCMonth() + 1);
41+
const year = String(date.getUTCFullYear()).slice(-2);
42+
43+
let hours = date.getUTCHours();
44+
const minutes = pad(date.getUTCMinutes());
45+
const ampm = hours >= 12 ? 'PM' : 'AM';
46+
47+
hours %= 12;
48+
if (hours === 0) {
49+
hours = 12;
50+
}
51+
52+
return `${day}/${month}/${year} ${pad(hours)}:${minutes} ${ampm} UTC`;
53+
}
54+
55+
function getGitHash() {
56+
return execSync('git rev-parse --short HEAD').toString().trim();
57+
}
58+
59+
const args = parseArgs(process.argv);
60+
61+
const buildType = args['build-type'] || 'Beta';
62+
const myanimelistClientId = args['myanimelist-client-id'];
63+
const anilistClientId = args['anilist-client-id'];
64+
65+
const gitHash = args['git-hash'] || getGitHash();
66+
const releaseDate = args['release-date'] || formatUtcDate(new Date());
67+
const nodeEnv =
68+
args['node-env'] ||
69+
(buildType.toLowerCase().includes('release') ? 'production' : 'development');
70+
const testValue =
71+
args.test || 'This is a test variable to verify .env generation';
72+
73+
const envContent = [
74+
`BUILD_TYPE=${JSON.stringify(buildType)}`,
75+
`GIT_HASH=${JSON.stringify(gitHash)}`,
76+
`RELEASE_DATE=${JSON.stringify(releaseDate)}`,
77+
`NODE_ENV=${JSON.stringify(nodeEnv)}`,
78+
`MYANIMELIST_CLIENT_ID=${JSON.stringify(myanimelistClientId)}`,
79+
`ANILIST_CLIENT_ID=${JSON.stringify(anilistClientId)}`,
80+
`TEST=${JSON.stringify(testValue)}`,
81+
'',
82+
].join('\n');
83+
84+
const envFilePath = path.join(__dirname, '..', '.env');
85+
const buildInfoPath = path.join(
86+
__dirname,
87+
'..',
88+
'src',
89+
'generated',
90+
'build-info.ts',
91+
);
92+
93+
const buildInfoContent = `// This file is generated. Do not edit manually.
94+
export const BUILD_TYPE = ${JSON.stringify(buildType)};
95+
export const GIT_HASH = ${JSON.stringify(gitHash)};
96+
export const RELEASE_DATE = ${JSON.stringify(releaseDate)};
97+
export const NODE_ENV = ${JSON.stringify(nodeEnv)};
98+
export const MYANIMELIST_CLIENT_ID = ${JSON.stringify(myanimelistClientId)};
99+
export const ANILIST_CLIENT_ID = ${JSON.stringify(anilistClientId)};
100+
export const TEST = ${JSON.stringify(testValue)};
101+
102+
export default {
103+
BUILD_TYPE,
104+
GIT_HASH,
105+
RELEASE_DATE,
106+
NODE_ENV,
107+
MYANIMELIST_CLIENT_ID,
108+
ANILIST_CLIENT_ID,
109+
TEST,
110+
};
111+
`;
45112

46113
try {
47-
fs.writeFileSync(envFilePath, finalContent, 'utf8');
114+
fs.mkdirSync(path.dirname(buildInfoPath), { recursive: true });
115+
fs.writeFileSync(buildInfoPath, buildInfoContent, 'utf8');
116+
fs.writeFileSync(envFilePath, envContent, 'utf8');
48117

49-
console.log(`Generated .env file for ${buildType} build\n`);
118+
console.log(`Generated .env for ${buildType} build`);
50119
console.table({
51120
BUILD_TYPE: buildType,
52-
GIT_HASH: commitHash,
53-
RELEASE_DATE: formattedDate,
54-
NODE_ENV: buildType === 'Release' ? 'production' : 'development',
121+
GIT_HASH: gitHash,
122+
RELEASE_DATE: releaseDate,
123+
NODE_ENV: nodeEnv,
55124
});
56-
console.log('\n');
57125
} catch (err) {
58126
console.error('Error: Could not write .env file:', err.message);
59127
process.exit(1);

src/screens/library/components/LibraryListView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import ServiceManager from '@services/ServiceManager';
1414
import { getPlugin } from '@plugins/pluginManager';
1515
import { useSelectionContext } from '../SelectionContext';
1616
import { ImageRequestInit } from '@plugins/types';
17-
import Config from 'react-native-config';
17+
import Config from '@env';
1818

1919
interface Props {
2020
categoryId: number;

src/screens/more/About.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { MoreHeader } from './components/MoreHeader';
88
import { useTheme } from '@hooks/persisted';
99
import { List, SafeAreaView } from '@components';
1010
import { AboutScreenProps } from '@navigators/types';
11-
import Config from 'react-native-config';
11+
import Config from '@env';
1212
import * as Clipboard from 'expo-clipboard';
1313
import { version } from '../../../package.json';
1414

src/services/Trackers/aniList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Linking from 'expo-linking';
22
import * as WebBrowser from 'expo-web-browser';
3-
import Config from 'react-native-config';
3+
import Config from '@env';
44
import { AuthenticationResult, Tracker } from './index';
55

66
const apiEndpoint = 'https://graphql.anilist.co';

0 commit comments

Comments
 (0)