mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-09-17 18:06:10 +08:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0e8e3aa420 | ||
![]() |
7426e93647 | ||
![]() |
b6fb2e7d2a | ||
![]() |
7f1dcbb571 | ||
![]() |
59fad93832 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -104,3 +104,4 @@ dist
|
||||
.tern-port
|
||||
|
||||
lib/
|
||||
.DS_Store
|
||||
|
4
cli.json
4
cli.json
@@ -106,11 +106,11 @@
|
||||
"hasValue": true
|
||||
},
|
||||
"intermediaDir": {
|
||||
"default": "build/intermedia/${platform}",
|
||||
"default": ".pushy/intermedia/${platform}",
|
||||
"hasValue": true
|
||||
},
|
||||
"output": {
|
||||
"default": "build/output/${platform}.${time}.ppk",
|
||||
"default": ".pushy/output/${platform}.${time}.ppk",
|
||||
"hasValue": true
|
||||
},
|
||||
"verbose": {}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-update-cli",
|
||||
"version": "1.2.3",
|
||||
"version": "1.3.0",
|
||||
"description": "Command tools for javaScript updater with `pushy` service for react native apps.",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
|
55
src/app.js
55
src/app.js
@@ -4,12 +4,9 @@
|
||||
|
||||
import { question } from './utils';
|
||||
import fs from 'fs';
|
||||
const Table = require('tty-table');
|
||||
|
||||
const {
|
||||
post,
|
||||
get,
|
||||
doDelete,
|
||||
} = require('./api');
|
||||
const { post, get, doDelete } = require('./api');
|
||||
|
||||
const validPlatforms = {
|
||||
ios: 1,
|
||||
@@ -20,28 +17,42 @@ export function checkPlatform(platform) {
|
||||
if (!validPlatforms[platform]) {
|
||||
throw new Error(`Invalid platform '${platform}'`);
|
||||
}
|
||||
return platform
|
||||
return platform;
|
||||
}
|
||||
|
||||
export function getSelectedApp(platform) {
|
||||
checkPlatform(platform);
|
||||
|
||||
if (!fs.existsSync('update.json')) {
|
||||
throw new Error(`App not selected. run 'pushy selectApp --platform ${platform}' first!`);
|
||||
throw new Error(
|
||||
`App not selected. run 'pushy selectApp --platform ${platform}' first!`,
|
||||
);
|
||||
}
|
||||
const updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
|
||||
if (!updateInfo[platform]) {
|
||||
throw new Error(`App not selected. run 'pushy selectApp --platform ${platform}' first!`);
|
||||
throw new Error(
|
||||
`App not selected. run 'pushy selectApp --platform ${platform}' first!`,
|
||||
);
|
||||
}
|
||||
return updateInfo[platform];
|
||||
}
|
||||
|
||||
export async function listApp(platform) {
|
||||
const { data } = await get('/app/list');
|
||||
const list = platform?data.filter(v=>v.platform===platform):data;
|
||||
const list = platform ? data.filter((v) => v.platform === platform) : data;
|
||||
|
||||
const header = [
|
||||
{ value: 'App Id' },
|
||||
{ value: 'App Name' },
|
||||
{ value: 'Platform' },
|
||||
];
|
||||
const rows = [];
|
||||
for (const app of list) {
|
||||
console.log(`${app.id}) ${app.name}(${app.platform})`);
|
||||
rows.push([app.id, app.name, app.platform]);
|
||||
}
|
||||
|
||||
console.log(Table(header, rows).render());
|
||||
|
||||
if (platform) {
|
||||
console.log(`\nTotal ${list.length} ${platform} apps`);
|
||||
} else {
|
||||
@@ -55,7 +66,7 @@ export async function chooseApp(platform) {
|
||||
|
||||
while (true) {
|
||||
const id = await question('Enter appId:');
|
||||
const app = list.find(v=>v.id === (id|0));
|
||||
const app = list.find((v) => v.id === (id | 0));
|
||||
if (app) {
|
||||
return app;
|
||||
}
|
||||
@@ -64,9 +75,11 @@ export async function chooseApp(platform) {
|
||||
|
||||
export const commands = {
|
||||
createApp: async function ({ options }) {
|
||||
const name = options.name || await question('App Name:');
|
||||
const name = options.name || (await question('App Name:'));
|
||||
const { downloadUrl } = options;
|
||||
const platform = checkPlatform(options.platform || await question('Platform(ios/android):'));
|
||||
const platform = checkPlatform(
|
||||
options.platform || (await question('Platform(ios/android):')),
|
||||
);
|
||||
const { id } = await post('/app/create', { name, platform });
|
||||
console.log(`Created app ${id}`);
|
||||
await this.selectApp({
|
||||
@@ -88,7 +101,9 @@ export const commands = {
|
||||
listApp(platform);
|
||||
},
|
||||
selectApp: async function ({ args, options }) {
|
||||
const platform = checkPlatform(options.platform || await question('Platform(ios/android):'));
|
||||
const platform = checkPlatform(
|
||||
options.platform || (await question('Platform(ios/android):')),
|
||||
);
|
||||
const id = args[0] || (await chooseApp(platform)).id;
|
||||
|
||||
let updateInfo = {};
|
||||
@@ -96,7 +111,9 @@ export const commands = {
|
||||
try {
|
||||
updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
|
||||
} catch (e) {
|
||||
console.error('Failed to parse file `update.json`. Try to remove it manually.');
|
||||
console.error(
|
||||
'Failed to parse file `update.json`. Try to remove it manually.',
|
||||
);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -105,6 +122,10 @@ export const commands = {
|
||||
appId: id,
|
||||
appKey,
|
||||
};
|
||||
fs.writeFileSync('update.json', JSON.stringify(updateInfo, null, 4), 'utf8');
|
||||
fs.writeFileSync(
|
||||
'update.json',
|
||||
JSON.stringify(updateInfo, null, 4),
|
||||
'utf8',
|
||||
);
|
||||
},
|
||||
}
|
||||
};
|
||||
|
@@ -52,8 +52,25 @@ export const commands = {
|
||||
if (!fn || !fn.endsWith('.ipa')) {
|
||||
throw new Error('Usage: pushy uploadIpa <ipaFile>');
|
||||
}
|
||||
const { versionName, buildTime } = await getIpaInfo(fn);
|
||||
const { appId } = await getSelectedApp('ios');
|
||||
const {
|
||||
versionName,
|
||||
buildTime,
|
||||
appId: appIdInPkg,
|
||||
appKey: appKeyInPkg,
|
||||
} = await getIpaInfo(fn);
|
||||
const { appId, appKey } = await getSelectedApp('ios');
|
||||
|
||||
if (appIdInPkg && appIdInPkg !== appId) {
|
||||
throw new Error(
|
||||
`appId不匹配!当前ipa:${appIdInPkg}, 当前update.json:${appId}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (appKeyInPkg && appKeyInPkg !== appKey) {
|
||||
throw new Error(
|
||||
`appKey不匹配!当前ipa:${appKeyInPkg}, 当前update.json:${appKey}`,
|
||||
);
|
||||
}
|
||||
|
||||
const { hash } = await uploadFile(fn);
|
||||
|
||||
@@ -70,8 +87,25 @@ export const commands = {
|
||||
if (!fn || !fn.endsWith('.apk')) {
|
||||
throw new Error('Usage: pushy uploadApk <apkFile>');
|
||||
}
|
||||
const { versionName, buildTime } = await getApkInfo(fn);
|
||||
const { appId } = await getSelectedApp('android');
|
||||
const {
|
||||
versionName,
|
||||
buildTime,
|
||||
appId: appIdInPkg,
|
||||
appKey: appKeyInPkg,
|
||||
} = await getApkInfo(fn);
|
||||
const { appId, appKey } = await getSelectedApp('android');
|
||||
|
||||
if (appIdInPkg && appIdInPkg !== appId) {
|
||||
throw new Error(
|
||||
`appId不匹配!当前apk:${appIdInPkg}, 当前update.json:${appId}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (appKeyInPkg && appKeyInPkg !== appKey) {
|
||||
throw new Error(
|
||||
`appKey不匹配!当前apk:${appKeyInPkg}, 当前update.json:${appKey}`,
|
||||
);
|
||||
}
|
||||
|
||||
const { hash } = await uploadFile(fn);
|
||||
|
||||
|
Reference in New Issue
Block a user