Skip to content

Commit c3ecad0

Browse files
author
Chris Brody
authored
Merge pull request #6 from brodybits/0.3.0-updates
0.3.0 updates
2 parents 474c2e6 + a26d8b8 commit c3ecad0

11 files changed

Lines changed: 46 additions & 70 deletions

File tree

.eslintrc.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@ rules:
66
- error
77
- always
88

9-
# TBD SKIP these rules for now:
10-
indent: 0
11-
space-before-function-paren: 0
12-
no-useless-escape: 0
13-
no-multi-spaces: 0
14-
arrow-spacing: 0
15-
space-infix-ops: 0
16-
object-curly-spacing: 0
17-
no-tabs: 0
18-
199
comma-dangle:
2010
- error
2111
- arrays: only-multiline

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ Usage: create-react-native-module [options] <name>
6060
6161
Options:
6262
63-
-h, --help output usage information
64-
-V, --version output the version number
65-
-p, --prefix <prefix> The prefix for the library (Default: `RN`)
66-
--module-prefix <modulePrefix> The module prefix for the library (Default: `react-native`)
63+
--help output usage information
64+
--prefix <prefix> The prefix for the library (Default: ``)
65+
--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`)
6767
--package-identifier <packageIdentifier> (Android only!) The package name for the Android module (Default: `com.reactlibrary`)
6868
--platforms <platforms> Platforms the library will be created for. (comma separated; default: `ios,android`)
6969
--github-account <github_account> The github account where the library is hosted (Default: `github_account`)
@@ -92,7 +92,8 @@ createLibrary({
9292
{
9393
name: String, /* The name of the library (Default: Library) */
9494
prefix: String, /* The prefix for the library (Default: RN) */
95-
modulePrefix: String, /* The module prefix for the library (Default: react-native) */
95+
moduleName: String, /* The module library package name to be used in package.json. Default: react-native-(name in param-case) */
96+
modulePrefix: String, /* The module prefix for the library, ignored if moduleName is specified (Default: react-native) */
9697
platforms: Array, /* Platforms the library will be created for. (Default: ['ios', 'android']) */
9798
packageIdentifier: String, /* (Android only!) The package name for the Android module (Default: com.reactlibrary) */
9899
githubAccount: String, /* The github account where the library is hosted (Default: `github_account`) */
@@ -107,8 +108,6 @@ createLibrary({
107108
## SOME KNOWN ISSUES
108109

109110
- CLI does not show the correct path of the generated library module
110-
- not all documented options work as documented
111-
- not all options are documented
112111

113112
## Behavior not tested or supported
114113

cli.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ updateNotifier({ pkg }).notify();
1111
program
1212
.usage(command.usage)
1313
.description(command.description)
14-
.action(function runAction() {
14+
.action(function runAction () {
1515
command.func(arguments, {}, this.opts());
1616
});
1717

1818
(command.options || [])
19-
.forEach(opt =>
20-
program.option(
19+
.forEach(opt => program.option(
2120
opt.command,
2221
opt.description,
2322
opt.parse || (value => value),

command.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ module.exports = {
99
func: (args, config, options) => {
1010
const name = args[0];
1111
const prefix = options.prefix;
12+
const moduleName = options.moduleName;
1213
const modulePrefix = options.modulePrefix;
1314
const packageIdentifier = options.packageIdentifier;
1415
const platforms = (options.platforms) ? options.platforms.split(',') : options.platforms;
15-
const overridePrefix = options.overridePrefix;
1616
const githubAccount = options.githubAccount;
1717
const authorName = options.authorName;
1818
const authorEmail = options.authorEmail;
@@ -24,10 +24,10 @@ module.exports = {
2424
createLibrary({
2525
name,
2626
prefix,
27+
moduleName,
2728
modulePrefix,
2829
packageIdentifier,
2930
platforms,
30-
overridePrefix,
3131
githubAccount,
3232
authorName,
3333
authorEmail,
@@ -49,14 +49,14 @@ ${emoji.get('arrow_right')} To get started type \`cd ./${name}\` and run \`npm
4949
},
5050
options: [{
5151
command: '--prefix [prefix]',
52-
description: 'The prefix for the library module (Default: `RN`)',
53-
default: 'RN',
52+
description: 'The prefix for the library module (Default: ``)',
53+
default: '',
5454
}, {
55-
command: '--override-prefix',
56-
description: 'Overrides the prefix check and allows the name to begin with uppercase characters',
55+
command: '--module-name [moduleName]',
56+
description: 'The module library package name to be used in package.json. Default: react-native-(name in param-case)',
5757
}, {
5858
command: '--module-prefix [modulePrefix]',
59-
description: 'The module prefix for the library module (Default: `react-native`)',
59+
description: 'The module prefix for the library module, ignored if --module-name is specified (Default: `react-native`)',
6060
default: 'react-native',
6161
}, {
6262
command: '--package-identifier [packageIdentifier]',

lib.js

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ const { hasPrefix, createFile, createFolder, npmAddScriptSync, exec } = require(
88
const { execSync } = require('child_process');
99

1010
const DEFAULT_NAME = 'Library';
11-
const DEFAULT_PREFIX = 'RN';
11+
const DEFAULT_PREFIX = '';
1212
const DEFAULT_MODULE_PREFIX = 'react-native';
1313
const DEFAULT_PACKAGE_IDENTIFIER = 'com.reactlibrary';
1414
const DEFAULT_PLATFORMS = ['android', 'ios'];
15-
const DEFAULT_OVERRIDE_PREFIX = false;
1615
const DEFAULT_GITHUB_ACCOUNT = 'github_account';
1716
const DEFAULT_AUTHOR_NAME = 'Your Name';
1817
const DEFAULT_AUTHOR_EMAIL = 'yourname@email.com';
@@ -37,37 +36,21 @@ const renderTemplate = renderTemplateIfValid;
3736
module.exports = ({
3837
name = DEFAULT_NAME,
3938
prefix = DEFAULT_PREFIX,
39+
moduleName = null,
4040
modulePrefix = DEFAULT_MODULE_PREFIX,
4141
packageIdentifier = DEFAULT_PACKAGE_IDENTIFIER,
4242
platforms = DEFAULT_PLATFORMS,
43-
overridePrefix = DEFAULT_OVERRIDE_PREFIX,
4443
githubAccount = DEFAULT_GITHUB_ACCOUNT,
4544
authorName = DEFAULT_AUTHOR_NAME,
4645
authorEmail = DEFAULT_AUTHOR_EMAIL,
4746
license = DEFAULT_LICENSE,
4847
view = false,
4948
generateExample = DEFAULT_GENERATE_EXAMPLE,
5049
}) => {
51-
if (!overridePrefix) {
52-
if (hasPrefix(name)) {
53-
throw new Error('Please don\'t include the prefix in the name');
54-
}
55-
56-
if (prefix === 'RCT') {
57-
throw new Error(`The \`RCT\` name prefix is reserved for core React modules.
58-
Please use a different prefix.`);
59-
}
60-
}
61-
6250
if (platforms.length === 0) {
6351
throw new Error('Please specify at least one platform to generate the library.');
6452
}
6553

