@@ -16,6 +16,7 @@ import copyTemplate from './util/copyTemplate.js';
1616import mapReplace from './util/mapReplace.js' ;
1717import { createPackageJson } from './util/packageJson.js' ;
1818import toCapitalizedWords from './util/toCapitalizedWords.js' ;
19+ import { createAppWrapper } from './util/createAppWrapper.js' ;
1920
2021const { prompt } = Enquirer ;
2122const program = new Command ( ) ;
@@ -27,17 +28,29 @@ program
2728 . option ( '-C, --no-initial-commit' , "don't perform an initial commit" )
2829 . option ( '-I, --no-install' , "don't install packages after initialization" )
2930 . option ( '-M, --module-federation' , 'install to use as module (only internal)' )
31+ . option ( '-T, --tobit-internal' , 'includes tobit internal packages (chayns-logger and tobit-textstrings)' )
3032 . option (
3133 '-p, --package-manager <manager>' ,
3234 'specify the package manager to use (`npm` or `yarn`). Defaults to the one used to execute the command.' ,
3335 )
3436 . action ( createChaynsApp )
3537 . parse ( process . argv ) ;
3638
37- async function createChaynsApp ( { git, initialCommit, install, packageManager, moduleFederation } ) {
39+ async function createChaynsApp ( { git, initialCommit, install, packageManager, moduleFederation, tobitInternal } ) {
3840 let projectVersion ;
3941 let projectType ;
4042
43+ if ( tobitInternal ) {
44+ try {
45+ const res = await fetch ( `https://repo.tobit.ag` , { method : 'HEAD' , signal : AbortSignal . timeout ( 3000 ) } ) ;
46+ if ( ! res . ok ) {
47+ tobitInternal = false ;
48+ }
49+ } catch {
50+ tobitInternal = false ;
51+ }
52+ }
53+
4154 if ( ! moduleFederation ) {
4255 ( { projectVersion } = await prompt ( {
4356 type : 'select' ,
@@ -96,6 +109,7 @@ async function createChaynsApp({ git, initialCommit, install, packageManager, mo
96109 'install-command' : usedPackageManager === 'yarn' ? 'yarn' : 'npm install' ,
97110 'run-command' : usedPackageManager === 'yarn' ? 'yarn' : 'npm run' ,
98111 'package-name-underscore' : projectName . replace ( '-' , '_' ) ,
112+ 'logger-import' : tobitInternal ? `import './utils/logger';\n` : '' ,
99113 } ) ;
100114 }
101115
@@ -223,6 +237,14 @@ async function createChaynsApp({ git, initialCommit, install, packageManager, mo
223237 getTemplatePath ( `../templates/api-v5/shared/ts/.eslintrc` ) ,
224238 path . join ( destination , '.eslintrc' ) ,
225239 ) ;
240+ if ( tobitInternal ) {
241+ const templateInternalPath = `../templates/api-v5/internal/${ extension } /src` ;
242+ await copyTemplate ( {
243+ destination : destination + '/src' ,
244+ projectName,
245+ templateDir : path . join ( ` ${ dirname } ` . trim ( ) , templateInternalPath ) ,
246+ } ) ;
247+ }
226248 }
227249
228250 // Main template
@@ -244,6 +266,7 @@ async function createChaynsApp({ git, initialCommit, install, packageManager, mo
244266 useRedux,
245267 useTypescript,
246268 useVitest,
269+ tobitInternal,
247270 } ) ;
248271
249272 // copy README
@@ -275,9 +298,9 @@ async function createChaynsApp({ git, initialCommit, install, packageManager, mo
275298
276299 await copyFile (
277300 getTemplatePath (
278- `../templates/api-v5/shared/${ extension } /src/constants/server-urls .${ extension } ` ,
301+ `../templates/api-v5/shared/${ extension } /src/constants/serverUrls .${ extension } ` ,
279302 ) ,
280- path . join ( destination , `/src/constants/server-urls .${ extension } ` ) ,
303+ path . join ( destination , `/src/constants/serverUrls .${ extension } ` ) ,
281304 ) ;
282305
283306 // copy tsconfig.json
@@ -314,6 +337,28 @@ async function createChaynsApp({ git, initialCommit, install, packageManager, mo
314337 ) ;
315338 }
316339
340+ if ( tobitInternal ) {
341+ if ( ! fs . existsSync ( path . join ( destination , '/src/utils' ) ) ) {
342+ fs . mkdirSync ( path . join ( destination , '/src/utils' ) ) ;
343+ }
344+ await copyFile (
345+ getTemplatePath ( `../templates/api-v5/internal/${ extension } /src/utils/logger.${ extension } ` ) ,
346+ path . join ( destination , `/src/utils/logger.${ extension } ` ) ,
347+ ) ;
348+
349+ const filePath = path . join ( destination , `/src/components/AppWrapper.${ extension } x` ) ;
350+ fs . writeFileSync ( filePath , createAppWrapper ( {
351+ useRedux,
352+ useTypescript,
353+ moduleFederation,
354+ tobitInternal,
355+ packageNameUnderscore : projectName . replace ( '-' , '_' ) ,
356+ } ) ) ;
357+
358+ const npmrcPath = path . join ( destination , '.npmrc' ) ;
359+ fs . writeFileSync ( npmrcPath , 'registry=https://repo.tobit.ag/repository/npm/\n' ) ;
360+ }
361+
317362 const fileDestination = path . join ( destination , 'toolkit.config.js' ) ;
318363 if ( moduleFederation ) {
319364 const toolkitFileName = `toolkit.config-module.js` ;
@@ -380,9 +425,20 @@ async function createChaynsApp({ git, initialCommit, install, packageManager, mo
380425
381426 const runCommand = usedPackageManager === 'yarn' ? 'yarn dev' : 'npm run dev' ;
382427
383- console . log (
384- `Open the created ${ chalk . yellowBright (
385- `./${ projectName } /` ,
386- ) } folder in your favorite editor and start ${ chalk . cyanBright ( '`' + runCommand + '`' ) } .\n`,
387- ) ;
428+ if ( tobitInternal ) {
429+ console . log (
430+ `Open the created ${ chalk . yellowBright (
431+ `./${ projectName } /` ,
432+ ) } folder in your favorite editor.`,
433+ ) ;
434+ console . log ( `Initialize ${ chalk . yellowBright ( 'tobit-textstrings' ) } by calling ${ chalk . cyanBright ( 'npx tobit-textstrings init' ) } .` )
435+ console . log ( `Search for ${ chalk . greenBright ( 'TODO:' ) } and follow the instructions.` ) ;
436+ console . log ( `Start ${ chalk . cyanBright ( '`' + runCommand + '`' ) } .\n` ) ;
437+ } else {
438+ console . log (
439+ `Open the created ${ chalk . yellowBright (
440+ `./${ projectName } /` ,
441+ ) } folder in your favorite editor and start ${ chalk . cyanBright ( '`' + runCommand + '`' ) } .\n`,
442+ ) ;
443+ }
388444}
0 commit comments