mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-04-26 06:05:47 +08:00
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:
9
packages/react-scripts/scripts/init.js
vendored
9
packages/react-scripts/scripts/init.js
vendored
@@ -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.');
|
||||
|
||||
Reference in New Issue
Block a user