Skip to content

Commit c49e137

Browse files
committed
add version
1 parent 75d33e8 commit c49e137

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"types": "dist/index.d.ts",
99
"sideEffects": false,
1010
"scripts": {
11+
"prebuild": "node scripts/update-version.js",
1112
"build": "rollup -c",
1213
"test": "jest",
1314
"test:watch": "jest --watch",
@@ -24,9 +25,9 @@
2425
"author": "AutoLocalise",
2526
"license": "MIT",
2627
"peerDependencies": {
27-
"react": ">=18.0.0",
28-
"react-native": ">=0.73.0",
29-
"@react-native-async-storage/async-storage": ">=1.18.0"
28+
"react": ">=16.8.0",
29+
"react-native": ">=0.60.0",
30+
"@react-native-async-storage/async-storage": ">=1.0.0"
3031
},
3132
"devDependencies": {
3233
"@rollup/plugin-commonjs": "^25.0.0",

scripts/update-version.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require("fs");
4+
const path = require("path");
5+
6+
// Read package.json
7+
const packageJsonPath = path.join(__dirname, "..", "package.json");
8+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
9+
10+
// Update version.ts
11+
const versionFilePath = path.join(__dirname, "..", "src", "version.ts");
12+
const versionContent = `// This file is auto-generated during build
13+
// Update this manually or via build script
14+
export const VERSION = "${packageJson.version}";
15+
`;
16+
17+
fs.writeFileSync(versionFilePath, versionContent);
18+
console.log(`Updated version.ts with version ${packageJson.version}`);

src/services/translation.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
TranslationResponse,
77
} from "../types";
88
import { getStorageAdapter } from "../storage";
9+
import { VERSION } from "../version";
910

1011
export class TranslationService {
1112
private config: TranslationConfig;
@@ -87,12 +88,13 @@ export class TranslationService {
8788
this.pendingTranslations.clear();
8889

8990
if (allTexts.length > 0) {
90-
// Modify API request to include context
91+
// Modify API request to include context and version
9192
const request: TranslationRequest = {
9293
texts: allTexts,
9394
sourceLocale: this.config.sourceLocale,
9495
targetLocale: this.config.targetLocale,
9596
apiKey: this.config.apiKey,
97+
version: `react-native-v${VERSION}`,
9698
};
9799

98100
try {

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface TranslationRequest {
2121
sourceLocale: string;
2222
targetLocale: string;
2323
apiKey: string;
24+
version: string;
2425
}
2526

2627
export interface TranslationResponse {

src/version.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This file is auto-generated during build
2+
// Update this manually or via build script
3+
export const VERSION = "0.0.0";

0 commit comments

Comments
 (0)