Skip to content

Commit 096cb20

Browse files
author
Chris Brody
authored
Merge pull request #9 from brodybits/0.4.0-updates
0.4.0 updates
2 parents 60f6c3c + b0bbabf commit 096cb20

8 files changed

Lines changed: 226 additions & 114 deletions

File tree

README.md

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,30 @@ Usage: create-react-native-module [options] <name>
6060
6161
Options:
6262
63-
--help output usage information
64-
--prefix <prefix> The prefix for the library (Default: ``)
63+
-V, --version output the version number
64+
--prefix <prefix> The prefix for the library module (Default: ``)
6565
--module-name <moduleName> The module library package name to be used in package.json. Default: react-native-(name in param-case)
66-
--module-prefix <modulePrefix> The module prefix for the library, ignored if --module-name is specified (Default: `react-native`)
66+
--module-prefix <modulePrefix> The module prefix for the library module, ignored if --module-name is specified (Default: `react-native`)
6767
--package-identifier <packageIdentifier> (Android only!) The package name for the Android module (Default: `com.reactlibrary`)
68-
--platforms <platforms> Platforms the library will be created for. (comma separated; default: `ios,android`)
69-
--github-account <github_account> The github account where the library is hosted (Default: `github_account`)
70-
--author-name <name> The author's name (Default: `Your Name`)
71-
--author-email <email> The author's email (Default: `yourname@email.com`)
72-
--license <license> The license type of this library (Default: `Apache-2.0`)
73-
--view Generate the module as a very simple native view component (Default: `false`)
74-
--generate-example <shouldGenerate> Generate an example project and links the library module to it, requires both react-native-cli and yarn to be installed globally (Default: `false`)
68+
--platforms <platforms> Platforms the library module will be created for - comma separated (Default: `ios,android`)
69+
--github-account <githubAccount> The github account where the library module is hosted (Default: `github_account`)
70+
--author-name <authorName> The author's name (Default: `Your Name`)
71+
--author-email <authorEmail> The author's email (Default: `yourname@email.com`)
72+
--license <license> The license type (Default: `Apache-2.0`)
73+
--view Generate the module as a very simple native view component
74+
--generate-example Generate an example project and links the library module to it, requires both react-native-cli and yarn to be installed globally
75+
-h, --help output usage information
7576
```
7677

7778
## Programmatic usage
7879

7980
```javascript
80-
const createLibrary = require('create-react-native-module');
81+
const createLibraryModule = require('create-react-native-module');
8182

