Add TypeScript app creation (#5550)

* Add TypeScript app creation

* Actually specify new extension

* Check for ts and tsx

* Fix types in default service worker file

* Mirror changes in JS version of SW

* Separate templates

* Use separate template directory

* Remove unused function

* Add a tsconfig file to the template

* Test install of typescript

* Add e2e for TypeScript

* Check for index.tsx to make sure we're not in the JS template

* Ensure TypeScript doesn't leak into normal installs

* Ignore some files

* Print version of CRA

* Fix script

* Add new template

* Move test to correct location

* Use `verifyTypeScriptSetup` routine to populate files

* Ensure tsconfig is created
This commit is contained in:
Joe Haddad
2018-10-24 16:28:36 -04:00
committed by GitHub
parent 68a37351d5
commit b50590f7f4
19 changed files with 446 additions and 7 deletions

View File

@@ -21,6 +21,7 @@ const execSync = require('child_process').execSync;
const spawn = require('react-dev-utils/crossSpawn');
const { defaultBrowsers } = require('react-dev-utils/browsersHelper');
const os = require('os');
const verifyTypeScriptSetup = require('./utils/verifyTypeScriptSetup');
function isInGitRepository() {
try {
@@ -90,6 +91,8 @@ module.exports = function(
// Copy over some of the devDependencies
appPackage.dependencies = appPackage.dependencies || {};
const useTypeScript = appPackage.dependencies['typescript'] != null;
// Setup the script rules
appPackage.scripts = {
start: 'react-scripts start',
@@ -122,7 +125,7 @@ module.exports = function(
// Copy the files for the user
const templatePath = template
? path.resolve(originalDirectory, template)
: path.join(ownPath, 'template');
: path.join(ownPath, useTypeScript ? 'template-typescript' : 'template');
if (fs.existsSync(templatePath)) {
fs.copySync(templatePath, appPath);
} else {
@@ -192,6 +195,10 @@ module.exports = function(
}
}
if (useTypeScript) {
verifyTypeScriptSetup();
}
if (tryGitInit(appPath)) {
console.log();
console.log('Initialized a git repository.');