Skip to content

Commit 52dd7db

Browse files
mkonicekfacebook-github-bot
authored andcommitted
Remove built-in navigation template (facebook#21155)
Summary: This is an updated (rebased) version of the very old facebook#16579. I added a [template](https://github.com/facebook/react-native/tree/master/local-cli/templates/HelloNavigation) for react-navigation directly into the React Native repo a long time ago. The feature `react-native init --template foo` supports both: - Remote templates (`react-native-template-foo` in npm as well as HTTP URLs) - Local templates that ship with react-native itself In retrospect, adding the local template wasn't a good idea. Templates should live outside of the React Native repo and be versioned independently. This way templates can be fixed independently of React Native releases, and people can use new templates without having to upgrade React Native. Pull Request resolved: facebook#21155 Differential Revision: D9885719 Pulled By: hramos fbshipit-source-id: d2982f374d3c451c09e348ce5fcdca9d0be5a474
1 parent 85505fd commit 52dd7db

File tree

16 files changed

+3
-855
lines changed

16 files changed

+3
-855
lines changed

local-cli/generator/templates.js

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,6 @@ const execSync = require('child_process').execSync;
1414
const fs = require('fs');
1515
const path = require('path');
1616

17-
/**
18-
* Templates released as part of react-native in local-cli/templates.
19-
*/
20-
const builtInTemplates = {
21-
navigation: 'HelloNavigation',
22-
};
23-
24-
function listTemplatesAndExit(newProjectName, options) {
25-
if (options.template === true) {
26-
// Just listing templates using 'react-native init --template'.
27-
// Not creating a new app.
28-
// Print available templates and exit.
29-
const templateKeys = Object.keys(builtInTemplates);
30-
if (templateKeys.length === 0) {
31-
// Just a guard, should never happen as long builtInTemplates
32-
// above is defined correctly :)
33-
console.log(
34-
'There are no templates available besides ' +
35-
'the default "Hello World" one.',
36-
);
37-
} else {
38-
console.log(
39-
'The available templates are:\n' +
40-
templateKeys.join('\n') +
41-
'\nYou can use these to create an app based on a template, for example: ' +
42-
'you could run: ' +
43-
'react-native init ' +
44-
newProjectName +
45-
' --template ' +
46-
templateKeys[0],
47-
);
48-
}
49-
// Exit 'react-native init'
50-
return true;
51-
}
52-
// Continue 'react-native init'
53-
return false;
54-
}
55-
5617
/**
5718
* @param destPath Create the new project at this path.
5819
* @param newProjectName For example 'AwesomeApp'.
@@ -92,41 +53,7 @@ function createProjectFromTemplate(
9253
// This way we don't have to duplicate the native files in every template.
9354
// If we duplicated them we'd make RN larger and risk that people would
9455
// forget to maintain all the copies so they would go out of sync.
95-
const builtInTemplateName = builtInTemplates[template];
96-
if (builtInTemplateName) {
97-
// template is e.g. 'navigation',
98-
// use the built-in local-cli/templates/HelloNavigation folder
99-
createFromBuiltInTemplate(
100-
builtInTemplateName,
101-
destPath,
102-
newProjectName,
103-
yarnVersion,
104-
);
105-
} else {
106-
// template is e.g. 'ignite',
107-
// use the template react-native-template-ignite from npm
108-
createFromRemoteTemplate(template, destPath, newProjectName, yarnVersion);
109-
}
110-
}
111-
112-
// (We might want to get rid of built-in templates in the future -
113-
// publish them to npm and install from there.)
114-
function createFromBuiltInTemplate(
115-
templateName,
116-
destPath,
117-
newProjectName,
118-
yarnVersion,
119-
) {
120-
const templatePath = path.resolve(
121-
'node_modules',
122-
'react-native',
123-
'local-cli',
124-
'templates',
125-
templateName,
126-
);
127-
copyProjectTemplateAndReplace(templatePath, destPath, newProjectName);
128-
installTemplateDependencies(templatePath, yarnVersion);
129-
installTemplateDevDependencies(templatePath, yarnVersion);
56+
createFromRemoteTemplate(template, destPath, newProjectName, yarnVersion);
13057
}
13158

13259
/**
@@ -264,6 +191,5 @@ function installTemplateDevDependencies(templatePath, yarnVersion) {
264191
}
265192

266193
module.exports = {
267-
listTemplatesAndExit,
268194
createProjectFromTemplate,
269195
};

local-cli/init/init.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
'use strict';
1111

1212
const {
13-
listTemplatesAndExit,
1413
createProjectFromTemplate,
1514
} = require('../generator/templates');
1615
const execSync = require('child_process').execSync;
@@ -44,14 +43,8 @@ function init(projectDir, argsOrName) {
4443
const newProjectName = args[0];
4544
const options = minimist(args);
4645

47-
if (listTemplatesAndExit(newProjectName, options)) {
48-
// Just listing templates using 'react-native init --template'
49-
// Not creating a new app.
50-
return;
51-
} else {
52-
console.log('Setting up new React Native app in ' + projectDir);
53-
generateProject(projectDir, newProjectName, options);
54-
}
46+
console.log('Setting up new React Native app in ' + projectDir);
47+
generateProject(projectDir, newProjectName, options);
5548
}
5649

5750
/**

local-cli/templates/HelloNavigation/App.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

local-cli/templates/HelloNavigation/README.md

Lines changed: 0 additions & 41 deletions
This file was deleted.

local-cli/templates/HelloNavigation/components/KeyboardSpacer.js

Lines changed: 0 additions & 120 deletions
This file was deleted.

local-cli/templates/HelloNavigation/components/ListItem.js

Lines changed: 0 additions & 56 deletions
This file was deleted.

local-cli/templates/HelloNavigation/dependencies.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)