forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
new-library.js
61 lines (51 loc) · 1.53 KB
/
new-library.js
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
'use strict';
var path = require('path');
var fs = require('fs');
var utils = require('./generator-utils');
function showHelp() {
console.log([
'Usage: react-native new-library <LibraryName>',
''
].join('\n'));
process.exit(1);
}
function newLibrary(libraryName) {
var root = process.cwd();
var libraries = path.resolve(root, 'Libraries');
var libraryDest = path.resolve(libraries, libraryName);
var source = path.resolve('node_modules', 'react-native', 'Libraries', 'Sample') + '/';
if (!fs.existsSync(libraries)) {
fs.mkdir(libraries);
}
if (fs.existsSync(libraryDest)) {
console.log('Library already exists in', libraryDest);
process.exit(1);
}
utils.walk(source).forEach(function(f) {
f = f.replace(source, ''); // Strip off absolute path
if (f === 'project.xcworkspace' || f.indexOf('.xcodeproj/xcuserdata') !== -1) {
return;
}
var dest = f.replace(/Sample/g, libraryName).replace(/^_/, '.');
utils.copyAndReplace(
path.resolve(source, f),
path.resolve(libraryDest, dest),
{ 'Sample': libraryName }
);
});
console.log('Created library in', libraryDest);
console.log('Next Steps:');
console.log(' Link your library in Xcode:');
console.log(' https://facebook.github.io/react-native/docs/linking-libraries-ios.html#content');
console.log('');
}
module.exports = {
init: function(args) {
var libraryName = args[1];
if (!libraryName) {
showHelp();
}
utils.validatePackageName(libraryName);
newLibrary(libraryName);
}
};