Permalink
Browse files

Rewrite 'react-native init' and 'react-native upgrade' without using …

…Yeoman in preparation for templates support

Summary:
This is the manually imported version of #10786

This was mostly straigthforward by replacing the local-cli folder with the version I had in my local git checkout,
plus a few other files I listed with git diff --name-only.

Reviewed By: hramos

Differential Revision: D4201118

fbshipit-source-id: 4d0fb54b0edda9de1abba427958e420fd2ac105c
  • Loading branch information...
1 parent eddc2c9 commit a477aec10d29b4651944cb4292daf06dfa953ea3 @mkonicek mkonicek committed with Facebook Github Bot Nov 19, 2016
Showing with 726 additions and 1,892 deletions.
  1. +2 −2 .flowconfig
  2. +0 −268 local-cli/__tests__/generators-test.js
  3. +0 −38 local-cli/android/android.js
  4. +0 −1 local-cli/commands.js
  5. +0 −31 local-cli/generate-android.js
  6. +0 −63 local-cli/generate/generate.js
  7. +0 −91 local-cli/generator-android/index.js
  8. +0 −3 local-cli/generator-android/templates/src/app/src/main/res/values/strings.xml
  9. +0 −3 local-cli/generator-android/templates/src/settings.gradle
  10. +0 −58 local-cli/generator-ios/index.js
  11. +0 −814 local-cli/generator-ios/templates/xcodeproj/project.pbxproj
  12. +0 −112 local-cli/generator-ios/templates/xcodeproj/xcshareddata/xcschemes/_xcscheme
  13. +0 −43 local-cli/generator-utils.js
  14. +101 −0 local-cli/generator/copyProjectTemplateAndReplace.js
  15. +0 −213 local-cli/generator/index.js
  16. +35 −0 local-cli/generator/printRunInstructions.js
  17. +118 −0 local-cli/generator/promptSync.js
  18. +6 −0 local-cli/init/gen.js
  19. +86 −30 local-cli/init/init.js
  20. +6 −5 local-cli/runAndroid/runAndroid.js
  21. +0 −2 local-cli/server/middleware/heapCapture/.gitignore
  22. +3 −0 local-cli/templates/HelloWorld/.babelrc
  23. 0 local-cli/{generator/templates/_buckconfig → templates/HelloWorld/.buckconfig}
  24. +1 −0 local-cli/templates/HelloWorld/.buckversion
  25. +45 −0 local-cli/templates/HelloWorld/.flowconfig
  26. 0 local-cli/{generator/templates/_gitattributes → templates/HelloWorld/.gitattributes}
  27. +3 −2 local-cli/{generator/templates/_gitignore → templates/HelloWorld/.gitignore}
  28. 0 local-cli/templates/HelloWorld/.nobuckcheck
  29. 0 local-cli/{generator/templates/_watchmanconfig → templates/HelloWorld/.watchmanconfig}
  30. 0 local-cli/{generator/templates → templates/HelloWorld}/__tests__/index.android.js
  31. 0 local-cli/{generator/templates → templates/HelloWorld}/__tests__/index.ios.js
  32. +2 −2 local-cli/{generator-android/templates/src → templates/HelloWorld/android}/app/BUCK
  33. +1 −1 local-cli/{generator-android/templates/src → templates/HelloWorld/android}/app/build.gradle
  34. 0 local-cli/{generator-android/templates/src → templates/HelloWorld/android}/app/proguard-rules.pro
  35. +1 −1 ...{generator-android/templates/src → templates/HelloWorld/android}/app/src/main/AndroidManifest.xml
  36. +2 −2 ...plates/package → templates/HelloWorld/android/app/src/main/java/com/helloworld}/MainActivity.java
  37. +1 −1 ...tes/package → templates/HelloWorld/android/app/src/main/java/com/helloworld}/MainApplication.java
  38. BIN ...ndroid/templates/bin → templates/HelloWorld/android}/app/src/main/res/mipmap-hdpi/ic_launcher.png
  39. BIN ...ndroid/templates/bin → templates/HelloWorld/android}/app/src/main/res/mipmap-mdpi/ic_launcher.png
  40. BIN ...droid/templates/bin → templates/HelloWorld/android}/app/src/main/res/mipmap-xhdpi/ic_launcher.png
  41. BIN ...roid/templates/bin → templates/HelloWorld/android}/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
  42. +3 −0 local-cli/templates/HelloWorld/android/app/src/main/res/values/strings.xml
  43. 0 ...enerator-android/templates/src → templates/HelloWorld/android}/app/src/main/res/values/styles.xml
  44. 0 local-cli/{generator-android/templates/src → templates/HelloWorld/android}/build.gradle
  45. 0 local-cli/{generator-android/templates/src → templates/HelloWorld/android}/gradle.properties
  46. BIN ...generator-android/templates/bin → templates/HelloWorld/android}/gradle/wrapper/gradle-wrapper.jar
  47. 0 ...or-android/templates/bin → templates/HelloWorld/android}/gradle/wrapper/gradle-wrapper.properties
  48. 0 local-cli/{generator-android/templates/bin → templates/HelloWorld/android}/gradlew
  49. 0 local-cli/{generator-android/templates/bin → templates/HelloWorld/android}/gradlew.bat
  50. 0 local-cli/{generator-android/templates/src → templates/HelloWorld/android}/keystores/BUCK
  51. 0 ...nerator-android/templates/src → templates/HelloWorld/android}/keystores/debug.keystore.properties
  52. +3 −0 local-cli/templates/HelloWorld/android/settings.gradle
  53. +2 −2 local-cli/{generator/templates → templates/HelloWorld}/index.android.js
  54. +2 −2 local-cli/{generator/templates → templates/HelloWorld}/index.ios.js
  55. 0 local-cli/{generator-ios/templates/app → templates/HelloWorld/ios/HelloWorld}/AppDelegate.h
  56. +1 −1 local-cli/{generator-ios/templates/app → templates/HelloWorld/ios/HelloWorld}/AppDelegate.m
  57. +1 −1 ...i/{generator-ios/templates/app → templates/HelloWorld/ios/HelloWorld}/Base.lproj/LaunchScreen.xib
  58. 0 ...lates/app → templates/HelloWorld/ios/HelloWorld}/Images.xcassets/AppIcon.appiconset/Contents.json
  59. 0 local-cli/{generator-ios/templates/app → templates/HelloWorld/ios/HelloWorld}/Info.plist
  60. 0 local-cli/{generator-ios/templates/app → templates/HelloWorld/ios/HelloWorld}/main.m
  61. +2 −2 ...nerator-ios/templates/tests/Tests.m → templates/HelloWorld/ios/HelloWorldTests/HelloWorldTests.m}
  62. 0 local-cli/{generator-ios/templates/tests → templates/HelloWorld/ios/HelloWorldTests}/Info.plist
  63. +3 −0 local-cli/upgrade/doUpgrade.js
  64. +125 −83 local-cli/upgrade/upgrade.js
  65. +107 −9 local-cli/util/copyAndReplace.js
  66. +58 −0 local-cli/util/yarn.js
  67. +1 −1 package.json
  68. +1 −1 react-native-cli/index.js
  69. +4 −4 scripts/run-ci-e2e-tests.js
