Skip to content

Commit d0495fb

Browse files
authored
Feat/deps (#10)
* init * add deps * sort key
1 parent 613f39a commit d0495fb

File tree

8 files changed

+125
-65
lines changed

8 files changed

+125
-65
lines changed

bun.lock

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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-update-cli",
3-
"version": "1.41.0",
3+
"version": "1.42.0",
44
"description": "Command tools for javaScript updater with `pushy` service for react native apps.",
55
"main": "index.js",
66
"bin": {
@@ -48,6 +48,7 @@
4848
"fs-extra": "8",
4949
"gradle-to-js": "^2.0.1",
5050
"i18next": "^24.2.2",
51+
"isomorphic-git": "^1.29.0",
5152
"isomorphic-unzip": "^1.1.5",
5253
"node-fetch": "^2.6.1",
5354
"plist": "^3.1.0",

src/bundle.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'node:path';
2-
import { getRNVersion, translateOptions } from './utils';
2+
import { translateOptions } from './utils';
33
import * as fs from 'fs-extra';
44
import { ZipFile } from 'yazl';
55
import { open as openZipFile } from 'yauzl';
@@ -10,6 +10,7 @@ import semverSatisfies from 'semver/functions/satisfies';
1010
const g2js = require('gradle-to-js/lib/parser');
1111
import os from 'node:os';
1212
const properties = require('properties');
13+
import { depVersions } from './utils/dep-versions';
1314

1415
let bsdiff;
1516
let hdiff;
@@ -82,11 +83,13 @@ async function runReactNativeBundleCommand({
8283
paths: [process.cwd()],
8384
});
8485
const expoCliVersion = JSON.parse(
85-
fs.readFileSync(
86-
require.resolve('@expo/cli/package.json', {
87-
paths: [process.cwd()],
88-
}),
89-
).toString(),
86+
fs
87+
.readFileSync(
88+
require.resolve('@expo/cli/package.json', {
89+
paths: [process.cwd()],
90+
}),
91+
)
92+
.toString(),
9093
).version;
9194
// expo cli 0.10.17 (expo 49) 开始支持 bundle:embed
9295
if (semverSatisfies(expoCliVersion, '>= 0.10.17')) {
@@ -175,19 +178,11 @@ async function runReactNativeBundleCommand({
175178
platform,
176179
'--reset-cache',
177180
]);
178-
181+
179182
if (cli.taro) {
180-
reactNativeBundleArgs.push(...[
181-
'--type',
182-
'rn',
183-
])
183+
reactNativeBundleArgs.push(...['--type', 'rn']);
184184
} else {
185-
reactNativeBundleArgs.push(...[
186-
'--dev',
187-
dev,
188-
'--entry-file',
189-
entryFile,
190-
])
185+
reactNativeBundleArgs.push(...['--dev', dev, '--entry-file', entryFile]);
191186
}
192187

193188
if (sourcemapOutput) {
@@ -927,9 +922,7 @@ export const commands = {
927922
throw new Error('Platform must be specified.');
928923
}
929924

930-
const { version, major, minor } = getRNVersion();
931-
932-
console.log(`Bundling with react-native: ${version}`);
925+
console.log(`Bundling with react-native: ${depVersions['react-native']}`);
933926

934927
await runReactNativeBundleCommand({
935928
bundleName,

src/package.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { checkPlatform, getSelectedApp } from './app';
55

66
import { getApkInfo, getIpaInfo, getAppInfo } from './utils';
77
import Table from 'tty-table';
8+
import { depVersions } from './utils/dep-versions';
89

910
export async function listPackage(appId: string) {
1011
const { data } = await get(`/app/${appId}/package/list?limit=1000`);
@@ -79,6 +80,7 @@ export const commands = {
7980
name: versionName,
8081
hash,
8182
buildTime,
83+
deps: depVersions,
8284
});
8385
saveToLocal(fn, `${appId}/package/${id}.ipa`);
8486
console.log(
@@ -116,6 +118,7 @@ export const commands = {
116118
name: versionName,
117119
hash,
118120
buildTime,
121+
deps: depVersions,
119122
});
120123
saveToLocal(fn, `${appId}/package/${id}.apk`);
121124
console.log(
@@ -153,6 +156,7 @@ export const commands = {
153156
name: versionName,
154157
hash,
155158
buildTime,
159+
deps: depVersions,
156160
});
157161
saveToLocal(fn, `${appId}/package/${id}.app`);
158162
console.log(

src/utils/dep-versions.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const currentPackage = require(`${process.cwd()}/package.json`);
2+
3+
const depKeys = Object.keys(currentPackage.dependencies);
4+
const devDepKeys = Object.keys(currentPackage.devDependencies);
5+
const dedupedDeps = [...new Set([...depKeys, ...devDepKeys])];
6+
7+
const _depVersions: Record<string, string> = {};
8+
9+
for (const dep of dedupedDeps) {
10+
try {
11+
const packageJsonPath = require.resolve(`${dep}/package.json`, {
12+
paths: [process.cwd()],
13+
});
14+
const version = require(packageJsonPath).version;
15+
_depVersions[dep] = version;
16+
} catch (e) {}
17+
}
18+
19+
export const depVersions = Object.keys(_depVersions)
20+
.sort() // Sort the keys alphabetically
21+
.reduce((obj, key) => {
22+
obj[key] = _depVersions[key]; // Rebuild the object with sorted keys
23+
return obj;
24+
}, {} as Record<string, string>);
25+
26+
// console.log({ depVersions });

0 commit comments

Comments
 (0)