@@ -6,18 +6,35 @@ const getTemplateTypeInfo = require('../utility/prompts/typescript');
66const templateCreator = require ( '../utility/template-creator' ) ;
77const packageManager = require ( '../utility/package-manager' ) ;
88const packageJsonUtils = require ( '../utility/package-json-utils' ) ;
9- const modifyJson = require ( '../utility/modify-json-file' ) ;
109const insertItemToArray = require ( '../utility/file-content' ) . insertItemToArray ;
11- const moduleUtils = require ( '../utility/module' ) ;
1210const stringUtils = require ( '../utility/string' ) ;
1311const typescriptUtils = require ( '../utility/typescript-extension' ) ;
1412const removeFile = require ( '../utility/file-operations' ) . remove ;
1513const latestVersions = require ( '../utility/latest-versions' ) ;
1614const { extractDepsVersionTag } = require ( '../utility/extract-deps-version-tag' ) ;
15+ const {
16+ updateJsonPropName,
17+ bumpReact,
18+ getCorrectPath,
19+ addStylesToApp,
20+ getComponentPageName,
21+ } = require ( './application.react' ) ;
22+
1723const defaultStyles = [
1824 'devextreme/dist/css/dx.light.css'
1925] ;
2026
27+ const isNextJsApp = ( ) => {
28+ const appPath = process . cwd ( ) ;
29+
30+ return fs . existsSync ( path . join ( appPath , 'next.config.ts' ) ) || fs . existsSync ( path . join ( appPath , 'next.config.mjs' ) ) ;
31+ } ;
32+
33+ const isTsApp = ( ) => {
34+ const appPath = process . cwd ( ) ;
35+ return fs . existsSync ( path . join ( appPath , 'next.config.ts' ) ) ;
36+ } ;
37+
2138const getExtension = ( appPath ) => {
2239 return fs . existsSync ( path . join ( appPath , 'src/app' , 'page.tsx' ) ) ? '.tsx' : '.jsx' ;
2340} ;
@@ -41,25 +58,6 @@ const preparePackageJsonForTemplate = (appPath, appName) => {
4158 packageJsonUtils . updateName ( appPath , appName ) ;
4259} ;
4360
44- const updateJsonPropName = ( path , name ) => {
45- modifyJson ( path , content => {
46- content . name = name ;
47-
48- return content ;
49- } ) ;
50- } ;
51-
52- const bumpReact = ( appPath , versionTag ) => {
53- const dependencies = [
54- { name : 'react' , version : versionTag } ,
55- { name : 'react-dom' , version : versionTag } ,
56- { name : '@types/react' , version : versionTag , dev : true } ,
57- { name : '@types/react-dom' , version : versionTag , dev : true } ,
58- ] ;
59-
60- packageJsonUtils . addDependencies ( appPath , dependencies ) ;
61- } ;
62-
6361const create = async ( appName , options ) => {
6462 const templateType = await getTemplateTypeInfo ( options . template ) ;
6563 const layoutType = await getLayoutInfo ( options . layout ) ;
@@ -105,10 +103,6 @@ const modifyAppFiles = (appPath, { project, isTypeScript }) => {
105103 fs . writeFileSync ( entryFilePath , content ) ;
106104} ;
107105
108- const getCorrectPath = ( extension , pathToApp , isTypeScript ) => {
109- return extension === '.ts' || extension === '.tsx' ? typescriptUtils . setFileExtension ( pathToApp , isTypeScript ) : pathToApp ;
110- } ;
111-
112106const addTemplate = ( appPath , appName , templateOptions ) => {
113107 const applicationTemplatePath = path . join (
114108 templateCreator . getTempaltePath ( 'nextjs' ) ,
@@ -144,24 +138,24 @@ const addTemplate = (appPath, appName, templateOptions) => {
144138
145139const install = ( options , appPath , styles ) => {
146140 appPath = appPath ? appPath : process . cwd ( ) ;
141+ const extension = options . isTypeScript || isTsApp ( ) ? 'ts' : 'js' ;
142+ const srcFolder = fs . existsSync ( path . join ( appPath , 'src' ) ) ? 'src' : '' ;
143+ const isAppRouterApp = fs . existsSync ( path . join ( appPath , srcFolder , 'app' ) ) && fs . lstatSync ( appPath ) . isDirectory ( ) ;
144+
145+ const entryFilePath = isAppRouterApp
146+ ? path . join ( 'app' , `layout.${ extension } ` )
147+ : path . join ( 'pages' , `_app.${ extension } ` ) ;
148+
149+ const jsx = fs . existsSync ( path . join ( appPath , srcFolder , entryFilePath + 'x' ) ) ? 'x' : '' ;
150+
151+ const pathToMainComponent = path . join ( appPath , srcFolder , entryFilePath + jsx ) ;
147152
148- const pathToMainComponent = path . join ( appPath , 'src/app' , `layout.${ options . isTypeScript ? 'tsx' : 'jsx' } ` ) ;
149153 addStylesToApp ( pathToMainComponent , styles || defaultStyles ) ;
150154 packageJsonUtils . addDevextreme ( appPath , options . dxversion , 'react' ) ;
151155
152156 packageManager . runInstall ( { cwd : appPath } ) ;
153157} ;
154158
155- const addStylesToApp = ( filePath , styles ) => {
156- styles . forEach ( style => {
157- moduleUtils . insertImport ( filePath , style ) ;
158- } ) ;
159- } ;
160-
161- const getComponentPageName = ( viewName ) => {
162- return `${ stringUtils . classify ( viewName ) } Page` ;
163- } ;
164-
165159const getNavigationData = ( viewName , componentName , icon ) => {
166160 const pagePath = stringUtils . dasherize ( viewName ) ;
167161 return {
@@ -224,6 +218,7 @@ const addView = (pageName, options) => {
224218} ;
225219
226220module . exports = {
221+ isNextJsApp,
227222 install,
228223 create,
229224 addTemplate,
0 commit comments