Skip to content
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

refactor!: rename some options #431

Merged
merged 12 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all 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: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ 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> [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)
--github-account <githubAccount> The github account where the library module is hosted (Default: `github_account`)
Expand All @@ -109,7 +109,7 @@ Options:
--generate-example Generate an example project and add the library module to it with symlink by defult, with overwrite of example metro.config.js to add workaround for Metro symlink issue - requires Yarn to be installed globally
--example-file-linkage DEPRECATED: do `yarn add file:../` instead of `yarn add link:../` in a generated example project, and add a postinstall workaround script, with no overwrite of example metro.config.js
--example-name <exampleName> Name for the example project (default: `example`)
--example-react-native-version <version> React Native template version for the generated example project, for example: react-native-tvos or react-native-tvos@0.62.2-1 (requires --tvos-enabled option); react-native@0.62 (default: `react-native@latest`)
--example-react-native-template <...> The React Native template used for the generated example project, for example: react-native-tvos or react-native-tvos@0.62.2-1 (requires --tvos-enabled option); react-native@0.62 (default: `react-native@latest`)
--write-example-podfile [iOS] EXPERIMENTAL FEATURE NOT SUPPORTED: write (or overwrite) example ios/Podfile
-h, --help output usage information
```
Expand All @@ -131,13 +131,13 @@ 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, /* [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) */
githubAccount: String, /* The github account where the library is hosted (Default: `github_account`) */
authorName: String, /* The author's name (Default: `Your Name`) */
Expand All @@ -147,7 +147,7 @@ createLibraryModule({
generateExample: Boolean, /* Generate an example project and add the library module to it with symlink by defult, with overwrite of example metro.config.js to add workaround for Metro symlink issue - requires Yarn to be installed globally (Default: false) */
exampleFileLinkage: Boolean, /* DEPRECATED: do `yarn add file:../` instead of `yarn add link:../` in a generated example project, and add a postinstall workaround script, with no overwrite of example metro.config.js (Default: false) */
exampleName: String, /* Name for the example project (Default: `example`) */
exampleReactNativeVersion: String, /* React Native template version for the generated example project, for example: react-native-tvos or react-native-tvos@0.62.2-1 (requires --tvos-enabled option); react-native@0.62 (Default: `react-native@latest`) */
exampleReactNativeTemplate: String, /* The React Native template used for the generated example project, for example: react-native-tvos or react-native-tvos@0.62.2-1 (requires --tvos-enabled option); react-native@0.62 (Default: `react-native@latest`) */
writeExamplePodfile: Boolean, /* [iOS] EXPERIMENTAL FEATURE NOT SUPPORTED: write (or overwrite) example ios/Podfile (Default: false) */
}
```
Expand All @@ -159,7 +159,7 @@ createLibraryModule({
__Create the module with no view:__

```console
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 @@ -234,7 +234,7 @@ The example app shows the following indications:
__Create the module with an extremely simple view:__

```console
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
30 changes: 15 additions & 15 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} yarn ${platform} # for React Native 0.60: npx 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(() => {
info(`
Expand All @@ -84,8 +84,8 @@ ${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',
Expand All @@ -101,8 +101,8 @@ ${postCreateInstructions(createOptions)}`);
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: '[Android] The native Java package identifier used for Android',
default: 'com.reactlibrary',
}, {
command: '--platforms <platforms>',
Expand Down Expand Up @@ -141,8 +141,8 @@ ${postCreateInstructions(createOptions)}`);
description: 'Name for the example project',
default: 'example',
}, {
command: '--example-react-native-version [exampleReactNativeVersion]',
description: 'React Native template version for the generated example project, for example: react-native-tvos or react-native-tvos@0.62.2-1 (requires --tvos-enabled option); react-native@0.62',
command: '--example-react-native-template [exampleReactNativeTemplate]',
description: 'The React Native template used for the generated example project, for example: react-native-tvos or react-native-tvos@0.62.2-1 (requires --tvos-enabled option); react-native@0.62',
default: 'react-native@latest',
}, {
command: '--write-example-podfile',
Expand Down
72 changes: 35 additions & 37 deletions lib/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ 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';
const DEFAULT_AUTHOR_EMAIL = 'yourname@email.com';
const DEFAULT_LICENSE = 'MIT';
const DEFAULT_GENERATE_EXAMPLE = false;
const DEFAULT_EXAMPLE_NAME = 'example';
const DEFAULT_EXAMPLE_REACT_NATIVE_VERSION = 'react-native@latest';
const DEFAULT_EXAMPLE_REACT_NATIVE_TEMPLATE = 'react-native@latest';

const renderTemplateIfValid = (fs, root, template, templateArgs) => {
// avoid throwing an exception in case there is no valid template.name member
Expand Down Expand Up @@ -68,10 +68,10 @@ 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 @@ -86,15 +86,15 @@ const generateWithNormalizedOptions = ({
generateExample = DEFAULT_GENERATE_EXAMPLE,
exampleFileLinkage = false,
exampleName = DEFAULT_EXAMPLE_NAME,
exampleReactNativeVersion = DEFAULT_EXAMPLE_REACT_NATIVE_VERSION,
exampleReactNativeTemplate = DEFAULT_EXAMPLE_REACT_NATIVE_TEMPLATE,
writeExamplePodfile = false,
}, {
fs = fsExtra, // (this can be mocked out for testing purposes)
execa = execaDefault, // (this can be mocked out for testing purposes)
reactNativeInit = reactNativeInitDefault // (can be overridden or 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 @@ -105,28 +105,27 @@ const generateWithNormalizedOptions = ({
info(
`CREATE new React Native module with the following options:

name: ${name}
root moduleName
(full package name): ${moduleName}
is view: ${view}
object class name prefix: ${prefix}
object class name: ${objectClassName}
library modulePrefix: ${modulePrefix}
Android packageIdentifier: ${packageIdentifier}
platforms: ${platforms}
Apple tvosEnabled: ${tvosEnabled}
authorName: ${authorName}
authorEmail: ${authorEmail}
author githubAccount: ${githubAccount}
license: ${license}
useAppleNetworking: ${useAppleNetworking}
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}
authorName: ${authorName}
authorEmail: ${authorEmail}
author githubAccount: ${githubAccount}
license: ${license}
useAppleNetworking: ${useAppleNetworking}
` + (generateExample
? `
generateExample: ${generateExample}
exampleFileLinkage: ${exampleFileLinkage}
exampleName: ${exampleName}
exampleReactNativeVersion: ${exampleReactNativeVersion}
writeExamplePodfile: ${writeExamplePodfile}
generateExample: ${generateExample}
exampleFileLinkage: ${exampleFileLinkage}
exampleName: ${exampleName}
exampleReactNativeTemplate: ${exampleReactNativeTemplate}
writeExamplePodfile: ${writeExamplePodfile}
` : ``));

// QUICK LOCAL INJECTION overwite of existing execSync / commandSync call from
Expand All @@ -153,7 +152,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 @@ -162,9 +161,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 @@ -178,7 +177,7 @@ exampleReactNativeVersion: ${exampleReactNativeVersion}
useAppleNetworking,
};

return renderTemplateIfValid(fs, moduleName, template, templateArgs);
return renderTemplateIfValid(fs, packageName, template, templateArgs);
}));
});
};
Expand All @@ -187,29 +186,28 @@ exampleReactNativeVersion: ${exampleReactNativeVersion}
// multiple test or sample apps in the future.
const generateExampleApp =
() => {
// TODO: rename --example-react-native-version to --example-react-native-template
info(`CREATE example app with the following template: ${exampleReactNativeVersion}`);
info(`CREATE example app with the following template: ${exampleReactNativeTemplate}`);

// resolve **absolute** module & example paths before
// react-native-init-func function call
// which may affect the process cwd state
// (absolute paths seem to be needed for the steps below function properly)
const modulePath = path.resolve('.', moduleName);
const modulePath = path.resolve('.', packageName);
const pathExampleApp = path.join(modulePath, exampleName);
const exampleAppSubdirectory = path.join('.', moduleName, exampleName);
const exampleAppSubdirectory = path.join('.', packageName, exampleName);

// (with the work done in a promise chain)
return Promise.resolve()
.then(() => {
return reactNativeInit([exampleName], {
template: exampleReactNativeVersion,
template: exampleReactNativeTemplate,
directory: exampleAppSubdirectory
});
})
.then(() => {
// Render the example template
const templateArgs = {
moduleName,
packageName,
objectClassName,
view,
useAppleNetworking,
Expand Down
6 changes: 3 additions & 3 deletions lib/normalized-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { pascalCase } = require('pascal-case');
const DEFAULT_MODULE_PREFIX = 'react-native';

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

const prefix = options.prefix || '';

Expand All @@ -23,9 +23,9 @@ module.exports = (options) => {
return Object.assign(
{ name, prefix, modulePrefix },
options,
moduleName
packageName
? {}
: { moduleName: `${modulePrefix}-${paramCase(name)}` },
: { packageName: `${modulePrefix}-${paramCase(name)}` },
objectClassName
? {}
: { objectClassName: `${prefix}${pascalCase(name)}` },
Expand Down
Loading