@bravemobile/react-native-code-push 12.0.2 → 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/debug/AndroidManifest.xml +9 -0
- 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.ts +86 -0
- package/cli/commands/initCommand/test/initIos.test.ts +99 -0
- 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/package.json +42 -12
- package/{AlertAdapter.js → src/AlertAdapter.js} +5 -5
- package/AGENTS.md +0 -32
- 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
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
async function initIos() {
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
// @ts-expect-error -- types for "xcode" are not available
|
|
4
|
+
import xcode from "xcode";
|
|
5
|
+
export async function initIos() {
|
|
6
6
|
console.log('log: Running iOS setup...');
|
|
7
7
|
const projectDir = path.join(process.cwd(), 'ios');
|
|
8
8
|
const files = fs.readdirSync(projectDir);
|
|
@@ -13,85 +13,72 @@ async function initIos() {
|
|
|
13
13
|
}
|
|
14
14
|
const projectName = xcodeprojFile.replace('.xcodeproj', '');
|
|
15
15
|
const appDelegatePath = findAppDelegate(path.join(projectDir, projectName));
|
|
16
|
-
|
|
17
16
|
if (!appDelegatePath) {
|
|
18
17
|
console.log('log: Could not find AppDelegate file');
|
|
19
18
|
return;
|
|
20
19
|
}
|
|
21
|
-
|
|
22
20
|
if (appDelegatePath.endsWith('.swift')) {
|
|
23
21
|
await setupSwift(appDelegatePath, projectDir, projectName);
|
|
24
|
-
}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
25
24
|
await setupObjectiveC(appDelegatePath);
|
|
26
25
|
}
|
|
27
|
-
|
|
28
26
|
console.log('log: Please run `cd ios && pod install` to complete the setup.');
|
|
29
27
|
}
|
|
30
|
-
|
|
31
28
|
function findAppDelegate(searchPath) {
|
|
32
|
-
if (!fs.existsSync(searchPath))
|
|
29
|
+
if (!fs.existsSync(searchPath))
|
|
30
|
+
return null;
|
|
33
31
|
const files = fs.readdirSync(searchPath);
|
|
34
32
|
const appDelegateFile = files.find(file => file.startsWith('AppDelegate') && (file.endsWith('.m') || file.endsWith('.mm') || file.endsWith('.swift')));
|
|
35
33
|
return appDelegateFile ? path.join(searchPath, appDelegateFile) : null;
|
|
36
34
|
}
|
|
37
|
-
|
|
38
|
-
function modifyObjectiveCAppDelegate(appDelegateContent) {
|
|
35
|
+
export function modifyObjectiveCAppDelegate(appDelegateContent) {
|
|
39
36
|
const IMPORT_STATEMENT = '#import <CodePush/CodePush.h>';
|
|
40
37
|
if (appDelegateContent.includes(IMPORT_STATEMENT)) {
|
|
41
38
|
console.log('log: AppDelegate already has CodePush imported.');
|
|
42
39
|
return appDelegateContent;
|
|
43
40
|
}
|
|
44
|
-
|
|
45
41
|
return appDelegateContent
|
|
46
42
|
.replace('#import "AppDelegate.h"\n', `#import "AppDelegate.h"\n${IMPORT_STATEMENT}\n`)
|
|
47
43
|
.replace('[[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];', '[CodePush bundleURL];');
|
|
48
44
|
}
|
|
49
|
-
|
|
50
|
-
function modifySwiftAppDelegate(appDelegateContent) {
|
|
45
|
+
export function modifySwiftAppDelegate(appDelegateContent) {
|
|
51
46
|
const CODEPUSH_CALL_STATEMENT = 'CodePush.bundleURL()';
|
|
52
47
|
if (appDelegateContent.includes(CODEPUSH_CALL_STATEMENT)) {
|
|
53
48
|
console.log('log: AppDelegate.swift already configured for CodePush.');
|
|
54
49
|
return appDelegateContent;
|
|
55
50
|
}
|
|
56
|
-
|
|
57
51
|
return appDelegateContent
|
|
58
52
|
.replace('Bundle.main.url(forResource: "main", withExtension: "jsbundle")', CODEPUSH_CALL_STATEMENT);
|
|
59
53
|
}
|
|
60
|
-
|
|
61
54
|
async function setupObjectiveC(appDelegatePath) {
|
|
62
55
|
const appDelegateContent = fs.readFileSync(appDelegatePath, 'utf-8');
|
|
63
56
|
const newContent = modifyObjectiveCAppDelegate(appDelegateContent);
|
|
64
57
|
fs.writeFileSync(appDelegatePath, newContent);
|
|
65
58
|
console.log('log: Successfully updated AppDelegate.m/mm.');
|
|
66
59
|
}
|
|
67
|
-
|
|
68
60
|
async function setupSwift(appDelegatePath, projectDir, projectName) {
|
|
69
61
|
const bridgingHeaderPath = await ensureBridgingHeader(projectDir, projectName);
|
|
70
62
|
if (!bridgingHeaderPath) {
|
|
71
63
|
console.log('log: Failed to create or find bridging header.');
|
|
72
64
|
return;
|
|
73
65
|
}
|
|
74
|
-
|
|
75
66
|
const appDelegateContent = fs.readFileSync(appDelegatePath, 'utf-8');
|
|
76
67
|
const newContent = modifySwiftAppDelegate(appDelegateContent);
|
|
77
68
|
fs.writeFileSync(appDelegatePath, newContent);
|
|
78
69
|
console.log('log: Successfully updated AppDelegate.swift.');
|
|
79
70
|
}
|
|
80
|
-
|
|
81
71
|
async function ensureBridgingHeader(projectDir, projectName) {
|
|
82
72
|
const projectPath = path.join(projectDir, `${projectName}.xcodeproj`, 'project.pbxproj');
|
|
83
73
|
const myProj = xcode.project(projectPath);
|
|
84
|
-
|
|
85
74
|
return new Promise((resolve, reject) => {
|
|
86
75
|
myProj.parse(function (err) {
|
|
87
76
|
if (err) {
|
|
88
77
|
console.error(`Error parsing Xcode project: ${err}`);
|
|
89
78
|
return reject(err);
|
|
90
79
|
}
|
|
91
|
-
|
|
92
80
|
const bridgingHeaderRelativePath = `${projectName}/${projectName}-Bridging-Header.h`;
|
|
93
81
|
const bridgingHeaderAbsolutePath = path.join(projectDir, bridgingHeaderRelativePath);
|
|
94
|
-
|
|
95
82
|
const configurations = myProj.pbxXCBuildConfigurationSection();
|
|
96
83
|
for (const name in configurations) {
|
|
97
84
|
const config = configurations[name];
|
|
@@ -99,30 +86,23 @@ async function ensureBridgingHeader(projectDir, projectName) {
|
|
|
99
86
|
config.buildSettings.SWIFT_OBJC_BRIDGING_HEADER = `"${bridgingHeaderRelativePath}"`;
|
|
100
87
|
}
|
|
101
88
|
}
|
|
102
|
-
|
|
103
89
|
if (!fs.existsSync(bridgingHeaderAbsolutePath)) {
|
|
104
90
|
fs.mkdirSync(path.dirname(bridgingHeaderAbsolutePath), { recursive: true });
|
|
105
91
|
fs.writeFileSync(bridgingHeaderAbsolutePath, '#import <CodePush/CodePush.h>\n');
|
|
106
92
|
console.log(`log: Created bridging header at ${bridgingHeaderAbsolutePath}`);
|
|
107
93
|
const groupKey = myProj.findPBXGroupKey({ name: projectName });
|
|
108
94
|
myProj.addHeaderFile(bridgingHeaderRelativePath, { public: true }, groupKey);
|
|
109
|
-
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
110
97
|
const headerContent = fs.readFileSync(bridgingHeaderAbsolutePath, 'utf-8');
|
|
111
98
|
if (!headerContent.includes('#import <CodePush/CodePush.h>')) {
|
|
112
99
|
fs.appendFileSync(bridgingHeaderAbsolutePath, '\n#import <CodePush/CodePush.h>\n');
|
|
113
100
|
console.log(`log: Updated bridging header at ${bridgingHeaderAbsolutePath}`);
|
|
114
101
|
}
|
|
115
102
|
}
|
|
116
|
-
|
|
117
103
|
fs.writeFileSync(projectPath, myProj.writeSync());
|
|
118
104
|
console.log('log: Updated Xcode project with bridging header path.');
|
|
119
105
|
resolve(bridgingHeaderAbsolutePath);
|
|
120
106
|
});
|
|
121
107
|
});
|
|
122
108
|
}
|
|
123
|
-
|
|
124
|
-
module.exports = {
|
|
125
|
-
initIos: initIos,
|
|
126
|
-
modifyObjectiveCAppDelegate: modifyObjectiveCAppDelegate,
|
|
127
|
-
modifySwiftAppDelegate: modifySwiftAppDelegate,
|
|
128
|
-
}
|
|
@@ -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 };
|