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

Compare commits

..

8 Commits

Author SHA1 Message Date
sunnylqm
7f062f681a v1.2.0 2020-10-21 17:33:01 +08:00
sunnylqm
7f5b9fd7fd Check gradleConfig 2020-10-21 15:50:44 +08:00
sunnylqm
13b21c49c1 Merge branch 'master' of github.com:sunnylqm/react-native-update-cli
# Conflicts:
#	package.json
2020-10-21 15:24:46 +08:00
sunnylqm
85db61704c v1.1.18 2020-10-18 12:16:35 +08:00
sunnylqm
57ddfc5d7d Add token when upload 2020-10-18 12:16:15 +08:00
sunnylqm
6cb38eeec1 v1.1.17 2020-10-13 18:12:35 +08:00
sunnylqm
8a7c21fb50 Do not throw update.json not found error 2020-10-13 18:12:15 +08:00
sunnylqm
16b1cc3ed4 v1.1.15 2020-08-25 11:41:18 +08:00
4 changed files with 51 additions and 32 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "react-native-update-cli", "name": "react-native-update-cli",
"version": "1.1.16", "version": "1.2.0",
"description": "Command tools for javaScript updater with `pushy` service for react native apps.", "description": "Command tools for javaScript updater with `pushy` service for react native apps.",
"main": "index.js", "main": "index.js",
"bin": { "bin": {
@@ -43,7 +43,7 @@
"request": "^2.88.2", "request": "^2.88.2",
"tcp-ping": "^0.1.1", "tcp-ping": "^0.1.1",
"tty-table": "4.1", "tty-table": "4.1",
"update-notifier": "^4.1.0", "update-notifier": "^4.1.1",
"yauzl": "^2.10.0", "yauzl": "^2.10.0",
"yazl": "2.5.1" "yazl": "2.5.1"
}, },

View File

