diff --git a/src/package.js b/src/package.js index 8dfc80a..045de79 100644 --- a/src/package.js +++ b/src/package.js @@ -3,7 +3,7 @@ */ const { get, post, uploadFile } = require('./api'); -import { question } from './utils'; +import { question, saveToLocal } from './utils'; import { checkPlatform, getSelectedApp } from './app'; @@ -60,6 +60,7 @@ export const commands = { hash, buildTime, }); + saveToLocal(fn, `${appId}/${id}.ipa`); console.log(`Ipa uploaded: ${id}`); }, uploadApk: async function({ args }) { @@ -77,6 +78,7 @@ export const commands = { hash, buildTime, }); + saveToLocal(fn, `${appId}/${id}.apk`); console.log(`Apk uploaded: ${id}`); }, packages: async function({ options }) { diff --git a/src/utils/index.js b/src/utils/index.js index 48e6dba..5003e70 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -4,6 +4,8 @@ import * as path from 'path'; import * as fs from 'fs-extra'; +import os from 'os'; +import path from 'path'; const AppInfoParser = require('app-info-parser'); var read = require('read'); @@ -40,7 +42,9 @@ export function translateOptions(options) { } export function getRNVersion() { - const version = JSON.parse(fs.readFileSync(path.resolve('node_modules/react-native/package.json'))).version; + const version = JSON.parse( + fs.readFileSync(path.resolve('node_modules/react-native/package.json')), + ).version; // We only care about major and minor version. const match = /^(\d+)\.(\d+)\./.exec(version); @@ -70,11 +74,17 @@ export async function getApkInfo(fn) { export async function getIpaInfo(fn) { const appInfoParser = new AppInfoParser(fn); - const { CFBundleShortVersionString: versionName } = await appInfoParser.parse(); - let buildTimeTxtBuffer = await appInfoParser.parser.getEntry(/payload\/.+?\.app\/pushy_build_time.txt/); + const { + CFBundleShortVersionString: versionName, + } = await appInfoParser.parse(); + let buildTimeTxtBuffer = await appInfoParser.parser.getEntry( + /payload\/.+?\.app\/pushy_build_time.txt/, + ); if (!buildTimeTxtBuffer) { // Not in root bundle when use `use_frameworks` - buildTimeTxtBuffer = await appInfoParser.parser.getEntry(/payload\/.+?\.app\/frameworks\/react_native_update.framework\/pushy_build_time.txt/); + buildTimeTxtBuffer = await appInfoParser.parser.getEntry( + /payload\/.+?\.app\/frameworks\/react_native_update.framework\/pushy_build_time.txt/, + ); } if (!buildTimeTxtBuffer) { throw new Error('Can not get build time for this app.'); @@ -82,3 +92,11 @@ export async function getIpaInfo(fn) { const buildTime = buildTimeTxtBuffer.toString().replace('\n', ''); return { versionName, buildTime }; } + +const localDir = path.resolve(os.homedir(), '.pushy'); +fs.ensureDirSync(localDir); +export function saveToLocal(originPath, destName) { + const destPath = path.join(localDir, destName); + fs.ensureDirSync(path.dirname(destPath)); + fs.copyFileSync(originPath, destPath); +}