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

more cresc config

This commit is contained in:
sunnylqm
2025-02-18 22:37:09 +08:00
parent e713f4bbd1
commit 546faef83f
3 changed files with 29 additions and 17 deletions

View File

@@ -6,16 +6,19 @@ import ProgressBar from 'progress';
import packageJson from '../package.json'; import packageJson from '../package.json';
import tcpp from 'tcp-ping'; import tcpp from 'tcp-ping';
import filesizeParser from 'filesize-parser'; import filesizeParser from 'filesize-parser';
import { pricingPageUrl } from './utils'; import { pricingPageUrl } from './utils/constants';
import type { Session } from 'types'; import type { Session } from 'types';
import FormData from 'form-data'; import FormData from 'form-data';
import { credentialFile } from 'utils/constants';
const tcpPing = util.promisify(tcpp.ping); const tcpPing = util.promisify(tcpp.ping);
let session: Session | undefined; let session: Session | undefined;
let savedSession: Session | undefined; let savedSession: Session | undefined;
const defaultEndpoint = 'https://update.reactnative.cn/api'; const defaultEndpoint = global.IS_CRESC
? 'https://api.cresc.dev'
: 'https://update.reactnative.cn/api';
let host = process.env.PUSHY_REGISTRY || defaultEndpoint; let host = process.env.PUSHY_REGISTRY || defaultEndpoint;
const userAgent = `react-native-update-cli/${packageJson.version}`; const userAgent = `react-native-update-cli/${packageJson.version}`;
@@ -26,14 +29,16 @@ export const replaceSession = (newSession: { token: string }) => {
session = newSession; session = newSession;
}; };
export const loadSession = async () => { export const loadSession = async () => {
if (fs.existsSync('.update')) { if (fs.existsSync(credentialFile)) {
try { try {
replaceSession(JSON.parse(fs.readFileSync('.update', 'utf8'))); replaceSession(JSON.parse(fs.readFileSync(credentialFile, 'utf8')));
savedSession = session; savedSession = session;
} catch (e) { } catch (e) {
console.error( console.error(
'Failed to parse file `.update`. Try to remove it manually.', `Failed to parse file ${credentialFile}. Try to remove it manually.`,
); );
throw e; throw e;
} }
@@ -45,14 +50,14 @@ export const saveSession = () => {
if (session !== savedSession) { if (session !== savedSession) {
const current = session; const current = session;
const data = JSON.stringify(current, null, 4); const data = JSON.stringify(current, null, 4);
fs.writeFileSync('.update', data, 'utf8'); fs.writeFileSync(credentialFile, data, 'utf8');
savedSession = current; savedSession = current;
} }
}; };
export const closeSession = () => { export const closeSession = () => {
if (fs.existsSync('.update')) { if (fs.existsSync(credentialFile)) {
fs.unlinkSync('.update'); fs.unlinkSync(credentialFile);
savedSession = undefined; savedSession = undefined;
} }
session = undefined; session = undefined;
@@ -137,7 +142,7 @@ export async function uploadFile(fn: string, key?: string) {
); );
} }
const bar = new ProgressBar(' 上传中 [:bar] :percent :etas', { const bar = new ProgressBar(' Uploading [:bar] :percent :etas', {
complete: '=', complete: '=',
incomplete: ' ', incomplete: ' ',
total: fileSize, total: fileSize,
@@ -145,9 +150,9 @@ export async function uploadFile(fn: string, key?: string) {
const form = new FormData(); const form = new FormData();
Object.entries(formData).forEach(([k, v]) => { for (const [k, v] of Object.entries(formData)) {
form.append(k, v); form.append(k, v);
}); }
const fileStream = fs.createReadStream(fn); const fileStream = fs.createReadStream(fn);
fileStream.on('data', (data) => { fileStream.on('data', (data) => {
bar.tick(data.length); bar.tick(data.length);

6
src/utils/constants.ts Normal file
View File

@@ -0,0 +1,6 @@
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
? 'https://cresc.dev/pricing'
: 'https://pushy.reactnative.cn/pricing.html';

View File

@@ -9,8 +9,9 @@ import latestVersion from '@badisi/latest-version';
import { checkPlugins } from './check-plugin'; import { checkPlugins } from './check-plugin';
import { read } from 'read'; import { read } from 'read';
import { tempDir } from './constants';
export async function question(query, password) { export async function question(query: string, password: boolean) {
if (NO_INTERACTIVE) { if (NO_INTERACTIVE) {
return ''; return '';
} }
@@ -21,7 +22,7 @@ export async function question(query, password) {
}); });
} }
export function translateOptions(options) { export function translateOptions(options: Record<string, string>) {
const ret = {}; const ret = {};
for (const key in options) { for (const key in options) {
const v = options[key]; const v = options[key];
@@ -163,16 +164,16 @@ export async function getIpaInfo(fn: string) {
return { versionName, buildTime, ...appCredential }; return { versionName, buildTime, ...appCredential };
} }
const localDir = path.resolve(os.homedir(), '.pushy'); const localDir = path.resolve(os.homedir(), tempDir);
fs.ensureDirSync(localDir); fs.ensureDirSync(localDir);
export function saveToLocal(originPath, destName) { export function saveToLocal(originPath: string, destName: string) {
// TODO // TODO
// const destPath = path.join(localDir, destName); // const destPath = path.join(localDir, destName);
// fs.ensureDirSync(path.dirname(destPath)); // fs.ensureDirSync(path.dirname(destPath));
// fs.copyFileSync(originPath, destPath); // fs.copyFileSync(originPath, destPath);
} }
async function getLatestVersion(pkgName) { async function getLatestVersion(pkgName: string) {
return Promise.race([ return Promise.race([
latestVersion(pkgName) latestVersion(pkgName)
.then((p) => p.latest) .then((p) => p.latest)
@@ -225,6 +226,6 @@ export async function printVersionCommand() {
} }
} }
export const pricingPageUrl = 'https://pushy.reactnative.cn/pricing.html';
export { checkPlugins }; export { checkPlugins };