@bravemobile/react-native-code-push 12.0.1 → 12.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +1 -52
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +4 -43
- package/bin/code-push.js +6 -0
- package/cli/commands/bundleCommand/{bundleCodePush.js → bundleCodePush.ts} +16 -24
- package/cli/commands/bundleCommand/{index.js → index.ts} +13 -14
- package/cli/commands/createHistoryCommand/{createReleaseHistory.js → createReleaseHistory.ts} +11 -28
- package/cli/commands/createHistoryCommand/{index.js → index.ts} +12 -13
- package/cli/commands/initCommand/{index.js → index.ts} +3 -3
- package/cli/commands/initCommand/{initAndroid.js → initAndroid.ts} +6 -11
- package/cli/commands/initCommand/initIos.ts +123 -0
- package/cli/commands/initCommand/test/{initAndroid.test.js → initAndroid.test.ts} +5 -4
- package/cli/commands/initCommand/test/{initIos.test.js → initIos.test.ts} +2 -1
- package/cli/commands/releaseCommand/{addToReleaseHistory.js → addToReleaseHistory.ts} +17 -45
- package/cli/commands/releaseCommand/{index.js → index.ts} +24 -25
- package/cli/commands/releaseCommand/release.ts +72 -0
- package/cli/commands/showHistoryCommand/{index.js → index.ts} +11 -12
- package/cli/commands/updateHistoryCommand/{index.js → index.ts} +17 -18
- package/cli/commands/updateHistoryCommand/{updateReleaseHistory.js → updateReleaseHistory.ts} +15 -41
- package/cli/constant.ts +4 -0
- package/cli/dist/commands/bundleCommand/bundleCodePush.js +34 -0
- package/cli/dist/commands/bundleCommand/index.js +14 -0
- package/cli/dist/commands/createHistoryCommand/createReleaseHistory.js +25 -0
- package/cli/dist/commands/createHistoryCommand/index.js +14 -0
- package/cli/dist/commands/initCommand/index.js +12 -0
- package/cli/dist/commands/initCommand/initAndroid.js +37 -0
- package/cli/{commands → dist/commands}/initCommand/initIos.js +13 -33
- package/cli/dist/commands/initCommand/test/initAndroid.test.js +75 -0
- package/cli/dist/commands/initCommand/test/initIos.test.js +95 -0
- package/cli/dist/commands/releaseCommand/addToReleaseHistory.js +32 -0
- package/cli/dist/commands/releaseCommand/index.js +38 -0
- package/cli/dist/commands/releaseCommand/release.js +36 -0
- package/cli/dist/commands/showHistoryCommand/index.js +14 -0
- package/cli/dist/commands/updateHistoryCommand/index.js +30 -0
- package/cli/dist/commands/updateHistoryCommand/updateReleaseHistory.js +26 -0
- package/cli/dist/constant.js +4 -0
- package/cli/dist/functions/getReactTempDir.js +10 -0
- package/cli/{functions → dist/functions}/makeCodePushBundle.js +5 -11
- package/cli/{functions → dist/functions}/prepareToBundleJS.js +2 -5
- package/cli/{functions → dist/functions}/runExpoBundleCommand.js +3 -21
- package/cli/{functions → dist/functions}/runHermesEmitBinaryCommand.js +12 -68
- package/cli/{functions → dist/functions}/runReactNativeBundleCommand.js +3 -23
- package/cli/dist/index.js +38 -0
- package/cli/dist/utils/file-utils.js +19 -0
- package/cli/dist/utils/fsUtils.js +37 -0
- package/cli/{utils → dist/utils}/hash-utils.js +19 -127
- package/cli/{utils → dist/utils}/promisfied-fs.js +5 -16
- package/cli/dist/utils/showLogo.js +21 -0
- package/cli/{utils → dist/utils}/zip.js +15 -51
- package/cli/functions/{getReactTempDir.js → getReactTempDir.ts} +2 -6
- package/cli/functions/makeCodePushBundle.ts +26 -0
- package/cli/functions/prepareToBundleJS.ts +10 -0
- package/cli/functions/runExpoBundleCommand.ts +45 -0
- package/cli/functions/runHermesEmitBinaryCommand.ts +186 -0
- package/cli/functions/runReactNativeBundleCommand.ts +51 -0
- package/cli/index.ts +48 -0
- package/cli/package.json +33 -0
- package/cli/utils/{file-utils.js → file-utils.ts} +4 -21
- package/cli/utils/{fsUtils.js → fsUtils.ts} +12 -19
- package/cli/utils/hash-utils.ts +146 -0
- package/cli/utils/promisfied-fs.ts +19 -0
- package/cli/utils/{showLogo.js → showLogo.ts} +1 -3
- package/cli/utils/zip.ts +65 -0
- package/expo/plugin/withCodePush.js +1 -2
- package/package.json +42 -12
- package/{AlertAdapter.js → src/AlertAdapter.js} +5 -5
- package/CONTRIBUTING.md +0 -134
- package/SECURITY.md +0 -41
- package/android/app/src/main/java/com/microsoft/codepush/react/ReactInstanceHolder.java +0 -17
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
- package/android/gradlew +0 -164
- package/android/gradlew.bat +0 -90
- package/app.plugin.js +0 -1
- package/babel.config.js +0 -3
- package/cli/commands/releaseCommand/release.js +0 -114
- package/cli/constant.js +0 -6
- package/cli/index.js +0 -49
- package/docs/api-android.md +0 -83
- package/docs/api-ios.md +0 -31
- package/docs/api-js.md +0 -592
- package/docs/multi-deployment-testing-android.md +0 -148
- package/docs/multi-deployment-testing-ios.md +0 -59
- package/eslint.config.mjs +0 -32
- package/scripts/generateBundledResourcesHash.js +0 -125
- package/scripts/getFilesInFolder.js +0 -19
- package/scripts/recordFilesBeforeBundleCommand.js +0 -41
- package/tsconfig.json +0 -18
- package/tslint.json +0 -32
- /package/{CodePush.js → src/CodePush.js} +0 -0
- /package/{logging.js → src/logging.js} +0 -0
- /package/{package-mixins.js → src/package-mixins.js} +0 -0
- /package/{versioning → src/versioning}/BaseVersioning.js +0 -0
- /package/{versioning → src/versioning}/BaseVersioning.test.js +0 -0
- /package/{versioning → src/versioning}/IncrementalVersioning.js +0 -0
- /package/{versioning → src/versioning}/IncrementalVersioning.test.js +0 -0
- /package/{versioning → src/versioning}/SemverVersioning.js +0 -0
- /package/{versioning → src/versioning}/SemverVersioning.test.js +0 -0
- /package/{versioning → src/versioning}/index.js +0 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { initAndroid, modifyMainApplicationKt } from "../initAndroid.js";
|
|
4
|
+
import { jest, expect, describe, it } from "@jest/globals";
|
|
5
|
+
const tempDir = path.join(__dirname, 'temp');
|
|
6
|
+
// https://github.com/react-native-community/template/blob/0.80.2/template/android/app/src/main/java/com/helloworld/MainApplication.kt
|
|
7
|
+
const ktTemplate = `
|
|
8
|
+
package com.helloworld
|
|
9
|
+
|
|
10
|
+
import android.app.Application
|
|
11
|
+
import com.facebook.react.PackageList
|
|
12
|
+
import com.facebook.react.ReactApplication
|
|
13
|
+
import com.facebook.react.ReactHost
|
|
14
|
+
import com.facebook.react.ReactNativeApplicationEntryPoint.loadReactNative
|
|
15
|
+
import com.facebook.react.ReactNativeHost
|
|
16
|
+
import com.facebook.react.ReactPackage
|
|
17
|
+
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
|
|
18
|
+
import com.facebook.react.defaults.DefaultReactNativeHost
|
|
19
|
+
|
|
20
|
+
class MainApplication : Application(), ReactApplication {
|
|
21
|
+
|
|
22
|
+
override val reactNativeHost: ReactNativeHost =
|
|
23
|
+
object : DefaultReactNativeHost(this) {
|
|
24
|
+
override fun getPackages(): List<ReactPackage> =
|
|
25
|
+
PackageList(this).packages.apply {
|
|
26
|
+
// Packages that cannot be autolinked yet can be added manually here, for example:
|
|
27
|
+
// add(MyReactNativePackage())
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
override fun getJSMainModuleName(): String = "index"
|
|
31
|
+
|
|
32
|
+
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
|
|
33
|
+
|
|
34
|
+
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
|
|
35
|
+
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
override val reactHost: ReactHost
|
|
39
|
+
get() = getDefaultReactHost(applicationContext, reactNativeHost)
|
|
40
|
+
|
|
41
|
+
override fun onCreate() {
|
|
42
|
+
super.onCreate()
|
|
43
|
+
loadReactNative(this)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
describe('Android init command', () => {
|
|
48
|
+
it('should correctly modify Kotlin MainApplication content', () => {
|
|
49
|
+
const modifiedContent = modifyMainApplicationKt(ktTemplate);
|
|
50
|
+
expect(modifiedContent).toContain('import com.microsoft.codepush.react.CodePush');
|
|
51
|
+
expect(modifiedContent).toContain('override fun getJSBundleFile(): String = CodePush.getJSBundleFile()');
|
|
52
|
+
});
|
|
53
|
+
it('should log a message and exit if MainApplication.java is found', async () => {
|
|
54
|
+
const originalCwd = process.cwd();
|
|
55
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
56
|
+
process.chdir(tempDir);
|
|
57
|
+
// Arrange
|
|
58
|
+
const javaAppDir = path.join(tempDir, 'android', 'app', 'src', 'main', 'java', 'com', 'helloworld');
|
|
59
|
+
fs.mkdirSync(javaAppDir, { recursive: true });
|
|
60
|
+
const javaFilePath = path.join(javaAppDir, 'MainApplication.java');
|
|
61
|
+
const originalContent = '// Java file content';
|
|
62
|
+
fs.writeFileSync(javaFilePath, originalContent);
|
|
63
|
+
const consoleSpy = jest.spyOn(console, 'log').mockImplementation(() => {
|
|
64
|
+
});
|
|
65
|
+
// Act
|
|
66
|
+
await initAndroid();
|
|
67
|
+
// Assert
|
|
68
|
+
expect(consoleSpy).toHaveBeenCalledWith('log: MainApplication.java is not supported. Please migrate to MainApplication.kt.');
|
|
69
|
+
const finalContent = fs.readFileSync(javaFilePath, 'utf-8');
|
|
70
|
+
expect(finalContent).toBe(originalContent); // Ensure file is not modified
|
|
71
|
+
consoleSpy.mockRestore();
|
|
72
|
+
process.chdir(originalCwd);
|
|
73
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { modifyObjectiveCAppDelegate, modifySwiftAppDelegate } from "../initIos.js";
|
|
2
|
+
import { expect, describe, it } from "@jest/globals";
|
|
3
|
+
// https://github.com/react-native-community/template/blob/0.80.2/template/ios/HelloWorld/AppDelegate.swift
|
|
4
|
+
const swiftTemplate = `
|
|
5
|
+
import UIKit
|
|
6
|
+
import React
|
|
7
|
+
import React_RCTAppDelegate
|
|
8
|
+
import ReactAppDependencyProvider
|
|
9
|
+
|
|
10
|
+
@main
|
|
11
|
+
class AppDelegate: UIResponder, UIApplicationDelegate {
|
|
12
|
+
var window: UIWindow?
|
|
13
|
+
var reactNativeDelegate: ReactNativeDelegate?
|
|
14
|
+
var reactNativeFactory: RCTReactNativeFactory?
|
|
15
|
+
|
|
16
|
+
func application(
|
|
17
|
+
_ application: UIApplication,
|
|
18
|
+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
|
|
19
|
+
) -> Bool {
|
|
20
|
+
let delegate = ReactNativeDelegate()
|
|
21
|
+
let factory = RCTReactNativeFactory(delegate: delegate)
|
|
22
|
+
delegate.dependencyProvider = RCTAppDependencyProvider()
|
|
23
|
+
reactNativeDelegate = delegate
|
|
24
|
+
reactNativeFactory = factory
|
|
25
|
+
window = UIWindow(frame: UIScreen.main.bounds)
|
|
26
|
+
factory.startReactNative(
|
|
27
|
+
withModuleName: "HelloWorld",
|
|
28
|
+
in: window,
|
|
29
|
+
launchOptions: launchOptions
|
|
30
|
+
)
|
|
31
|
+
return true
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
class ReactNativeDelegate: RCTDefaultReactNativeFactoryDelegate {
|
|
36
|
+
override func sourceURL(for bridge: RCTBridge) -> URL? {
|
|
37
|
+
self.bundleURL()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
override func bundleURL() -> URL? {
|
|
41
|
+
#if DEBUG
|
|
42
|
+
RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
|
|
43
|
+
#else
|
|
44
|
+
Bundle.main.url(forResource: "main", withExtension: "jsbundle")
|
|
45
|
+
#endif
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
// https://github.com/react-native-community/template/blob/0.76.9/template/ios/HelloWorld/AppDelegate.mm
|
|
50
|
+
const objcTemplate = `
|
|
51
|
+
#import "AppDelegate.h"
|
|
52
|
+
|
|
53
|
+
#import <React/RCTBundleURLProvider.h>
|
|
54
|
+
|
|
55
|
+
@implementation AppDelegate
|
|
56
|
+
|
|
57
|
+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
|
58
|
+
{
|
|
59
|
+
self.moduleName = @"HelloWorld";
|
|
60
|
+
// You can add your custom initial props in the dictionary below.
|
|
61
|
+
// They will be passed down to the ViewController used by React Native.
|
|
62
|
+
self.initialProps = @{};
|
|
63
|
+
|
|
64
|
+
return [super application:application didFinishLaunchingWithOptions:launchOptions];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
|
|
68
|
+
{
|
|
69
|
+
return [self bundleURL];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
- (NSURL *)bundleURL
|
|
73
|
+
{
|
|
74
|
+
#if DEBUG
|
|
75
|
+
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
|
|
76
|
+
#else
|
|
77
|
+
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
|
|
78
|
+
#endif
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@end
|
|
82
|
+
`;
|
|
83
|
+
describe('iOS init command - pure functions', () => {
|
|
84
|
+
it('should correctly modify Swift AppDelegate content', () => {
|
|
85
|
+
const modifiedContent = modifySwiftAppDelegate(swiftTemplate);
|
|
86
|
+
expect(modifiedContent).toContain('CodePush.bundleURL()');
|
|
87
|
+
expect(modifiedContent).not.toContain('Bundle.main.url(forResource: "main", withExtension: "jsbundle")');
|
|
88
|
+
});
|
|
89
|
+
it('should correctly modify Objective-C AppDelegate content', () => {
|
|
90
|
+
const modifiedContent = modifyObjectiveCAppDelegate(objcTemplate);
|
|
91
|
+
expect(modifiedContent).toContain('#import <CodePush/CodePush.h>');
|
|
92
|
+
expect(modifiedContent).toContain('[CodePush bundleURL]');
|
|
93
|
+
expect(modifiedContent).not.toContain('[[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];');
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
export async function addToReleaseHistory(appVersion, binaryVersion, bundleDownloadUrl, packageHash, getReleaseHistory, setReleaseHistory, platform, identifier, mandatory, enable, rollout) {
|
|
4
|
+
const releaseHistory = await getReleaseHistory(binaryVersion, platform, identifier);
|
|
5
|
+
const updateInfo = releaseHistory[appVersion];
|
|
6
|
+
if (updateInfo) {
|
|
7
|
+
console.error(`v${appVersion} is already released`);
|
|
8
|
+
process.exit(1);
|
|
9
|
+
}
|
|
10
|
+
const newReleaseHistory = structuredClone(releaseHistory);
|
|
11
|
+
newReleaseHistory[appVersion] = {
|
|
12
|
+
enabled: enable,
|
|
13
|
+
mandatory: mandatory,
|
|
14
|
+
downloadUrl: bundleDownloadUrl,
|
|
15
|
+
packageHash: packageHash,
|
|
16
|
+
};
|
|
17
|
+
if (typeof rollout === 'number') {
|
|
18
|
+
newReleaseHistory[appVersion].rollout = rollout;
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
const JSON_FILE_NAME = `${binaryVersion}.json`;
|
|
22
|
+
const JSON_FILE_PATH = path.resolve(process.cwd(), JSON_FILE_NAME);
|
|
23
|
+
console.log(`log: creating JSON file... ("${JSON_FILE_NAME}")\n`, JSON.stringify(newReleaseHistory, null, 2));
|
|
24
|
+
fs.writeFileSync(JSON_FILE_PATH, JSON.stringify(newReleaseHistory));
|
|
25
|
+
await setReleaseHistory(binaryVersion, JSON_FILE_PATH, newReleaseHistory, platform, identifier);
|
|
26
|
+
fs.unlinkSync(JSON_FILE_PATH);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error('Error occurred while updating history:', error);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { program, Option } from "commander";
|
|
2
|
+
import { findAndReadConfigFile } from "../../utils/fsUtils.js";
|
|
3
|
+
import { release } from "./release.js";
|
|
4
|
+
import { OUTPUT_BUNDLE_DIR, CONFIG_FILE_NAME, ROOT_OUTPUT_DIR, ENTRY_FILE } from "../../constant.js";
|
|
5
|
+
program.command('release')
|
|
6
|
+
.description('Deploys a new CodePush update for a target binary app.\nAfter creating the CodePush bundle, it uploads the file and updates the ReleaseHistory information.\n`bundleUploader`, `getReleaseHistory`, and `setReleaseHistory` functions should be implemented in the config file.')
|
|
7
|
+
.requiredOption('-b, --binary-version <string>', '(Required) The target binary version')
|
|
8
|
+
.requiredOption('-v, --app-version <string>', '(Required) The app version to be released. It must be greater than the binary version.')
|
|
9
|
+
.addOption(new Option('-f, --framework <type>', 'framework type (expo)').choices(['expo']))
|
|
10
|
+
.addOption(new Option('-p, --platform <type>', 'platform').choices(['ios', 'android']).default('ios'))
|
|
11
|
+
.option('-i, --identifier <string>', 'reserved characters to distinguish the release.')
|
|
12
|
+
.option('-c, --config <path>', 'set config file name (JS/TS)', CONFIG_FILE_NAME)
|
|
13
|
+
.option('-o, --output-path <string>', 'path to output root directory', ROOT_OUTPUT_DIR)
|
|
14
|
+
.option('-e, --entry-file <string>', 'path to JS/TS entry file', ENTRY_FILE)
|
|
15
|
+
.option('-j, --js-bundle-name <string>', 'JS bundle file name (default-ios: "main.jsbundle" / default-android: "index.android.bundle")')
|
|
16
|
+
.option('-m, --mandatory <bool>', 'make the release to be mandatory', parseBoolean, false)
|
|
17
|
+
.option('--enable <bool>', 'make the release to be enabled', parseBoolean, true)
|
|
18
|
+
.option('--rollout <number>', 'rollout percentage (0-100)', parseFloat)
|
|
19
|
+
.option('--skip-bundle <bool>', 'skip bundle process', parseBoolean, false)
|
|
20
|
+
.option('--skip-cleanup <bool>', 'skip cleanup process', parseBoolean, false)
|
|
21
|
+
.option('--output-bundle-dir <string>', 'name of directory containing the bundle file created by the "bundle" command', OUTPUT_BUNDLE_DIR)
|
|
22
|
+
.action(async (options) => {
|
|
23
|
+
const config = findAndReadConfigFile(process.cwd(), options.config);
|
|
24
|
+
if (typeof options.rollout === 'number' && (options.rollout < 0 || options.rollout > 100)) {
|
|
25
|
+
console.error('Rollout percentage number must be between 0 and 100 (inclusive).');
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
await release(config.bundleUploader, config.getReleaseHistory, config.setReleaseHistory, options.binaryVersion, options.appVersion, options.framework, options.platform, options.identifier, options.outputPath, options.entryFile, options.bundleName, options.mandatory, options.enable, options.rollout, options.skipBundle, options.skipCleanup, `${options.outputPath}/${options.outputBundleDir}`);
|
|
29
|
+
console.log('🚀 Release completed.');
|
|
30
|
+
});
|
|
31
|
+
function parseBoolean(value) {
|
|
32
|
+
if (value === 'true')
|
|
33
|
+
return true;
|
|
34
|
+
if (value === 'false')
|
|
35
|
+
return false;
|
|
36
|
+
else
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { bundleCodePush } from "../bundleCommand/bundleCodePush.js";
|
|
4
|
+
import { addToReleaseHistory } from "./addToReleaseHistory.js";
|
|
5
|
+
export async function release(bundleUploader, getReleaseHistory, setReleaseHistory, binaryVersion, appVersion, framework, platform, identifier, outputPath, entryFile, jsBundleName, mandatory, enable, rollout, skipBundle, skipCleanup, bundleDirectory) {
|
|
6
|
+
const bundleFileName = skipBundle
|
|
7
|
+
? readBundleFileNameFrom(bundleDirectory)
|
|
8
|
+
: await bundleCodePush(framework, platform, outputPath, entryFile, jsBundleName, bundleDirectory);
|
|
9
|
+
const bundleFilePath = `${bundleDirectory}/${bundleFileName}`;
|
|
10
|
+
const downloadUrl = await (async () => {
|
|
11
|
+
try {
|
|
12
|
+
const { downloadUrl } = await bundleUploader(bundleFilePath, platform, identifier);
|
|
13
|
+
return downloadUrl;
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
console.error('Failed to upload the bundle file. Exiting the program.\n', error);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
})();
|
|
20
|
+
await addToReleaseHistory(appVersion, binaryVersion, downloadUrl, bundleFileName, getReleaseHistory, setReleaseHistory, platform, identifier, mandatory, enable, rollout);
|
|
21
|
+
if (!skipCleanup) {
|
|
22
|
+
cleanUpOutputs(outputPath);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function cleanUpOutputs(dir) {
|
|
26
|
+
fs.rmSync(dir, { recursive: true });
|
|
27
|
+
}
|
|
28
|
+
function readBundleFileNameFrom(bundleDirectory) {
|
|
29
|
+
const files = fs.readdirSync(bundleDirectory);
|
|
30
|
+
if (files.length !== 1) {
|
|
31
|
+
console.error('The bundlePath must contain only one file.');
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
const bundleFilePath = path.join(bundleDirectory, files[0]);
|
|
35
|
+
return path.basename(bundleFilePath);
|
|
36
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { program, Option } from "commander";
|
|
2
|
+
import { findAndReadConfigFile } from "../../utils/fsUtils.js";
|
|
3
|
+
import { CONFIG_FILE_NAME } from "../../constant.js";
|
|
4
|
+
program.command('show-history')
|
|
5
|
+
.description('Retrieves and prints the release history of a specific binary version.\n`getReleaseHistory` function should be implemented in the config file.')
|
|
6
|
+
.requiredOption('-b, --binary-version <string>', '(Required) The target binary version for retrieving the release history.')
|
|
7
|
+
.addOption(new Option('-p, --platform <type>', 'platform').choices(['ios', 'android']).default('ios'))
|
|
8
|
+
.option('-i, --identifier <string>', 'reserved characters to distinguish the release.')
|
|
9
|
+
.option('-c, --config <path>', 'configuration file name (JS/TS)', CONFIG_FILE_NAME)
|
|
10
|
+
.action(async (options) => {
|
|
11
|
+
const config = findAndReadConfigFile(process.cwd(), options.config);
|
|
12
|
+
const releaseHistory = await config.getReleaseHistory(options.binaryVersion, options.platform, options.identifier);
|
|
13
|
+
console.log(JSON.stringify(releaseHistory, null, 2));
|
|
14
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { program, Option } from "commander";
|
|
2
|
+
import { findAndReadConfigFile } from "../../utils/fsUtils.js";
|
|
3
|
+
import { updateReleaseHistory } from "./updateReleaseHistory.js";
|
|
4
|
+
import { CONFIG_FILE_NAME } from "../../constant.js";
|
|
5
|
+
program.command('update-history')
|
|
6
|
+
.description('Updates the release history for a specific binary version.\n`getReleaseHistory`, `setReleaseHistory` functions should be implemented in the config file.')
|
|
7
|
+
.requiredOption('-v, --app-version <string>', '(Required) The app version for which update information is to be modified.')
|
|
8
|
+
.requiredOption('-b, --binary-version <string>', '(Required) The target binary version of the app for which update information is to be modified.')
|
|
9
|
+
.addOption(new Option('-p, --platform <type>', 'platform').choices(['ios', 'android']).default('ios'))
|
|
10
|
+
.option('-i, --identifier <string>', 'reserved characters to distinguish the release.')
|
|
11
|
+
.option('-c, --config <path>', 'set config file name (JS/TS)', CONFIG_FILE_NAME)
|
|
12
|
+
.option('-m, --mandatory <bool>', 'make the release to be mandatory', parseBoolean, undefined)
|
|
13
|
+
.option('-e, --enable <bool>', 'make the release to be enabled', parseBoolean, undefined)
|
|
14
|
+
.option('--rollout <number>', 'rollout percentage (0-100)', parseFloat, undefined)
|
|
15
|
+
.action(async (options) => {
|
|
16
|
+
const config = findAndReadConfigFile(process.cwd(), options.config);
|
|
17
|
+
if (typeof options.mandatory !== "boolean" && typeof options.enable !== "boolean") {
|
|
18
|
+
console.error('No options specified. Exiting the program.');
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
await updateReleaseHistory(options.appVersion, options.binaryVersion, config.getReleaseHistory, config.setReleaseHistory, options.platform, options.identifier, options.mandatory, options.enable, options.rollout);
|
|
22
|
+
});
|
|
23
|
+
function parseBoolean(value) {
|
|
24
|
+
if (value === 'true')
|
|
25
|
+
return true;
|
|
26
|
+
if (value === 'false')
|
|
27
|
+
return false;
|
|
28
|
+
else
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
export async function updateReleaseHistory(appVersion, binaryVersion, getReleaseHistory, setReleaseHistory, platform, identifier, mandatory, enable, rollout) {
|
|
4
|
+
const releaseHistory = await getReleaseHistory(binaryVersion, platform, identifier);
|
|
5
|
+
const updateInfo = releaseHistory[appVersion];
|
|
6
|
+
if (!updateInfo)
|
|
7
|
+
throw new Error(`v${appVersion} is not released`);
|
|
8
|
+
if (typeof mandatory === "boolean")
|
|
9
|
+
updateInfo.mandatory = mandatory;
|
|
10
|
+
if (typeof enable === "boolean")
|
|
11
|
+
updateInfo.enabled = enable;
|
|
12
|
+
if (typeof rollout === "number")
|
|
13
|
+
updateInfo.rollout = rollout;
|
|
14
|
+
try {
|
|
15
|
+
const JSON_FILE_NAME = `${binaryVersion}.json`;
|
|
16
|
+
const JSON_FILE_PATH = path.resolve(process.cwd(), JSON_FILE_NAME);
|
|
17
|
+
console.log(`log: creating JSON file... ("${JSON_FILE_NAME}")\n`, JSON.stringify(releaseHistory, null, 2));
|
|
18
|
+
fs.writeFileSync(JSON_FILE_PATH, JSON.stringify(releaseHistory));
|
|
19
|
+
await setReleaseHistory(binaryVersion, JSON_FILE_PATH, releaseHistory, platform, identifier);
|
|
20
|
+
fs.unlinkSync(JSON_FILE_PATH);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
console.error('Error occurred while updating history:', error);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import path from "path";
|
|
2
|
+
import shell from "shelljs";
|
|
3
|
+
import { zip } from "../utils/zip.js";
|
|
4
|
+
import { generatePackageHashFromDirectory } from "../utils/hash-utils.js";
|
|
6
5
|
/**
|
|
7
6
|
* Create a CodePush bundle file and return the information.
|
|
8
7
|
*
|
|
@@ -10,19 +9,14 @@ const {generatePackageHashFromDirectory} = require('../utils/hash-utils');
|
|
|
10
9
|
* @param bundleDirectory {string} The directory path to save the CodePush bundle file
|
|
11
10
|
* @return {Promise<{ bundleFileName: string }>}
|
|
12
11
|
*/
|
|
13
|
-
async function makeCodePushBundle(contentsPath, bundleDirectory) {
|
|
12
|
+
export async function makeCodePushBundle(contentsPath, bundleDirectory) {
|
|
14
13
|
const updateContentsZipPath = await zip(contentsPath);
|
|
15
|
-
|
|
16
14
|
const packageHash = await generatePackageHashFromDirectory(contentsPath, path.join(contentsPath, '..'));
|
|
17
|
-
|
|
18
15
|
shell.mkdir('-p', `./${bundleDirectory}`);
|
|
19
16
|
shell.mv(updateContentsZipPath, `./${bundleDirectory}/${packageHash}`);
|
|
20
|
-
|
|
21
17
|
return {
|
|
22
18
|
// To allow the "release" command to get the file and hash value from the result of the "bundle" command,
|
|
23
19
|
// use the hash value as the name of the file.
|
|
24
20
|
bundleFileName: packageHash,
|
|
25
21
|
};
|
|
26
22
|
}
|
|
27
|
-
|
|
28
|
-
module.exports = { makeCodePushBundle };
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import shell from "shelljs";
|
|
3
2
|
/**
|
|
4
3
|
* @param deleteDirs {string[]} Directories to delete
|
|
5
4
|
* @param makeDir {string} Directory path to create
|
|
6
5
|
*/
|
|
7
|
-
function prepareToBundleJS({ deleteDirs, makeDir }) {
|
|
6
|
+
export function prepareToBundleJS({ deleteDirs, makeDir }) {
|
|
8
7
|
shell.rm('-rf', deleteDirs);
|
|
9
8
|
shell.mkdir('-p', makeDir);
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
module.exports = { prepareToBundleJS };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import path from "path";
|
|
2
|
+
import shell from "shelljs";
|
|
4
3
|
/**
|
|
5
4
|
* Run `expo bundle` CLI command
|
|
6
5
|
*
|
|
@@ -11,23 +10,10 @@ const shell = require('shelljs');
|
|
|
11
10
|
* @param sourcemapOutput {string} Path to output sourcemap file (Warning: if sourcemapOutput points to the outputPath, the sourcemap will be included in the CodePush bundle and increase the deployment size)
|
|
12
11
|
* @return {void}
|
|
13
12
|
*/
|
|
14
|
-
function runExpoBundleCommand(
|
|
15
|
-
bundleName,
|
|
16
|
-
outputPath,
|
|
17
|
-
platform,
|
|
18
|
-
sourcemapOutput,
|
|
19
|
-
entryFile,
|
|
20
|
-
) {
|
|
21
|
-
/**
|
|
22
|
-
* @return {string}
|
|
23
|
-
*/
|
|
13
|
+
export function runExpoBundleCommand(bundleName, outputPath, platform, sourcemapOutput, entryFile) {
|
|
24
14
|
function getCliPath() {
|
|
25
15
|
return path.join('node_modules', '.bin', 'expo');
|
|
26
16
|
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @type {string[]}
|
|
30
|
-
*/
|
|
31
17
|
const expoBundleArgs = [
|
|
32
18
|
'export:embed',
|
|
33
19
|
'--assets-dest',
|
|
@@ -44,10 +30,6 @@ function runExpoBundleCommand(
|
|
|
44
30
|
sourcemapOutput,
|
|
45
31
|
'--reset-cache',
|
|
46
32
|
];
|
|
47
|
-
|
|
48
33
|
console.log('Running "expo export:embed" command:\n');
|
|
49
|
-
|
|
50
34
|
shell.exec(`${getCliPath()} ${expoBundleArgs.join(' ')}`);
|
|
51
35
|
}
|
|
52
|
-
|
|
53
|
-
module.exports = { runExpoBundleCommand };
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* code based on appcenter-cli
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const shell = require('shelljs');
|
|
9
|
-
|
|
4
|
+
import childProcess from "child_process";
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import shell from "shelljs";
|
|
10
8
|
/**
|
|
11
9
|
* Run Hermes compile CLI command
|
|
12
10
|
*
|
|
@@ -16,15 +14,7 @@ const shell = require('shelljs');
|
|
|
16
14
|
* @param extraHermesFlags {string[]} Additional options to pass to `hermesc` command
|
|
17
15
|
* @return {Promise<void>}
|
|
18
16
|
*/
|
|
19
|
-
async function runHermesEmitBinaryCommand(
|
|
20
|
-
bundleName,
|
|
21
|
-
outputPath,
|
|
22
|
-
sourcemapOutput,
|
|
23
|
-
extraHermesFlags = [],
|
|
24
|
-
) {
|
|
25
|
-
/**
|
|
26
|
-
* @type {string[]}
|
|
27
|
-
*/
|
|
17
|
+
export async function runHermesEmitBinaryCommand(bundleName, outputPath, sourcemapOutput, extraHermesFlags = []) {
|
|
28
18
|
const hermesArgs = [
|
|
29
19
|
'-emit-binary',
|
|
30
20
|
'-out',
|
|
@@ -35,23 +25,20 @@ async function runHermesEmitBinaryCommand(
|
|
|
35
25
|
if (sourcemapOutput) {
|
|
36
26
|
hermesArgs.push('-output-source-map');
|
|
37
27
|
}
|
|
38
|
-
|
|
39
28
|
console.log('Converting JS bundle to byte code via Hermes, running command:\n');
|
|
40
|
-
|
|
41
29
|
return new Promise((resolve, reject) => {
|
|
42
30
|
try {
|
|
43
31
|
const hermesCommand = getHermesCommand();
|
|
44
|
-
|
|
45
32
|
const disableAllWarningsArg = '-w';
|
|
46
33
|
shell.exec(`${hermesCommand} ${hermesArgs.join(' ')} ${disableAllWarningsArg}`);
|
|
47
|
-
|
|
48
34
|
// Copy HBC bundle to overwrite JS bundle
|
|
49
35
|
const source = path.join(outputPath, bundleName + '.hbc');
|
|
50
36
|
const destination = path.join(outputPath, bundleName);
|
|
51
37
|
shell.cp(source, destination);
|
|
52
38
|
shell.rm(source);
|
|
53
39
|
resolve();
|
|
54
|
-
}
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
55
42
|
reject(e);
|
|
56
43
|
}
|
|
57
44
|
}).then(() => {
|
|
@@ -59,18 +46,15 @@ async function runHermesEmitBinaryCommand(
|
|
|
59
46
|
// skip source map compose if source map is not enabled
|
|
60
47
|
return;
|
|
61
48
|
}
|
|
62
|
-
|
|
63
49
|
// compose-source-maps.js file path
|
|
64
50
|
const composeSourceMapsPath = getComposeSourceMapsPath();
|
|
65
51
|
if (composeSourceMapsPath === null) {
|
|
66
52
|
throw new Error('react-native compose-source-maps.js scripts is not found');
|
|
67
53
|
}
|
|
68
|
-
|
|
69
54
|
const jsCompilerSourceMapFile = path.join(outputPath, bundleName + '.hbc' + '.map');
|
|
70
55
|
if (!fs.existsSync(jsCompilerSourceMapFile)) {
|
|
71
56
|
throw new Error(`sourcemap file ${jsCompilerSourceMapFile} is not found`);
|
|
72
57
|
}
|
|
73
|
-
|
|
74
58
|
return new Promise((resolve, reject) => {
|
|
75
59
|
const composeSourceMapsArgs = [
|
|
76
60
|
composeSourceMapsPath,
|
|
@@ -81,65 +65,44 @@ async function runHermesEmitBinaryCommand(
|
|
|
81
65
|
];
|
|
82
66
|
const composeSourceMapsProcess = childProcess.spawn('node', composeSourceMapsArgs);
|
|
83
67
|
console.log(`${composeSourceMapsPath} ${composeSourceMapsArgs.join(' ')}`);
|
|
84
|
-
|
|
85
68
|
composeSourceMapsProcess.stdout.on('data', (data) => {
|
|
86
69
|
console.log(data.toString().trim());
|
|
87
70
|
});
|
|
88
|
-
|
|
89
71
|
composeSourceMapsProcess.stderr.on('data', (data) => {
|
|
90
72
|
console.error(data.toString().trim());
|
|
91
73
|
});
|
|
92
|
-
|
|
93
74
|
composeSourceMapsProcess.on('close', (exitCode, signal) => {
|
|
94
75
|
if (exitCode !== 0) {
|
|
95
76
|
reject(new Error(`"compose-source-maps" command failed (exitCode=${exitCode}, signal=${signal}).`));
|
|
96
77
|
}
|
|
97
|
-
|
|
98
78
|
// Delete the HBC sourceMap, otherwise it will be included in 'code-push' bundle as well
|
|
99
79
|
fs.unlink(jsCompilerSourceMapFile, (err) => {
|
|
100
80
|
if (err != null) {
|
|
101
81
|
console.error(err);
|
|
102
82
|
reject(err);
|
|
103
83
|
}
|
|
104
|
-
|
|
105
84
|
resolve();
|
|
106
85
|
});
|
|
107
86
|
});
|
|
108
87
|
});
|
|
109
88
|
});
|
|
110
89
|
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* @return {string}
|
|
114
|
-
*/
|
|
115
90
|
function getHermesCommand() {
|
|
116
|
-
/**
|
|
117
|
-
* @type {(file: string) => boolean}
|
|
118
|
-
*/
|
|
119
91
|
const fileExists = (file) => {
|
|
120
92
|
try {
|
|
121
93
|
return fs.statSync(file).isFile();
|
|
122
|
-
}
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
123
96
|
return false;
|
|
124
97
|
}
|
|
125
98
|
};
|
|
126
99
|
// Hermes is bundled with react-native since 0.69
|
|
127
|
-
const bundledHermesEngine = path.join(
|
|
128
|
-
getReactNativePackagePath(),
|
|
129
|
-
'sdks',
|
|
130
|
-
'hermesc',
|
|
131
|
-
getHermesOSBin(),
|
|
132
|
-
getHermesOSExe(),
|
|
133
|
-
);
|
|
100
|
+
const bundledHermesEngine = path.join(getReactNativePackagePath(), 'sdks', 'hermesc', getHermesOSBin(), getHermesOSExe());
|
|
134
101
|
if (fileExists(bundledHermesEngine)) {
|
|
135
102
|
return bundledHermesEngine;
|
|
136
103
|
}
|
|
137
104
|
throw new Error('Hermes engine binary not found. Please upgrade to react-native 0.69 or later');
|
|
138
105
|
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* @return {string}
|
|
142
|
-
*/
|
|
143
106
|
function getHermesOSBin() {
|
|
144
107
|
switch (process.platform) {
|
|
145
108
|
case 'win32':
|
|
@@ -153,10 +116,6 @@ function getHermesOSBin() {
|
|
|
153
116
|
return 'linux64-bin';
|
|
154
117
|
}
|
|
155
118
|
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* @return {string}
|
|
159
|
-
*/
|
|
160
119
|
function getHermesOSExe() {
|
|
161
120
|
const hermesExecutableName = 'hermesc';
|
|
162
121
|
switch (process.platform) {
|
|
@@ -166,10 +125,6 @@ function getHermesOSExe() {
|
|
|
166
125
|
return hermesExecutableName;
|
|
167
126
|
}
|
|
168
127
|
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* @return {string | null}
|
|
172
|
-
*/
|
|
173
128
|
function getComposeSourceMapsPath() {
|
|
174
129
|
// detect if compose-source-maps.js script exists
|
|
175
130
|
const composeSourceMaps = path.join(getReactNativePackagePath(), 'scripts', 'compose-source-maps.js');
|
|
@@ -178,10 +133,6 @@ function getComposeSourceMapsPath() {
|
|
|
178
133
|
}
|
|
179
134
|
return null;
|
|
180
135
|
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* @return {string}
|
|
184
|
-
*/
|
|
185
136
|
function getReactNativePackagePath() {
|
|
186
137
|
const result = childProcess.spawnSync('node', [
|
|
187
138
|
'--print',
|
|
@@ -191,23 +142,16 @@ function getReactNativePackagePath() {
|
|
|
191
142
|
if (result.status === 0 && directoryExistsSync(packagePath)) {
|
|
192
143
|
return packagePath;
|
|
193
144
|
}
|
|
194
|
-
|
|
195
145
|
return path.join('node_modules', 'react-native');
|
|
196
146
|
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* @param dirname {string}
|
|
200
|
-
* @return {boolean}
|
|
201
|
-
*/
|
|
202
147
|
function directoryExistsSync(dirname) {
|
|
203
148
|
try {
|
|
204
149
|
return fs.statSync(dirname).isDirectory();
|
|
205
|
-
}
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
206
152
|
if (err.code !== 'ENOENT') {
|
|
207
153
|
throw err;
|
|
208
154
|
}
|
|
209
155
|
}
|
|
210
156
|
return false;
|
|
211
157
|
}
|
|
212
|
-
|
|
213
|
-
module.exports = { runHermesEmitBinaryCommand };
|