Skip to content

Commit 546faef

Browse files
committed
more cresc config
1 parent e713f4b commit 546faef

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

src/api.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ 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 } from './utils';
9+
import { pricingPageUrl } from './utils/constants';
1010
import type { Session } from 'types';
1111
import FormData from 'form-data';
12+
import { credentialFile } from 'utils/constants';
1213

1314
const tcpPing = util.promisify(tcpp.ping);
1415

1516
let session: Session | undefined;
1617
let savedSession: Session | undefined;
1718

18-
const defaultEndpoint = 'https://update.reactnative.cn/api';
19+
const defaultEndpoint = global.IS_CRESC
20+
? 'https://api.cresc.dev'
21+
: 'https://update.reactnative.cn/api';
1922
let host = process.env.PUSHY_REGISTRY || defaultEndpoint;
2023

2124
const userAgent = `react-native-update-cli/${packageJson.version}`;
@@ -26,14 +29,16 @@ export const replaceSession = (newSession: { token: string }) => {
2629
session = newSession;
2730
};
2831

32+
33+
2934
export const loadSession = async () => {
30-
if (fs.existsSync('.update')) {
35+
if (fs.existsSync(credentialFile)) {
3136
try {
32-
replaceSession(JSON.parse(fs.readFileSync('.update', 'utf8')));
37+
replaceSession(JSON.parse(fs.readFileSync(credentialFile, 'utf8')));
3338
savedSession = session;
3439
} catch (e) {
3540
console.error(
36-
'Failed to parse file `.update`. Try to remove it manually.',
41+
`Failed to parse file ${credentialFile}. Try to remove it manually.`,
3742
);
3843
throw e;
3944
}
@@ -45,14 +50,14 @@ export const saveSession = () => {
4550
if (session !== savedSession) {
4651
const current = session;
4752
const data = JSON.stringify(current, null, 4);
48-
fs.writeFileSync('.update', data, 'utf8');
53+
fs.writeFileSync(credentialFile, data, 'utf8');
4954
savedSession = current;
5055
}
5156
};
5257

5358
export const closeSession = () => {
54-
if (fs.existsSync('.update')) {
55-
fs.unlinkSync('.update');
59+
if (fs.existsSync(credentialFile)) {
60+
fs.unlinkSync(credentialFile);
5661
savedSession = undefined;
5762
}
5863
session = undefined;
@@ -137,17 +142,17 @@ export async function uploadFile(fn: string, key?: string) {
137142
);
138143
}
139144

140-
const bar = new ProgressBar(' 上传中 [:bar] :percent :etas', {
145+
const bar = new ProgressBar(' Uploading [:bar] :percent :etas', {
141146
complete: '=',
142147
incomplete: ' ',
143148
total: fileSize,
144149
});
145150

146151
const form = new FormData();
147152

148-
Object.entries(formData).forEach(([k, v]) => {
153+
for (const [k, v] of Object.entries(formData)) {
149154
form.append(k, v);
150-
});
155+
}
151156
const fileStream = fs.createReadStream(fn);
152157
fileStream.on('data', (data) => {
153158
bar.tick(data.length);

src/utils/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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
5+
? 'https://cresc.dev/pricing'
6+
: 'https://pushy.reactnative.cn/pricing.html';

src/utils/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import latestVersion from '@badisi/latest-version';
99
import { checkPlugins } from './check-plugin';
1010

1111
import { read } from 'read';
12+
import { tempDir } from './constants';
1213

13-
export async function question(query, password) {
14+
export async function question(query: string, password: boolean) {
1415
if (NO_INTERACTIVE) {
1516
return '';
1617
}
@@ -21,7 +22,7 @@ export async function question(query, password) {
2122
});
2223
}
2324

24-
export function translateOptions(options) {
25+
export function translateOptions(options: Record<string, string>) {
2526
const ret = {};
2627
for (const key in options) {
2728
const v = options[key];
@@ -163,16 +164,16 @@ export async function getIpaInfo(fn: string) {
163164
return { versionName, buildTime, ...appCredential };
164165
}
165166

166-
const localDir = path.resolve(os.homedir(), '.pushy');
167+
const localDir = path.resolve(os.homedir(), tempDir);
167168
fs.ensureDirSync(localDir);
168-
export function saveToLocal(originPath, destName) {
169+
export function saveToLocal(originPath: string, destName: string) {
169170
// TODO
170171
// const destPath = path.join(localDir, destName);
171172
// fs.ensureDirSync(path.dirname(destPath));
172173
// fs.copyFileSync(originPath, destPath);
173174
}
174175

175-
async function getLatestVersion(pkgName) {
176+
async function getLatestVersion(pkgName: string) {
176177
return Promise.race([
177178
latestVersion(pkgName)
178179
.then((p) => p.latest)
@@ -225,6 +226,6 @@ export async function printVersionCommand() {
225226
}
226227
}
227228

228-
export const pricingPageUrl = 'https://pushy.reactnative.cn/pricing.html';
229+
229230

230231
export { checkPlugins };

0 commit comments

Comments
 (0)