mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-09-18 02:16:11 +08:00
Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0f8cf3c399 | ||
![]() |
6a0d82c7a5 | ||
![]() |
eed19992d8 | ||
![]() |
1b5078831c | ||
![]() |
bc9aff343a | ||
![]() |
7aaa32a5a2 | ||
![]() |
ab7920fe38 | ||
![]() |
d912ace4a7 | ||
![]() |
8af4d314ce | ||
![]() |
f2d5269512 | ||
![]() |
fe24c4ca36 | ||
![]() |
cf61c297a6 | ||
![]() |
f9adc700ed | ||
![]() |
dcff16cbb5 | ||
![]() |
2bb8e83010 | ||
![]() |
0cfc6e4f0d | ||
![]() |
da7bdbfdd2 | ||
![]() |
07ee28ba3b |
27
cli.json
27
cli.json
@@ -88,6 +88,29 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"updateVersionInfo": {
|
||||||
|
"options": {
|
||||||
|
"platform": {
|
||||||
|
"hasValue": true
|
||||||
|
},
|
||||||
|
"versionId": {
|
||||||
|
"hasValue": true
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"default": false,
|
||||||
|
"hasValue": true
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"default": false,
|
||||||
|
"hasValue": true
|
||||||
|
},
|
||||||
|
"metaInfo": {
|
||||||
|
"default": false,
|
||||||
|
"hasValue": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
"build": {
|
"build": {
|
||||||
"description": "Bundle javascript and copy assets."
|
"description": "Bundle javascript and copy assets."
|
||||||
},
|
},
|
||||||
@@ -117,7 +140,9 @@
|
|||||||
"default": ".pushy/output/${platform}.${time}.ppk",
|
"default": ".pushy/output/${platform}.${time}.ppk",
|
||||||
"hasValue": true
|
"hasValue": true
|
||||||
},
|
},
|
||||||
"verbose": {}
|
"sourcemap": {
|
||||||
|
"default": false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"release": {
|
"release": {
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-native-update-cli",
|
"name": "react-native-update-cli",
|
||||||
"version": "1.8.1",
|
"version": "1.16.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": {
|
||||||
@@ -36,9 +36,10 @@
|
|||||||
"cli-arguments": "^0.2.1",
|
"cli-arguments": "^0.2.1",
|
||||||
"filesize-parser": "^1.5.0",
|
"filesize-parser": "^1.5.0",
|
||||||
"fs-extra": "8",
|
"fs-extra": "8",
|
||||||
"gradle-to-js": "^2.0.0",
|
"gradle-to-js": "^2.0.1",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
"progress": "^2.0.3",
|
"progress": "^2.0.3",
|
||||||
|
"properties": "^1.2.1",
|
||||||
"read": "^1.0.7",
|
"read": "^1.0.7",
|
||||||
"request": "^2.88.2",
|
"request": "^2.88.2",
|
||||||
"tcp-ping": "^0.1.1",
|
"tcp-ping": "^0.1.1",
|
||||||
|
1024
pnpm-lock.yaml
generated
1024
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const defaultEndpoint = 'http://u.reactnative.cn/api';
|
const defaultEndpoint = 'https://update.reactnative.cn/api';
|
||||||
let host = process.env.PUSHY_REGISTRY || defaultEndpoint;
|
let host = process.env.PUSHY_REGISTRY || defaultEndpoint;
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
import request from 'request';
|
import request from 'request';
|
||||||
|
114
src/bundle.js
114
src/bundle.js
@@ -8,6 +8,7 @@ import { checkPlatform } from './app';
|
|||||||
const { spawn, spawnSync } = require('child_process');
|
const { spawn, spawnSync } = require('child_process');
|
||||||
const g2js = require('gradle-to-js/lib/parser');
|
const g2js = require('gradle-to-js/lib/parser');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
|
const properties = require('properties');
|
||||||
|
|
||||||
var bsdiff, hdiff, diff;
|
var bsdiff, hdiff, diff;
|
||||||
try {
|
try {
|
||||||
@@ -49,7 +50,9 @@ async function runReactNativeBundleCommand(
|
|||||||
fs.emptyDirSync(outputFolder);
|
fs.emptyDirSync(outputFolder);
|
||||||
|
|
||||||
Array.prototype.push.apply(reactNativeBundleArgs, [
|
Array.prototype.push.apply(reactNativeBundleArgs, [
|
||||||
path.join('node_modules', 'react-native', 'local-cli', 'cli.js'),
|
require.resolve('react-native/local-cli/cli.js', {
|
||||||
|
paths: [process.cwd()],
|
||||||
|
}), // 'react-native' package may be symlinked
|
||||||
'bundle',
|
'bundle',
|
||||||
'--assets-dest',
|
'--assets-dest',
|
||||||
outputFolder,
|
outputFolder,
|
||||||
@@ -94,8 +97,39 @@ async function runReactNativeBundleCommand(
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if (gradleConfig.enableHermes) {
|
let hermesEnabled = false;
|
||||||
await compileHermesByteCode(bundleName, outputFolder);
|
|
||||||
|
if (platform === 'android') {
|
||||||
|
const gradlePropeties = await new Promise((resolve) => {
|
||||||
|
properties.parse(
|
||||||
|
'./android/gradle.properties',
|
||||||
|
{ path: true },
|
||||||
|
function (error, props) {
|
||||||
|
if (error) {
|
||||||
|
console.error(error);
|
||||||
|
resolve(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(props);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
hermesEnabled = gradlePropeties.hermesEnabled;
|
||||||
|
|
||||||
|
if (typeof hermesEnabled !== 'boolean')
|
||||||
|
hermesEnabled = gradleConfig.enableHermes;
|
||||||
|
} else if (
|
||||||
|
platform === 'ios' &&
|
||||||
|
fs.existsSync('ios/Pods/hermes-engine')
|
||||||
|
) {
|
||||||
|
hermesEnabled = true;
|
||||||
|
}
|
||||||
|
if (hermesEnabled) {
|
||||||
|
await compileHermesByteCode(
|
||||||
|
bundleName,
|
||||||
|
outputFolder,
|
||||||
|
sourcemapOutput,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
resolve(null);
|
resolve(null);
|
||||||
}
|
}
|
||||||
@@ -132,28 +166,43 @@ async function checkGradleConfig() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function compileHermesByteCode(bundleName, outputFolder) {
|
async function compileHermesByteCode(
|
||||||
|
bundleName,
|
||||||
|
outputFolder,
|
||||||
|
sourcemapOutput,
|
||||||
|
) {
|
||||||
console.log(`Hermes enabled, now compiling to hermes bytecode:\n`);
|
console.log(`Hermes enabled, now compiling to hermes bytecode:\n`);
|
||||||
const hermesPackage = fs.existsSync('node_modules/hermes-engine')
|
// >= rn 0.69
|
||||||
? 'node_modules/hermes-engine' // 0.2+
|
const rnDir = path.dirname(require.resolve('react-native'));
|
||||||
: 'node_modules/hermesvm'; // < 0.2
|
const hermesCommand = path.join(
|
||||||
const hermesPath = `${hermesPackage}/${getHermesOSBin()}`;
|
rnDir,
|
||||||
|
`/sdks/hermesc/${getHermesOSBin()}/hermesc`,
|
||||||
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' },
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// < rn 0.69
|
||||||
|
if (!fs.existsSync(hermesCommand)) {
|
||||||
|
const hermesPackage = fs.existsSync('node_modules/hermes-engine')
|
||||||
|
? 'node_modules/hermes-engine' // 0.2+
|
||||||
|
: 'node_modules/hermesvm'; // < 0.2
|
||||||
|
const hermesPath = `${hermesPackage}/${getHermesOSBin()}`;
|
||||||
|
|
||||||
|
hermesCommand = fs.existsSync(`${hermesPath}/hermesc`)
|
||||||
|
? `${hermesPath}/hermesc` // 0.5+
|
||||||
|
: `${hermesPath}/hermes`; // < 0.5
|
||||||
|
}
|
||||||
|
const args = [
|
||||||
|
'-emit-binary',
|
||||||
|
'-out',
|
||||||
|
path.join(outputFolder, bundleName),
|
||||||
|
path.join(outputFolder, bundleName),
|
||||||
|
'-O',
|
||||||
|
];
|
||||||
|
if (sourcemapOutput) {
|
||||||
|
args.push('-output-source-map');
|
||||||
|
}
|
||||||
|
spawnSync(path.join.apply(null, hermesCommand.split('/')), args, {
|
||||||
|
stdio: 'ignore',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function pack(dir, output) {
|
async function pack(dir, output) {
|
||||||
@@ -514,19 +563,13 @@ export const commands = {
|
|||||||
options.platform || (await question('平台(ios/android):')),
|
options.platform || (await question('平台(ios/android):')),
|
||||||
);
|
);
|
||||||
|
|
||||||
let {
|
let { bundleName, entryFile, intermediaDir, output, dev, sourcemap } =
|
||||||
bundleName,
|
translateOptions({
|
||||||
entryFile,
|
...options,
|
||||||
intermediaDir,
|
platform,
|
||||||
output,
|
});
|
||||||
dev,
|
|
||||||
verbose,
|
|
||||||
} = translateOptions({
|
|
||||||
...options,
|
|
||||||
platform,
|
|
||||||
});
|
|
||||||
|
|
||||||
// const sourcemapOutput = path.join(intermediaDir, bundleName + ".map");
|
const sourcemapOutput = path.join(intermediaDir, bundleName + '.map');
|
||||||
|
|
||||||
const realOutput = output.replace(/\$\{time\}/g, '' + Date.now());
|
const realOutput = output.replace(/\$\{time\}/g, '' + Date.now());
|
||||||
|
|
||||||
@@ -545,6 +588,7 @@ export const commands = {
|
|||||||
entryFile,
|
entryFile,
|
||||||
intermediaDir,
|
intermediaDir,
|
||||||
platform,
|
platform,
|
||||||
|
sourcemap ? sourcemapOutput : '',
|
||||||
);
|
);
|
||||||
|
|
||||||
await pack(path.resolve(intermediaDir), realOutput);
|
await pack(path.resolve(intermediaDir), realOutput);
|
||||||
|
@@ -65,7 +65,7 @@ export const commands = {
|
|||||||
} = await getIpaInfo(fn);
|
} = await getIpaInfo(fn);
|
||||||
const { appId, appKey } = await getSelectedApp('ios');
|
const { appId, appKey } = await getSelectedApp('ios');
|
||||||
|
|
||||||
if (appIdInPkg && appIdInPkg !== appId) {
|
if (appIdInPkg && appIdInPkg != appId) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`appId不匹配!当前ipa: ${appIdInPkg}, 当前update.json: ${appId}`,
|
`appId不匹配!当前ipa: ${appIdInPkg}, 当前update.json: ${appId}`,
|
||||||
);
|
);
|
||||||
@@ -100,7 +100,7 @@ export const commands = {
|
|||||||
} = await getApkInfo(fn);
|
} = await getApkInfo(fn);
|
||||||
const { appId, appKey } = await getSelectedApp('android');
|
const { appId, appKey } = await getSelectedApp('android');
|
||||||
|
|
||||||
if (appIdInPkg && appIdInPkg !== appId) {
|
if (appIdInPkg && appIdInPkg != appId) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`appId不匹配!当前apk: ${appIdInPkg}, 当前update.json: ${appId}`,
|
`appId不匹配!当前apk: ${appIdInPkg}, 当前update.json: ${appId}`,
|
||||||
);
|
);
|
||||||
|
@@ -43,7 +43,11 @@ export function translateOptions(options) {
|
|||||||
|
|
||||||
export function getRNVersion() {
|
export function getRNVersion() {
|
||||||
const version = JSON.parse(
|
const version = JSON.parse(
|
||||||
fs.readFileSync(path.resolve('node_modules/react-native/package.json')),
|
fs.readFileSync(
|
||||||
|
require.resolve('react-native/package.json', {
|
||||||
|
paths: [process.cwd()],
|
||||||
|
}),
|
||||||
|
),
|
||||||
).version;
|
).version;
|
||||||
|
|
||||||
// We only care about major and minor version.
|
// We only care about major and minor version.
|
||||||
@@ -106,9 +110,8 @@ export async function getIpaInfo(fn) {
|
|||||||
if (updateJsonFile) {
|
if (updateJsonFile) {
|
||||||
appCredential = JSON.parse(updateJsonFile.toString()).ios;
|
appCredential = JSON.parse(updateJsonFile.toString()).ios;
|
||||||
}
|
}
|
||||||
const {
|
const { CFBundleShortVersionString: versionName } =
|
||||||
CFBundleShortVersionString: versionName,
|
await appInfoParser.parse();
|
||||||
} = await appInfoParser.parse();
|
|
||||||
let buildTimeTxtBuffer = await appInfoParser.parser.getEntry(
|
let buildTimeTxtBuffer = await appInfoParser.parser.getEntry(
|
||||||
/payload\/.+?\.app\/pushy_build_time.txt/,
|
/payload\/.+?\.app\/pushy_build_time.txt/,
|
||||||
);
|
);
|
||||||
@@ -139,11 +142,11 @@ export function saveToLocal(originPath, destName) {
|
|||||||
export function printVersionCommand() {
|
export function printVersionCommand() {
|
||||||
console.log('react-native-update-cli: ' + pkg.version);
|
console.log('react-native-update-cli: ' + pkg.version);
|
||||||
try {
|
try {
|
||||||
const PACKAGE_JSON_PATH = path.resolve(
|
const PACKAGE_JSON_PATH = require.resolve(
|
||||||
process.cwd(),
|
'react-native-update/package.json',
|
||||||
'node_modules',
|
{
|
||||||
'react-native-update',
|
paths: [process.cwd()],
|
||||||
'package.json',
|
},
|
||||||
);
|
);
|
||||||
console.log('react-native-update: ' + require(PACKAGE_JSON_PATH).version);
|
console.log('react-native-update: ' + require(PACKAGE_JSON_PATH).version);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@@ -149,4 +149,18 @@ export const commands = {
|
|||||||
});
|
});
|
||||||
console.log('操作成功');
|
console.log('操作成功');
|
||||||
},
|
},
|
||||||
|
updateVersionInfo: async function ({ args, options }) {
|
||||||
|
const platform = checkPlatform(
|
||||||
|
options.platform || (await question('平台(ios/android):')),
|
||||||
|
);
|
||||||
|
const { appId } = await getSelectedApp(platform);
|
||||||
|
const versionId = options.versionId || (await chooseVersion(appId)).id;
|
||||||
|
|
||||||
|
const updateParams = {};
|
||||||
|
options.name && (updateParams.name = options.name);
|
||||||
|
options.description && (updateParams.description = options.description);
|
||||||
|
options.metaInfo && (updateParams.metaInfo = options.metaInfo);
|
||||||
|
await put(`/app/${appId}/version/${versionId}`, updateParams);
|
||||||
|
console.log('操作成功');
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user