Skip to content

Commit

Permalink
refactor!: remove prefix options (#432)
Browse files Browse the repository at this point in the history
* refactor!: remove --prefix option
* refactor!: remove --module-prefix option
* test: remove tests with null prefix
* test: remove test with custom module prefix
* test: remove prefix option from 2 test cases
* test: update test snapshots
* docs: remove --prefix option from command-line examples
* refactor: rename internal package prefix constant
  (and remove extra const)

BREAKING CHANGE: affects anyone using the removed options
  • Loading branch information
Chris Brody authored Mar 16, 2021
1 parent 8bfc561 commit 254ab07
Show file tree
Hide file tree
Showing 25 changed files with 87 additions and 2,975 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ Options:
--package-name <packageName> The full package name to be used in package.json. Default: react-native-(name in param-case)
--view Generate the package as a very simple native view component
--object-class-name The name of the object class to be exported by both JavaScript and native code. Default: (name in PascalCase)
--prefix <prefix> DEPRECATED: The prefix of the name of the object class to be exported by both JavaScript and native code, ignored if --object-class-name is specified (Default: ``)
--module-prefix <modulePrefix> The prefix of the generated module package name, ignored if --module-name is specified (Default: `react-native`)
--native-package-id <nativePackageId> [Android] The native Java package identifier used for Android (Default: `com.reactlibrary`)
--platforms <platforms> Platforms the library module will be created for - comma separated (Default: `ios,android`)
--tvos-enabled Generate the module with tvOS build enabled (requires react-native-tvos fork, with minimum version of 0.60, and iOS platform to be enabled)
Expand Down Expand Up @@ -134,8 +132,6 @@ createLibraryModule({
packageName: String, /* The full package name to be used in package.json. Default: react-native-(name in param-case) */
view: Boolean, /* Generate the package as a very simple native view component (Default: false) */
objectClassName: String, /* The name of the object class to be exported by both JavaScript and native code. Default: (name in PascalCase) */
prefix: String, /* DEPRECATED: The prefix of the name of the object class to be exported by both JavaScript and native code, ignored if objectClassName is specified (Default: ``) */
modulePrefix: String, /* The prefix of the generated module package name, ignored if moduleName is specified (Default: `react-native`) */
platforms: Array | String, /* Platforms the library will be created for. (Default: ['android', 'ios']) */
nativePackageId: String, /* [Android] The native Java package identifier used for Android (Default: `com.reactlibrary`) */
tvosEnabled: Boolean, /* Generate the module with tvOS build enabled (requires react-native-tvos fork, with minimum version of 0.60, and iOS platform to be enabled) */
Expand All @@ -159,7 +155,7 @@ createLibraryModule({
__Create the module with no view:__

```console
create-react-native-module --prefix CB --native-package-id io.mylibrary --generate-example AliceHelper
create-react-native-module --package-identifier io.mylibrary --generate-example AliceHelper
```

The module would be generated in the `react-native-alice-helper` subdirectory, and the example test app would be in `react-native-alice-helper/example`.
Expand Down Expand Up @@ -234,7 +230,7 @@ The example app shows the following indications:
__Create the module with an extremely simple view:__

```console
create-react-native-module --prefix CB --native-package-id io.mylibrary --view --generate-example CarolWidget
create-react-native-module --package-identifier io.mylibrary --view --generate-example CarolWidget
```

The module would be generated in the `react-native-carol-widget` subdirectory, and the example test app would be in `react-native-carol-widget/example`.
Expand Down
8 changes: 0 additions & 8 deletions lib/cli-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,6 @@ ${postCreateInstructions(createOptions)}`);
}, {
command: '--object-class-name [objectClassName]',
description: 'The name of the object class to be exported by both JavaScript and native code. Default: (name in PascalCase)',
}, {
command: '--prefix [prefix]',
description: 'DEPRECATED: The prefix of the name of the object class to be exported by both JavaScript and native code, ignored if --object-class-name is specified',
default: '',
}, {
command: '--module-prefix [modulePrefix]',
description: 'The prefix of the generated module package name, ignored if --module-name is specified',
default: 'react-native',
}, {
command: '--native-package-id [nativePackageId]',
description: '[Android] The native Java package identifier used for Android',
Expand Down
4 changes: 0 additions & 4 deletions lib/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ const npmAddScriptSync = (packageJsonPath, script, fs) => {

const generateWithNormalizedOptions = ({
name,
prefix, // (only needed for logging purposes in this function)
packageName,
objectClassName,
modulePrefix,
nativePackageId = DEFAULT_NATIVE_PACKAGE_ID,
// namespace - library API member removed since Windows platform
// is now removed (may be added back someday in the future)
Expand Down Expand Up @@ -108,9 +106,7 @@ const generateWithNormalizedOptions = ({
name: ${name}
full package name: ${packageName}
is view: ${view}
object class name prefix: ${prefix}
object class name: ${objectClassName}
library modulePrefix: ${modulePrefix}
Android nativePackageId: ${nativePackageId}
platforms: ${platforms}
Apple tvosEnabled: ${tvosEnabled}
Expand Down
16 changes: 7 additions & 9 deletions lib/normalized-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@ const { paramCase } = require('param-case');

const { pascalCase } = require('pascal-case');

// TODO: refactor all defaults from here & lib.js into a new module
const DEFAULT_MODULE_PREFIX = 'react-native';
const PACKAGE_PREFIX = 'react-native';

module.exports = (options) => {
const { name, packageName, objectClassName } = options;

const prefix = options.prefix || '';

const modulePrefix = options.modulePrefix || DEFAULT_MODULE_PREFIX;

if (typeof name !== 'string') {
throw new TypeError("Please write your library's name");
}
Expand All @@ -21,14 +16,17 @@ module.exports = (options) => {
// const namespace = options.namespace;

return Object.assign(
{ name, prefix, modulePrefix },
{ name },
options,
packageName
? {}
: { packageName: `${modulePrefix}-${paramCase(name)}` },
: {
// TODO: do not add PACKAGE_PREFIX if it is not needed
packageName: `${PACKAGE_PREFIX}-${paramCase(name)}`
},
objectClassName
? {}
: { objectClassName: `${prefix}${pascalCase(name)}` },
: { objectClassName: `${pascalCase(name)}` },
// namespace - library API member removed since Windows platform
// is now removed (may be added back someday in the future)
// namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Options:
--package-name [packageName] The full package name to be used in package.json. Default: react-native-(name in param-case)
--view Generate the package as a very simple native view component
--object-class-name [objectClassName] The name of the object class to be exported by both JavaScript and native code. Default: (name in PascalCase)
--prefix [prefix] DEPRECATED: The prefix of the name of the object class to be exported by both JavaScript and native code, ignored if --object-class-name is specified (default: \\"\\")
--module-prefix [modulePrefix] The prefix of the generated module package name, ignored if --module-name is specified (default: \\"react-native\\")
--native-package-id [nativePackageId] [Android] The native Java package identifier used for Android (default: \\"com.reactlibrary\\")
--platforms <platforms> Platforms the library module will be created for - comma separated (default: \\"ios,android\\")
--tvos-enabled Generate the module with tvOS build enabled (requires react-native-tvos fork, with minimum version of 0.60, and iOS platform to be enabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Options:
--package-name [packageName] The full package name to be used in package.json. Default: react-native-(name in param-case)
--view Generate the package as a very simple native view component
--object-class-name [objectClassName] The name of the object class to be exported by both JavaScript and native code. Default: (name in PascalCase)
--prefix [prefix] DEPRECATED: The prefix of the name of the object class to be exported by both JavaScript and native code, ignored if --object-class-name is specified (default: \\"\\")
--module-prefix [modulePrefix] The prefix of the generated module package name, ignored if --module-name is specified (default: \\"react-native\\")
--native-package-id [nativePackageId] [Android] The native Java package identifier used for Android (default: \\"com.reactlibrary\\")
--platforms <platforms> Platforms the library module will be created for - comma separated (default: \\"ios,android\\")
--tvos-enabled Generate the module with tvOS build enabled (requires react-native-tvos fork, with minimum version of 0.60, and iOS platform to be enabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ Object {
"command": "--object-class-name [objectClassName]",
"description": "The name of the object class to be exported by both JavaScript and native code. Default: (name in PascalCase)",
},
Object {
"command": "--prefix [prefix]",
"default": "",
"description": "DEPRECATED: The prefix of the name of the object class to be exported by both JavaScript and native code, ignored if --object-class-name is specified",
},
Object {
"command": "--module-prefix [modulePrefix]",
"default": "react-native",
"description": "The prefix of the generated module package name, ignored if --module-name is specified",
},
Object {
"command": "--native-package-id [nativePackageId]",
"default": "com.reactlibrary",
Expand Down
Loading

0 comments on commit 254ab07

Please sign in to comment.