mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-11-08 10:15:47 +08:00
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:
11
src/api.ts
11
src/api.ts
@@ -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) {
|
||||
|
||||
11
src/index.ts
11
src/index.ts
@@ -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))
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
declare global {
|
||||
var NO_INTERACTIVE: boolean;
|
||||
var USE_ACC_OSS: boolean;
|
||||
var IS_CRESC: boolean;
|
||||
}
|
||||
|
||||
export interface Session {
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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 '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user