react-native/local-cli/init.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

2015-05-14 14:18:44 +00:00
'use strict';
var path = require('path');
2015-03-28 15:50:31 +00:00
var utils = require('./generator-utils');
2015-05-14 14:18:44 +00:00
function init(projectDir, appName) {
console.log('Setting up new React Native app in ' + projectDir);
2015-05-14 17:08:56 +00:00
var source = path.resolve(__dirname, '..', 'Examples/SampleApp');
2015-05-14 14:18:44 +00:00
2015-03-28 15:50:31 +00:00
utils.walk(source).forEach(function(f) {
2015-05-14 14:18:44 +00:00
f = f.replace(source + '/', ''); // Strip off absolute path
2015-03-28 15:50:31 +00:00
if (f === 'project.xcworkspace' || f.indexOf('.xcodeproj/xcuserdata') !== -1) {
2015-05-14 19:05:32 +00:00
return;
}
2015-05-14 14:18:44 +00:00
var replacements = {
'Examples/SampleApp/': '',
'../../Libraries/': 'node_modules/react-native/Libraries/',
'../../React/': 'node_modules/react-native/React/',
'SampleApp': appName
};
2015-05-14 19:05:32 +00:00
var dest = f.replace(/SampleApp/g, appName).replace(/^_/, '.');
2015-03-28 15:50:31 +00:00
utils.copyAndReplace(
2015-05-14 14:18:44 +00:00
path.resolve(source, f),
path.resolve(projectDir, dest),
replacements
);
});
2015-05-14 14:35:09 +00:00
console.log('Next Steps:');
console.log(' Open ' + path.resolve(projectDir, appName) + '.xcodeproj in Xcode');
console.log(' Hit Run button');
console.log('');
2015-05-14 14:18:44 +00:00
}
module.exports = init;