Skip to content

Commit e33fef8

Browse files
committed
Merge pull request #405 from JoeStanton/new-library-cmd
[CLI] New Library Generator
2 parents 80814f6 + 857c30b commit e33fef8

11 files changed

Lines changed: 433 additions & 32 deletions

File tree

Libraries/Sample/Sample.android.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Stub of Sample for Android.
3+
*
4+
* @providesModule Sample
5+
* @flow
6+
*/
7+
'use strict';
8+
9+
var warning = require('warning');
10+
11+
var Sample = {
12+
test: function() {
13+
warning("Not yet implemented for Android.");
14+
}
15+
};
16+
17+
module.exports = Sample;

Libraries/Sample/Sample.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#import "RCTBridgeModule.h"
2+
3+
@interface Sample : NSObject <RCTBridgeModule>
4+
5+
@end

Libraries/Sample/Sample.ios.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @providesModule Sample
3+
* @flow
4+
*/
5+
'use strict';
6+
7+
var NativeSample = require('NativeModules').Sample;
8+
var invariant = require('invariant');
9+
10+
/**
11+
* High-level docs for the Sample iOS API can be written here.
12+
*/
13+
14+
var Sample = {
15+
test: function() {
16+
NativeSample.test();
17+
}
18+
};
19+
20+
module.exports = Sample;

