Skip to content

refactor!: rename & remove multiple options #377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,10 @@ Usage: create-react-native-module [options] <name>
Options:

-V, --version output the version number
--module-name <moduleName> The module package name to be used in package.json. Default: react-native-(name in param-case)
--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`)
--package-identifier <packageIdentifier> [Android] The Java package identifier used by the Android module (Default: `com.reactlibrary`)
--native-package-id <nativePackageId> The Java package identifier used by the Android module (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)
--github-account <githubAccount> The github account where the library module is hosted (Default: `github_account`)
Expand Down Expand Up @@ -126,13 +124,11 @@ createLibraryModule({
```javascript
{
name: String, /* The name of the library (mandatory) */
moduleName: String, /* The module package name to be used in package.json. Default: react-native-(name in param-case) */
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']) */
packageIdentifier: String, /* [Android] The Java package identifier used by the Android module (Default: com.reactlibrary) */
nativePackageId: String, /* The Java package identifier used by the Android module (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) */
githubAccount: String, /* The github account where the library is hosted (Default: `github_account`) */
authorName: String, /* The author's name (Default: `Your Name`) */
Expand All @@ -154,7 +150,7 @@ createLibraryModule({
__Create the module with no view:__

```
create-react-native-module --prefix CB --package-identifier io.mylibrary --generate-example AliceHelper
create-react-native-module --prefix CB --native-package-id 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 @@ -225,7 +221,7 @@ The example app shows the following indications:
__Create the module with an extremely simple view:__

```
create-react-native-module --prefix CB --package-identifier io.mylibrary --view --generate-example CarolWidget
create-react-native-module --prefix CB --native-package-id 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
34 changes: 13 additions & 21 deletions lib/cli-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const normalizedOptions = require('./normalized-options');
const createLibraryModule = require('./lib');

const postCreateInstructions = ({
moduleName,
packageName,
platforms,
generateExample,
exampleName
Expand All @@ -18,21 +18,21 @@ const postCreateInstructions = ({
YOU'RE ALL SET!
` + (generateExample
? `
${emoji.get('bulb')} check out the example app in ${moduleName}/${exampleName}
${emoji.get('bulb')} check out the example app in ${packageName}/${exampleName}
${emoji.get('bulb')} recommended: run Metro Bundler in a new shell
${logSymbols.info} (cd ${moduleName}/${exampleName} && yarn start)
${logSymbols.info} (cd ${packageName}/${exampleName} && yarn start)
${emoji.get('bulb')} enter the following commands to run the example app:
${logSymbols.info} cd ${moduleName}/${exampleName}
${logSymbols.info} cd ${packageName}/${exampleName}
${platforms.split(',').map(platform =>
`${logSymbols.info} react-native run-${platform}`
).join(`
`)}
${logSymbols.warning} IMPORTANT NOTICES
${logSymbols.warning} After clean checkout, these first steps are needed:
${logSymbols.info} run Yarn in ${moduleName}/${exampleName}/ios
${logSymbols.info} (cd ${moduleName}/${exampleName} && yarn)
${logSymbols.info} do \`pod install\` for iOS in ${moduleName}/${exampleName}/ios
${logSymbols.info} cd ${moduleName}/${exampleName}
${logSymbols.info} run Yarn in ${packageName}/${exampleName}/ios
${logSymbols.info} (cd ${packageName}/${exampleName} && yarn)
${logSymbols.info} do \`pod install\` for iOS in ${packageName}/${exampleName}/ios
${logSymbols.info} cd ${packageName}/${exampleName}
${logSymbols.info} (cd ios && pod install)
${logSymbols.warning} KNOWN ISSUE with adding dependencies to the library root
${logSymbols.info} see https://github.com/brodybits/create-react-native-module/issues/308
Expand Down Expand Up @@ -68,7 +68,7 @@ module.exports = {

const createOptions = normalizedOptions(preNormalizedOptions);

const rootModuleName = createOptions.moduleName;
const rootModuleName = createOptions.packageName;

return createLibraryModule(createOptions).then(() => {
log(`
Expand All @@ -84,25 +84,17 @@ ${postCreateInstructions(createOptions)}`);
});
},
options: [{
command: '--module-name [moduleName]',
description: 'The module package name to be used in package.json. Default: react-native-(name in param-case)',
command: '--package-name [packageName]',
description: 'The full package name to be used in package.json. Default: react-native-(name in param-case)',
}, {
command: '--view',
description: 'Generate the package as a very simple native view component',
}, {
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: '--package-identifier [packageIdentifier]',
description: '[Android] The Java package identifier used by the Android module',
command: '--native-package-id [nativePackageId]',
description: 'The Java package identifier used by the Android module',
default: 'com.reactlibrary',
}, {
command: '--platforms <platforms>',
Expand Down
35 changes: 15 additions & 20 deletions lib/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const normalizedOptions = require('./normalized-options');
const templates = require('../templates');
const exampleTemplates = require('../templates/example');

const DEFAULT_PACKAGE_IDENTIFIER = 'com.reactlibrary';
const DEFAULT_NATIVE_PACKAGE_ID = 'com.reactlibrary';
const DEFAULT_PLATFORMS = ['android', 'ios'];
const DEFAULT_GITHUB_ACCOUNT = 'github_account';
const DEFAULT_AUTHOR_NAME = 'Your Name';
Expand Down Expand Up @@ -64,11 +64,9 @@ const npmAddScriptSync = (packageJsonPath, script, fs) => {

const generateWithNormalizedOptions = ({
name,
prefix, // (only needed for logging purposes in this function)
moduleName,
packageName,
objectClassName,
modulePrefix,
packageIdentifier = DEFAULT_PACKAGE_IDENTIFIER,
nativePackageId = DEFAULT_NATIVE_PACKAGE_ID,
// namespace - library API member removed since Windows platform
// is now removed (may be added back someday in the future)
// namespace,
Expand All @@ -89,8 +87,8 @@ const generateWithNormalizedOptions = ({
fs = fsExtra, // (this can be mocked out for testing purposes)
execa = execaDefault, // (this can be mocked out for testing purposes)
}) => {
if (packageIdentifier === DEFAULT_PACKAGE_IDENTIFIER) {
warn(`While \`{DEFAULT_PACKAGE_IDENTIFIER}\` is the default package
if (nativePackageId === DEFAULT_NATIVE_PACKAGE_ID) {
warn(`While \`{DEFAULT_NATIVE_PACKAGE_ID}\` is the default package
identifier, it is recommended to customize the package identifier.`);
}

Expand All @@ -102,13 +100,10 @@ const generateWithNormalizedOptions = ({
`CREATE new React Native module with the following options:

name: ${name}
root moduleName
(full package name): ${moduleName}
full package name: ${packageName}
is view: ${view}
object class name prefix: ${prefix}
object class name: ${objectClassName}
library modulePrefix: ${modulePrefix}
Android packageIdentifier: ${packageIdentifier}
Android nativePackageId: ${nativePackageId}
platforms: ${platforms}
Apple tvosEnabled: ${tvosEnabled}
authorName: ${authorName}
Expand Down Expand Up @@ -161,7 +156,7 @@ exampleReactNativeVersion: ${exampleReactNativeVersion}
info('CREATE: Generating the React Native library module');

const generateLibraryModule = () => {
return fs.ensureDir(moduleName).then(() => {
return fs.ensureDir(packageName).then(() => {
return Promise.all(templates.filter((template) => {
if (template.platform) {
return (platforms.indexOf(template.platform) >= 0);
Expand All @@ -170,9 +165,9 @@ exampleReactNativeVersion: ${exampleReactNativeVersion}
return true;
}).map((template) => {
const templateArgs = {
moduleName,
packageName,
objectClassName,
packageIdentifier,
nativePackageId,
// namespace - library API member removed since Windows platform
// is now removed (may be added back someday in the future)
// namespace,
Expand All @@ -186,7 +181,7 @@ exampleReactNativeVersion: ${exampleReactNativeVersion}
useAppleNetworking,
};

return renderTemplateIfValid(fs, moduleName, template, templateArgs);
return renderTemplateIfValid(fs, packageName, template, templateArgs);
}));
});
};
Expand All @@ -201,7 +196,7 @@ exampleReactNativeVersion: ${exampleReactNativeVersion}
info(
`CREATE example app with the following command: ${exampleReactNativeInitCommand}`);

const execOptions = { cwd: `./${moduleName}`, stdio: 'inherit' };
const execOptions = { cwd: `./${packageName}`, stdio: 'inherit' };

// (with the work done in a promise chain)
return Promise.resolve()
Expand All @@ -215,7 +210,7 @@ exampleReactNativeVersion: ${exampleReactNativeVersion}
.then(() => {
// Render the example template
const templateArgs = {
moduleName,
packageName,
objectClassName,
view,
useAppleNetworking,
Expand All @@ -226,15 +221,15 @@ exampleReactNativeVersion: ${exampleReactNativeVersion}

return Promise.all(
exampleTemplates.map((template) => {
return renderTemplateIfValid(fs, moduleName, template, templateArgs);
return renderTemplateIfValid(fs, packageName, template, templateArgs);
})
);
})
.then(() => {
// Adds and link the new library
return new Promise((resolve, reject) => {
// determine this path before the next steps:
const pathExampleApp = `./${moduleName}/${exampleName}`;
const pathExampleApp = `./${packageName}/${exampleName}`;

// postinstall workaround script *only* needed in case
// the DEPRECATED --example-file-linkage option
Expand Down
14 changes: 5 additions & 9 deletions lib/normalized-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ const { pascalCase } = require('pascal-case');
const DEFAULT_MODULE_PREFIX = 'react-native';

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

const prefix = options.prefix || '';

const modulePrefix = options.modulePrefix || DEFAULT_MODULE_PREFIX;
const { name, packageName, objectClassName } = options;

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

return Object.assign(
{ name, prefix, modulePrefix },
{ name },
options,
moduleName
packageName
? {}
: { moduleName: `${modulePrefix}-${paramCase(name)}` },
: { packageName: `${DEFAULT_MODULE_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
40 changes: 20 additions & 20 deletions templates/android.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = platform => [{
name: () => `${platform}/build.gradle`,
content: ({ packageIdentifier }) => `// ${platform}/build.gradle
content: ({ nativePackageId }) => `// ${platform}/build.gradle

// based on:
//
Expand Down Expand Up @@ -83,7 +83,7 @@ def configureReactNativePom(def pom) {
name packageJson.title
artifactId packageJson.name
version = packageJson.version
group = "${packageIdentifier}"
group = "${nativePackageId}"
description packageJson.description
url packageJson.repository.baseUrl

Expand Down Expand Up @@ -151,19 +151,19 @@ afterEvaluate { project ->
`,
}, {
name: () => `${platform}/src/main/AndroidManifest.xml`,
content: ({ packageIdentifier }) => `<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="${packageIdentifier}">
content: ({ nativePackageId }) => `<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="${nativePackageId}">

</manifest>
`,
}, {
// for module without view:
name: ({ objectClassName, packageIdentifier, view }) =>
name: ({ objectClassName, nativePackageId, view }) =>
!view &&
`${platform}/src/main/java/${packageIdentifier.split('.').join('/')}/${objectClassName}Module.java`,
content: ({ objectClassName, packageIdentifier, view }) =>
`${platform}/src/main/java/${nativePackageId.split('.').join('/')}/${objectClassName}Module.java`,
content: ({ objectClassName, nativePackageId, view }) =>
!view &&
`package ${packageIdentifier};
`package ${nativePackageId};

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
Expand Down Expand Up @@ -193,12 +193,12 @@ public class ${objectClassName}Module extends ReactContextBaseJavaModule {
`,
}, {
// manager for view:
name: ({ objectClassName, packageIdentifier, view }) =>
name: ({ objectClassName, nativePackageId, view }) =>
view &&
`${platform}/src/main/java/${packageIdentifier.split('.').join('/')}/${objectClassName}Manager.java`,
content: ({ objectClassName, packageIdentifier, view }) =>
`${platform}/src/main/java/${nativePackageId.split('.').join('/')}/${objectClassName}Manager.java`,
content: ({ objectClassName, nativePackageId, view }) =>
view &&
`package ${packageIdentifier};
`package ${nativePackageId};

import android.view.View;

Expand Down Expand Up @@ -227,12 +227,12 @@ public class ${objectClassName}Manager extends SimpleViewManager<View> {
`,
}, {
// package for module without view:
name: ({ objectClassName, packageIdentifier, view }) =>
name: ({ objectClassName, nativePackageId, view }) =>
!view &&
`${platform}/src/main/java/${packageIdentifier.split('.').join('/')}/${objectClassName}Package.java`,
content: ({ objectClassName, packageIdentifier, view }) =>
`${platform}/src/main/java/${nativePackageId.split('.').join('/')}/${objectClassName}Package.java`,
content: ({ objectClassName, nativePackageId, view }) =>
!view &&
`package ${packageIdentifier};
`package ${nativePackageId};

import java.util.Arrays;
import java.util.Collections;
Expand All @@ -257,12 +257,12 @@ public class ${objectClassName}Package implements ReactPackage {
`,
}, {
// package for manager for view:
name: ({ objectClassName, packageIdentifier, view }) =>
name: ({ objectClassName, nativePackageId, view }) =>
view &&
`${platform}/src/main/java/${packageIdentifier.split('.').join('/')}/${objectClassName}Package.java`,
content: ({ objectClassName, packageIdentifier, view }) =>
`${platform}/src/main/java/${nativePackageId.split('.').join('/')}/${objectClassName}Package.java`,
content: ({ objectClassName, nativePackageId, view }) =>
view &&
`package ${packageIdentifier};
`package ${nativePackageId};

import java.util.Arrays;
import java.util.Collections;
Expand Down
Loading