@@ -7,51 +7,106 @@ const runCommand = require('../src/utility/run-command');
77const { toolingVersionOptionName } = require ( '../src/utility/extract-tooling-version' ) ;
88const classify = require ( '../src/utility/string' ) . classify ;
99
10- const appName = 'my-app' ;
11- const sandboxPath = path . join ( process . cwd ( ) , './testing/sandbox/react' ) ;
12- const appPath = path . join ( sandboxPath , appName ) ;
13- const appLayoutPath = path . join ( sandboxPath , appName , 'src/Content.jsx' ) ;
14-
15- exports . engine = 'react' ;
16- exports . appPath = appPath ;
17- exports . deployPath = path . join ( appPath , 'dist' ) ;
18- exports . npmArgs = [ 'run' , 'build' ] ;
19- exports . fileExtention = 'jsx' ;
20-
21- exports . createApp = async ( toolingVersion ) => {
22- await rimraf ( sandboxPath ) ;
23- fs . mkdirSync ( sandboxPath , { recursive : true } ) ;
24-
25- const additionalArguments = toolingVersion && [ `--${ toolingVersionOptionName } ${ toolingVersion } ` ] || [ ] ;
26- await runCommand ( 'node' , [
27- path . join ( process . cwd ( ) , './index.js' ) ,
28- 'new' ,
29- 'react-app' ,
30- '--layout=side-nav-outer-toolbar' ,
31- '--template=javascript' ,
32- ...additionalArguments
33- ] , {
34- cwd : sandboxPath ,
35- forceNoCmd : true
36- } ) ;
37-
38- await runCommand ( 'node' , [
39- path . join ( process . cwd ( ) , './index.js' ) ,
40- 'add' ,
41- 'view' ,
42- 'new-page'
43- ] , {
44- cwd : appPath ,
45- forceNoCmd : true
46- } ) ;
47-
48- fs . writeFileSync ( path . join ( appPath , '.env' ) , 'SKIP_PREFLIGHT_CHECK=true' + EOL + 'BROWSER=none' ) ;
10+ function getConfig ( { engine, template, fileExtension, templateExtension, transpiler } ) {
11+ const appName = 'my-app' ;
12+ const sandboxPath = path . join ( process . cwd ( ) , `./testing/sandbox/${ engine } ` ) ;
13+ const appPath = path . join ( sandboxPath , appName ) ;
14+ const appLayoutPath = path . join ( sandboxPath , appName , `src/Content.${ templateExtension } ` ) ;
15+
16+ const config = {
17+ engine : engine ,
18+ appPath : appPath ,
19+ deployPath : path . join ( appPath , 'dist' ) ,
20+ npmArgs : [ 'run' , 'build' ] ,
21+ fileExtension,
22+ } ;
23+
24+ config . createApp = async ( toolingVersion ) => {
25+ await rimraf ( sandboxPath ) ;
26+ fs . mkdirSync ( sandboxPath , { recursive : true } ) ;
27+
28+ const additionalArguments = toolingVersion && [ `--${ toolingVersionOptionName } ${ toolingVersion } ` ] || [ ] ;
29+ await runCommand ( 'node' , [
30+ path . join ( process . cwd ( ) , './index.js' ) ,
31+ 'new' ,
32+ 'react-app' ,
33+ '--layout=side-nav-outer-toolbar' ,
34+ `--template=${ template } ` ,
35+ `--transpiler=${ transpiler } ` ,
36+ ...additionalArguments
37+ ] , {
38+ cwd : sandboxPath ,
39+ forceNoCmd : true
40+ } ) ;
41+
42+ await runCommand ( 'node' , [
43+ path . join ( process . cwd ( ) , './index.js' ) ,
44+ 'add' ,
45+ 'view' ,
46+ 'new-page'
47+ ] , {
48+ cwd : appPath ,
49+ forceNoCmd : true
50+ } ) ;
51+
52+ fs . writeFileSync ( path . join ( appPath , '.env' ) , 'SKIP_PREFLIGHT_CHECK=true' + EOL + 'BROWSER=none' ) ;
53+ } ;
54+
55+ config . setLayout = ( layoutName ) => {
56+ const regexToFind = / S i d e N a v \w + T o o l b a r a s S i d e N a v B a r L a y o u t / g;
57+ const newSubStr = `${ classify ( layoutName ) } as SideNavBarLayout` ;
58+ const data = fs . readFileSync ( appLayoutPath , 'utf8' ) ;
59+ const result = data . replace ( regexToFind , newSubStr ) ;
60+ fs . writeFileSync ( appLayoutPath , result , 'utf8' ) ;
61+ } ;
62+
63+ return config ;
64+ }
65+
66+
67+ const reactJs = {
68+ ...getConfig ( {
69+ engine : 'react' ,
70+ template : 'javascript' ,
71+ templateExtension : 'jsx' ,
72+ fileExtension : 'jsx' ,
73+ transpiler : 'babel' ,
74+ } ) ,
75+ } ;
76+
77+ const reactSwcJs = {
78+ ...getConfig ( {
79+ engine : 'react-swc' ,
80+ template : 'javascript' ,
81+ templateExtension : 'jsx' ,
82+ fileExtension : 'jsx' ,
83+ transpiler : 'swc' ,
84+ } ) ,
85+ } ;
86+
87+ const reactTs = {
88+ ...getConfig ( {
89+ engine : 'react-ts' ,
90+ template : 'typescript' ,
91+ templateExtension : 'tsx' ,
92+ fileExtension : 'ts' ,
93+ transpiler : 'babel' ,
94+ } )
95+ } ;
96+
97+ const reactSwcTs = {
98+ ...getConfig ( {
99+ engine : 'react-swc-ts' ,
100+ template : 'typescript' ,
101+ templateExtension : 'tsx' ,
102+ fileExtension : 'ts' ,
103+ transpiler : 'swc' ,
104+ } )
49105} ;
50106
51- exports . setLayout = ( layoutName ) => {
52- const regexToFind = / S i d e N a v \w + T o o l b a r a s S i d e N a v B a r L a y o u t / g;
53- const newSubStr = `${ classify ( layoutName ) } as SideNavBarLayout` ;
54- const data = fs . readFileSync ( appLayoutPath , 'utf8' ) ;
55- const result = data . replace ( regexToFind , newSubStr ) ;
56- fs . writeFileSync ( appLayoutPath , result , 'utf8' ) ;
107+ module . exports = {
108+ reactJs,
109+ reactTs,
110+ reactSwcJs,
111+ reactSwcTs,
57112} ;
0 commit comments