Libraries/Sample/Sample.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#import "Sample.h"
2+
3+
@implementation Sample
4+
5+
RCT_EXPORT_MODULE()
6+
7+
RCT_EXPORT_METHOD(test)
8+
{
9+
// Your implementation here
10+
}
11+
12+
@end
Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
// !$*UTF8*$!
2+
{
3+
archiveVersion = 1;
4+
classes = {
5+
};
6+
objectVersion = 46;
7+
objects = {
8+
9+
/* Begin PBXBuildFile section */
10+
13BE3DEE1AC21097009241FE /* Sample.m in Sources */ = {isa = PBXBuildFile; fileRef = 13BE3DED1AC21097009241FE /* Sample.m */; };
11+
/* End PBXBuildFile section */
12+
13+
/* Begin PBXCopyFilesBuildPhase section */
14+
58B511D91A9E6C8500147676 /* CopyFiles */ = {
15+
isa = PBXCopyFilesBuildPhase;
16+
buildActionMask = 2147483647;
17+
dstPath = "include/$(PRODUCT_NAME)";
18+
dstSubfolderSpec = 16;
19+
files = (
20+
);
21+
runOnlyForDeploymentPostprocessing = 0;
22+
};
23+
/* End PBXCopyFilesBuildPhase section */
24+
25+
/* Begin PBXFileReference section */
26+
134814201AA4EA6300B7C361 /* libSample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libSample.a; sourceTree = BUILT_PRODUCTS_DIR; };
27+
13BE3DEC1AC21097009241FE /* Sample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Sample.h; sourceTree = "<group>"; };
28+
13BE3DED1AC21097009241FE /* Sample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Sample.m; sourceTree = "<group>"; };
29+
/* End PBXFileReference section */
30+
31+
/* Begin PBXFrameworksBuildPhase section */
32+
58B511D81A9E6C8500147676 /* Frameworks */ = {
33+
isa = PBXFrameworksBuildPhase;
34+
buildActionMask = 2147483647;
35+
files = (
36+
);
37+
runOnlyForDeploymentPostprocessing = 0;
38+
};
39+
/* End PBXFrameworksBuildPhase section */
40+
41+
/* Begin PBXGroup section */
42+
134814211AA4EA7D00B7C361 /* Products */ = {
43+
isa = PBXGroup;
44+
children = (
45+
134814201AA4EA6300B7C361 /* libSample.a */,
46+
);
47+
name = Products;
48+
sourceTree = "<group>";
49+
};
50+
58B511D21A9E6C8500147676 = {
51+
isa = PBXGroup;
52+
children = (
53+
13BE3DEC1AC21097009241FE /* Sample.h */,
54+
13BE3DED1AC21097009241FE /* Sample.m */,
55+
134814211AA4EA7D00B7C361 /* Products */,
56+
);
57+
sourceTree = "<group>";
58+
};
59+
/* End PBXGroup section */
60+
61+
/* Begin PBXNativeTarget section */
62+
58B511DA1A9E6C8500147676 /* Sample */ = {
63+
isa = PBXNativeTarget;
64+
buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "Sample" */;
65+
buildPhases = (
66+
58B511D71A9E6C8500147676 /* Sources */,
67+
58B511D81A9E6C8500147676 /* Frameworks */,
68+
58B511D91A9E6C8500147676 /* CopyFiles */,
69+
);
70+
buildRules = (
71+
);
72+
dependencies = (
73+
);
74+
name = Sample;
75+
productName = RCTDataManager;
76+
productReference = 134814201AA4EA6300B7C361 /* libSample.a */;
77+
productType = "com.apple.product-type.library.static";
78+
};
79+
/* End PBXNativeTarget section */
80+
81+
/* Begin PBXProject section */
82+
58B511D31A9E6C8500147676 /* Project object */ = {
83+
isa = PBXProject;
84+
attributes = {
85+
LastUpgradeCheck = 0610;
86+
ORGANIZATIONNAME = Facebook;
87+
TargetAttributes = {
88+
58B511DA1A9E6C8500147676 = {
89+
CreatedOnToolsVersion = 6.1.1;
90+
};
91+
};
92+
};
93+
buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "Sample" */;
94+
compatibilityVersion = "Xcode 3.2";
95+
developmentRegion = English;
96+
hasScannedForEncodings = 0;
97+
knownRegions = (
98+
en,
99+
);
100+
mainGroup = 58B511D21A9E6C8500147676;
101+
productRefGroup = 58B511D21A9E6C8500147676;
102+
projectDirPath = "";
103+
projectRoot = "";
104+
targets = (
105+
58B511DA1A9E6C8500147676 /* Sample */,
106+
);
107+
};
108+
/* End PBXProject section */
109+
110+
/* Begin PBXSourcesBuildPhase section */
111+
58B511D71A9E6C8500147676 /* Sources */ = {
112+
isa = PBXSourcesBuildPhase;
113+
buildActionMask = 2147483647;
114+
files = (
115+
13BE3DEE1AC21097009241FE /* Sample.m in Sources */,
116+
);
117+
runOnlyForDeploymentPostprocessing = 0;
118+
};
119+
/* End PBXSourcesBuildPhase section */
120+
121+
/* Begin XCBuildConfiguration section */
122+
58B511ED1A9E6C8500147676 /* Debug */ = {
123+
isa = XCBuildConfiguration;
124+
buildSettings = {
125+
ALWAYS_SEARCH_USER_PATHS = NO;
126+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
127+
CLANG_CXX_LIBRARY = "libc++";
128+
CLANG_ENABLE_MODULES = YES;
129+
CLANG_ENABLE_OBJC_ARC = YES;
130+
CLANG_WARN_BOOL_CONVERSION = YES;
131+
CLANG_WARN_CONSTANT_CONVERSION = YES;
132+
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
133+
CLANG_WARN_EMPTY_BODY = YES;
134+
CLANG_WARN_ENUM_CONVERSION = YES;
135+
CLANG_WARN_INT_CONVERSION = YES;
136+
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
137+
CLANG_WARN_UNREACHABLE_CODE = YES;
138+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
139+
COPY_PHASE_STRIP = NO;
140+
ENABLE_STRICT_OBJC_MSGSEND = YES;
141+
GCC_C_LANGUAGE_STANDARD = gnu99;
142+
GCC_DYNAMIC_NO_PIC = NO;
143+
GCC_OPTIMIZATION_LEVEL = 0;
144+
GCC_PREPROCESSOR_DEFINITIONS = (
145+
"DEBUG=1",
146+
"$(inherited)",
147+
);
148+
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
149+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
150+
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
151+
GCC_WARN_UNDECLARED_SELECTOR = YES;
152+
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
153+
GCC_WARN_UNUSED_FUNCTION = YES;
154+
GCC_WARN_UNUSED_VARIABLE = YES;
155+
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
156+
MTL_ENABLE_DEBUG_INFO = YES;
157+
ONLY_ACTIVE_ARCH = YES;
158+
SDKROOT = iphoneos;
159+
};
160+
name = Debug;
161+
};
162+
58B511EE1A9E6C8500147676 /* Release */ = {
163+
isa = XCBuildConfiguration;
164+
buildSettings = {
165+
ALWAYS_SEARCH_USER_PATHS = NO;
166+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
167+
CLANG_CXX_LIBRARY = "libc++";
168+
CLANG_ENABLE_MODULES = YES;
169+
CLANG_ENABLE_OBJC_ARC = YES;
170+
CLANG_WARN_BOOL_CONVERSION = YES;
171+
CLANG_WARN_CONSTANT_CONVERSION = YES;
172+
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
173+
CLANG_WARN_EMPTY_BODY = YES;
174+
CLANG_WARN_ENUM_CONVERSION = YES;
175+
CLANG_WARN_INT_CONVERSION = YES;
176+
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
177+
CLANG_WARN_UNREACHABLE_CODE = YES;
178+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
179+
COPY_PHASE_STRIP = YES;
180+
ENABLE_NS_ASSERTIONS = NO;
181+
ENABLE_STRICT_OBJC_MSGSEND = YES;
182+
GCC_C_LANGUAGE_STANDARD = gnu99;
183+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
184+
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
185+
GCC_WARN_UNDECLARED_SELECTOR = YES;
186+
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
187+
GCC_WARN_UNUSED_FUNCTION = YES;
188+
GCC_WARN_UNUSED_VARIABLE = YES;
189+
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
190+
MTL_ENABLE_DEBUG_INFO = NO;
191+
SDKROOT = iphoneos;
192+
VALIDATE_PRODUCT = YES;
193+
};
194+
name = Release;
195+
};
196+
58B511F01A9E6C8500147676 /* Debug */ = {
197+
isa = XCBuildConfiguration;
198+
buildSettings = {
199+
HEADER_SEARCH_PATHS = (
200+
"$(inherited)",
201+
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
202+
"$(SRCROOT)/../../React/**",
203+
"$(SRCROOT)/../../node_modules/react-native/React/**",
204+
);
205+
LIBRARY_SEARCH_PATHS = "$(inherited)";
206+
OTHER_LDFLAGS = "-ObjC";
207+
PRODUCT_NAME = Sample;
208+
SKIP_INSTALL = YES;
209+
};
210+
name = Debug;
211+
};
212+
58B511F11A9E6C8500147676 /* Release */ = {
213+
isa = XCBuildConfiguration;
214+
buildSettings = {
215+
HEADER_SEARCH_PATHS = (
216+
"$(inherited)",
217+
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
218+
"$(SRCROOT)/../../React/**",
219+
);
220+
LIBRARY_SEARCH_PATHS = "$(inherited)";
221+
OTHER_LDFLAGS = "-ObjC";
222+
PRODUCT_NAME = Sample;
223+
SKIP_INSTALL = YES;
224+
};
225+
name = Release;
226+
};
227+
/* End XCBuildConfiguration section */
228+
229+
/* Begin XCConfigurationList section */
230+
58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "Sample" */ = {
231+
isa = XCConfigurationList;
232+
buildConfigurations = (
233+
58B511ED1A9E6C8500147676 /* Debug */,
234+
58B511EE1A9E6C8500147676 /* Release */,
235+
);
236+
defaultConfigurationIsVisible = 0;
237+
defaultConfigurationName = Release;
238+
};
239+
58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "Sample" */ = {
240+
isa = XCConfigurationList;
241+
buildConfigurations = (
242+
58B511F01A9E6C8500147676 /* Debug */,
243+
58B511F11A9E6C8500147676 /* Release */,
244+
);
245+
defaultConfigurationIsVisible = 0;
246+
defaultConfigurationName = Release;
247+
};
248+
/* End XCConfigurationList section */
249+
};
250+
rootObject = 58B511D31A9E6C8500147676 /* Project object */;
251+
}

