Skip to content

Commit 80917bd

Browse files
author
Heiner Pöpping
committed
🎨 Format files with prettier
1 parent d732d13 commit 80917bd

File tree

11 files changed

+146
-83
lines changed

11 files changed

+146
-83
lines changed

src/index.js

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,34 @@ program
2828
.option('-C, --no-initial-commit', "don't perform an initial commit")
2929
.option('-I, --no-install', "don't install packages after initialization")
3030
.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)')
31+
.option(
32+
'-T, --tobit-internal',
33+
'includes tobit internal packages (chayns-logger and tobit-textstrings)',
34+
)
3235
.option(
3336
'-p, --package-manager <manager>',
3437
'specify the package manager to use (`npm` or `yarn`). Defaults to the one used to execute the command.',
3538
)
3639
.action(createChaynsApp)
3740
.parse(process.argv);
3841

39-
async function createChaynsApp({ git, initialCommit, install, packageManager, moduleFederation, tobitInternal }) {
42+
async function createChaynsApp({
43+
git,
44+
initialCommit,
45+
install,
46+
packageManager,
47+
moduleFederation,
48+
tobitInternal,
49+
}) {
4050
let projectVersion;
4151
let projectType;
4252

4353
if (tobitInternal) {
4454
try {
45-
const res = await fetch(`https://repo.tobit.ag`, { method: 'HEAD', signal: AbortSignal.timeout(3000) });
55+
const res = await fetch(`https://repo.tobit.ag`, {
56+
method: 'HEAD',
57+
signal: AbortSignal.timeout(3000),
58+
});
4659
if (!res.ok) {
4760
tobitInternal = false;
4861
}
@@ -342,28 +355,38 @@ async function createChaynsApp({ git, initialCommit, install, packageManager, mo
342355
fs.mkdirSync(path.join(destination, '/src/utils'));
343356
}
344357
await copyFile(
345-
getTemplatePath(`../templates/api-v5/internal/${extension}/src/utils/logger.${extension}`),
358+
getTemplatePath(
359+
`../templates/api-v5/internal/${extension}/src/utils/logger.${extension}`,
360+
),
346361
path.join(destination, `/src/utils/logger.${extension}`),
347362
);
348363

349364
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-
}));
365+
fs.writeFileSync(
366+
filePath,
367+
createAppWrapper({
368+
useRedux,
369+
useTypescript,
370+
moduleFederation,
371+
tobitInternal,
372+
packageNameUnderscore: projectName.replace('-', '_'),
373+
}),
374+
);
357375

358376
const npmrcPath = path.join(destination, '.npmrc');
359377
fs.writeFileSync(npmrcPath, 'registry=https://repo.tobit.ag/repository/npm/\n');
360378
}
361379

362-
const fileSource = getTemplatePath(`../templates/api-v5/shared/toolkit.config${moduleFederation ? '-module' : ''}.js`);
380+
const fileSource = getTemplatePath(
381+
`../templates/api-v5/shared/toolkit.config${moduleFederation ? '-module' : ''}.js`,
382+
);
363383
const fileDestination = path.join(destination, 'toolkit.config.js');
364384
let configContent = fs.readFileSync(fileSource, 'utf-8');
365385
if (tobitInternal) {
366-
configContent = configContent.replace(/(\s+)(port:.*)/, `$1$2$1cert: '//fs1/SSL/tobitag.crt',$1key: '//fs1/SSL/tobitag.key',`);
386+
configContent = configContent.replace(
387+
/(\s+)(port:.*)/,
388+
`$1$2$1cert: '//fs1/SSL/tobitag.crt',$1key: '//fs1/SSL/tobitag.key',`,
389+
);
367390
}
368391
fs.writeFileSync(fileDestination, configContent);
369392
}
@@ -425,7 +448,9 @@ async function createChaynsApp({ git, initialCommit, install, packageManager, mo
425448
`./${projectName}/`,
426449
)} folder in your favorite editor.`,
427450
);
428-
console.log(`Initialize ${chalk.yellowBright('tobit-textstrings')} by calling ${chalk.cyanBright('npx tobit-textstrings init')}.`)
451+
console.log(
452+
`Initialize ${chalk.yellowBright('tobit-textstrings')} by calling ${chalk.cyanBright('npx tobit-textstrings init')}.`,
453+
);
429454
console.log(`Search for ${chalk.greenBright('TODO:')} and follow the instructions.`);
430455
console.log(`Start ${chalk.cyanBright('`' + runCommand + '`')}.\n`);
431456
} else {

src/util/copyTemplate.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ export default async function copyTemplate({ destination, templateDir, adjustCon
1414
content = adjustContent(content);
1515
}
1616

17-
const realFileName = filename
18-
.replace('template-gitignore', '.gitignore');
17+
const realFileName = filename.replace('template-gitignore', '.gitignore');
1918

2019
const fileDestination = path.join(destination, realFileName);
2120

src/util/createAppWrapper.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
2-
export const createAppWrapper = ({ useTypescript, moduleFederation, useRedux, tobitInternal, packageNameUnderscore }) => {
1+
export const createAppWrapper = ({
2+
useTypescript,
3+
moduleFederation,
4+
useRedux,
5+
tobitInternal,
6+
packageNameUnderscore,
7+
}) => {
38
const lines = [];
49
let indent = 0;
510

@@ -13,22 +18,28 @@ export const createAppWrapper = ({ useTypescript, moduleFederation, useRedux, to
1318
if (moduleFederation && useRedux) {
1419
reactNamedImportsList.push('useState');
1520
}
16-
const reactNamedImports = reactNamedImportsList.length ? `, { ${reactNamedImportsList.join(', ')} }` : '';
21+
const reactNamedImports = reactNamedImportsList.length
22+
? `, { ${reactNamedImportsList.join(', ')} }`
23+
: '';
1724

1825
lines.push(`import React${reactNamedImports} from 'react';`);
1926

2027
if (useRedux) {
2128
lines.push(`import { Provider } from 'react-redux';`);
2229
}
2330

24-
lines.push(`import { ChaynsProvider${moduleFederation ? ', withCompatMode' : ''} } from 'chayns-api';`)
31+
lines.push(
32+
`import { ChaynsProvider${moduleFederation ? ', withCompatMode' : ''} } from 'chayns-api';`,
33+
);
2534
lines.push(`import { PageProvider } from '@chayns-components/core';`);
2635
if (tobitInternal) {
2736
lines.push(`import { TextStringProvider } from 'tobit-textstrings';`);
2837
}
29-
lines.push(`import App from './App';`)
38+
lines.push(`import App from './App';`);
3039
if (useRedux) {
31-
lines.push(`import ${moduleFederation ? '{ createStore }' : 'store'} from '../redux-modules';`);
40+
lines.push(
41+
`import ${moduleFederation ? '{ createStore }' : 'store'} from '../redux-modules';`,
42+
);
3243
}
3344
if (tobitInternal && moduleFederation) {
3445
lines.push(`import '../utils/logger';`);
@@ -41,20 +52,26 @@ export const createAppWrapper = ({ useTypescript, moduleFederation, useRedux, to
4152
}
4253

4354
if (moduleFederation && useRedux) {
44-
lines.push(`const AppWrapper = (${moduleFederation ? 'props' : ''}${moduleFederation && useTypescript ? ': ComponentPropsWithoutRef<typeof ChaynsProvider>' : ''}) => {`);
55+
lines.push(
56+
`const AppWrapper = (${moduleFederation ? 'props' : ''}${moduleFederation && useTypescript ? ': ComponentPropsWithoutRef<typeof ChaynsProvider>' : ''}) => {`,
57+
);
4558
indent += 4;
4659
lines.push(`${' '.repeat(indent)}const [store] = useState(createStore);`);
4760
lines.push('');
4861
lines.push(`${' '.repeat(indent)}return (`);
4962
} else {
50-
lines.push(`const AppWrapper = (${moduleFederation ? 'props' : ''}${moduleFederation && useTypescript ? ': ComponentPropsWithoutRef<typeof ChaynsProvider>' : ''}) => (`);
63+
lines.push(
64+
`const AppWrapper = (${moduleFederation ? 'props' : ''}${moduleFederation && useTypescript ? ': ComponentPropsWithoutRef<typeof ChaynsProvider>' : ''}) => (`,
65+
);
5166
}
5267
indent += 4;
5368

5469
if (moduleFederation) {
5570
lines.push(`${' '.repeat(indent)}<div className="${packageNameUnderscore}">`);
5671
indent += 4;
57-
lines.push(`${' '.repeat(indent)}{/* eslint-disable-next-line react/jsx-props-no-spreading */}`);
72+
lines.push(
73+
`${' '.repeat(indent)}{/* eslint-disable-next-line react/jsx-props-no-spreading */}`,
74+
);
5875
}
5976

6077
lines.push(`${' '.repeat(indent)}<ChaynsProvider${moduleFederation ? ' {...props}' : ''}>`);
@@ -110,11 +127,11 @@ export const createAppWrapper = ({ useTypescript, moduleFederation, useRedux, to
110127

111128
lines.push('');
112129
if (moduleFederation) {
113-
lines.push('export default withCompatMode(AppWrapper);')
130+
lines.push('export default withCompatMode(AppWrapper);');
114131
} else {
115132
lines.push('export default AppWrapper;');
116133
}
117134
lines.push('');
118135

119136
return lines.join('\n');
120-
}
137+
};

templates/api-v5/internal/js/src/redux-modules/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ const rootReducer = combineReducers({
66
counter: counterReducer,
77
});
88

9-
export const createStore = (preloadedState) => configureStore({
10-
reducer: rootReducer,
11-
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(loggerMiddleware),
12-
preloadedState,
13-
});
9+
export const createStore = (preloadedState) =>
10+
configureStore({
11+
reducer: rootReducer,
12+
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(loggerMiddleware),
13+
preloadedState,
14+
});
1415

1516
const store = createStore();
1617

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,39 @@
1-
import logger from "../utils/logger";
1+
import logger from '../utils/logger';
22

33
export const loggerMiddleware = () => (next) => (action) => {
44
try {
55
const metaAction = action;
6-
if (metaAction.meta.requestStatus === 'rejected') {
6+
if (metaAction?.meta?.requestStatus === 'rejected') {
77
if (metaAction.meta.aborted || metaAction.meta.condition) {
88
return next(action);
99
}
1010
if (process.env.NODE_ENV === 'development') {
11-
// eslint-disable-next-line no-console
12-
console.log('redux action error', action);
11+
console.warn('redux action error', action);
1312
}
14-
logger.error({
15-
message: 'redux action error',
16-
customText: metaAction.type,
17-
data: { arg: metaAction.meta.arg },
18-
section: 'redux-modules/loggerMiddleware',
19-
}, metaAction.error);
13+
logger.error(
14+
{
15+
message: 'redux action error',
16+
customText: metaAction.type,
17+
data: { arg: metaAction.meta.arg },
18+
section: 'redux-modules/loggerMiddleware',
19+
},
20+
metaAction.error,
21+
);
2022
}
2123
return next(action);
2224
} catch (ex) {
23-
logger.error({
24-
message: 'error in store',
25-
data: {
26-
action,
27-
}
28-
}, ex);
25+
if (process.env.NODE_ENV === 'development') {
26+
console.warn('error in store', action);
27+
}
28+
logger.error(
29+
{
30+
message: 'error in store',
31+
data: {
32+
action,
33+
},
34+
},
35+
ex,
36+
);
2937
}
3038
return undefined;
3139
};

templates/api-v5/internal/js/src/utils/logger.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ const logger = new ChaynsLogger({
66
applicationUid: '<applicationUid>',
77
overrideOnError: true,
88
overrideConsoleError: process.env.NODE_ENV !== 'development',
9-
useDevServer: process.env.NODE_ENV === 'development' || ['qa', 'development'].includes(process.env.BUILD_ENV),
9+
useDevServer:
10+
process.env.NODE_ENV === 'development' ||
11+
['qa', 'development'].includes(process.env.BUILD_ENV),
1012
version: process.env.BUILD_VERSION,
1113
throttleTime: 1000,
1214
middleware: (payload) => {
@@ -28,4 +30,4 @@ const logger = new ChaynsLogger({
2830
},
2931
});
3032

31-
export default logger;
33+
export default logger;

templates/api-v5/internal/ts/src/redux-modules/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ const rootReducer = combineReducers({
66
counter: counterReducer,
77
});
88

9-
export const createStore = (preloadedState?: RootState) => configureStore({
10-
reducer: rootReducer,
11-
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(loggerMiddleware),
12-
preloadedState,
13-
});
9+
export const createStore = (preloadedState?: RootState) =>
10+
configureStore({
11+
reducer: rootReducer,
12+
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(loggerMiddleware),
13+
preloadedState,
14+
});
1415

1516
const store = createStore();
1617

1718
export type RootState = ReturnType<typeof rootReducer>;
18-
export type AppDispatch = ReturnType<typeof createStore>["dispatch"];
19+
export type AppDispatch = ReturnType<typeof createStore>['dispatch'];
1920

2021
export default store;
Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Middleware } from "@reduxjs/toolkit";
2-
import logger from "../utils/logger";
1+
import { Middleware } from '@reduxjs/toolkit';
2+
import logger from '../utils/logger';
33

44
type MetaAction = {
55
type: string;
@@ -10,9 +10,9 @@ type MetaAction = {
1010
requestStatus: 'pending' | 'rejected' | 'fulfilled';
1111
aborted?: boolean;
1212
condition?: boolean;
13-
},
13+
};
1414
error?: Error;
15-
}
15+
};
1616

1717
export const loggerMiddleware: Middleware = () => (next) => (action) => {
1818
try {
@@ -25,25 +25,31 @@ export const loggerMiddleware: Middleware = () => (next) => (action) => {
2525
// eslint-disable-next-line no-console
2626
console.warn('redux action error', action);
2727
}
28-
logger.error({
29-
message: 'redux action error',
30-
customText: metaAction.type,
31-
data: { arg: metaAction.meta.arg },
32-
section: 'redux-modules/loggerMiddleware',
33-
}, metaAction.error);
28+
logger.error(
29+
{
30+
message: 'redux action error',
31+
customText: metaAction.type,
32+
data: { arg: metaAction.meta.arg },
33+
section: 'redux-modules/loggerMiddleware',
34+
},
35+
metaAction.error,
36+
);
3437
}
3538
return next(action);
3639
} catch (ex) {
3740
if (process.env.NODE_ENV === 'development') {
3841
// eslint-disable-next-line no-console
3942
console.warn('error in store', action);
4043
}
41-
logger.error({
42-
message: 'error in store',
43-
data: {
44-
action,
45-
}
46-
}, ex as Error);
44+
logger.error(
45+
{
46+
message: 'error in store',
47+
data: {
48+
action,
49+
},
50+
},
51+
ex as Error,
52+
);
4753
}
4854
return undefined;
4955
};

templates/api-v5/internal/ts/src/utils/logger.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ const logger = new ChaynsLogger({
66
applicationUid: '<applicationUid>',
77
overrideOnError: true,
88
overrideConsoleError: process.env.NODE_ENV !== 'development',
9-
useDevServer: process.env.NODE_ENV === 'development' || ['qa', 'development'].includes(process.env.BUILD_ENV),
9+
useDevServer:
10+
process.env.NODE_ENV === 'development' ||
11+
['qa', 'development'].includes(process.env.BUILD_ENV),
1012
version: process.env.BUILD_VERSION,
1113
throttleTime: 1000,
1214
middleware: (payload) => {
@@ -28,4 +30,4 @@ const logger = new ChaynsLogger({
2830
},
2931
});
3032

31-
export default logger;
33+
export default logger;

0 commit comments

Comments
 (0)