-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathcli-command.js
More file actions
146 lines (131 loc) · 5.83 KB
/
Copy pathcli-command.js
File metadata and controls
146 lines (131 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const { info, error } = require('console');
const emoji = require('node-emoji');
const logSymbols = require('log-symbols');
const normalizedOptions = require('./normalized-options');
const createLibraryModule = require('./lib');
const postCreateInstructions = ({
packageName,
platforms,
generateExample,
exampleName
}) => `
====================================================
YOU'RE ALL SET!
` + (generateExample
? `
${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 ${packageName}/${exampleName} && yarn start)
${emoji.get('bulb')} enter the following commands to run the example app:
${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 ${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
`
: `
${emoji.get('bulb')} next time consider using \`--generate-example\` to add a generated example!
`);
module.exports = {
name: 'create-library',
description: 'creates a React Native library module for one or more platforms',
usage: '[options] <name>',
action: (args, options) => {
if (!args || args.length < 1) {
throw new Error('missing lib module name');
}
if (args.length > 1) {
throw new Error('too many arguments');
}
const name = args[0];
const beforeCreation = Date.now();
const preNormalizedOptions = Object.assign({}, { name }, options);
// NOTE: There is a trick where the new normalizedOptions()
// from normalized-options.js is applied by both command.js & lib.js.
// This is to ensure that the CLI gets the correct module name for the
// final log message, and that the exported programmatic
// function can be completely tested from using the CLI.
const createOptions = normalizedOptions(preNormalizedOptions);
const rootModuleName = createOptions.packageName;
return createLibraryModule(createOptions).then(() => {
info(`
${emoji.get('books')} Created library module ${rootModuleName} in \`./${rootModuleName}\`.
${emoji.get('clock9')} It took ${Date.now() - beforeCreation}ms.
${postCreateInstructions(createOptions)}`);
}).catch((err) => {
error(`Error while creating library module ${rootModuleName}`);
if (err.stack) {
error(err.stack);
}
});
},
options: [{
command: '--package-name [packageName]',
description: 'The full package name to be used in package.json. Default: react-native-(name in param-case)',
}, {
command: '--is-view',
description: 'Generate the package as a very simple native view component. Status: EXPERIMENTAL, with limited testing.',
}, {
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: '--native-package-id [nativePackageId]',
description: '[Android] The native Java package identifier used for Android',
default: 'com.reactlibrary',
}, {
command: '--platforms <platforms>',
description: 'Platforms the library module will be created for - comma separated',
default: 'ios,android',
}, {
command: '--swift',
description: 'EXPERIMENAL: Generate the iOS native module in Swift',
}, {
command: '--tvos-enabled',
description: 'Generate the module with tvOS build enabled (requires react-native-tvos fork, with minimum version of 0.60, and iOS platform to be enabled)',
}, {
command: '--github-account [githubAccount]',
description: 'The github account where the library module is hosted',
default: 'github_account',
}, {
command: '--author-name [authorName]',
description: 'The author\'s name',
default: 'Your Name',
}, {
command: '--author-email [authorEmail]',
description: 'The author\'s email',
default: 'yourname@email.com',
}, {
command: '--license [license]',
description: 'The license type',
default: 'MIT',
}, {
command: '--use-apple-networking',
description: '[iOS] Use `AFNetworking` dependency as a sample in the podspec & use it from the iOS code',
}, {
command: '--generate-example',
description: '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',
}, {
command: '--example-file-linkage',
description: "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",
}, {
command: '--example-name [exampleName]',
description: 'Name for the example project',
default: 'example',
}, {
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',
description: '[iOS] EXPERIMENTAL FEATURE NOT SUPPORTED: write (or overwrite) example ios/Podfile',
}]
};