1
0
mirror of https://gitcode.com/github-mirrors/react-native-update-cli.git synced 2025-11-08 02:05:48 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

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
This commit is contained in:
sunnylqm
2025-02-19 22:53:24 +08:00
parent 04b5d12daa
commit 4e51f291ca
7 changed files with 71 additions and 35 deletions

View File

@@ -6,7 +6,7 @@ import ProgressBar from 'progress';
import packageJson from '../package.json';
import tcpp from 'tcp-ping';
import filesizeParser from 'filesize-parser';
import { pricingPageUrl, credentialFile } from './utils/constants';
import { pricingPageUrl, credentialFile, IS_CRESC } from './utils/constants';
import type { Session } from 'types';
import FormData from 'form-data';
@@ -15,10 +15,12 @@ const tcpPing = util.promisify(tcpp.ping);
let session: Session | undefined;
let savedSession: Session | undefined;
const defaultEndpoint = global.IS_CRESC
const defaultEndpoint = IS_CRESC
? 'https://api.cresc.dev'
: 'https://update.reactnative.cn/api';
let host = process.env.PUSHY_REGISTRY || defaultEndpoint;
const host =
process.env.PUSHY_REGISTRY || process.env.RNU_API || defaultEndpoint;
const userAgent = `react-native-update-cli/${packageJson.version}`;
@@ -28,8 +30,6 @@ export const replaceSession = (newSession: { token: string }) => {
session = newSession;
};
export const loadSession = async () => {
if (fs.existsSync(credentialFile)) {
try {
@@ -60,7 +60,6 @@ export const closeSession = () => {
savedSession = undefined;
}
session = undefined;
host = process.env.PUSHY_REGISTRY || defaultEndpoint;
};
async function query(url: string, options: fetch.RequestInit) {

View File

@@ -4,18 +4,13 @@ import { loadSession } from './api';
import updateNotifier from 'update-notifier';
import { printVersionCommand } from './utils';
import pkg from '../package.json';
import path from 'node:path';
import i18next from 'i18next';
import en from './locales/en';
import zh from './locales/zh';
const scriptName: 'cresc' | 'pushy' = path.basename(process.argv[1]) as
| 'cresc'
| 'pushy';
global.IS_CRESC = scriptName === 'cresc';
import { IS_CRESC } from './utils/constants';
i18next.init({
lng: global.IS_CRESC ? 'en' : 'zh',
lng: IS_CRESC ? 'en' : 'zh',
// debug: process.env.NODE_ENV !== 'production',
resources: {
en,
@@ -57,7 +52,7 @@ async function run() {
const argv = require('cli-arguments').parse(require('../cli.json'));
global.NO_INTERACTIVE = argv.options['no-interactive'];
global.USE_ACC_OSS = argv.options['acc'];
global.USE_ACC_OSS = argv.options.acc;
loadSession()
.then(() => commands[argv.command](argv))

View File

@@ -1,7 +1,6 @@
declare global {
var NO_INTERACTIVE: boolean;
var USE_ACC_OSS: boolean;
var IS_CRESC: boolean;
}
export interface Session {

View File

@@ -1,6 +1,13 @@
export const credentialFile = global.IS_CRESC ? '.cresc.token' : '.update';
export const updateJson = global.IS_CRESC ? 'cresc.config.json' : 'update.json';
export const tempDir = global.IS_CRESC ? '.cresc.temp' : '.pushy';
export const pricingPageUrl = global.IS_CRESC
import path from 'node:path';
const scriptName: 'cresc' | 'pushy' = path.basename(process.argv[1]) as
| 'cresc'
| 'pushy';
export const IS_CRESC = scriptName === 'cresc';
export const credentialFile = IS_CRESC ? '.cresc.token' : '.update';
export const updateJson = IS_CRESC ? 'cresc.config.json' : 'update.json';
export const tempDir = IS_CRESC ? '.cresc.temp' : '.pushy';
export const pricingPageUrl = IS_CRESC
? 'https://cresc.dev/pricing'
: 'https://pushy.reactnative.cn/pricing.html';

View File

@@ -11,7 +11,7 @@ import { checkPlugins } from './check-plugin';
import { read } from 'read';
import { tempDir } from './constants';
export async function question(query: string, password: boolean) {
export async function question(query: string, password?: boolean) {
if (NO_INTERACTIVE) {
return '';
}