Skip to content

Commit ad1e811

Browse files
author
Chris Brody
authored
Merge pull request #105 from brodybits/normalized-options-cleanup-with-testing
normalized options cleanup with some additional testing
2 parents 21d9163 + d375f63 commit ad1e811

File tree

18 files changed

+2781
-62
lines changed

18 files changed

+2781
-62
lines changed

lib/cli-command.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ module.exports = {
3131

3232
const beforeCreation = Date.now();
3333

34-
const platforms = (options.platforms)
35-
? options.platforms.split(',') : options.platforms;
36-
37-
const preNormalizedOptions = Object.assign({}, { name }, options, {
38-
platforms
39-
});
34+
const preNormalizedOptions = Object.assign({}, { name }, options);
4035

4136
// NOTE: There is a trick where the new normalizedOptions()
4237
// from normalized-options.js is applied by both command.js & lib.js.

lib/lib.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const { npmAddScriptSync } = require('./utils');
2222
const templates = require('../templates');
2323
const exampleTemplates = require('../templates/example');
2424

25-
const DEFAULT_PREFIX = '';
2625
const DEFAULT_PACKAGE_IDENTIFIER = 'com.reactlibrary';
2726
const DEFAULT_PLATFORMS = ['android', 'ios'];
2827
const DEFAULT_GITHUB_ACCOUNT = 'github_account';
@@ -47,14 +46,14 @@ const renderTemplateIfValid = (fs, root, template, templateArgs) => {
4746
);
4847
};
4948

