Skip to content

Commit 009bda6

Browse files
migrate to create-vite from create-app for React app creating
1 parent 671084d commit 009bda6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+14
-683
lines changed

packages/devextreme-cli/src/applications/application.react.js

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ const defaultStyles = [
1919
];
2020

2121
const getExtension = (appPath) => {
22-
return fs.existsSync(path.join(appPath, 'src', 'App.tsx')) ? '.tsx' : '.js';
22+
return fs.existsSync(path.join(appPath, 'src', 'App.tsx')) ? '.tsx' : '.jsx';
2323
};
2424

2525
const pathToPagesIndex = () => {
2626
const extension = getExtension(process.cwd());
2727
return path.join(process.cwd(), 'src', 'pages', `index${extension}`);
2828
};
2929

30-
const preparePackageJsonForTemplate = (appPath, appName, isTypeScript) => {
30+
const preparePackageJsonForTemplate = (appPath, appName) => {
3131
const dependencies = [
32-
{ name: 'sass', version: '^1.34.1' },
32+
{ name: 'sass-embedded', version: '^1.85.1' },
3333
{ name: 'devextreme-cli', version: latestVersions['devextreme-cli'], dev: true },
3434
{ name: 'react-router-dom', version: '^6.3.0' },
3535
];
@@ -61,26 +61,24 @@ const create = async(appName, options) => {
6161
isTypeScript: typescriptUtils.isTypeScript(templateType)
6262
});
6363
const toolingVersion = extractToolingVersion(options);
64-
const commandArguments = [`-p=create-react-app${toolingVersion}`, 'create-react-app', appName];
64+
const commandArguments = [`-p=create-vite${toolingVersion}`, 'create-vite', appName];
6565

66-
const templateSuffix = templateOptions.isTypeScript ? '-typescript' : '';
67-
const templatePath = path.resolve(__dirname, `../templates/cra-template${templateSuffix}`);
68-
69-
commandArguments.push(`--template file:${templatePath}`);
66+
commandArguments.push(`--template react${templateOptions.isTypeScript ? '-ts' : ''}`);
7067

7168
await runCommand('npx', commandArguments);
7269

7370
const appPath = path.join(process.cwd(), appName);
7471

7572
modifyIndexHtml(appPath, templateOptions.project);
73+
7674
addTemplate(appPath, appName, templateOptions);
7775
};
7876

7977
const modifyIndexHtml = (appPath, appName) => {
80-
const indexHtmlPath = path.join(appPath, 'public', 'index.html');
78+
const indexHtmlPath = path.join(appPath, 'index.html');
8179

8280
let htmlContent = fs.readFileSync(indexHtmlPath).toString();
83-
htmlContent = htmlContent.replace(/<title>(\w+\s*)+<\/title>/, `<title>${appName}<\/title>`);
81+
htmlContent = htmlContent.replace(/<title>[^<]+<\/title>/, `<title>${appName}<\/title>`);
8482
htmlContent = htmlContent.replace('<body>', '<body class="dx-viewport">');
8583

8684
fs.writeFileSync(indexHtmlPath, htmlContent);
@@ -97,7 +95,6 @@ const addTemplate = (appPath, appName, templateOptions) => {
9795
);
9896

9997
const manifestPath = path.join(appPath, 'public', 'manifest.json');
100-
const indexPath = path.join(appPath, 'src', templateOptions.isTypeScript ? 'index.tsx' : 'index.js');
10198

10299
const styles = [
103100
'./themes/generated/theme.additional.css',
@@ -108,15 +105,15 @@ const addTemplate = (appPath, appName, templateOptions) => {
108105
];
109106

110107
templateCreator.moveTemplateFilesToProject(applicationTemplatePath, appPath, templateOptions, getCorrectPath);
111-
removeFile(path.join(appPath, 'src', 'App.css'));
108+
112109
!templateOptions.isTypeScript && removeFile(path.join(appPath, 'src', 'types.js'));
110+
113111
if(!templateOptions.empty) {
114112
addSamplePages(appPath, templateOptions);
115113
}
116114

117115
preparePackageJsonForTemplate(appPath, appName, templateOptions.isTypeScript);
118116
updateJsonPropName(manifestPath, appName);
119-
addPolyfills(packageJsonUtils.getPackageJsonPath(), indexPath);
120117
install({}, appPath, styles);
121118
};
122119

@@ -130,15 +127,6 @@ const install = (options, appPath, styles) => {
130127
packageManager.runInstall({ cwd: appPath });
131128
};
132129

133-
const addPolyfills = (packagePath, indexPath) => {
134-
const packages = [
135-
{ name: 'react-app-polyfill', version: '^1.0.0' }
136-
];
137-
138-
packageJsonUtils.addDependencies(packagePath, packages);
139-
moduleUtils.insertImport(indexPath, './polyfills');
140-
};
141-
142130
const addStylesToApp = (filePath, styles) => {
143131
styles.forEach(style => {
144132
moduleUtils.insertImport(filePath, style);

packages/devextreme-cli/src/templates/cra-template-typescript/LICENSE

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

packages/devextreme-cli/src/templates/cra-template-typescript/README.md

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

packages/devextreme-cli/src/templates/cra-template-typescript/package.json

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

packages/devextreme-cli/src/templates/cra-template-typescript/template.json

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

packages/devextreme-cli/src/templates/cra-template-typescript/template/README.md

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

packages/devextreme-cli/src/templates/cra-template-typescript/template/gitignore

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

packages/devextreme-cli/src/templates/cra-template-typescript/template/public/index.html

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

packages/devextreme-cli/src/templates/cra-template-typescript/template/src/App.css

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

packages/devextreme-cli/src/templates/cra-template-typescript/template/src/App.test.tsx

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

0 commit comments

Comments
 (0)