Skip to content

Commit 70785e3

Browse files
hramosfacebook-github-bot
authored andcommitted
generate-specs-cli: Parse arguments using yargs
Summary: Make `generate-specs-cli.js` use named arguments. Updated all `generate-specs-cli.js` callsites to make use of named arguments. Changelog: [Internal] Reviewed By: sota000 Differential Revision: D31908041 fbshipit-source-id: f2cb5967db3c3b847e1095e35e8d5d21585be27b
1 parent 58c9d8e commit 70785e3

6 files changed

Lines changed: 59 additions & 18 deletions

File tree

packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTask.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,15 @@ abstract class GenerateCodegenArtifactsTask : Exec() {
6868
windowsAwareYarn(
6969
*nodeExecutableAndArgs.get().toTypedArray(),
7070
reactRoot.file("scripts/generate-specs-cli.js").get().asFile.absolutePath,
71+
"--platform",
7172
"android",
73+
"--schemaPath",
7274
generatedSchemaFile.get().asFile.absolutePath,
75+
"--outputDir",
7376
generatedSrcDir.get().asFile.absolutePath,
77+
"--libraryName",
7478
libraryName.get(),
79+
"--javaPackageName",
7580
codegenJavaPackageName.get()))
7681
}
7782
}

packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTaskTest.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,15 @@ class GenerateCodegenArtifactsTaskTest {
100100
"yarn",
101101
"--verbose",
102102
File(reactRoot, "scripts/generate-specs-cli.js").toString(),
103+
"--platform",
103104
"android",
105+
"--schemaPath",
104106
File(outputDir, "schema.json").toString(),
107+
"--outputDir",
105108
outputDir.toString(),
109+
"--libraryName",
106110
"example-test",
111+
"--javaPackageName",
107112
"com.example.test",
108113
),
109114
task.commandLine.toMutableList())

packages/rn-tester/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ SPEC CHECKSUMS:
881881
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
882882
DoubleConversion: 831926d9b8bf8166fd87886c4abab286c2422662
883883
FBLazyVector: b81a2b70c72d8b0aefb652cea22c11e9ffd02949
884-
FBReactNativeSpec: 8c199be18a891a49a1e24b3501e953a51311a46c
884+
FBReactNativeSpec: c72b6aa43f36a4bfa45376f24ac5d10339070635
885885
Flipper: 30e8eeeed6abdc98edaf32af0cda2f198be4b733
886886
Flipper-Boost-iOSX: fd1e2b8cbef7e662a122412d7ac5f5bea715403c
887887
Flipper-DoubleConversion: 57ffbe81ef95306cc9e69c4aa3aeeeeb58a6a28c
@@ -923,10 +923,10 @@ SPEC CHECKSUMS:
923923
React-RCTTest: 12bbd7fc2e72bd9920dc7286c5b8ef96639582b6
924924
React-RCTText: e9146b2c0550a83d1335bfe2553760070a2d75c7
925925
React-RCTVibration: 50be9c390f2da76045ef0dfdefa18b9cf9f35cfa
926-
React-rncore: f592388ccb12d9317609bdb1d8dda236e6c0a2be
926+
React-rncore: 95c628b2be148269a3189ad1c9f4390b6c73a7d7
927927
React-runtimeexecutor: 4b0c6eb341c7d3ceb5e2385cb0fdb9bf701024f3
928928
ReactCommon: 7a2714d1128f965392b6f99a8b390e3aa38c9569
929-
ScreenshotManager: dd14e8064e4e3e84c7f568431c8439cb7c1df81e
929+
ScreenshotManager: 965ca5b82e28f0d7baac83c275521770407c60a4
930930
Yoga: c0d06f5380d34e939f55420669a60fe08b79bd75
931931
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
932932

scripts/generate-artifacts.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ function main(appRootDir) {
178178
RN_ROOT,
179179
'scripts',
180180
'generate-specs-cli.js',
181-
)} ios ${pathToSchema} ${pathToTempOutputDir} ${library.config.name}`,
181+
)} --platform ios --schemaPath ${pathToSchema} --outputDir ${pathToTempOutputDir} --libraryName ${
182+
library.config.name
183+
}`,
182184
);
183185
fs.mkdirSync(pathToOutputDirIOS, {recursive: true});
184186
execSync(`cp -R ${pathToTempOutputDir}/* ${pathToOutputDirIOS}`);

scripts/generate-specs-cli.js

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,42 @@ try {
2222
const fs = require('fs');
2323
const mkdirp = require('mkdirp');
2424
const path = require('path');
25+
const yargs = require('yargs');
26+
27+
const argv = yargs
28+
.option('p', {
29+
alias: 'platform',
30+
describe: 'Platform to generate native code artifacts for.',
31+
})
32+
.option('s', {
33+
alias: 'schemaPath',
34+
describe: 'The path to the schema file.',
35+
})
36+
.option('o', {
37+
alias: 'outputDir',
38+
describe:
39+
'Path to directory where native code source files should be saved.',
40+
})
41+
.option('n', {
42+
alias: 'libraryName',
43+
describe: 'Name of specs library.',
44+
default: 'FBReactNativeSpec',
45+
})
46+
.option('j', {
47+
alias: 'javaPackageName',
48+
describe: 'Name of Java package.',
49+
default: 'com.facebook.fbreact.specs',
50+
})
51+
.option('t', {
52+
alias: 'libraryType',
53+
describe: 'all, components, or modules.',
54+
default: 'all',
55+
})
56+
.usage('Usage: $0 <args>')
57+
.demandOption(
58+
['platform', 'schemaPath', 'outputDir'],
59+
'Please provide platform, schema path, and output directory.',
60+
).argv;
2561

2662
const GENERATORS = {
2763
all: {
@@ -97,20 +133,13 @@ function generateSpec(
97133
}
98134

99135
function main() {
100-
const args = process.argv.slice(2);
101-
const platform = args[0];
102-
const schemaPath = args[1];
103-
const outputDir = args[2];
104-
const libraryName = args[3] || 'FBReactNativeSpec';
105-
const javaPackageName = args[4] || 'com.facebook.fbreact.specs';
106-
const libraryType = args[5] || 'all'; // all, components, or modules
107136
generateSpec(
108-
platform,
109-
schemaPath,
110-
outputDir,
111-
libraryName,
112-
javaPackageName,
113-
libraryType,
137+
argv.platform,
138+
argv.schemaPath,
139+
argv.outputDir,
140+
argv.libraryName,
141+
argv.javaPackageName,
142+
argv.libraryType,
114143
);
115144
}
116145

scripts/react_native_pods.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def use_react_native_codegen!(spec, options={})
436436
generateCodegenArtifactsFromSchema () {
437437
describe "Generating codegen artifacts from schema"
438438
pushd "$RN_DIR" >/dev/null || exit 1
439-
"$NODE_BINARY" "scripts/generate-specs-cli.js" ios "$GENERATED_SCHEMA_FILE" "$TEMP_OUTPUT_DIR" "$LIBRARY_NAME" "" "$LIBRARY_TYPE"
439+
"$NODE_BINARY" "scripts/generate-specs-cli.js" --platform ios --schemaPath "$GENERATED_SCHEMA_FILE" --outputDir "$TEMP_OUTPUT_DIR" --libraryName "$LIBRARY_NAME" --libraryType "$LIBRARY_TYPE"
440440
popd >/dev/null || exit 1
441441
}
442442

0 commit comments

Comments
 (0)