50-
const generateWithOptions = ({
51-
name = 'unknown', // (should be normalized)
52-
prefix = DEFAULT_PREFIX,
53-
moduleName = 'unknown', // (should be normalized)
54-
className = 'unknown', // (should be normalized)
55-
modulePrefix = '', // (should be normalized)
49+
const generateWithNormalizedOptions = ({
50+
name,
51+
prefix,
52+
moduleName,
53+
className,
54+
modulePrefix,
5655
packageIdentifier = DEFAULT_PACKAGE_IDENTIFIER,
57-
namespace = 'unknown', // (should be normalized)
56+
namespace,
5857
platforms = DEFAULT_PLATFORMS,
5958
githubAccount = DEFAULT_GITHUB_ACCOUNT,
6059
authorName = DEFAULT_AUTHOR_NAME,
@@ -241,5 +240,7 @@ module.exports = function lib (options) {
241240
? arguments[1]
242241
: {};
243242

244-
return generateWithOptions(normalizedOptions(options), ioImports);
243+
return generateWithNormalizedOptions(
244+
normalizedOptions(options),
245+
ioImports);
245246
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`create alice-bobbi module with defaults, with platforms: 'bogus' 1`] = `
4+
Array [
5+
"* ensureDir dir: react-native-alice-bobbi
6+
",
7+
"* ensureDir dir: react-native-alice-bobbi/
8+
",
9+
"* ensureDir dir: react-native-alice-bobbi/
10+
",
11+
"* ensureDir dir: react-native-alice-bobbi/
12+
",
13+
"* ensureDir dir: react-native-alice-bobbi/
14+
",
15+
"* ensureDir dir: react-native-alice-bobbi/
16+
",
17+
"* ensureDir dir: react-native-alice-bobbi/
18+
",
19+
"* outputFile name: react-native-alice-bobbi/README.md
20+
content:
21+
--------
22+
# react-native-alice-bobbi
23+
24+
## Getting started
25+
26+
\`$ npm install react-native-alice-bobbi --save\`
27+
28+
### Mostly automatic installation
29+
30+
\`$ react-native link react-native-alice-bobbi\`
31+
32+
### Manual installation
33+
34+
35+
36+
## Usage
37+
\`\`\`javascript
38+
import AliceBobbi from 'react-native-alice-bobbi';
39+
40+
// TODO: What to do with the module?
41+
AliceBobbi;
42+
\`\`\`
43+
44+
<<<<<<<< ======== >>>>>>>>
45+
",
46+
"* outputFile name: react-native-alice-bobbi/package.json
47+
content:
48+
--------
49+
{
50+
\\"name\\": \\"react-native-alice-bobbi\\",
51+
\\"title\\": \\"React Native Alice Bobbi\\",
52+
\\"version\\": \\"1.0.0\\",
53+
\\"description\\": \\"TODO\\",
54+
\\"main\\": \\"index.js\\",
55+
\\"scripts\\": {
56+
\\"test\\": \\"echo \\\\\\"Error: no test specified\\\\\\" && exit 1\\"
57+
},
58+
\\"repository\\": {
59+
\\"type\\": \\"git\\",
60+
\\"url\\": \\"git+https://github.com/github_account/react-native-alice-bobbi.git\\",
61+
\\"baseUrl\\": \\"https://github.com/github_account/react-native-alice-bobbi\\"
62+
},
63+
\\"keywords\\": [
64+
\\"react-native\\"
65+
],
66+
\\"author\\": {
67+
\\"name\\": \\"Your Name\\",
68+
\\"email\\": \\"[email protected]\\"
69+
},
70+
\\"license\\": \\"MIT\\",
71+
\\"licenseFilename\\": \\"LICENSE\\",
72+
\\"readmeFilename\\": \\"README.md\\",
73+
\\"peerDependencies\\": {
74+
\\"react\\": \\"^16.8.1\\",
75+
\\"react-native\\": \\">=0.59.0-rc.0 <1.0.x\\"
76+
},
77+
\\"devDependencies\\": {
78+
\\"react\\": \\"^16.8.3\\",
79+
\\"react-native\\": \\"^0.59.10\\"
80+
}
81+
}
82+
83+
<<<<<<<< ======== >>>>>>>>
84+
",
85+
"* outputFile name: react-native-alice-bobbi/index.js
86+
content:
87+
--------
88+
import { NativeModules } from 'react-native';
89+
90+
const { AliceBobbi } = NativeModules;
91+
92+
export default AliceBobbi;
93+
94+
<<<<<<<< ======== >>>>>>>>
95+
",
96+
"* outputFile name: react-native-alice-bobbi/.gitignore
97+
content:
98+
--------
99+
# OSX
100+
#
101+
.DS_Store
102+
103+
# node.js
104+
#
105+
node_modules/
106+
npm-debug.log
107+
yarn-error.log
108+
109+
<<<<<<<< ======== >>>>>>>>
110+
",
111+
"* outputFile name: react-native-alice-bobbi/.gitattributes
112+
content:
113+
--------
114+
115+
<<<<<<<< ======== >>>>>>>>
116+
",
117+
"* outputFile name: react-native-alice-bobbi/.npmignore
118+
content:
119+
--------
120+
121+
<<<<<<<< ======== >>>>>>>>
122+
",
123+
]
124+
`;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const lib = require('../../../../../../lib/lib.js');
2+
3+
const ioInject = require('../../../../helpers/io-inject.js');
4+
5+
test(`create alice-bobbi module with defaults, with platforms: 'bogus'`, async () => {
6+
const mysnap = [];
7+
8+
const inject = ioInject(mysnap);
9+
10+
const options = {
11+
name: 'alice-bobbi',
12+
platforms: 'bogus'
13+
};
14+
15+
await lib(options, inject);
16+
expect(mysnap).toMatchSnapshot();
17+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`create alice-bobbi module with defaults, with bogus platforms: [] 1`] = `
4+
Array [
5+
"* ensureDir dir: react-native-alice-bobbi
6+
",
7+
"* ensureDir dir: react-native-alice-bobbi/
8+
",
9+
"* ensureDir dir: react-native-alice-bobbi/
10+
",
11+
"* ensureDir dir: react-native-alice-bobbi/
12+
",
13+
"* ensureDir dir: react-native-alice-bobbi/
14+
",
15+
"* ensureDir dir: react-native-alice-bobbi/
16+
",
17+
"* ensureDir dir: react-native-alice-bobbi/
18+
",
19+
"* outputFile name: react-native-alice-bobbi/README.md
20+
content:
21+
--------
22+
# react-native-alice-bobbi
23+
24+
## Getting started
25+
26+
\`$ npm install react-native-alice-bobbi --save\`
27+
28+
### Mostly automatic installation
29+
30+
\`$ react-native link react-native-alice-bobbi\`
31+
32+
### Manual installation
33+
34+
35+
36+
## Usage
37+
\`\`\`javascript
38+
import AliceBobbi from 'react-native-alice-bobbi';
39+
40+
// TODO: What to do with the module?
41+
AliceBobbi;
42+
\`\`\`
43+
44+
<<<<<<<< ======== >>>>>>>>
45+
",
46+
"* outputFile name: react-native-alice-bobbi/package.json
47+
content:
48+
--------
49+
{
50+
\\"name\\": \\"react-native-alice-bobbi\\",
51+
\\"title\\": \\"React Native Alice Bobbi\\",
52+
\\"version\\": \\"1.0.0\\",
53+
\\"description\\": \\"TODO\\",
54+
\\"main\\": \\"index.js\\",
55+
\\"scripts\\": {
56+
\\"test\\": \\"echo \\\\\\"Error: no test specified\\\\\\" && exit 1\\"
57+
},
58+
\\"repository\\": {
59+
\\"type\\": \\"git\\",
60+
\\"url\\": \\"git+https://github.com/github_account/react-native-alice-bobbi.git\\",
61+
\\"baseUrl\\": \\"https://github.com/github_account/react-native-alice-bobbi\\"
62+
},
63+
\\"keywords\\": [
64+
\\"react-native\\"
65+
],
66+
\\"author\\": {
67+
\\"name\\": \\"Your Name\\",
68+
\\"email\\": \\"[email protected]\\"
69+
},
70+
\\"license\\": \\"MIT\\",
71+
\\"licenseFilename\\": \\"LICENSE\\",
72+
\\"readmeFilename\\": \\"README.md\\",
73+
\\"peerDependencies\\": {
74+
\\"react\\": \\"^16.8.1\\",
75+
\\"react-native\\": \\">=0.59.0-rc.0 <1.0.x\\"
76+
},
77+
\\"devDependencies\\": {
78+
\\"react\\": \\"^16.8.3\\",
79+
\\"react-native\\": \\"^0.59.10\\"
80+
}
81+
}
82+
83+
<<<<<<<< ======== >>>>>>>>
84+
",
85+
"* outputFile name: react-native-alice-bobbi/index.js
86+
content:
87+
--------
88+
import { NativeModules } from 'react-native';
89+
90+
const { AliceBobbi } = NativeModules;
91+
92+
export default AliceBobbi;
93+
94+
<<<<<<<< ======== >>>>>>>>
95+
",
96+
"* outputFile name: react-native-alice-bobbi/.gitignore
97+
content:
98+
--------
99+
# OSX
100+
#
101+
.DS_Store
102+
103+
# node.js
104+
#
105+
node_modules/
106+
npm-debug.log
107+
yarn-error.log
108+
109+
<<<<<<<< ======== >>>>>>>>
110+
",
111+
"* outputFile name: react-native-alice-bobbi/.gitattributes
112+
content:
113+
--------
114+
115+
<<<<<<<< ======== >>>>>>>>
116+
",
117+
"* outputFile name: react-native-alice-bobbi/.npmignore
118+
content:
119+
--------
120+
121+
<<<<<<<< ======== >>>>>>>>
122+
",
123+
]
124+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const lib = require('../../../../../../lib/lib.js');
2+
3+
const ioInject = require('../../../../helpers/io-inject.js');
4+
5+
test('create alice-bobbi module with defaults, with bogus platforms: []', async () => {
6+
const mysnap = [];
7+
8+
const inject = ioInject(mysnap);
9+
10+
const options = {
11+
name: 'alice-bobbi',
12+
platforms: []
13+
};
14+
15+
await lib(options, inject);
16+
expect(mysnap).toMatchSnapshot();
17+
});

0 commit comments

Comments
 (0)