Libraries/Sample/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Sample",
3+
"version": "0.0.1",
4+
"keywords": "react-native"
5+
}

local-cli/cli.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var path = require('path');
1010
var init = require('./init.js');
1111
var install = require('./install.js');
1212
var bundle = require('./bundle.js');
13+
var newLibrary = require('./new-library.js');
1314

1415
function printUsage() {
1516
console.log([
@@ -18,7 +19,8 @@ function printUsage() {
1819
'Commands:',
1920
' start: starts the webserver',
2021
' install: installs npm react components',
21-
' bundle: builds the javascript bundle for offline use'
22+
' bundle: builds the javascript bundle for offline use',
23+
' new-library: generates a native library bridge'
2224
].join('\n'));
2325
process.exit(1);
2426
}
@@ -51,6 +53,9 @@ function run() {
5153
case 'bundle':
5254
bundle.init(args);
5355
break;
56+
case 'new-library':
57+
newLibrary.init(args);
58+
break;
5459
case 'init':
5560
printInitWarning();
5661
break;

local-cli/generator-utils.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
'use strict';
2+
3+
var path = require('path');
4+
var fs = require('fs');
5+
6+
function copyAndReplace(src, dest, replacements) {
7+
if (fs.lstatSync(src).isDirectory()) {
8+
if (!fs.existsSync(dest)) {
9+
fs.mkdirSync(dest);
10+
}
11+
} else {
12+
var content = fs.readFileSync(src, 'utf8');
13+
Object.keys(replacements).forEach(function(regex) {
14+
content = content.replace(new RegExp(regex, 'g'), replacements[regex]);
15+
});
16+
fs.writeFileSync(dest, content);
17+
}
18+
}
19+
20+
function walk(current) {
21+
if (!fs.lstatSync(current).isDirectory()) {
22+
return [current];
23+
}
24+
25+
var files = fs.readdirSync(current).map(function(child) {
26+
child = path.join(current, child);
27+
return walk(child);
28+
});
29+
return [].concat.apply([current], files);
30+
}
31+
32+
function validatePackageName(name) {
33+
if (!name.match(/^[$A-Z_][0-9A-Z_$]*$/i)) {
34+
console.error(
35+
'"%s" is not a valid name for a project. Please use a valid identifier ' +
36+
'name (alphanumeric).',
37+
name
38+
);
39+
process.exit(1);
40+
}
41+
}
42+
43+
module.exports = {
44+
copyAndReplace: copyAndReplace,
45+
walk: walk,
46+
validatePackageName: validatePackageName
47+
};

0 commit comments

Comments
 (0)