Skip to content

Commit 842e6be

Browse files
authored
refactor: migrate cli tools code to TypeScript (#91)
* refactor: migrate cli tools code to TypeScript * chore: remove unused dependencies
1 parent a65c085 commit 842e6be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+743
-1219
lines changed

.gitignore

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -77,33 +77,6 @@ build/Release
7777
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
7878
node_modules
7979

80-
# Xcode
81-
#
82-
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
83-
84-
## Build generated
85-
build/
86-
DerivedData
87-
88-
## Various settings
89-
*.pbxuser
90-
!default.pbxuser
91-
*.mode1v3
92-
!default.mode1v3
93-
*.mode2v3
94-
!default.mode2v3
95-
*.perspectivev3
96-
!default.perspectivev3
97-
xcuserdata
98-
99-
## OSX
100-
.DS_Store
101-
102-
## Other
103-
*.xccheckout
104-
*.moved-aside
105-
*.xcuserstate
106-
10780
# Intellij project files
10881
*.iml
10982
*.ipr
@@ -113,7 +86,7 @@ xcuserdata
11386
#Gradle
11487
.gradletasknamecache
11588
.gradle/
116-
build/
89+
*/build/
11790
bin/
11891

11992
# Built application files
@@ -127,14 +100,8 @@ bin/
127100
*.class
128101

129102
# Generated files
130-
bin/
131103
gen/
132104

133-
# Gradle files
134-
.gradle/
135-
build/
136-
*/build/
137-
138105
# Local configuration file (sdk path, etc)
139106
local.properties
140107

@@ -173,7 +140,6 @@ windows/obj/
173140
*.bak
174141
*.[Cc]ache
175142
*.ilk
176-
*.log
177143
*.lib
178144
*.sbr
179145
*.sdf
@@ -195,3 +161,11 @@ Examples/testapp_rn
195161

196162
# prevent CLI code ignored (ignored by "[Rr]elease*/")
197163
!cli/commands/releaseCommand/
164+
165+
# CLI TypeScript build output
166+
cli/dist/
167+
168+
# Don't ignore CLI executable
169+
!bin/
170+
bin/*
171+
!bin/code-push.js

.npmignore

Lines changed: 0 additions & 110 deletions
This file was deleted.

babel.config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
module.exports = {
2-
presets: [['@babel/preset-env', {targets: {node: 'current'}}]],
3-
};
2+
presets: [[
3+
'@babel/preset-env', {targets: {node: 'current'}}],
4+
'@babel/preset-typescript'
5+
],
6+
};

bin/code-push.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env node
2+
3+
import('../cli/dist/index.js').catch((error) => {
4+
console.error(error);
5+
process.exit(1);
6+
});

cli/commands/bundleCommand/bundleCodePush.js renamed to cli/commands/bundleCommand/bundleCodePush.ts

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
1-
const fs = require('fs');
2-
const { prepareToBundleJS } = require('../../functions/prepareToBundleJS');
3-
const { runReactNativeBundleCommand } = require('../../functions/runReactNativeBundleCommand');
4-
const { runExpoBundleCommand } = require('../../functions/runExpoBundleCommand');
5-
const { getReactTempDir } = require('../../functions/getReactTempDir');
6-
const { runHermesEmitBinaryCommand } = require('../../functions/runHermesEmitBinaryCommand');
7-
const { makeCodePushBundle } = require('../../functions/makeCodePushBundle');
8-
const { ROOT_OUTPUT_DIR, ENTRY_FILE } = require('../../constant');
1+
import fs from "fs";
2+
import { prepareToBundleJS } from "../../functions/prepareToBundleJS.js";
3+
import { runReactNativeBundleCommand } from "../../functions/runReactNativeBundleCommand.js";
4+
import { runExpoBundleCommand } from "../../functions/runExpoBundleCommand.js";
5+
import { getReactTempDir } from "../../functions/getReactTempDir.js";
6+
import { runHermesEmitBinaryCommand } from "../../functions/runHermesEmitBinaryCommand.js";
7+
import { makeCodePushBundle } from "../../functions/makeCodePushBundle.js";
8+
import { ROOT_OUTPUT_DIR, ENTRY_FILE } from "../../constant.js";
99

1010
/**
11-
* @param framework {string|undefined} 'expo'
12-
* @param platform {string} 'ios' | 'android'
13-
* @param outputRootPath {string}
14-
* @param entryFile {string}
15-
* @param jsBundleName {string|undefined}
16-
* @param bundleDirectory {string}
1711
* @return {Promise<string>} CodePush bundle file name (equals to packageHash)
1812
*/
19-
async function bundleCodePush(
20-
framework,
21-
platform = 'ios',
22-
outputRootPath = ROOT_OUTPUT_DIR,
23-
entryFile = ENTRY_FILE,
24-
jsBundleName, // JS bundle file name (not CodePush bundle file)
25-
bundleDirectory, // CodePush bundle output directory
26-
) {
13+
export async function bundleCodePush(
14+
framework: 'expo' | undefined,
15+
platform: 'ios' | 'android' = 'ios',
16+
outputRootPath: string = ROOT_OUTPUT_DIR,
17+
entryFile: string = ENTRY_FILE,
18+
jsBundleName: string, // JS bundle file name (not CodePush bundle file)
19+
bundleDirectory: string, // CodePush bundle output directory
20+
): Promise<string> {
2721
if (fs.existsSync(outputRootPath)) {
2822
fs.rmSync(outputRootPath, { recursive: true });
2923
}
@@ -67,5 +61,3 @@ async function bundleCodePush(
6761

6862
return codePushBundleFileName;
6963
}
70-
71-
module.exports = { bundleCodePush: bundleCodePush };
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
const { program, Option } = require("commander");
2-
const { bundleCodePush } = require("./bundleCodePush");
3-
const { OUTPUT_BUNDLE_DIR, ROOT_OUTPUT_DIR, ENTRY_FILE } = require('../../constant');
1+
import { program, Option } from "commander";
2+
import { bundleCodePush } from "./bundleCodePush.js";
3+
import { OUTPUT_BUNDLE_DIR, ROOT_OUTPUT_DIR, ENTRY_FILE } from "../../constant.js";
4+
5+
type Options = {
6+
framework: 'expo' | undefined;
7+
platform: 'ios' | 'android';
8+
outputPath: string;
9+
entryFile: string;
10+
bundleName: string;
11+
outputBundleDir: string;
12+
}
413

514
program.command('bundle')
615
.description('Creates a CodePush bundle file (assumes Hermes is enabled).')
@@ -10,17 +19,7 @@ program.command('bundle')
1019
.option('-e, --entry-file <string>', 'path to JS/TS entry file', ENTRY_FILE)
1120
.option('-b, --bundle-name <string>', 'bundle file name (default-ios: "main.jsbundle" / default-android: "index.android.bundle")')
1221
.option('--output-bundle-dir <string>', 'name of directory containing the bundle file created by the "bundle" command', OUTPUT_BUNDLE_DIR)
13-
/**
14-
* @param {Object} options
15-
* @param {string} options.framework
16-
* @param {string} options.platform
17-
* @param {string} options.outputPath
18-
* @param {string} options.entryFile
19-
* @param {string} options.bundleName
20-
* @param {string} options.outputBundleDir
21-
* @return {void}
22-
*/
23-
.action((options) => {
22+
.action((options: Options) => {
2423
bundleCodePush(
2524
options.framework,
2625
options.platform,

cli/commands/createHistoryCommand/createReleaseHistory.js renamed to cli/commands/createHistoryCommand/createReleaseHistory.ts

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,21 @@
1-
const fs = require('fs');
2-
const path = require('path');
1+
import fs from "fs";
2+
import path from "path";
3+
import type { CliConfigInterface, ReleaseHistoryInterface, ReleaseInfo } from "../../../typings/react-native-code-push.d.ts";
34

4-
/**
5-
*
6-
* @param targetVersion {string}
7-
* @param setReleaseHistory {
8-
* function(
9-
* targetBinaryVersion: string,
10-
* jsonFilePath: string,
11-
* releaseInfo: ReleaseHistoryInterface,
12-
* platform: string,
13-
* identifier: string
14-
* ): Promise<void>}
15-
* @param platform {"ios" | "android"}
16-
* @param identifier {string}
17-
* @returns {Promise<void>}
18-
*/
19-
async function createReleaseHistory(
20-
targetVersion,
21-
setReleaseHistory,
22-
platform,
23-
identifier,
24-
) {
25-
const BINARY_RELEASE = {
5+
export async function createReleaseHistory(
6+
targetVersion: string,
7+
setReleaseHistory: CliConfigInterface['setReleaseHistory'],
8+
platform: 'ios' | 'android',
9+
identifier?: string,
10+
): Promise<void> {
11+
const BINARY_RELEASE: ReleaseInfo = {
2612
enabled: true,
2713
mandatory: false,
2814
downloadUrl: "",
2915
packageHash: "",
3016
};
3117

32-
/** @type {ReleaseHistoryInterface} */
33-
const INITIAL_HISTORY = {
18+
const INITIAL_HISTORY: ReleaseHistoryInterface = {
3419
[targetVersion]: BINARY_RELEASE
3520
};
3621

@@ -49,5 +34,3 @@ async function createReleaseHistory(
4934
process.exit(1)
5035
}
5136
}
52-
53-
module.exports = { createReleaseHistory: createReleaseHistory }

cli/commands/createHistoryCommand/index.js renamed to cli/commands/createHistoryCommand/index.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
const { program, Option } = require("commander");
2-
const { findAndReadConfigFile } = require("../../utils/fsUtils");
3-
const { createReleaseHistory } = require("./createReleaseHistory");
4-
const { CONFIG_FILE_NAME } = require('../../constant');
1+
import { program, Option } from "commander";
2+
import { findAndReadConfigFile } from "../../utils/fsUtils.js";
3+
import { createReleaseHistory } from "./createReleaseHistory.js";
4+
import { CONFIG_FILE_NAME } from "../../constant.js";
5+
6+
type Options = {
7+
binaryVersion: string;
8+
platform: 'ios' | 'android';
9+
identifier?: string;
10+
config: string;
11+
}
512

613
program.command('create-history')
714
.description('Creates a new release history for the binary app.')
815
.requiredOption('-b, --binary-version <string>', '(Required) The target binary version')
916
.addOption(new Option('-p, --platform <type>', 'platform').choices(['ios', 'android']).default('ios'))
1017
.option('-i, --identifier <string>', 'reserved characters to distinguish the release.')
1118
.option('-c, --config <path>', 'set config file name (JS/TS)', CONFIG_FILE_NAME)
12-
/**
13-
* @param {Object} options
14-
* @param {string} options.binaryVersion
15-
* @param {string} options.platform
16-
* @param {string} options.identifier
17-
* @param {string} options.config
18-
* @return {void}
19-
*/
20-
.action(async (options) => {
19+
.action(async (options: Options) => {
2120
const config = findAndReadConfigFile(process.cwd(), options.config);
2221

2322
await createReleaseHistory(
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const { initAndroid } = require('./initAndroid');
2-
const { initIos } = require('./initIos');
3-
const { program } = require('commander');
1+
import { initAndroid } from "./initAndroid.js";
2+
import { initIos } from "./initIos.js";
3+
import { program } from "commander";
44

55
program
66
.command('init')

0 commit comments

Comments
 (0)