mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-09-16 09:41:38 +08:00
add commit info
This commit is contained in:
@@ -6,6 +6,8 @@ import { checkPlatform, getSelectedApp } from './app';
|
||||
import { getApkInfo, getIpaInfo, getAppInfo } from './utils';
|
||||
import Table from 'tty-table';
|
||||
import { depVersions } from './utils/dep-versions';
|
||||
import { getCommitInfo } from './utils/git';
|
||||
import type { Platform } from 'types';
|
||||
|
||||
export async function listPackage(appId: string) {
|
||||
const { data } = await get(`/app/${appId}/package/list?limit=1000`);
|
||||
@@ -81,13 +83,14 @@ export const commands = {
|
||||
hash,
|
||||
buildTime,
|
||||
deps: depVersions,
|
||||
commit: await getCommitInfo(),
|
||||
});
|
||||
saveToLocal(fn, `${appId}/package/${id}.ipa`);
|
||||
console.log(
|
||||
`已成功上传ipa原生包(id: ${id}, version: ${versionName}, buildTime: ${buildTime})`,
|
||||
);
|
||||
},
|
||||
uploadApk: async ({ args }) => {
|
||||
uploadApk: async ({ args }: { args: string[] }) => {
|
||||
const fn = args[0];
|
||||
if (!fn || !fn.endsWith('.apk')) {
|
||||
throw new Error('使用方法: pushy uploadApk apk后缀文件');
|
||||
@@ -119,13 +122,14 @@ export const commands = {
|
||||
hash,
|
||||
buildTime,
|
||||
deps: depVersions,
|
||||
commit: await getCommitInfo(),
|
||||
});
|
||||
saveToLocal(fn, `${appId}/package/${id}.apk`);
|
||||
console.log(
|
||||
`已成功上传apk原生包(id: ${id}, version: ${versionName}, buildTime: ${buildTime})`,
|
||||
);
|
||||
},
|
||||
uploadApp: async ({ args }) => {
|
||||
uploadApp: async ({ args }: { args: string[] }) => {
|
||||
const fn = args[0];
|
||||
if (!fn || !fn.endsWith('.app')) {
|
||||
throw new Error('使用方法: pushy uploadApp app后缀文件');
|
||||
@@ -157,34 +161,35 @@ export const commands = {
|
||||
hash,
|
||||
buildTime,
|
||||
deps: depVersions,
|
||||
commit: await getCommitInfo(),
|
||||
});
|
||||
saveToLocal(fn, `${appId}/package/${id}.app`);
|
||||
console.log(
|
||||
`已成功上传app原生包(id: ${id}, version: ${versionName}, buildTime: ${buildTime})`,
|
||||
);
|
||||
},
|
||||
parseApp: async ({ args }) => {
|
||||
parseApp: async ({ args }: { args: string[] }) => {
|
||||
const fn = args[0];
|
||||
if (!fn || !fn.endsWith('.app')) {
|
||||
throw new Error('使用方法: pushy parseApp app后缀文件');
|
||||
}
|
||||
console.log(await getAppInfo(fn));
|
||||
},
|
||||
parseIpa: async ({ args }) => {
|
||||
parseIpa: async ({ args }: { args: string[] }) => {
|
||||
const fn = args[0];
|
||||
if (!fn || !fn.endsWith('.ipa')) {
|
||||
throw new Error('使用方法: pushy parseIpa ipa后缀文件');
|
||||
}
|
||||
console.log(await getIpaInfo(fn));
|
||||
},
|
||||
parseApk: async ({ args }) => {
|
||||
parseApk: async ({ args }: { args: string[] }) => {
|
||||
const fn = args[0];
|
||||
if (!fn || !fn.endsWith('.apk')) {
|
||||
throw new Error('使用方法: pushy parseApk apk后缀文件');
|
||||
}
|
||||
console.log(await getApkInfo(fn));
|
||||
},
|
||||
packages: async ({ options }) => {
|
||||
packages: async ({ options }: { options: { platform: Platform } }) => {
|
||||
const platform = checkPlatform(
|
||||
options.platform || (await question('平台(ios/android/harmony):')),
|
||||
);
|
||||
|
50
src/utils/git.ts
Normal file
50
src/utils/git.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import git from 'isomorphic-git';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
export interface CommitInfo {
|
||||
hash: string;
|
||||
message: string;
|
||||
author: string;
|
||||
date: number;
|
||||
origin: string;
|
||||
}
|
||||
|
||||
function findGitRoot(dir = process.cwd()) {
|
||||
const gitRoot = fs.readdirSync(dir).find((dir) => dir === '.git');
|
||||
if (gitRoot) {
|
||||
// console.log({ gitRoot });
|
||||
return path.join(dir, gitRoot);
|
||||
}
|
||||
const parentDir = path.dirname(dir);
|
||||
if (parentDir === dir) {
|
||||
return null;
|
||||
}
|
||||
return findGitRoot(parentDir);
|
||||
}
|
||||
|
||||
const gitRoot = findGitRoot();
|
||||
|
||||
export async function getCommitInfo(): Promise<CommitInfo | undefined> {
|
||||
if (!gitRoot) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const remotes = await git.listRemotes({ fs, gitdir: gitRoot });
|
||||
const origin =
|
||||
remotes.find((remote) => remote.remote === 'origin') || remotes[0];
|
||||
const { commit, oid } = (
|
||||
await git.log({ fs, gitdir: gitRoot, depth: 1 })
|
||||
)[0];
|
||||
return {
|
||||
hash: oid,
|
||||
message: commit.message,
|
||||
author: commit.author.name || commit.committer.name,
|
||||
date: commit.committer.timestamp,
|
||||
origin: origin.url,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return;
|
||||
}
|
||||
}
|
@@ -11,7 +11,6 @@ import { checkPlugins } from './check-plugin';
|
||||
import { read } from 'read';
|
||||
import { tempDir } from './constants';
|
||||
import { depVersions } from './dep-versions';
|
||||
import { getCommitInfo } from './git';
|
||||
|
||||
export async function question(query: string, password?: boolean) {
|
||||
if (NO_INTERACTIVE) {
|
||||
@@ -169,8 +168,6 @@ async function getLatestVersion(pkgNames: string[]) {
|
||||
}
|
||||
|
||||
export async function printVersionCommand() {
|
||||
const result = await getCommitInfo();
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
let [latestPushyCliVersion, latestPushyVersion] = await getLatestVersion([
|
||||
'react-native-update-cli',
|
||||
'react-native-update',
|
||||
|
@@ -5,6 +5,7 @@ import { checkPlatform, getSelectedApp } from './app';
|
||||
import { choosePackage } from './package';
|
||||
import { compare } from 'compare-versions';
|
||||
import { depVersions } from './utils/dep-versions';
|
||||
import { getCommitInfo } from './utils/git';
|
||||
|
||||
async function showVersion(appId: string, offset: number) {
|
||||
const { data, count } = await get(`/app/${appId}/version/list`);
|
||||
@@ -98,13 +99,15 @@ export const commands = {
|
||||
|
||||
const { hash } = await uploadFile(fn);
|
||||
|
||||
const versionName = name || (await question('输入版本名称: ')) || '(未命名)';
|
||||
const versionName =
|
||||
name || (await question('输入版本名称: ')) || '(未命名)';
|
||||
const { id } = await post(`/app/${appId}/version/create`, {
|
||||
name: versionName,
|
||||
hash,
|
||||
description: description || (await question('输入版本描述:')),
|
||||
metaInfo: metaInfo || (await question('输入自定义的 meta info:')),
|
||||
deps: depVersions,
|
||||
commit: await getCommitInfo(),
|
||||
});
|
||||
// TODO local diff
|
||||
saveToLocal(fn, `${appId}/ppk/${id}.ppk`);
|
||||
|
Reference in New Issue
Block a user