mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-09-17 18:06:10 +08:00
Compare commits
27 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3987a5191f | ||
![]() |
9903fb97e4 | ||
![]() |
834c0bb351 | ||
![]() |
fa8ba44bfa | ||
![]() |
6e4e89428c | ||
![]() |
e018761fc8 | ||
![]() |
6534379d81 | ||
![]() |
bb777bf973 | ||
![]() |
ea05d4ab66 | ||
![]() |
a259ff671d | ||
![]() |
3f68fa0f11 | ||
![]() |
fa750ba157 | ||
![]() |
91fc0caa07 | ||
![]() |
36e1be084d | ||
![]() |
e099002629 | ||
![]() |
5dd3b64720 | ||
![]() |
31ec3edc5a | ||
![]() |
4b772194d1 | ||
![]() |
792418c964 | ||
![]() |
d5f468aa44 | ||
![]() |
04f75cd51b | ||
![]() |
5a05679e2b | ||
![]() |
69f4372b63 | ||
![]() |
dbfdce6412 | ||
![]() |
1372a30ea3 | ||
![]() |
d51ef37a62 | ||
![]() |
90a59cfe7b |
47
.github/workflows/lint.yml
vendored
Normal file
47
.github/workflows/lint.yml
vendored
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
name: lint
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
# Cancel a currently running workflow from the same PR/branch/tag
|
||||||
|
# when a new workflow is triggered
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
node-version: [20.x]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: oven-sh/setup-bun@v2
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '20.x'
|
||||||
|
registry-url: 'https://registry.npmjs.org'
|
||||||
|
|
||||||
|
- name: Get yarn cache directory path
|
||||||
|
id: yarn-cache-dir-path
|
||||||
|
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Install Dependency
|
||||||
|
env:
|
||||||
|
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
NODE_OPTIONS: '--max_old_space_size=4096'
|
||||||
|
run: bun install --frozen-lockfile
|
||||||
|
|
||||||
|
- name: Run lint
|
||||||
|
env:
|
||||||
|
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
NODE_OPTIONS: '--max_old_space_size=4096'
|
||||||
|
run: bun lint
|
22
.github/workflows/publish.yml
vendored
Normal file
22
.github/workflows/publish.yml
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
name: Publish Package to npmjs
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [published]
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
id-token: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: oven-sh/setup-bun@v2
|
||||||
|
# Setup .npmrc file to publish to npm
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '20.x'
|
||||||
|
registry-url: 'https://registry.npmjs.org'
|
||||||
|
- run: bun install --frozen-lockfile
|
||||||
|
- run: npm publish --access public
|
||||||
|
env:
|
||||||
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
15
.swcrc
Normal file
15
.swcrc
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"jsc": {
|
||||||
|
"loose": true,
|
||||||
|
"target": "es2018",
|
||||||
|
"parser": {
|
||||||
|
"syntax": "typescript",
|
||||||
|
"tsx": false,
|
||||||
|
"decorators": false,
|
||||||
|
"dynamicImport": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"module": {
|
||||||
|
"type": "commonjs"
|
||||||
|
}
|
||||||
|
}
|
29
cli.json
29
cli.json
@@ -3,11 +3,9 @@
|
|||||||
"defaultCommand": "help",
|
"defaultCommand": "help",
|
||||||
"commands": {
|
"commands": {
|
||||||
"help": {},
|
"help": {},
|
||||||
|
|
||||||
"login": {},
|
"login": {},
|
||||||
"logout": {},
|
"logout": {},
|
||||||
"me": {},
|
"me": {},
|
||||||
|
|
||||||
"createApp": {
|
"createApp": {
|
||||||
"options": {
|
"options": {
|
||||||
"name": {
|
"name": {
|
||||||
@@ -33,7 +31,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"uploadIpa": {},
|
"uploadIpa": {},
|
||||||
"uploadApk": {},
|
"uploadApk": {},
|
||||||
"parseIpa": {},
|
"parseIpa": {},
|
||||||
@@ -45,7 +42,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"publish": {
|
"publish": {
|
||||||
"options": {
|
"options": {
|
||||||
"platform": {
|
"platform": {
|
||||||
@@ -69,7 +65,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"update": {
|
"update": {
|
||||||
"options": {
|
"options": {
|
||||||
"platform": {
|
"platform": {
|
||||||
@@ -81,7 +76,6 @@
|
|||||||
"packageId": {
|
"packageId": {
|
||||||
"hasValue": true
|
"hasValue": true
|
||||||
},
|
},
|
||||||
|
|
||||||
"packageVersion": {
|
"packageVersion": {
|
||||||
"hasValue": true
|
"hasValue": true
|
||||||
},
|
},
|
||||||
@@ -90,10 +84,12 @@
|
|||||||
},
|
},
|
||||||
"maxPackageVersion": {
|
"maxPackageVersion": {
|
||||||
"hasValue": true
|
"hasValue": true
|
||||||
|
},
|
||||||
|
"rollout": {
|
||||||
|
"hasValue": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"updateVersionInfo": {
|
"updateVersionInfo": {
|
||||||
"options": {
|
"options": {
|
||||||
"platform": {
|
"platform": {
|
||||||
@@ -116,7 +112,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"build": {
|
"build": {
|
||||||
"description": "Bundle javascript and copy assets."
|
"description": "Bundle javascript and copy assets."
|
||||||
},
|
},
|
||||||
@@ -199,6 +194,24 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"hdiffFromPPK": {
|
||||||
|
"description": "Create hdiff patch from a Prepare package(.ppk)",
|
||||||
|
"options": {
|
||||||
|
"output": {
|
||||||
|
"default": ".pushy/output/hdiff-${time}.ppk-patch",
|
||||||
|
"hasValue": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"hdiffFromApp": {
|
||||||
|
"description": "Create hdiff patch from a Harmony package(.app)",
|
||||||
|
"options": {
|
||||||
|
"output": {
|
||||||
|
"default": ".pushy/output/hdiff-${time}.app-patch",
|
||||||
|
"hasValue": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"hdiffFromIpa": {
|
"hdiffFromIpa": {
|
||||||
"description": "Create hdiff patch from a iOS package(.ipa)",
|
"description": "Create hdiff patch from a iOS package(.ipa)",
|
||||||
"options": {
|
"options": {
|
||||||
|
3
index.js
3
index.js
@@ -1,4 +1 @@
|
|||||||
/**
|
|
||||||
* Created by tdzl2003 on 2/22/16.
|
|
||||||
*/
|
|
||||||
module.exports = require('./lib');
|
module.exports = require('./lib');
|
41
package.json
41
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-native-update-cli",
|
"name": "react-native-update-cli",
|
||||||
"version": "1.30.0",
|
"version": "1.36.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": {
|
||||||
@@ -12,7 +12,8 @@
|
|||||||
"cli.json"
|
"cli.json"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepublish": "babel src --out-dir lib && chmod +x lib/index.js"
|
"build": "swc src -d lib --strip-leading-paths",
|
||||||
|
"prepare": "npm run build && chmod +x lib/index.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -31,36 +32,40 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/reactnativecn/react-native-pushy/tree/master/react-native-pushy-cli",
|
"homepage": "https://github.com/reactnativecn/react-native-pushy/tree/master/react-native-pushy-cli",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bplist-parser": "^0.2.0",
|
"@badisi/latest-version": "^7.0.10",
|
||||||
|
"bplist-parser": "^0.3.2",
|
||||||
"bytebuffer": "^5.0.1",
|
"bytebuffer": "^5.0.1",
|
||||||
"cgbi-to-png": "^1.0.7",
|
"cgbi-to-png": "^1.0.7",
|
||||||
|
"chalk": "4",
|
||||||
"cli-arguments": "^0.2.1",
|
"cli-arguments": "^0.2.1",
|
||||||
"commander": "^7.2.0",
|
"commander": "^12.1.0",
|
||||||
"compare-versions": "^6.1.1",
|
"compare-versions": "^6.1.1",
|
||||||
"filesize-parser": "^1.5.0",
|
"filesize-parser": "^1.5.1",
|
||||||
|
"form-data": "^4.0.1",
|
||||||
"fs-extra": "8",
|
"fs-extra": "8",
|
||||||
"gradle-to-js": "^2.0.1",
|
"gradle-to-js": "^2.0.1",
|
||||||
"isomorphic-unzip": "^1.1.5",
|
"isomorphic-unzip": "^1.1.5",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
"plist": "^3.0.1",
|
"plist": "^3.1.0",
|
||||||
"progress": "^2.0.3",
|
"progress": "^2.0.3",
|
||||||
"properties": "^1.2.1",
|
"properties": "^1.2.1",
|
||||||
"read": "^1.0.7",
|
"read": "^4.0.0",
|
||||||
"request": "^2.88.2",
|
"semver": "^7.6.3",
|
||||||
"tcp-ping": "^0.1.1",
|
"tcp-ping": "^0.1.1",
|
||||||
"tty-table": "4.2",
|
"tty-table": "4.2",
|
||||||
"update-notifier": "^5.1.0",
|
"update-notifier": "^5.1.0",
|
||||||
"yauzl": "^2.10.0",
|
"yauzl": "^3.2.0",
|
||||||
"yazl": "2.5.1"
|
"yazl": "3.3.1"
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"babel-cli": "^6.26.0",
|
|
||||||
"babel-plugin-syntax-object-rest-spread": "^6.13.0",
|
|
||||||
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
|
|
||||||
"babel-plugin-transform-es2015-spread": "^6.22.0",
|
|
||||||
"babel-plugin-transform-object-rest-spread": "^6.26.0"
|
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 10"
|
"node": ">= 10"
|
||||||
}
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@swc/cli": "^0.5.1",
|
||||||
|
"@swc/core": "^1.9.3",
|
||||||
|
"@types/node": "^22.9.3",
|
||||||
|
"oxlint": "^0.13.1",
|
||||||
|
"typescript": "^5.7.2"
|
||||||
|
},
|
||||||
|
"packageManager": "yarn@1.22.22"
|
||||||
}
|
}
|
||||||
|
3570
pnpm-lock.yaml
generated
3570
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,20 +1,22 @@
|
|||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
const defaultEndpoint = 'https://update.reactnative.cn/api';
|
import fs from 'node:fs';
|
||||||
let host = process.env.PUSHY_REGISTRY || defaultEndpoint;
|
import util from 'node:util';
|
||||||
import fs from 'fs';
|
import path from 'node:path';
|
||||||
import request from 'request';
|
|
||||||
import ProgressBar from 'progress';
|
import ProgressBar from 'progress';
|
||||||
import packageJson from '../package.json';
|
import packageJson from '../package.json';
|
||||||
import tcpp from 'tcp-ping';
|
import tcpp from 'tcp-ping';
|
||||||
import util from 'util';
|
|
||||||
import path from 'path';
|
|
||||||
import filesizeParser from 'filesize-parser';
|
import filesizeParser from 'filesize-parser';
|
||||||
import { pricingPageUrl } from './utils';
|
import { pricingPageUrl } from './utils';
|
||||||
|
import { Session } from 'types';
|
||||||
|
import FormData from 'form-data';
|
||||||
|
|
||||||
const tcpPing = util.promisify(tcpp.ping);
|
const tcpPing = util.promisify(tcpp.ping);
|
||||||
|
|
||||||
let session = undefined;
|
let session: Session | undefined;
|
||||||
let savedSession = undefined;
|
let savedSession: Session | undefined;
|
||||||
|
|
||||||
|
const defaultEndpoint = 'https://update.reactnative.cn/api';
|
||||||
|
let host = process.env.PUSHY_REGISTRY || defaultEndpoint;
|
||||||
|
|
||||||
const userAgent = `react-native-update-cli/${packageJson.version}`;
|
const userAgent = `react-native-update-cli/${packageJson.version}`;
|
||||||
|
|
||||||
@@ -22,7 +24,7 @@ export const getSession = function () {
|
|||||||
return session;
|
return session;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const replaceSession = function (newSession) {
|
export const replaceSession = function (newSession: { token: string }) {
|
||||||
session = newSession;
|
session = newSession;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -59,26 +61,28 @@ export const closeSession = function () {
|
|||||||
host = process.env.PUSHY_REGISTRY || defaultEndpoint;
|
host = process.env.PUSHY_REGISTRY || defaultEndpoint;
|
||||||
};
|
};
|
||||||
|
|
||||||
async function query(url, options) {
|
async function query(url: string, options: fetch.RequestInit) {
|
||||||
const resp = await fetch(url, options);
|
const resp = await fetch(url, options);
|
||||||
const text = await resp.text();
|
const text = await resp.text();
|
||||||
let json;
|
let json;
|
||||||
try {
|
try {
|
||||||
json = JSON.parse(text);
|
json = JSON.parse(text);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(`Server error: ${text}`);
|
if (resp.statusText.includes('Unauthorized')) {
|
||||||
|
throw new Error('登录信息已过期,请使用 pushy login 命令重新登录');
|
||||||
|
} else {
|
||||||
|
throw new Error(`Server error: ${resp.statusText}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resp.status !== 200) {
|
if (resp.status !== 200) {
|
||||||
throw Object.assign(new Error(json.message || json.error), {
|
throw new Error(`${resp.status}: ${resp.statusText}`);
|
||||||
status: resp.status,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
function queryWithoutBody(method) {
|
function queryWithoutBody(method: string) {
|
||||||
return function (api) {
|
return function (api: string) {
|
||||||
return query(host + api, {
|
return query(host + api, {
|
||||||
method,
|
method,
|
||||||
headers: {
|
headers: {
|
||||||
@@ -89,8 +93,8 @@ function queryWithoutBody(method) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function queryWithBody(method) {
|
function queryWithBody(method: string) {
|
||||||
return function (api, body) {
|
return function (api: string, body: Record<string, any>) {
|
||||||
return query(host + api, {
|
return query(host + api, {
|
||||||
method,
|
method,
|
||||||
headers: {
|
headers: {
|
||||||
@@ -108,12 +112,11 @@ export const post = queryWithBody('POST');
|
|||||||
export const put = queryWithBody('PUT');
|
export const put = queryWithBody('PUT');
|
||||||
export const doDelete = queryWithBody('DELETE');
|
export const doDelete = queryWithBody('DELETE');
|
||||||
|
|
||||||
export async function uploadFile(fn, key) {
|
export async function uploadFile(fn: string, key?: string) {
|
||||||
const { url, backupUrl, formData, maxSize } = await post('/upload', {
|
const { url, backupUrl, formData, maxSize } = await post('/upload', {
|
||||||
ext: path.extname(fn),
|
ext: path.extname(fn),
|
||||||
});
|
});
|
||||||
let realUrl = url;
|
let realUrl = url;
|
||||||
|
|
||||||
if (backupUrl) {
|
if (backupUrl) {
|
||||||
if (global.USE_ACC_OSS) {
|
if (global.USE_ACC_OSS) {
|
||||||
realUrl = backupUrl;
|
realUrl = backupUrl;
|
||||||
@@ -134,9 +137,9 @@ export async function uploadFile(fn, key) {
|
|||||||
const fileSize = fs.statSync(fn).size;
|
const fileSize = fs.statSync(fn).size;
|
||||||
if (maxSize && fileSize > filesizeParser(maxSize)) {
|
if (maxSize && fileSize > filesizeParser(maxSize)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`此文件大小${(fileSize / 1048576).toFixed(
|
`此文件大小 ${(fileSize / 1048576).toFixed(
|
||||||
1,
|
1,
|
||||||
)}m, 超出当前额度${maxSize}。您可以考虑升级付费业务以提升此额度。详情请访问: ${pricingPageUrl}`,
|
)}m , 超出当前额度 ${maxSize} 。您可以考虑升级付费业务以提升此额度。详情请访问: ${pricingPageUrl}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,32 +149,30 @@ export async function uploadFile(fn, key) {
|
|||||||
total: fileSize,
|
total: fileSize,
|
||||||
});
|
});
|
||||||
|
|
||||||
const info = await new Promise((resolve, reject) => {
|
const form = new FormData();
|
||||||
if (key) {
|
|
||||||
formData.key = key;
|
|
||||||
}
|
|
||||||
formData.file = fs.createReadStream(fn);
|
|
||||||
|
|
||||||
formData.file.on('data', function (data) {
|
Object.entries(formData).forEach(([k, v]) => {
|
||||||
|
form.append(k, v);
|
||||||
|
});
|
||||||
|
const fileStream = fs.createReadStream(fn);
|
||||||
|
fileStream.on('data', function (data) {
|
||||||
bar.tick(data.length);
|
bar.tick(data.length);
|
||||||
});
|
});
|
||||||
request.post(
|
|
||||||
realUrl,
|
if (key) {
|
||||||
{
|
form.append('key', key);
|
||||||
formData,
|
|
||||||
},
|
|
||||||
(err, resp, body) => {
|
|
||||||
if (err) {
|
|
||||||
return reject(err);
|
|
||||||
}
|
}
|
||||||
if (resp.statusCode > 299) {
|
form.append('file', fileStream);
|
||||||
return reject(
|
|
||||||
Object.assign(new Error(body), { status: resp.statusCode }),
|
const res = await fetch(realUrl, {
|
||||||
);
|
method: 'POST',
|
||||||
}
|
body: form,
|
||||||
resolve({ hash: formData.key });
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
return info;
|
|
||||||
|
if (res.status > 299) {
|
||||||
|
throw new Error(`${res.status}: ${res.statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// const body = await response.json();
|
||||||
|
return { hash: key || formData.key };
|
||||||
}
|
}
|
189
src/bundle.js
189
src/bundle.js
@@ -1,14 +1,15 @@
|
|||||||
import path from 'path';
|
import path from 'node:path';
|
||||||
import { getRNVersion, translateOptions } from './utils';
|
import { getRNVersion, translateOptions } from './utils';
|
||||||
import * as fs from 'fs-extra';
|
import * as fs from 'fs-extra';
|
||||||
import { ZipFile } from 'yazl';
|
import { ZipFile } from 'yazl';
|
||||||
import { open as openZipFile } from 'yauzl';
|
import { open as openZipFile } from 'yauzl';
|
||||||
import { question, printVersionCommand } from './utils';
|
import { question, printVersionCommand } from './utils';
|
||||||
import { checkPlatform } from './app';
|
import { checkPlatform } from './app';
|
||||||
import { spawn, spawnSync } from 'child_process';
|
import { spawn, spawnSync } from 'node:child_process';
|
||||||
const g2js = require('gradle-to-js/lib/parser');
|
const g2js = require('gradle-to-js/lib/parser');
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
const properties = require('properties');
|
const properties = require('properties');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
let bsdiff, hdiff, diff;
|
let bsdiff, hdiff, diff;
|
||||||
try {
|
try {
|
||||||
@@ -33,7 +34,7 @@ async function runReactNativeBundleCommand(
|
|||||||
gradleConfig = await checkGradleConfig();
|
gradleConfig = await checkGradleConfig();
|
||||||
if (gradleConfig.crunchPngs !== false) {
|
if (gradleConfig.crunchPngs !== false) {
|
||||||
console.warn(
|
console.warn(
|
||||||
'android的crunchPngs选项似乎尚未禁用(如已禁用则请忽略此提示),这可能导致热更包体积异常增大,具体请参考 https://pushy.reactnative.cn/docs/getting-started.html#%E7%A6%81%E7%94%A8-android-%E7%9A%84-crunch-%E4%BC%98%E5%8C%96 \n',
|
'android 的 crunchPngs 选项似乎尚未禁用(如已禁用则请忽略此提示),这可能导致热更包体积异常增大,具体请参考 https://pushy.reactnative.cn/docs/getting-started.html#%E7%A6%81%E7%94%A8-android-%E7%9A%84-crunch-%E4%BC%98%E5%8C%96 \n',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,24 +52,47 @@ async function runReactNativeBundleCommand(
|
|||||||
|
|
||||||
fs.emptyDirSync(outputFolder);
|
fs.emptyDirSync(outputFolder);
|
||||||
|
|
||||||
let cliPath = require.resolve('react-native/local-cli/cli.js', {
|
let cliPath;
|
||||||
paths: [process.cwd()],
|
|
||||||
});
|
|
||||||
let usingExpo = false;
|
let usingExpo = false;
|
||||||
try {
|
try {
|
||||||
require.resolve('expo-router', {
|
|
||||||
paths: [process.cwd()],
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(`expo-router detected, will use @expo/cli to bundle.\n`);
|
|
||||||
// if using expo-router, use expo-cli
|
|
||||||
cliPath = require.resolve('@expo/cli', {
|
cliPath = require.resolve('@expo/cli', {
|
||||||
paths: [process.cwd()],
|
paths: [process.cwd()],
|
||||||
});
|
});
|
||||||
usingExpo = true;
|
usingExpo = true;
|
||||||
} catch (e) {}
|
} catch (e) {
|
||||||
const bundleCommand = usingExpo ? 'export:embed' : 'bundle';
|
try {
|
||||||
|
// rn >= 0.75
|
||||||
|
cliPath = require.resolve('@react-native-community/cli/build/bin.js', {
|
||||||
|
paths: [process.cwd()],
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
// rn < 0.75
|
||||||
|
cliPath = require.resolve('react-native/local-cli/cli.js', {
|
||||||
|
paths: [process.cwd()],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const bundleCommand = usingExpo ? 'export:embed' : platform === 'harmony' ? 'bundle-harmony' : 'bundle';
|
||||||
|
if (platform == 'harmony') {
|
||||||
|
Array.prototype.push.apply(reactNativeBundleArgs, [
|
||||||
|
cliPath,
|
||||||
|
bundleCommand,
|
||||||
|
'--dev',
|
||||||
|
development,
|
||||||
|
'--entry-file',
|
||||||
|
entryFile,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (sourcemapOutput) {
|
||||||
|
reactNativeBundleArgs.push('--sourcemap-output', sourcemapOutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config) {
|
||||||
|
reactNativeBundleArgs.push('--config', config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
Array.prototype.push.apply(reactNativeBundleArgs, [
|
Array.prototype.push.apply(reactNativeBundleArgs, [
|
||||||
cliPath,
|
cliPath,
|
||||||
bundleCommand,
|
bundleCommand,
|
||||||
@@ -92,6 +116,7 @@ async function runReactNativeBundleCommand(
|
|||||||
if (config) {
|
if (config) {
|
||||||
reactNativeBundleArgs.push('--config', config);
|
reactNativeBundleArgs.push('--config', config);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const reactNativeBundleProcess = spawn('node', reactNativeBundleArgs);
|
const reactNativeBundleProcess = spawn('node', reactNativeBundleArgs);
|
||||||
console.log(
|
console.log(
|
||||||
@@ -141,6 +166,8 @@ async function runReactNativeBundleCommand(
|
|||||||
fs.existsSync('ios/Pods/hermes-engine')
|
fs.existsSync('ios/Pods/hermes-engine')
|
||||||
) {
|
) {
|
||||||
hermesEnabled = true;
|
hermesEnabled = true;
|
||||||
|
}else if (platform === 'harmony') {
|
||||||
|
await copyHarmonyBundle(outputFolder);
|
||||||
}
|
}
|
||||||
if (hermesEnabled) {
|
if (hermesEnabled) {
|
||||||
await compileHermesByteCode(
|
await compileHermesByteCode(
|
||||||
@@ -155,6 +182,21 @@ async function runReactNativeBundleCommand(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function copyHarmonyBundle(outputFolder) {
|
||||||
|
const harmonyRawPath = 'harmony/entry/src/main/resources/rawfile';
|
||||||
|
|
||||||
|
try {
|
||||||
|
await fs.ensureDir(outputFolder);
|
||||||
|
await fs.copy(harmonyRawPath, outputFolder);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`Successfully copied from ${harmonyRawPath} to ${outputFolder}`,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error in copyHarmonyBundle:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getHermesOSBin() {
|
function getHermesOSBin() {
|
||||||
if (os.platform() === 'win32') return 'win64-bin';
|
if (os.platform() === 'win32') return 'win64-bin';
|
||||||
if (os.platform() === 'darwin') return 'osx-bin';
|
if (os.platform() === 'darwin') return 'osx-bin';
|
||||||
@@ -166,7 +208,9 @@ async function checkGradleConfig() {
|
|||||||
let crunchPngs;
|
let crunchPngs;
|
||||||
try {
|
try {
|
||||||
const gradleConfig = await g2js.parseFile('android/app/build.gradle');
|
const gradleConfig = await g2js.parseFile('android/app/build.gradle');
|
||||||
|
crunchPngs = gradleConfig.android.buildTypes.release.crunchPngs;
|
||||||
const projectConfig = gradleConfig['project.ext.react'];
|
const projectConfig = gradleConfig['project.ext.react'];
|
||||||
|
if (projectConfig) {
|
||||||
for (const packagerConfig of projectConfig) {
|
for (const packagerConfig of projectConfig) {
|
||||||
if (
|
if (
|
||||||
packagerConfig.includes('enableHermes') &&
|
packagerConfig.includes('enableHermes') &&
|
||||||
@@ -176,7 +220,7 @@ async function checkGradleConfig() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
crunchPngs = gradleConfig.android.buildTypes.release.crunchPngs;
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
return {
|
return {
|
||||||
enableHermes,
|
enableHermes,
|
||||||
@@ -213,6 +257,10 @@ async function compileHermesByteCode(
|
|||||||
'-O',
|
'-O',
|
||||||
];
|
];
|
||||||
if (sourcemapOutput) {
|
if (sourcemapOutput) {
|
||||||
|
fs.copyFileSync(
|
||||||
|
sourcemapOutput,
|
||||||
|
path.join(outputFolder, bundleName + '.txt.map'),
|
||||||
|
);
|
||||||
args.push('-output-source-map');
|
args.push('-output-source-map');
|
||||||
}
|
}
|
||||||
console.log(
|
console.log(
|
||||||
@@ -221,6 +269,28 @@ async function compileHermesByteCode(
|
|||||||
spawnSync(hermesCommand, args, {
|
spawnSync(hermesCommand, args, {
|
||||||
stdio: 'ignore',
|
stdio: 'ignore',
|
||||||
});
|
});
|
||||||
|
if (sourcemapOutput) {
|
||||||
|
const composerPath =
|
||||||
|
'node_modules/react-native/scripts/compose-source-maps.js';
|
||||||
|
if (!fs.existsSync(composerPath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(`Composing source map`);
|
||||||
|
spawnSync(
|
||||||
|
'node',
|
||||||
|
[
|
||||||
|
composerPath,
|
||||||
|
path.join(outputFolder, bundleName + '.txt.map'),
|
||||||
|
path.join(outputFolder, bundleName + '.map'),
|
||||||
|
'-o',
|
||||||
|
sourcemapOutput,
|
||||||
|
],
|
||||||
|
{
|
||||||
|
stdio: 'ignore',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
fs.removeSync(path.join(outputFolder, bundleName + '.txt.map'));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function pack(dir, output) {
|
async function pack(dir, output) {
|
||||||
@@ -302,7 +372,7 @@ async function diffFromPPK(origin, next, output) {
|
|||||||
// isFile
|
// isFile
|
||||||
originMap[entry.crc32] = entry.fileName;
|
originMap[entry.crc32] = entry.fileName;
|
||||||
|
|
||||||
if (entry.fileName === 'index.bundlejs') {
|
if (entry.fileName === 'index.bundlejs' || entry.fileName === 'bundle.harmony.js') {
|
||||||
// This is source.
|
// This is source.
|
||||||
return readEntire(entry, zipFile).then((v) => (originSource = v));
|
return readEntire(entry, zipFile).then((v) => (originSource = v));
|
||||||
}
|
}
|
||||||
@@ -364,6 +434,16 @@ async function diffFromPPK(origin, next, output) {
|
|||||||
);
|
);
|
||||||
//console.log('End diff');
|
//console.log('End diff');
|
||||||
});
|
});
|
||||||
|
}else if (entry.fileName === 'bundle.harmony.js') {
|
||||||
|
//console.log('Found bundle');
|
||||||
|
return readEntire(entry, nextZipfile).then((newSource) => {
|
||||||
|
//console.log('Begin diff');
|
||||||
|
zipfile.addBuffer(
|
||||||
|
diff(originSource, newSource),
|
||||||
|
'bundle.harmony.js.patch',
|
||||||
|
);
|
||||||
|
//console.log('End diff');
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// If same file.
|
// If same file.
|
||||||
const originEntry = originEntries[entry.fileName];
|
const originEntry = originEntries[entry.fileName];
|
||||||
@@ -486,7 +566,17 @@ async function diffFromPackage(
|
|||||||
);
|
);
|
||||||
//console.log('End diff');
|
//console.log('End diff');
|
||||||
});
|
});
|
||||||
} else {
|
} else if (entry.fileName === 'bundle.harmony.js') {
|
||||||
|
//console.log('Found bundle');
|
||||||
|
return readEntire(entry, nextZipfile).then((newSource) => {
|
||||||
|
//console.log('Begin diff');
|
||||||
|
zipfile.addBuffer(
|
||||||
|
diff(originSource, newSource),
|
||||||
|
'bundle.harmony.js.patch',
|
||||||
|
);
|
||||||
|
//console.log('End diff');
|
||||||
|
});
|
||||||
|
}else {
|
||||||
// If same file.
|
// If same file.
|
||||||
if (originEntries[entry.fileName] === entry.crc32) {
|
if (originEntries[entry.fileName] === entry.crc32) {
|
||||||
copies[entry.fileName] = '';
|
copies[entry.fileName] = '';
|
||||||
@@ -518,22 +608,53 @@ async function diffFromPackage(
|
|||||||
await writePromise;
|
await writePromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
function enumZipEntries(zipFn, callback) {
|
async function enumZipEntries(zipFn, callback, nestedPath = '') {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
openZipFile(zipFn, { lazyEntries: true }, (err, zipfile) => {
|
openZipFile(zipFn, { lazyEntries: true }, async (err, zipfile) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
zipfile.on('end', resolve);
|
zipfile.on('end', resolve);
|
||||||
zipfile.on('error', reject);
|
zipfile.on('error', reject);
|
||||||
zipfile.on('entry', (entry) => {
|
zipfile.on('entry', async (entry) => {
|
||||||
const result = callback(entry, zipfile);
|
const fullPath = nestedPath + entry.fileName;
|
||||||
if (result && typeof result.then === 'function') {
|
|
||||||
result.then(() => zipfile.readEntry());
|
try {
|
||||||
} else {
|
if (
|
||||||
zipfile.readEntry();
|
!entry.fileName.endsWith('/') &&
|
||||||
}
|
entry.fileName.toLowerCase().endsWith('.hap')
|
||||||
|
) {
|
||||||
|
const tempDir = path.join(os.tmpdir(), 'nested_zip_' + Date.now());
|
||||||
|
await fs.ensureDir(tempDir);
|
||||||
|
const tempZipPath = path.join(tempDir, 'temp.zip');
|
||||||
|
|
||||||
|
await new Promise((res, rej) => {
|
||||||
|
zipfile.openReadStream(entry, async (err, readStream) => {
|
||||||
|
if (err) return rej(err);
|
||||||
|
const writeStream = fs.createWriteStream(tempZipPath);
|
||||||
|
readStream.pipe(writeStream);
|
||||||
|
writeStream.on('finish', res);
|
||||||
|
writeStream.on('error', rej);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await enumZipEntries(tempZipPath, callback, fullPath + '/');
|
||||||
|
|
||||||
|
await fs.remove(tempDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = callback(entry, zipfile, fullPath);
|
||||||
|
if (result && typeof result.then === 'function') {
|
||||||
|
await result;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('处理文件时出错:', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
zipfile.readEntry();
|
||||||
|
});
|
||||||
|
|
||||||
zipfile.readEntry();
|
zipfile.readEntry();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -598,7 +719,6 @@ export const commands = {
|
|||||||
const { version, major, minor } = getRNVersion();
|
const { version, major, minor } = getRNVersion();
|
||||||
|
|
||||||
console.log('Bundling with react-native: ', version);
|
console.log('Bundling with react-native: ', version);
|
||||||
printVersionCommand();
|
|
||||||
|
|
||||||
await runReactNativeBundleCommand(
|
await runReactNativeBundleCommand(
|
||||||
bundleName,
|
bundleName,
|
||||||
@@ -668,6 +788,21 @@ export const commands = {
|
|||||||
console.log(`${realOutput} generated.`);
|
console.log(`${realOutput} generated.`);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async hdiffFromApp({ args, options }) {
|
||||||
|
const { origin, next, realOutput } = diffArgsCheck(
|
||||||
|
args,
|
||||||
|
options,
|
||||||
|
'hdiffFromApp',
|
||||||
|
);
|
||||||
|
await diffFromPackage(
|
||||||
|
origin,
|
||||||
|
next,
|
||||||
|
realOutput,
|
||||||
|
'resources/rawfile/bundle.harmony.js',
|
||||||
|
);
|
||||||
|
console.log(`${realOutput} generated.`);
|
||||||
|
},
|
||||||
|
|
||||||
async diffFromIpa({ args, options }) {
|
async diffFromIpa({ args, options }) {
|
||||||
const { origin, next, realOutput } = diffArgsCheck(
|
const { origin, next, realOutput } = diffArgsCheck(
|
||||||
args,
|
args,
|
||||||
|
@@ -5,9 +5,13 @@ import updateNotifier from 'update-notifier';
|
|||||||
import { printVersionCommand } from './utils/index.js';
|
import { printVersionCommand } from './utils/index.js';
|
||||||
import pkg from '../package.json';
|
import pkg from '../package.json';
|
||||||
|
|
||||||
updateNotifier({ pkg }).notify({ isGlobal: true });
|
updateNotifier({ pkg }).notify({
|
||||||
|
isGlobal: true,
|
||||||
|
message:
|
||||||
|
'建议运行 `{updateCommand}` 来更新命令行工具以获得功能、性能和安全性的持续改进',
|
||||||
|
});
|
||||||
|
|
||||||
function printUsage({ args }) {
|
function printUsage() {
|
||||||
// const commandName = args[0];
|
// const commandName = args[0];
|
||||||
// TODO: print usage of commandName, or print global usage.
|
// TODO: print usage of commandName, or print global usage.
|
||||||
|
|
||||||
@@ -27,8 +31,8 @@ const commands = {
|
|||||||
help: printUsage,
|
help: printUsage,
|
||||||
};
|
};
|
||||||
|
|
||||||
function run() {
|
async function run() {
|
||||||
printVersionCommand();
|
await printVersionCommand();
|
||||||
if (process.argv.indexOf('-v') >= 0 || process.argv[2] === 'version') {
|
if (process.argv.indexOf('-v') >= 0 || process.argv[2] === 'version') {
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
8
src/types.ts
Normal file
8
src/types.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
declare global {
|
||||||
|
var NO_INTERACTIVE: boolean;
|
||||||
|
var USE_ACC_OSS: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Session {
|
||||||
|
token: string;
|
||||||
|
}
|
@@ -1,26 +1,23 @@
|
|||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import os from 'os';
|
import os from 'node:os';
|
||||||
import path from 'path';
|
import path from 'node:path';
|
||||||
import pkg from '../../package.json';
|
import pkg from '../../package.json';
|
||||||
import AppInfoParser from './app-info-parser';
|
import AppInfoParser from './app-info-parser';
|
||||||
import semverLt from 'semver/functions/lt';
|
import semverSatisfies from 'semver/functions/satisfies';
|
||||||
|
import chalk from 'chalk';
|
||||||
|
import latestVersion from '@badisi/latest-version';
|
||||||
|
|
||||||
import read from 'read';
|
import { read } from 'read';
|
||||||
|
|
||||||
export function question(query, password) {
|
export async function question(query, password) {
|
||||||
if (NO_INTERACTIVE) {
|
if (NO_INTERACTIVE) {
|
||||||
return Promise.resolve('');
|
return '';
|
||||||
}
|
}
|
||||||
return new Promise((resolve, reject) =>
|
return read({
|
||||||
read(
|
|
||||||
{
|
|
||||||
prompt: query,
|
prompt: query,
|
||||||
silent: password,
|
silent: password,
|
||||||
replace: password ? '*' : undefined,
|
replace: password ? '*' : undefined,
|
||||||
},
|
});
|
||||||
(err, result) => (err ? reject(err) : resolve(result)),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function translateOptions(options) {
|
export function translateOptions(options) {
|
||||||
@@ -136,8 +133,23 @@ export function saveToLocal(originPath, destName) {
|
|||||||
// fs.copyFileSync(originPath, destPath);
|
// fs.copyFileSync(originPath, destPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function printVersionCommand() {
|
async function getLatestVersion(pkgName) {
|
||||||
console.log('react-native-update-cli: ' + pkg.version);
|
return Promise.race([
|
||||||
|
latestVersion(pkgName)
|
||||||
|
.then((p) => p.latest)
|
||||||
|
.catch(() => ''),
|
||||||
|
new Promise((resolve) => setTimeout(() => resolve(''), 2000)),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function printVersionCommand() {
|
||||||
|
let latestPushyCliVersion = await getLatestVersion('react-native-update-cli');
|
||||||
|
latestPushyCliVersion = latestPushyCliVersion
|
||||||
|
? ` (最新:${chalk.green(latestPushyCliVersion)})`
|
||||||
|
: '';
|
||||||
|
console.log(
|
||||||
|
`react-native-update-cli: ${pkg.version}${latestPushyCliVersion}`,
|
||||||
|
);
|
||||||
let pushyVersion = '';
|
let pushyVersion = '';
|
||||||
try {
|
try {
|
||||||
const PACKAGE_JSON_PATH = require.resolve(
|
const PACKAGE_JSON_PATH = require.resolve(
|
||||||
@@ -147,19 +159,28 @@ export function printVersionCommand() {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
pushyVersion = require(PACKAGE_JSON_PATH).version;
|
pushyVersion = require(PACKAGE_JSON_PATH).version;
|
||||||
console.log('react-native-update: ' + pushyVersion);
|
let latestPushyVersion = await getLatestVersion('react-native-update');
|
||||||
|
latestPushyVersion = latestPushyVersion
|
||||||
|
? ` (最新:${chalk.green(latestPushyVersion)})`
|
||||||
|
: '';
|
||||||
|
console.log(`react-native-update: ${pushyVersion}${latestPushyVersion}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('react-native-update: 无法获取版本号,请在项目目录中运行命令');
|
console.log('react-native-update: 无法获取版本号,请在项目目录中运行命令');
|
||||||
}
|
}
|
||||||
if (pushyVersion) {
|
if (pushyVersion) {
|
||||||
if (semverLt(pushyVersion, '8.5.1')) {
|
if (semverSatisfies(pushyVersion, '<8.5.2')) {
|
||||||
console.warn(
|
console.warn(
|
||||||
'当前版本已不再支持,请至少升级到 v8 的最新小版本后重新打包(代码无需改动): npm i react-native-update@8',
|
`当前版本已不再支持,请至少升级到 v8 的最新小版本后重新打包(代码无需改动): npm i react-native-update@8 .
|
||||||
|
如有使用安装 apk 的功能,请注意添加所需权限 https://pushy.reactnative.cn/docs/api#async-function-downloadandinstallapkurl`,
|
||||||
);
|
);
|
||||||
}
|
} else if (semverSatisfies(pushyVersion, '9.0.0 - 9.2.1')) {
|
||||||
if (semverLt(pushyVersion, '9.2.1')) {
|
|
||||||
console.warn(
|
console.warn(
|
||||||
'当前版本已不再支持,请至少升级到 v9 的最新小版本后重新打包(代码无需改动): npm i react-native-update@9',
|
`当前版本已不再支持,请至少升级到 v9 的最新小版本后重新打包(代码无需改动,可直接热更): npm i react-native-update@9 .
|
||||||
|
如有使用安装 apk 的功能,请注意添加所需权限 https://pushy.reactnative.cn/docs/api#async-function-downloadandinstallapkurl`,
|
||||||
|
);
|
||||||
|
} else if (semverSatisfies(pushyVersion, '10.0.0 - 10.17.0')) {
|
||||||
|
console.warn(
|
||||||
|
`当前版本已不再支持,请升级到 v10 的最新小版本(代码无需改动,可直接热更): npm i react-native-update@10`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -124,20 +124,26 @@ export const commands = {
|
|||||||
options.platform || (await question('平台(ios/android):')),
|
options.platform || (await question('平台(ios/android):')),
|
||||||
);
|
);
|
||||||
const { appId } = await getSelectedApp(platform);
|
const { appId } = await getSelectedApp(platform);
|
||||||
const versionId = options.versionId || (await chooseVersion(appId)).id;
|
let versionId = options.versionId || (await chooseVersion(appId)).id;
|
||||||
|
if (versionId === 'null') {
|
||||||
|
versionId = null;
|
||||||
|
}
|
||||||
|
|
||||||
let pkgId;
|
let pkgId;
|
||||||
let pkgVersion = options.packageVersion;
|
let pkgVersion = options.packageVersion;
|
||||||
let minPkgVersion = options.minPackageVersion;
|
let minPkgVersion = options.minPackageVersion;
|
||||||
let maxPkgVersion = options.maxPackageVersion;
|
let maxPkgVersion = options.maxPackageVersion;
|
||||||
if (pkgVersion) {
|
let rollout = options.rollout;
|
||||||
pkgVersion = pkgVersion.trim();
|
if (rollout === undefined) {
|
||||||
const { data } = await get(`/app/${appId}/package/list?limit=1000`);
|
rollout = null;
|
||||||
const pkg = data.find((d) => d.name === pkgVersion);
|
|
||||||
if (pkg) {
|
|
||||||
pkgId = pkg.id;
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`未查询到匹配原生版本:${pkgVersion}`);
|
try {
|
||||||
|
rollout = parseInt(rollout);
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error('rollout 必须是 1-100 的整数');
|
||||||
|
}
|
||||||
|
if (rollout < 1 || rollout > 100) {
|
||||||
|
throw new Error('rollout 必须是 1-100 的整数');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (minPkgVersion) {
|
if (minPkgVersion) {
|
||||||
@@ -145,15 +151,29 @@ export const commands = {
|
|||||||
const { data } = await get(`/app/${appId}/package/list?limit=1000`);
|
const { data } = await get(`/app/${appId}/package/list?limit=1000`);
|
||||||
const pkgs = data.filter((d) => compare(d.name, minPkgVersion, '>='));
|
const pkgs = data.filter((d) => compare(d.name, minPkgVersion, '>='));
|
||||||
if (pkgs.length === 0) {
|
if (pkgs.length === 0) {
|
||||||
throw new Error(
|
throw new Error(`未查询到 >= ${minPkgVersion} 的原生版本`);
|
||||||
`未查询到 >= ${minPkgVersion} 的原生版本`,
|
}
|
||||||
|
if (rollout) {
|
||||||
|
const rolloutConfig = {};
|
||||||
|
for (const pkg of pkgs) {
|
||||||
|
rolloutConfig[pkg.name] = rollout;
|
||||||
|
}
|
||||||
|
await put(`/app/${appId}/version/${versionId}`, {
|
||||||
|
config: {
|
||||||
|
rollout: rolloutConfig,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
console.log(
|
||||||
|
`已在原生版本 ${pkgs
|
||||||
|
.map((p) => p.name)
|
||||||
|
.join(', ')} 上设置灰度发布 ${rollout}% 热更版本 ${versionId}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
for (const pkg of pkgs) {
|
for (const pkg of pkgs) {
|
||||||
await put(`/app/${appId}/package/${pkg.id}`, {
|
await put(`/app/${appId}/package/${pkg.id}`, {
|
||||||
versionId,
|
versionId,
|
||||||
});
|
});
|
||||||
console.log(`已将版本 ${versionId} 绑定到原生版本 ${pkg.name}`);
|
console.log(`已将热更版本 ${versionId} 绑定到原生版本 ${pkg.name} (id: ${pkg.id})`);
|
||||||
}
|
}
|
||||||
console.log(`操作完成,共已绑定 ${pkgs.length} 个原生版本`);
|
console.log(`操作完成,共已绑定 ${pkgs.length} 个原生版本`);
|
||||||
return;
|
return;
|
||||||
@@ -163,19 +183,44 @@ export const commands = {
|
|||||||
const { data } = await get(`/app/${appId}/package/list?limit=1000`);
|
const { data } = await get(`/app/${appId}/package/list?limit=1000`);
|
||||||
const pkgs = data.filter((d) => compare(d.name, maxPkgVersion, '<='));
|
const pkgs = data.filter((d) => compare(d.name, maxPkgVersion, '<='));
|
||||||
if (pkgs.length === 0) {
|
if (pkgs.length === 0) {
|
||||||
throw new Error(
|
throw new Error(`未查询到 <= ${maxPkgVersion} 的原生版本`);
|
||||||
`未查询到 <= ${maxPkgVersion} 的原生版本`,
|
}
|
||||||
|
if (rollout) {
|
||||||
|
const rolloutConfig = {};
|
||||||
|
for (const pkg of pkgs) {
|
||||||
|
rolloutConfig[pkg.name] = rollout;
|
||||||
|
}
|
||||||
|
await put(`/app/${appId}/version/${versionId}`, {
|
||||||
|
config: {
|
||||||
|
rollout: rolloutConfig,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
console.log(
|
||||||
|
`已在原生版本 ${pkgs
|
||||||
|
.map((p) => p.name)
|
||||||
|
.join(', ')} 上设置灰度发布 ${rollout}% 热更版本 ${versionId}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
for (const pkg of pkgs) {
|
for (const pkg of pkgs) {
|
||||||
await put(`/app/${appId}/package/${pkg.id}`, {
|
await put(`/app/${appId}/package/${pkg.id}`, {
|
||||||
versionId,
|
versionId,
|
||||||
});
|
});
|
||||||
console.log(`已将版本 ${versionId} 绑定到原生版本 ${pkg.name}`);
|
console.log(`已将热更版本 ${versionId} 绑定到原生版本 ${pkg.name} (id: ${pkg.id})`);
|
||||||
}
|
}
|
||||||
console.log(`操作完成,共已绑定 ${pkgs.length} 个原生版本`);
|
console.log(`操作完成,共已绑定 ${pkgs.length} 个原生版本`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { data } = await get(`/app/${appId}/package/list?limit=1000`);
|
||||||
|
if (pkgVersion) {
|
||||||
|
pkgVersion = pkgVersion.trim();
|
||||||
|
const pkg = data.find((d) => d.name === pkgVersion);
|
||||||
|
if (pkg) {
|
||||||
|
pkgId = pkg.id;
|
||||||
|
} else {
|
||||||
|
throw new Error(`未查询到匹配原生版本:${pkgVersion}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!pkgId) {
|
if (!pkgId) {
|
||||||
pkgId = options.packageId || (await choosePackage(appId)).id;
|
pkgId = options.packageId || (await choosePackage(appId)).id;
|
||||||
}
|
}
|
||||||
@@ -183,10 +228,30 @@ export const commands = {
|
|||||||
if (!pkgId) {
|
if (!pkgId) {
|
||||||
throw new Error('请提供 packageId 或 packageVersion 参数');
|
throw new Error('请提供 packageId 或 packageVersion 参数');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!pkgVersion) {
|
||||||
|
const pkg = data.find((d) => d.id === pkgId);
|
||||||
|
if (pkg) {
|
||||||
|
pkgVersion = pkg.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rollout) {
|
||||||
|
await put(`/app/${appId}/version/${versionId}`, {
|
||||||
|
config: {
|
||||||
|
rollout: {
|
||||||
|
[pkgVersion]: rollout,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
console.log(
|
||||||
|
`已将在原生版本 ${pkgVersion} (id: ${pkgId}) 上设置灰度发布 ${rollout}% 热更版本 ${versionId} `,
|
||||||
|
);
|
||||||
|
}
|
||||||
await put(`/app/${appId}/package/${pkgId}`, {
|
await put(`/app/${appId}/package/${pkgId}`, {
|
||||||
versionId,
|
versionId,
|
||||||
});
|
});
|
||||||
console.log('操作成功');
|
console.log(`已将热更版本 ${versionId} 绑定到原生版本 ${pkgVersion} (id: ${pkgId})`);
|
||||||
},
|
},
|
||||||
updateVersionInfo: async function ({ args, options }) {
|
updateVersionInfo: async function ({ args, options }) {
|
||||||
const platform = checkPlatform(
|
const platform = checkPlatform(
|
||||||
|
75
tsconfig.json
Normal file
75
tsconfig.json
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
/* Basic Options */
|
||||||
|
"target": "ESNext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
|
||||||
|
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
|
||||||
|
"lib": [
|
||||||
|
"ESNext"
|
||||||
|
] /* Specify library files to be included in the compilation. */,
|
||||||
|
"allowJs": true /* Allow javascript files to be compiled. */,
|
||||||
|
// "checkJs": true /* Report errors in .js files. */,
|
||||||
|
"jsx": "react" /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */,
|
||||||
|
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||||
|
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||||
|
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||||
|
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||||
|
// "outDir": "lib" /* Redirect output structure to the directory. */,
|
||||||
|
// "rootDir": "src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
|
||||||
|
// "composite": true, /* Enable project compilation */
|
||||||
|
// "removeComments": true, /* Do not emit comments to output. */
|
||||||
|
"noEmit": true /* Do not emit outputs. */,
|
||||||
|
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||||
|
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||||
|
"isolatedModules": true /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */,
|
||||||
|
|
||||||
|
/* Strict Type-Checking Options */
|
||||||
|
"strict": true /* Enable all strict type-checking options. */,
|
||||||
|
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
|
||||||
|
"strictNullChecks": true /* Enable strict null checks. */,
|
||||||
|
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||||
|
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||||
|
"noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */,
|
||||||
|
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||||
|
|
||||||
|
/* Additional Checks */
|
||||||
|
// "noUnusedLocals": true /* Report errors on unused locals. */,
|
||||||
|
// "noUnusedParameters": true /* Report errors on unused parameters. */,
|
||||||
|
"noImplicitReturns": false /* Report error when not all code paths in function return a value. */,
|
||||||
|
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||||
|
|
||||||
|
/* Module Resolution Options */
|
||||||
|
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||||
|
"baseUrl": "./src" /* Base directory to resolve non-absolute module names. */,
|
||||||
|
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||||
|
// "rootDirs": [
|
||||||
|
// "src",
|
||||||
|
// "db",
|
||||||
|
// "config",
|
||||||
|
// "models"
|
||||||
|
// ] /* List of root folders whose combined content represents the structure of the project at runtime. */,
|
||||||
|
"typeRoots": [
|
||||||
|
"src/types"
|
||||||
|
] /* List of folders to include type definitions from. */,
|
||||||
|
// "types": [], /* Type declaration files to be included in compilation. */
|
||||||
|
"allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
|
||||||
|
// "paths": {
|
||||||
|
// "@/*": ["src/*"]
|
||||||
|
// },
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
||||||
|
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||||
|
|
||||||
|
/* Source Map Options */
|
||||||
|
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||||
|
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||||
|
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||||
|
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||||
|
|
||||||
|
/* Experimental Options */
|
||||||
|
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||||
|
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"incremental": true
|
||||||
|
},
|
||||||
|
"exclude": ["node_modules", "lib"]
|
||||||
|
}
|
Reference in New Issue
Block a user