@@ -147,6 +147,10 @@ async function uploadFile(fn, key) {
realUrl, realUrl,
{ {
formData, formData,
headers: {
'User-Agent': userAgent,
'X-AccessToken': session ? session.token : '',
},
}, },
(err, resp, body) => { (err, resp, body) => {
if (err) { if (err) {

View File

@@ -37,6 +37,14 @@ async function runReactNativeBundleCommand(
sourcemapOutput, sourcemapOutput,
config, config,
) { ) {
let gradleConfig = {};
if (platform === 'android') {
gradleConfig = await checkGradleConfig();
if (gradleConfig.crunchPngs !== false) {
throw new Error('请先禁用android的crunchPngs优化具体请参考 https://pushy.reactnative.cn/docs/getting-started.html#%E7%A6%81%E7%94%A8android%E7%9A%84crunch%E4%BC%98%E5%8C%96')
}
}
let reactNativeBundleArgs = []; let reactNativeBundleArgs = [];
let envArgs = process.env.PUSHY_ENV_ARGS; let envArgs = process.env.PUSHY_ENV_ARGS;
@@ -96,7 +104,7 @@ async function runReactNativeBundleCommand(
), ),
); );
} else { } else {
if (platform === 'android') { if (gradleConfig.enableHermes) {
await compileHermesByteCode(bundleName, outputFolder); await compileHermesByteCode(bundleName, outputFolder);
} }
resolve(null); resolve(null);
@@ -111,11 +119,13 @@ function getHermesOSBin() {
if (os.platform() === 'linux') return 'linux64-bin'; if (os.platform() === 'linux') return 'linux64-bin';
} }
async function compileHermesByteCode(bundleName, outputFolder) { async function checkGradleConfig() {
let enableHermes = false; let enableHermes = false;
let crunchPngs;
try { try {
const gradleConfig = await g2js.parseFile('android/app/build.gradle'); const gradleConfig = await g2js.parseFile('android/app/build.gradle');
const projectConfig = gradleConfig['project.ext.react']; const projectConfig = gradleConfig['project.ext.react'];
crunchPngs = gradleConfig.android.buildTypes.release.crunchPngs;
for (const packagerConfig of projectConfig) { for (const packagerConfig of projectConfig) {
if ( if (
packagerConfig.includes('enableHermes') && packagerConfig.includes('enableHermes') &&
@@ -126,31 +136,36 @@ async function compileHermesByteCode(bundleName, outputFolder) {
} }
} }
} catch (e) {} } catch (e) {}
if (enableHermes) { return {
console.log(`Hermes enabled, now compiling to hermes bytecode:\n`); enableHermes,
const hermesPackage = fs.existsSync('node_modules/hermes-engine') crunchPngs,
? 'node_modules/hermes-engine' // 0.2+
: 'node_modules/hermesvm'; // < 0.2
const hermesPath = `${hermesPackage}/${getHermesOSBin()}`;
const hermesCommand = fs.existsSync(`${hermesPath}/hermesc`)
? `${hermesPath}/hermesc` // 0.5+
: `${hermesPath}/hermes`; // < 0.5
spawnSync(
path.join.apply(null, hermesCommand.split('/')),
[
'-emit-binary',
'-out',
path.join(outputFolder, bundleName),
path.join(outputFolder, bundleName),
'-O',
],
{ stdio: 'ignore' },
);
} }
} }
async function compileHermesByteCode(bundleName, outputFolder) {
console.log(`Hermes enabled, now compiling to hermes bytecode:\n`);
const hermesPackage = fs.existsSync('node_modules/hermes-engine')
? 'node_modules/hermes-engine' // 0.2+
: 'node_modules/hermesvm'; // < 0.2
const hermesPath = `${hermesPackage}/${getHermesOSBin()}`;
const hermesCommand = fs.existsSync(`${hermesPath}/hermesc`)
? `${hermesPath}/hermesc` // 0.5+
: `${hermesPath}/hermes`; // < 0.5
spawnSync(
path.join.apply(null, hermesCommand.split('/')),
[
'-emit-binary',
'-out',
path.join(outputFolder, bundleName),
path.join(outputFolder, bundleName),
'-O',
],
{ stdio: 'ignore' },
);
}
async function pack(dir, output) { async function pack(dir, output) {
console.log('Packing'); console.log('Packing');
fs.ensureDirSync(path.dirname(output)); fs.ensureDirSync(path.dirname(output));

View File

@@ -68,10 +68,10 @@ export async function getApkInfo(fn) {
const updateJsonFile = await appInfoParser.parser.getEntry( const updateJsonFile = await appInfoParser.parser.getEntry(
/res\/raw\/update.json/, /res\/raw\/update.json/,
); );
if (!updateJsonFile) { let appCredential = {};
throw new Error('找不到update.json文件'); if (updateJsonFile) {
appCredential = JSON.parse(updateJsonFile.toString()).android;
} }
const appCredential = JSON.parse(updateJsonFile.toString()).android;
const { versionName, application } = await appInfoParser.parse(); const { versionName, application } = await appInfoParser.parse();
let buildTime = 0; let buildTime = 0;
if (Array.isArray(application.metaData)) { if (Array.isArray(application.metaData)) {
@@ -102,10 +102,10 @@ export async function getIpaInfo(fn) {
const updateJsonFile = await appInfoParser.parser.getEntry( const updateJsonFile = await appInfoParser.parser.getEntry(
/payload\/.+?\.app\/assets\/update.json/, /payload\/.+?\.app\/assets\/update.json/,
); );
if (!updateJsonFile) { let appCredential = {};
throw new Error('找不到update.json文件'); if (updateJsonFile) {
appCredential = JSON.parse(updateJsonFile.toString()).ios;
} }
const appCredential = JSON.parse(updateJsonFile.toString()).ios;
const { const {
CFBundleShortVersionString: versionName, CFBundleShortVersionString: versionName,
} = await appInfoParser.parse(); } = await appInfoParser.parse();