Skip to content

Commit 4e51f29

Browse files
committed
Refactor project configuration and dependencies
- Move IS_CRESC logic to constants module - Update package.json with new type definitions - Simplify global variable usage - Update bun.lock with latest package versions - Improve type safety and configuration management
1 parent 04b5d12 commit 4e51f29

File tree

7 files changed

+71
-35
lines changed

7 files changed

+71
-35
lines changed

bun.lock

Lines changed: 48 additions & 15 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,13 @@
6969
"@swc/cli": "^0.5.1",
7070
"@swc/core": "^1.9.3",
7171
"@types/filesize-parser": "^1.5.3",
72+
"@types/fs-extra": "^11.0.4",
7273
"@types/node": "^22.9.3",
7374
"@types/node-fetch": "^2.6.12",
7475
"@types/progress": "^2.0.7",
76+
"@types/semver": "^7.5.8",
7577
"@types/tcp-ping": "^0.1.6",
78+
"@types/update-notifier": "^6.0.8",
7679
"typescript": "^5.7.2"
7780
},
7881
"packageManager": "[email protected]+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"

src/api.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import ProgressBar from 'progress';
66
import packageJson from '../package.json';
77
import tcpp from 'tcp-ping';
88
import filesizeParser from 'filesize-parser';
9-
import { pricingPageUrl, credentialFile } from './utils/constants';
9+
import { pricingPageUrl, credentialFile, IS_CRESC } from './utils/constants';
1010
import type { Session } from 'types';
1111
import FormData from 'form-data';
1212

@@ -15,10 +15,12 @@ const tcpPing = util.promisify(tcpp.ping);
1515
let session: Session | undefined;
1616
let savedSession: Session | undefined;
1717

18-
const defaultEndpoint = global.IS_CRESC
18+
const defaultEndpoint = IS_CRESC
1919
? 'https://api.cresc.dev'
2020
: 'https://update.reactnative.cn/api';
21-
let host = process.env.PUSHY_REGISTRY || defaultEndpoint;
21+
22+
const host =
23+
process.env.PUSHY_REGISTRY || process.env.RNU_API || defaultEndpoint;
2224

2325
const userAgent = `react-native-update-cli/${packageJson.version}`;
2426

@@ -28,8 +30,6 @@ export const replaceSession = (newSession: { token: string }) => {
2830
session = newSession;
2931
};
3032

31-
32-
3333
export const loadSession = async () => {
3434
if (fs.existsSync(credentialFile)) {
3535
try {
@@ -60,7 +60,6 @@ export const closeSession = () => {
6060
savedSession = undefined;
6161
}
6262
session = undefined;
63-
host = process.env.PUSHY_REGISTRY || defaultEndpoint;
6463
};
6564

6665
async function query(url: string, options: fetch.RequestInit) {

src/index.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@ import { loadSession } from './api';
44
import updateNotifier from 'update-notifier';
55
import { printVersionCommand } from './utils';
66
import pkg from '../package.json';
7-
import path from 'node:path';
87
import i18next from 'i18next';
98
import en from './locales/en';
109
import zh from './locales/zh';
11-
12-
const scriptName: 'cresc' | 'pushy' = path.basename(process.argv[1]) as
13-
| 'cresc'
14-
| 'pushy';
15-
global.IS_CRESC = scriptName === 'cresc';
10+
import { IS_CRESC } from './utils/constants';
1611

1712
i18next.init({
18-
lng: global.IS_CRESC ? 'en' : 'zh',
13+
lng: IS_CRESC ? 'en' : 'zh',
1914
// debug: process.env.NODE_ENV !== 'production',
2015
resources: {
2116
en,
@@ -57,7 +52,7 @@ async function run() {
5752

5853
const argv = require('cli-arguments').parse(require('../cli.json'));
5954
global.NO_INTERACTIVE = argv.options['no-interactive'];
60-
global.USE_ACC_OSS = argv.options['acc'];
55+
global.USE_ACC_OSS = argv.options.acc;
6156

6257
loadSession()
6358
.then(() => commands[argv.command](argv))

src/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
declare global {
22
var NO_INTERACTIVE: boolean;
33
var USE_ACC_OSS: boolean;
4-
var IS_CRESC: boolean;
54
}
65

76
export interface Session {

src/utils/constants.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
export const credentialFile = global.IS_CRESC ? '.cresc.token' : '.update';
2-
export const updateJson = global.IS_CRESC ? 'cresc.config.json' : 'update.json';
3-
export const tempDir = global.IS_CRESC ? '.cresc.temp' : '.pushy';
4-
export const pricingPageUrl = global.IS_CRESC
1+
import path from 'node:path';
2+
3+
const scriptName: 'cresc' | 'pushy' = path.basename(process.argv[1]) as
4+
| 'cresc'
5+
| 'pushy';
6+
export const IS_CRESC = scriptName === 'cresc';
7+
8+
export const credentialFile = IS_CRESC ? '.cresc.token' : '.update';
9+
export const updateJson = IS_CRESC ? 'cresc.config.json' : 'update.json';
10+
export const tempDir = IS_CRESC ? '.cresc.temp' : '.pushy';
11+
export const pricingPageUrl = IS_CRESC
512
? 'https://cresc.dev/pricing'
613
: 'https://pushy.reactnative.cn/pricing.html';

src/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { checkPlugins } from './check-plugin';
1111
import { read } from 'read';
1212
import { tempDir } from './constants';
1313

14-
export async function question(query: string, password: boolean) {
14+
export async function question(query: string, password?: boolean) {
1515
if (NO_INTERACTIVE) {
1616
return '';
1717
}

0 commit comments

Comments
 (0)