66-
if (prefix === DEFAULT_PREFIX) {
67-
console.warn(`While \`${DEFAULT_PREFIX}\` is the default prefix,
68-
it is recommended to customize the prefix.`);
69-
}
70-
7154
if (packageIdentifier === DEFAULT_PACKAGE_IDENTIFIER) {
7255
console.warn(`While \`{DEFAULT_PACKAGE_IDENTIFIER}\` is the default package
7356
identifier, it is recommended to customize the package identifier.`);
@@ -94,9 +77,9 @@ module.exports = ({
9477
}
9578

9679
const className = `${prefix}${pascalCase(name)}`;
97-
const moduleName = `${modulePrefix}-${paramCase(name)}`;
80+
const rootName = moduleName || `${modulePrefix}-${paramCase(name)}`;
9881
const namespace = pascalCase(name).split(/(?=[A-Z])/).join('.');
99-
const rootFolderName = moduleName;
82+
const rootFolderName = rootName;
10083

10184
return createFolder(rootFolderName)
10285
.then(() => {
@@ -112,7 +95,7 @@ module.exports = ({
11295
}
11396
const templateArgs = {
11497
name: className,
115-
moduleName,
98+
moduleName: rootName,
11699
packageIdentifier,
117100
namespace,
118101
platforms,
@@ -141,7 +124,7 @@ module.exports = ({
141124

142125
const templateArgs = {
143126
name: className,
144-
moduleName,
127+
moduleName: rootName,
145128
view,
146129
};
147130

templates/.eslintrc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
rules:
2+
no-tabs: 0
3+
no-useless-escape: 0

templates/android.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = platform => [{
99
dependencies {
1010
// Matches the RN Hello World template
1111
// https://github.com/facebook/react-native/blob/1e8f3b11027fe0a7514b4fc97d0798d3c64bc895/local-cli/templates/HelloWorld/android/build.gradle#L8
12-
classpath 'com.android.tools.build:gradle:3.3.1'
12+
classpath 'com.android.tools.build:gradle:3.2.1'
1313
}
1414
}
1515
@@ -20,8 +20,8 @@ def safeExtGet(prop, fallback) {
2020
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
2121
}
2222
23-
def DEFAULT_COMPILE_SDK_VERSION = 27
24-
def DEFAULT_BUILD_TOOLS_VERSION = "27.0.3"
23+
def DEFAULT_COMPILE_SDK_VERSION = 28
24+
def DEFAULT_BUILD_TOOLS_VERSION = "28.0.2"
2525
def DEFAULT_MIN_SDK_VERSION = 16
2626
def DEFAULT_TARGET_SDK_VERSION = 27
2727

templates/example.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module.exports = [{
44
name: () => 'scripts/examples_postinstall.js',
55
content: () =>
6-
`#!/usr/bin/env node
6+
`#!/usr/bin/env node
77
88
/*
99
* Using libraries within examples and linking them within packages.json like:
@@ -118,7 +118,7 @@ module.exports = [{
118118
}, {
119119
name: () => 'example/App.js',
120120
content: ({ moduleName, name, view }) =>
121-
`/**
121+
`/**
122122
* Sample React Native App
123123
*
124124
* adapted from App.js generated by the following command:
@@ -132,7 +132,7 @@ import React, { Component } from 'react';
132132
import { Platform, StyleSheet, Text, View } from 'react-native';
133133
import ${name} from '${moduleName}';` +
134134
(!view
135-
? `
135+
? `
136136
137137
export default class App extends Component<{}> {
138138
state = {
@@ -158,7 +158,7 @@ export default class App extends Component<{}> {
158158
);
159159
}
160160
}`
161-
: `
161+
: `
162162
163163
export default class App extends Component<{}> {
164164
render() {

templates/general.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ ${name};
114114
}, {
115115
// for module without view:
116116
name: ({ view }) => !view && 'index.js',
117-
content: ({ name }) =>`import { NativeModules } from 'react-native';
117+
content: ({ name }) =>
118+
`import { NativeModules } from 'react-native';
118119
119120
const { ${name} } = NativeModules;
120121
@@ -123,7 +124,8 @@ export default ${name};
123124
}, {
124125
// for module with view:
125126
name: ({ view }) => view && 'index.js',
126-
content: ({ name }) =>`import { requireNativeComponent } from 'react-native';
127+
content: ({ name }) =>
128+
`import { requireNativeComponent } from 'react-native';
127129
128130
const ${name} = requireNativeComponent('${name}', null);
129131
@@ -132,7 +134,7 @@ export default ${name};
132134
}, {
133135
name: () => '.gitignore',
134136
content: ({ platforms }) => {
135-
let content =`# OSX
137+
let content = `# OSX
136138
#
137139
.DS_Store
138140

templates/windows.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const uuid = require('uuid').v1().toUpperCase();
44
module.exports = platform => [{
55
name: ({ name }) => `${platform}/${name}.sln`,
66
content: ({ name }) =>
7-
`Microsoft Visual Studio Solution File, Format Version 12.00
7+
`Microsoft Visual Studio Solution File, Format Version 12.00
88
# Visual Studio 14
99
VisualStudioVersion = 14.0.25123.0
1010
MinimumVisualStudioVersion = 10.0.40219.1
@@ -96,7 +96,7 @@ EndGlobal
9696
}, {
9797
name: () => `${platform}/.gitignore`,
9898
content: () =>
99-
`*AppPackages*
99+
`*AppPackages*
100100
*BundleArtifacts*
101101
*ReactAssets*
102102
@@ -178,7 +178,7 @@ packages/
178178
}, {
179179
name: ({ name }) => `${platform}/.npmignore`,
180180
content: () =>
181-
`
181+
`
182182
# Make sure we don't publish build artifacts to NPM
183183
ARM/
184184
Debug/
@@ -191,7 +191,7 @@ obj/
191191
}, {
192192
name: ({ name }) => `${platform}/${name}/project.json`,
193193
content: () =>
194-
`{
194+
`{
195195
"dependencies": {
196196
"Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2"
197197
},
@@ -211,7 +211,7 @@ obj/
211211
}, {
212212
name: ({ name }) => `${platform}/${name}/${name}.csproj`,
213213
content: ({ name, namespace }) =>
214-
`<?xml version="1.0" encoding="utf-8"?>
214+
`<?xml version="1.0" encoding="utf-8"?>
215215
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
216216
<Import Project="$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props')" />
217217
<PropertyGroup>
@@ -368,7 +368,7 @@ obj/
368368
}, {
369369
name: ({ name }) => `${platform}/${name}/${name}Module.cs`,
370370
content: ({ name, namespace }) =>
371-
`using ReactNative.Bridge;
371+
`using ReactNative.Bridge;
372372
using System;
373373
using System.Collections.Generic;
374374
using Windows.ApplicationModel.Core;
@@ -405,7 +405,7 @@ namespace ${namespace}.${name}
405405
}, {
406406
name: ({ name }) => `${platform}/${name}/${name}Package.cs`,
407407
content: ({ name, namespace }) =>
408-
`using ReactNative.Bridge;
408+
`using ReactNative.Bridge;
409409
using ReactNative.Modules.Core;
410410
using ReactNative.UIManager;
411411
using System;
@@ -462,7 +462,7 @@ namespace ${namespace}.${name}
462462
}, {
463463
name: ({ name }) => `${platform}/${name}/Properties/${name}.rd.xml`,
464464
content: ({ name }) =>
465-
`<?xml version="1.0" encoding="utf-8"?>
465+
`<?xml version="1.0" encoding="utf-8"?>
466466
<!--
467467
This file contains Runtime Directives, specifications about types your application accesses
468468
through reflection and other dynamic code patterns. Runtime Directives are used to control the
@@ -494,7 +494,7 @@ namespace ${namespace}.${name}
494494
}, {
495495
name: ({ name }) => `${platform}/${name}/Properties/AssemblyInfo.cs`,
496496
content: ({ name }) =>
497-
`using System.Reflection;
497+
`using System.Reflection;
498498
using System.Runtime.CompilerServices;
499499
using System.Runtime.InteropServices;
500500

0 commit comments

Comments
 (0)