View
@@ -2,8 +2,8 @@
; We fork some components by platform
.*/*[.]android.js
-; Ignore generators because they are not real JS files
-.*/local-cli/generator/templates/.*
+; Ignore templates for 'react-native init'
+.*/local-cli/templates/.*
; Ignore the website subdir
<PROJECT_ROOT>/website/.*
@@ -1,268 +0,0 @@
-/**
- * Copyright (c) 2015-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- */
-'use strict';
-
-jest.autoMockOff();
-
-var path = require('path');
-var fs = require('fs');
-
-// eslint-disable-next-line improperly-disabled-jasmine-tests
-xdescribe('React Yeoman Generators', function() {
- describe('react:react', function() {
- var assert;
-
- beforeEach(function() {
- // A deep dependency of yeoman spams console.log with giant json objects.
- // yeoman-generator/node_modules/
- // download/node_modules/
- // caw/node_modules/
- // get-proxy/node_modules/
- // rc/index.js
- var log = console.log;
- console.log = function() {};
- assert = require('yeoman-generator').assert;
- var helpers = require('yeoman-generator').test;
- console.log = log;
-
- var generated = false;
-
- runs(function() {
- helpers.run(path.resolve(__dirname, '../generator'))
- .withArguments(['TestApp'])
- .on('end', function() {
- generated = true;
- });
- });
-
- waitsFor(function() {
- jest.runAllTicks();
- jest.runOnlyPendingTimers();
- return generated;
- }, 'generation', 750);
- });
-
- it('creates files', function() {
- assert.file([
- '.flowconfig',
- '.gitignore',
- '.watchmanconfig',
- 'index.ios.js',
- 'index.android.js'
- ]);
- });
-
- it('replaces vars in index.ios.js', function() {
- assert.fileContent('index.ios.js', 'var TestApp = React.createClass({');
- assert.fileContent(
- 'index.ios.js',
- 'AppRegistry.registerComponent(\'TestApp\', () => TestApp);'
- );
-
- assert.noFileContent('index.ios.js', '<%= name %>');
- });
-
- it('replaces vars in index.android.js', function() {
- assert.fileContent('index.android.js', 'var TestApp = React.createClass({');
- assert.fileContent(
- 'index.android.js',
- 'AppRegistry.registerComponent(\'TestApp\', () => TestApp);'
- );
-
- assert.noFileContent('index.ios.js', '<%= name %>');
- });
-
- it('composes with ios generator', function() {
- var stat = fs.statSync('ios');
-
- expect(stat.isDirectory()).toBe(true);
- });
-
- it('composes with android generator', function() {
- var stat = fs.statSync('android');
-
- expect(stat.isDirectory()).toBe(true);
- });
- });
-
- describe('react:android', function () {
- var assert;
-
- beforeEach(function (done) {
- // A deep dependency of yeoman spams console.log with giant json objects.
- // yeoman-generator/node_modules/
- // download/node_modules/
- // caw/node_modules/
- // get-proxy/node_modules/
- // rc/index.js
- var log = console.log;
- console.log = function() {};
- assert = require('yeoman-generator').assert;
- var helpers = require('yeoman-generator').test;
- console.log = log;
-
- var generated = false;
-
- runs(function() {
- helpers.run(path.resolve(__dirname, '..', 'generator-android'))
- .withArguments(['TestAppAndroid'])
- .withOptions({
- 'package': 'com.reactnative.test',
- })
- .on('end', function() {
- generated = true;
- });
- });
-
- waitsFor(function() {
- jest.runAllTicks();
- jest.runOnlyPendingTimers();
- return generated;
- }, 'generation', 750);
- });
-
- it('creates files', function () {
- assert.file([
- path.join('android', 'build.gradle'),
- path.join('android', 'gradle.properties'),
- path.join('android', 'gradlew.bat'),
- path.join('android', 'gradlew'),
- path.join('android', 'settings.gradle'),
- path.join('android', 'app', 'build.gradle'),
- path.join('android', 'app', 'proguard-rules.pro'),
- path.join('android', 'app', 'src', 'main', 'AndroidManifest.xml'),
- path.join('android', 'app', 'src', 'main', 'java', 'com', 'reactnative', 'test', 'MainActivity.java'),
- path.join('android', 'app', 'src', 'main', 'res', 'mipmap-hdpi', 'ic_launcher.png'),
- path.join('android', 'app', 'src', 'main', 'res', 'mipmap-mdpi', 'ic_launcher.png'),
- path.join('android', 'app', 'src', 'main', 'res', 'mipmap-xhdpi', 'ic_launcher.png'),
- path.join('android', 'app', 'src', 'main', 'res', 'mipmap-xxhdpi', 'ic_launcher.png'),
- path.join('android', 'app', 'src', 'main', 'res', 'values', 'strings.xml'),
- path.join('android', 'app', 'src', 'main', 'res', 'values', 'styles.xml'),
- path.join('android', 'gradle', 'wrapper', 'gradle-wrapper.jar'),
- path.join('android', 'gradle', 'wrapper', 'gradle-wrapper.properties')
- ]);
- });
-
- it('replaces variables', function() {
- assert.fileContent(path.join('android', 'app', 'build.gradle'), 'applicationId "com.reactnative.test"');
- assert.fileContent(
- path.join('android', 'app', 'src', 'main', 'AndroidManifest.xml'),
- 'package="com.reactnative.test"'
- );
- assert.fileContent(
- path.join('android', 'app', 'src', 'main', 'AndroidManifest.xml'),
- 'name=".MainActivity"'
- );
- assert.fileContent(
- path.join('android', 'app', 'src', 'main', 'java', 'com', 'reactnative', 'test', 'MainActivity.java'),
- 'package com.reactnative.test;'
- );
- assert.fileContent(
- path.join('android', 'app', 'src', 'main', 'java', 'com', 'reactnative', 'test', 'MainActivity.java'),
- 'mReactRootView.startReactApplication(mReactInstanceManager, "TestAppAndroid", null);'
- );
- assert.fileContent(
- path.join('android', 'app', 'src', 'main', 'res', 'values', 'strings.xml'),
- '<string name="app_name">TestAppAndroid</string>'
- );
- });
- });
-
- describe('react:ios', function() {
- var assert;
-
- beforeEach(function() {
- // A deep dependency of yeoman spams console.log with giant json objects.
- // yeoman-generator/node_modules/
- // download/node_modules/
- // caw/node_modules/
- // get-proxy/node_modules/
- // rc/index.js
- var log = console.log;
- console.log = function() {};
- assert = require('yeoman-generator').assert;
- var helpers = require('yeoman-generator').test;
- console.log = log;
-
- var generated = false;
-
- runs(function() {
- helpers.run(path.resolve(__dirname, '../generator-ios'))
- .withArguments(['TestAppIOS'])
- .on('end', function() {
- generated = true;
- });
- });
-
- waitsFor(function() {
- jest.runAllTicks();
- jest.runOnlyPendingTimers();
- return generated;
- }, 'generation', 750);
- });
-
- it('creates files', function() {
- assert.file([
- 'ios/TestAppIOS/AppDelegate.h',
- 'ios/TestAppIOS/AppDelegate.m',
- 'ios/TestAppIOS/Base.lproj/LaunchScreen.xib',
- 'ios/TestAppIOS/Images.xcassets/AppIcon.appiconset/Contents.json',
- 'ios/TestAppIOS/Info.plist',
- 'ios/TestAppIOS/main.m',
- 'ios/TestAppIOS.xcodeproj/project.pbxproj',
- 'ios/TestAppIOS.xcodeproj/xcshareddata/xcschemes/TestAppIOS.xcscheme',
- 'ios/TestAppIOSTests/TestAppIOSTests.m',
- 'ios/TestAppIOSTests/Info.plist'
- ]);
- });
-
- it('replaces vars in AppDelegate.m', function() {
- var appDelegate = 'ios/TestAppIOS/AppDelegate.m';
-
- assert.fileContent(appDelegate, 'moduleName:@"TestAppIOS"');
- assert.noFileContent(appDelegate, '<%= name %>');
- });
-
- it('replaces vars in LaunchScreen.xib', function() {
- var launchScreen = 'ios/TestAppIOS/Base.lproj/LaunchScreen.xib';
-
- assert.fileContent(launchScreen, 'text="TestAppIOS"');
- assert.noFileContent(launchScreen, '<%= name %>');
- });
-
- it('replaces vars in TestAppIOSTests.m', function() {
- var tests = 'ios/TestAppIOSTests/TestAppIOSTests.m';
-
- assert.fileContent(tests, '@interface TestAppIOSTests : XCTestCase');
- assert.fileContent(tests, '@implementation TestAppIOSTests');
- assert.noFileContent(tests, '<%= name %>');
- });
-
- it('replaces vars in project.pbxproj', function() {
- var pbxproj = 'ios/TestAppIOS.xcodeproj/project.pbxproj';
- assert.fileContent(pbxproj, '"TestAppIOS"');
- assert.fileContent(pbxproj, '"TestAppIOSTests"');
- assert.fileContent(pbxproj, 'TestAppIOS.app');
- assert.fileContent(pbxproj, 'TestAppIOSTests.xctest');
-
- assert.noFileContent(pbxproj, '<%= name %>');
- });
-
- it('replaces vars in xcscheme', function() {
- var xcscheme = 'ios/TestAppIOS.xcodeproj/xcshareddata/xcschemes/TestAppIOS.xcscheme';
- assert.fileContent(xcscheme, '"TestAppIOS"');
- assert.fileContent(xcscheme, '"TestAppIOS.app"');
- assert.fileContent(xcscheme, 'TestAppIOS.xcodeproj');
- assert.fileContent(xcscheme, '"TestAppIOSTests.xctest"');
- assert.fileContent(xcscheme, '"TestAppIOSTests"');
-
- assert.noFileContent(xcscheme, '<%= name %>');
- });
- });
-});
@@ -1,38 +0,0 @@
-/**
- * Copyright (c) 2015-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- */
-'use strict';
-
-var fs = require('fs');
-var generate = require('../generate/generate');
-
-function android(argv, config, args) {
- return generate([
- '--platform', 'android',
- '--project-path', process.cwd(),
- '--project-name', args.projectName,
- ], config);
-}
-
-module.exports = {
- name: 'android',
- description: 'creates an empty android project',
- func: android,
- options: [{
- command: '--project-name [name]',
- default: () => {
- try {
- return JSON.parse(
- fs.readFileSync('package.json', 'utf8')
- ).name;
- } catch (e) {
- return 'unknown-app-name';
- }
- },
- }],
-};
@@ -36,7 +36,6 @@ export type Command = {
};
const documentedCommands = [
- require('./android/android'),
require('./server/server'),
require('./runIOS/runIOS'),
require('./runAndroid/runAndroid'),
@@ -1,31 +0,0 @@
-/**
- * Copyright (c) 2015-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- */
-'use strict';
-
-var path = require('path');
-var yeoman = require('yeoman-environment');
-
-/**
- * Simple utility for running the android yeoman generator.
- *
- * @param {String} projectDir root project directory (i.e. contains index.js)
- * @param {String} name name of the root JS module for this app
- */
-module.exports = function(projectDir, name) {
- var oldCwd = process.cwd();
- process.chdir(projectDir);
-
- var env = yeoman.createEnv();
- var generatorPath = path.join(__dirname, 'generator');
- env.register(generatorPath, 'react:app');
- var args = ['react:app', name].concat(process.argv.slice(4));
- env.run(args, {'skip-ios': true}, function() {
- process.chdir(oldCwd);
- });
-};
Oops, something went wrong.

0 comments on commit a477aec

Please sign in to comment.