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

support taro

This commit is contained in:
sunnylqm
2025-02-13 16:02:04 +08:00
parent f16aff5674
commit 1d1e6cde0f
2 changed files with 197 additions and 97 deletions

View File

@@ -145,6 +145,15 @@
},
"sourcemap": {
"default": false
},
"taro": {
"default": false
},
"expo": {
"default": false
},
"rncli": {
"default": false
}
}
},

View File

@@ -22,16 +22,29 @@ try {
hdiff = require('node-hdiffpatch').diff;
} catch (e) {}
async function runReactNativeBundleCommand(
bundleName: string,
development: string,
entryFile: string,
outputFolder: string,
platform: string,
sourcemapOutput: string,
config: string,
) {
async function runReactNativeBundleCommand({
bundleName,
dev,
entryFile,
outputFolder,
platform,
sourcemapOutput,
config,
cli,
}: {
bundleName: string;
dev: string;
entryFile: string;
outputFolder: string;
platform: string;
sourcemapOutput: string;
config?: string;
cli: {
taro?: boolean;
expo?: boolean;
rncli?: boolean;
};
}) {
let gradleConfig: {
crunchPngs?: boolean;
enableHermes?: boolean;
@@ -58,9 +71,10 @@ async function runReactNativeBundleCommand(
fs.emptyDirSync(outputFolder);
let cliPath;
let cliPath: string | undefined;
let usingExpo = false;
const getExpoCli = () => {
try {
cliPath = require.resolve('@expo/cli', {
paths: [process.cwd()],
@@ -75,9 +89,13 @@ async function runReactNativeBundleCommand(
// expo cli 0.10.17 (expo 49) 开始支持 bundle:embed
if (semverSatisfies(expoCliVersion, '>= 0.10.17')) {
usingExpo = true;
} else {
cliPath = undefined;
}
} catch (e) {}
if (!usingExpo) {
};
const getRnCli = () => {
try {
// rn >= 0.75
cliPath = require.resolve('@react-native-community/cli/build/bin.js', {
@@ -89,20 +107,49 @@ async function runReactNativeBundleCommand(
paths: [process.cwd()],
});
}
};
const getTaroCli = () => {
try {
cliPath = require.resolve('@tarojs/cli/bin/taro.js', {
paths: [process.cwd()],
});
} catch (e) {}
};
if (cli.expo) {
getExpoCli();
} else if (cli.taro) {
getTaroCli();
} else if (cli.rncli) {
getRnCli();
}
if (!cliPath) {
getExpoCli();
if (!usingExpo) {
getRnCli();
}
}
const bundleParams = await checkPlugins();
const isSentry = bundleParams.sentry;
const bundleCommand = usingExpo
? 'export:embed'
: platform === 'harmony'
? 'bundle-harmony'
: 'bundle';
let bundleCommand = 'bundle';
if (usingExpo) {
bundleCommand = 'export:embed';
} else if (platform === 'harmony') {
bundleCommand = 'bundle-harmony';
} else if (cli.taro) {
bundleCommand = 'build';
}
if (platform === 'harmony') {
Array.prototype.push.apply(reactNativeBundleArgs, [
cliPath,
bundleCommand,
'--dev',
development,
dev,
'--entry-file',
entryFile,
]);
@@ -122,15 +169,25 @@ async function runReactNativeBundleCommand(
outputFolder,
'--bundle-output',
path.join(outputFolder, bundleName),
'--dev',
development,
'--entry-file',
entryFile,
'--platform',
platform,
'--reset-cache',
]);
if (cli.taro) {
reactNativeBundleArgs.push(...[
'--type',
'rn',
])
} else {
reactNativeBundleArgs.push(...[
'--dev',
dev,
'--entry-file',
entryFile,
])
}
if (sourcemapOutput) {
reactNativeBundleArgs.push('--sourcemap-output', sourcemapOutput);
}
@@ -165,7 +222,9 @@ async function runReactNativeBundleCommand(
let hermesEnabled: boolean | undefined = false;
if (platform === 'android') {
const gradlePropeties = await new Promise<{ hermesEnabled?: boolean }>((resolve) => {
const gradlePropeties = await new Promise<{
hermesEnabled?: boolean;
}>((resolve) => {
properties.parse(
'./android/gradle.properties',
{ path: true },
@@ -322,7 +381,11 @@ async function compileHermesByteCode(
}
}
async function copyDebugidForSentry(bundleName: string, outputFolder: string, sourcemapOutput: string) {
async function copyDebugidForSentry(
bundleName: string,
outputFolder: string,
sourcemapOutput: string,
) {
if (sourcemapOutput) {
let copyDebugidPath;
try {
@@ -423,7 +486,10 @@ async function pack(dir: string, output: string) {
}
const childs = fs.readdirSync(root);
for (const name of childs) {
if (ignorePackingFileNames.includes(name) || ignorePackingExtensions.some(ext => name.endsWith(`.${ext}`))) {
if (
ignorePackingFileNames.includes(name) ||
ignorePackingExtensions.some((ext) => name.endsWith(`.${ext}`))
) {
continue;
}
const fullPath = path.join(root, name);
@@ -723,9 +789,16 @@ async function diffFromPackage(
await writePromise;
}
export async function enumZipEntries(zipFn: string, callback: (entry: any, zipFile: any) => void, nestedPath = '') {
export async function enumZipEntries(
zipFn: string,
callback: (entry: any, zipFile: any) => void,
nestedPath = '',
) {
return new Promise((resolve, reject) => {
openZipFile(zipFn, { lazyEntries: true }, async (err: any, zipfile: ZipFile) => {
openZipFile(
zipFn,
{ lazyEntries: true },
async (err: any, zipfile: ZipFile) => {
if (err) {
return reject(err);
}
@@ -740,7 +813,10 @@ export async function enumZipEntries(zipFn: string, callback: (entry: any, zipFi
!entry.fileName.endsWith('/') &&
entry.fileName.toLowerCase().endsWith('.hap')
) {
const tempDir = path.join(os.tmpdir(), `nested_zip_${Date.now()}`);
const tempDir = path.join(
os.tmpdir(),
`nested_zip_${Date.now()}`,
);
await fs.ensureDir(tempDir);
const tempZipPath = path.join(tempDir, 'temp.zip');
@@ -771,7 +847,8 @@ export async function enumZipEntries(zipFn: string, callback: (entry: any, zipFi
});
zipfile.readEntry();
});
},
);
});
}
@@ -817,8 +894,17 @@ export const commands = {
options.platform || (await question('平台(ios/android/harmony):')),
);
const { bundleName, entryFile, intermediaDir, output, dev, sourcemap } =
translateOptions({
const {
bundleName,
entryFile,
intermediaDir,
output,
dev,
sourcemap,
taro,
expo,
rncli,
} = translateOptions({
...options,
platform,
});
@@ -839,14 +925,19 @@ export const commands = {
console.log(`Bundling with react-native: ${version}`);
await runReactNativeBundleCommand(
await runReactNativeBundleCommand({
bundleName,
dev,
entryFile,
intermediaDir,
outputFolder: intermediaDir,
platform,
sourcemap || sourcemapPlugin ? sourcemapOutput : '',
);
sourcemapOutput: sourcemap || sourcemapPlugin ? sourcemapOutput : '',
cli: {
taro,
expo,
rncli,
},
});
await pack(path.resolve(intermediaDir), realOutput);