82-
createLibrary({
83-
name: 'MyFancyLibrary'
83+
createLibraryModule({
84+
name: 'MyFancyLibraryModule'
8485
}).then(() => {
85-
console.log('Oh yay! My library has been created!');
86+
console.log('Oh yay! My library module has been created!');
8687
})
8788
```
8889

@@ -91,7 +92,7 @@ createLibrary({
9192
```javascript
9293
{
9394
name: String, /* The name of the library (Default: Library) */
94-
prefix: String, /* The prefix for the library (Default: RN) */
95+
prefix: String, /* The prefix for the library (Default: ``) */
9596
moduleName: String, /* The module library package name to be used in package.json. Default: react-native-(name in param-case) */
9697
modulePrefix: String, /* The module prefix for the library, ignored if moduleName is specified (Default: react-native) */
9798
platforms: Array, /* Platforms the library will be created for. (Default: ['ios', 'android']) */
@@ -100,15 +101,11 @@ createLibrary({
100101
authorName: String, /* The author's name (Default: `Your Name`) */
101102
authorEmail: String, /* The author's email (Default: `yourname@email.com`) */
102103
license: String, /* The license type of this library (Default: `Apache-2.0`) */
103-
view: Boolean, /* Generate the module as a very simple native view component (Default: `false`) */
104-
generateExample: Boolean, /* Generate an example project and links the library module to it, requires both react-native-cli and yarn to be installed globally (Default: `false`) */
104+
view: Boolean, /* Generate the module as a very simple native view component (Default: false) */
105+
generateExample: Boolean, /* Generate an example project and links the library module to it, requires both react-native-cli and yarn to be installed globally (Default: false) */
105106
}
106107
```
107108

108-
## SOME KNOWN ISSUES
109-
110-
- CLI does not show the correct path of the generated library module
111-
112109
## Behavior not tested or supported
113110

114111
- Windows platform support
@@ -123,7 +120,7 @@ __Create the module with no view:__
123120
create-react-native-module --prefix CB --package-identifier io.mylibrary --generate-example AliceHelper
124121
```
125122

126-
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`. (Note that this tool will show an incorrect project name when it is finished.)
123+
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`.
127124

128125
Then go into the example app subdirectory:
129126

@@ -182,7 +179,7 @@ __Create the module with an extremely simple view:__
182179
create-react-native-module --prefix CB --package-identifier io.mylibrary --view --generate-example CarolWidget
183180
```
184181

185-
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`. (Note that this tool will show an incorrect project name when it is finished.)
182+
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`.
186183

187184
Then go into the example app subdirectory:
188185

cli.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const pkg = require('./package.json');
99
updateNotifier({ pkg }).notify();
1010

1111
program
12+
.version(pkg.version)
1213
.usage(command.usage)
1314
.description(command.description)
1415
.action(function runAction () {

command.js

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const emoji = require('node-emoji');
22

3-
const createLibrary = require('./lib');
3+
const normalizedOptions = require('./normalized-options');
4+
5+
const createLibraryModule = require('./lib');
46

57
module.exports = {
68
name: 'create-library',
@@ -21,7 +23,14 @@ module.exports = {
2123
const generateExample = options.generateExample;
2224

2325
const beforeCreation = Date.now();
24-
createLibrary({
26+
27+
// NOTE: There is a trick where the new normalizedOptions()
28+
// from normalized-options.js is applied by both command.js & lib.js.
29+
// This is to ensure that the CLI gets the correct module name for the
30+
// final log message, and that the exported programmatic
31+
// function can be completely tested from using the CLI.
32+
33+
const createOptions = normalizedOptions({
2534
name,
2635
prefix,
2736
moduleName,
@@ -34,13 +43,17 @@ module.exports = {
3443
license,
3544
view,
3645
generateExample,
37-
}).then(() => {
46+
});
47+
48+
const rootModuleName = createOptions.moduleName;
49+
50+
createLibraryModule(createOptions).then(() => {
3851
console.log(`
39-
${emoji.get('books')} Created library module ${name} in \`./${name}\`.
52+
${emoji.get('books')} Created library module ${rootModuleName} in \`./${rootModuleName}\`.
4053
${emoji.get('clock9')} It took ${Date.now() - beforeCreation}ms.
41-
${emoji.get('arrow_right')} To get started type \`cd ./${name}\` and run \`npm install\``);
54+
${emoji.get('arrow_right')} To get started type \`cd ./${rootModuleName}\` and run \`npm install\``);
4255
}).catch((err) => {
43-
console.error(`Error while creating library module ${name}`);
56+
console.error(`Error while creating library module ${rootModuleName}`);
4457

4558
if (err.stack) {
4659
console.error(err.stack);
@@ -49,44 +62,44 @@ ${emoji.get('arrow_right')} To get started type \`cd ./${name}\` and run \`npm
4962
},
5063
options: [{
5164
command: '--prefix [prefix]',
52-
description: 'The prefix for the library module (Default: ``)',
65+
description: 'The prefix for the library module',
5366
default: '',
5467
}, {
5568
command: '--module-name [moduleName]',
5669
description: 'The module library package name to be used in package.json. Default: react-native-(name in param-case)',
5770
}, {
5871
command: '--module-prefix [modulePrefix]',
59-
description: 'The module prefix for the library module, ignored if --module-name is specified (Default: `react-native`)',
72+
description: 'The module prefix for the library module, ignored if --module-name is specified',
6073
default: 'react-native',
6174
}, {
6275
command: '--package-identifier [packageIdentifier]',
63-
description: '(Android only!) The package name for the Android module (Default: `com.reactlibrary`)',
76+
description: '(Android only!) The package name for the Android module',
6477
default: 'com.reactlibrary',
6578
}, {
6679
command: '--platforms <platforms>',
67-
description: 'Platforms the library module will be created for. (comma separated; default: `ios,android`)',
80+
description: 'Platforms the library module will be created for - comma separated',
6881
default: 'ios,android',
6982
}, {
7083
command: '--github-account [githubAccount]',
71-
description: 'The github account where the library module is hosted (Default: `github_account`)',
84+
description: 'The github account where the library module is hosted',
7285
default: 'github_account',
7386
}, {
7487
command: '--author-name [authorName]',
75-
description: 'The author\'s name (Default: `Your Name`)',
88+
description: 'The author\'s name',
7689
default: 'Your Name',
7790
}, {
7891
command: '--author-email [authorEmail]',
79-
description: 'The author\'s email (Default: `yourname@email.com`)',
92+
description: 'The author\'s email',
8093
default: 'yourname@email.com',
8194
}, {
8295
command: '--license [license]',
83-
description: 'The license type (Default: `Apache-2.0`)',
96+
description: 'The license type',
8497
default: 'Apache-2.0',
8598
}, {
8699
command: '--view',
87-
description: 'Generate the module as a very simple native view component (Default: `false`)',
100+
description: 'Generate the module as a very simple native view component',
88101
}, {
89102
command: '--generate-example',
90-
description: 'Generate an example project and links the library module to it, requires both react-native-cli and yarn to be installed globally (Default: `false`)',
103+
description: 'Generate an example project and links the library module to it, requires both react-native-cli and yarn to be installed globally',
91104
}]
92105
};

0 commit comments

Comments
 (0)