create-chayns-app 1.1.28 → 1.2.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/index.cjs +130 -0
  2. package/package.json +24 -16
  3. package/templates/api-v5/internal/js/src/redux-modules/index.js +17 -0
  4. package/templates/api-v5/internal/js/src/redux-modules/loggerMiddleware.js +31 -0
  5. package/templates/api-v5/internal/js/src/utils/logger.js +31 -0
  6. package/templates/api-v5/internal/ts/src/redux-modules/index.ts +20 -0
  7. package/templates/api-v5/internal/ts/src/redux-modules/loggerMiddleware.ts +45 -0
  8. package/templates/api-v5/internal/ts/src/utils/logger.ts +31 -0
  9. package/templates/api-v5/page/src/components/AppWrapper.jsx +7 -9
  10. package/templates/api-v5/page/src/index.html +1 -1
  11. package/templates/api-v5/page/src/index.jsx +2 -2
  12. package/templates/api-v5/page-module/src/components/App.jsx +19 -16
  13. package/templates/api-v5/page-module/src/components/AppWrapper.jsx +10 -12
  14. package/templates/api-v5/page-module-redux/src/components/App.jsx +22 -16
  15. package/templates/api-v5/page-module-redux/src/components/AppWrapper.jsx +7 -7
  16. package/templates/api-v5/page-redux/src/components/AppWrapper.jsx +9 -11
  17. package/templates/api-v5/page-redux/src/index.html +1 -1
  18. package/templates/api-v5/page-redux/src/index.jsx +2 -2
  19. package/templates/api-v5/page-ts/src/components/AppWrapper.tsx +7 -9
  20. package/templates/api-v5/page-ts/src/index.html +1 -1
  21. package/templates/api-v5/page-ts/src/index.tsx +2 -2
  22. package/templates/api-v5/page-ts-module/src/components/App.tsx +17 -14
  23. package/templates/api-v5/page-ts-module/src/components/AppWrapper.tsx +7 -7
  24. package/templates/api-v5/page-ts-module-redux/src/components/App.tsx +21 -14
  25. package/templates/api-v5/page-ts-module-redux/src/components/AppWrapper.tsx +13 -9
  26. package/templates/api-v5/page-ts-redux/src/components/AppWrapper.tsx +9 -11
  27. package/templates/api-v5/page-ts-redux/src/index.html +1 -1
  28. package/templates/api-v5/page-ts-redux/src/index.tsx +1 -2
  29. package/templates/api-v5/shared/.env.development.local +0 -2
  30. package/templates/api-v5/shared/{ts/src/constants/server-urls.ts → js/src/constants/serverUrls.js} +0 -1
  31. package/templates/api-v5/shared/js/src/redux-modules/counter/slice.js +5 -0
  32. package/templates/api-v5/shared/js/src/redux-modules/index.js +7 -3
  33. package/templates/api-v5/shared/toolkit.config-module.js +4 -2
  34. package/templates/api-v5/shared/toolkit.config.js +3 -3
  35. package/templates/api-v5/shared/{js/src/constants/server-urls.js → ts/src/constants/serverUrls.ts} +0 -1
  36. package/templates/api-v5/shared/ts/src/hooks/redux.ts +5 -0
  37. package/templates/api-v5/shared/ts/src/redux-modules/counter/slice.ts +5 -0
  38. package/templates/api-v5/shared/ts/src/redux-modules/index.ts +8 -4
  39. package/templates/api-v5/shared/ts/src/types/environment.d.ts +2 -2
  40. package/templates/api-v5/shared/ts/src/types/global.d.ts +5 -0
  41. package/templates/api-v5/shared/ts/tsconfig.json +17 -19
  42. package/templates/page/README.md +5 -8
  43. package/templates/page/src/index.html +1 -1
  44. package/templates/shared/README.md +5 -8
  45. package/templates/shared/tests/setup.js +9 -0
  46. package/templates/shared/vitest.config.mjs +18 -0
  47. package/.github/workflows/publish.yml +0 -21
  48. package/dist/index.js +0 -40
  49. package/templates/api-v5/shared/js/src/redux-modules/counter/selectors.js +0 -5
  50. package/templates/api-v5/shared/js/template-package-redux.json +0 -40
  51. package/templates/api-v5/shared/js/template-package.json +0 -38
  52. package/templates/api-v5/shared/ts/src/redux-modules/counter/selectors.ts +0 -6
  53. package/templates/api-v5/shared/ts/template-package-redux.json +0 -39
  54. package/templates/api-v5/shared/ts/template-package.json +0 -37
  55. package/templates/page/template-package.json +0 -33
  56. package/templates/shared/template-gitignore +0 -30
@@ -1,30 +1,37 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
2
  import { WaitUntil } from 'chayns-api';
3
3
  import { SmallWaitCursor } from '@chayns-components/core';
4
-
4
+ import { useSelector } from 'react-redux';
5
+ import { selectCounterValue } from '../redux-modules/counter/slice';
5
6
  import './app.scss';
6
7
 
7
8
  const App = () => {
9
+ const counter = useSelector(selectCounterValue);
8
10
 
9
- const taskList = [
10
- // tasks on first level are executed parallel
11
- () => new Promise((resolve) => {setTimeout(resolve, 1000)}), // Add your initial Requests, textstrings here
11
+ const [taskList] = useState(() => [
12
+ // first level tasks are executed one after the other
13
+ () =>
14
+ new Promise((resolve) => {
15
+ setTimeout(resolve, 1000);
16
+ }), // Add your initial Requests, textstrings here
12
17
  [
13
- // tasks in second level are executed one after another
14
- ]
15
- ]
18
+ // second level tasks are executed in parallel
19
+ ],
20
+ ]);
16
21
 
17
- return (<div className="{{ package-name-underscore }}">
22
+ return (
18
23
  <WaitUntil
19
24
  tasks={taskList}
20
- loadingComponent={(
21
- <div style={{ textAlign: 'center' }}>
22
- <SmallWaitCursor/>
25
+ loadingComponent={
26
+ <div style={{ display: 'flex', justifyContent: 'center' }}>
27
+ <SmallWaitCursor />
23
28
  </div>
24
- )}
29
+ }
25
30
  >
26
31
  <h1>Hi! Welcome to your newly created chayns application!</h1>
27
- </WaitUntil></div>);
32
+ <p>Count: {counter}</p>
33
+ </WaitUntil>
34
+ );
28
35
  };
29
36
 
30
37
  export default App;
@@ -1,17 +1,21 @@
1
- import React from 'react';
1
+ import React, { ComponentPropsWithoutRef } from 'react';
2
+ import { Provider } from 'react-redux';
2
3
  import { ChaynsProvider, withCompatMode } from 'chayns-api';
3
4
  import { PageProvider } from '@chayns-components/core';
4
5
  import App from './App';
6
+ import store from '../redux-modules';
5
7
 
6
- const AppWrapper = ({ ...props }) => {
7
- return (
8
- /* eslint-disable-next-line react/jsx-props-no-spreading */
8
+ const AppWrapper = (props: ComponentPropsWithoutRef<typeof ChaynsProvider>) => (
9
+ <div className="{{ package-name-underscore }}">
10
+ {/* eslint-disable-next-line react/jsx-props-no-spreading */}
9
11
  <ChaynsProvider {...props}>
10
- <PageProvider>
11
- <App/>
12
- </PageProvider>
12
+ <Provider store={store}>
13
+ <PageProvider>
14
+ <App />
15
+ </PageProvider>
16
+ </Provider>
13
17
  </ChaynsProvider>
14
- )
15
- }
18
+ </div>
19
+ );
16
20
 
17
21
  export default withCompatMode(AppWrapper);
@@ -5,16 +5,14 @@ import { PageProvider } from '@chayns-components/core';
5
5
  import App from './App';
6
6
  import store from '../redux-modules';
7
7
 
8
- const AppWrapper = () => {
9
- return (
10
- <ChaynsProvider>
11
- <Provider store={store}>
12
- <PageProvider>
13
- <App/>
14
- </PageProvider>
15
- </Provider>
16
- </ChaynsProvider>
17
- )
18
- }
8
+ const AppWrapper = () => (
9
+ <ChaynsProvider>
10
+ <Provider store={store}>
11
+ <PageProvider>
12
+ <App />
13
+ </PageProvider>
14
+ </Provider>
15
+ </ChaynsProvider>
16
+ );
19
17
 
20
18
  export default AppWrapper;
@@ -9,6 +9,6 @@
9
9
  <title>{{ readable-package-name }}</title>
10
10
  </head>
11
11
  <body>
12
- <div id="root" {{ tapp-style }}></div>
12
+ <div id="root"{{ tapp-style }}></div>
13
13
  </body>
14
14
  </html>
@@ -1,11 +1,10 @@
1
1
  import React from 'react';
2
2
  import { createRoot } from 'react-dom/client';
3
3
  import AppWrapper from './components/AppWrapper';
4
-
4
+ {{ logger-import }}
5
5
  try {
6
6
  const root = createRoot(document.querySelector('#root') as Element);
7
7
  root.render(<AppWrapper />);
8
8
  } catch (e) {
9
9
  console.error('Encountered error at `ReactDOM.render`: ', e);
10
10
  }
11
-
@@ -1,5 +1,3 @@
1
- PUBLIC_BUILD_ENV=development
2
-
3
1
  # set your development port here
4
2
  PORT=8080
5
3
 
@@ -1,2 +1 @@
1
-
2
1
  export const YOUR_WEBAPI_URL = process.env.PUBLIC_YOUR_WEBAPI_URL;
@@ -16,8 +16,13 @@ const slice = createSlice({
16
16
  state.value += payload;
17
17
  },
18
18
  },
19
+ selectors: {
20
+ selectCounterState: (state) => state,
21
+ selectCounterValue: (state) => state.value,
22
+ },
19
23
  });
20
24
 
21
25
  export const { increment, decrement, incrementByAmount } = slice.actions;
26
+ export const { selectCounterState, selectCounterValue } = slice.selectors;
22
27
  export const counterReducer = slice.reducer;
23
28
  export const counterSliceName = slice.name;
@@ -2,10 +2,14 @@ import { configureStore, combineReducers } from '@reduxjs/toolkit';
2
2
  import { counterReducer } from './counter/slice';
3
3
 
4
4
  const rootReducer = combineReducers({
5
- counter: counterReducer
5
+ counter: counterReducer,
6
6
  });
7
7
 
8
- const Store = configureStore({
8
+ export const createStore = (preloadedState) => configureStore({
9
9
  reducer: rootReducer,
10
+ preloadedState,
10
11
  });
11
- export default Store;
12
+
13
+ const store = createStore();
14
+
15
+ export default store;
@@ -7,7 +7,9 @@ module.exports = buildToolkitConfig({
7
7
  },
8
8
  output: {
9
9
  exposeModules: {
10
- './AppWrapper': './src/components/AppWrapper'
10
+ './AppWrapper': './src/components/AppWrapper',
11
11
  },
12
+ cssVersion: '5.0',
13
+ prefixCss: true,
12
14
  },
13
- })
15
+ });
@@ -7,12 +7,12 @@ module.exports = buildToolkitConfig({
7
7
  },
8
8
  output: {
9
9
  entryPoints: {
10
- 'index': {
10
+ index: {
11
11
  pathIndex: './src/index',
12
12
  pathHtml: './src/index.html',
13
13
  },
14
14
  // Add more entrypoints here
15
15
  },
16
- cssVersion: '5.0'
16
+ cssVersion: '5.0',
17
17
  },
18
- })
18
+ });
@@ -1,2 +1 @@
1
-
2
1
  export const YOUR_WEBAPI_URL = process.env.PUBLIC_YOUR_WEBAPI_URL;
@@ -0,0 +1,5 @@
1
+ import { useDispatch, useSelector } from 'react-redux';
2
+ import type { RootState, AppDispatch } from '../redux-modules';
3
+
4
+ export const useAppDispatch = useDispatch.withTypes<AppDispatch>();
5
+ export const useAppSelector = useSelector.withTypes<RootState>();
@@ -16,8 +16,13 @@ const counterSlice = createSlice({
16
16
  state.value += payload;
17
17
  },
18
18
  },
19
+ selectors: {
20
+ selectCounterState: (state) => state,
21
+ selectCounterValue: (state) => state.value,
22
+ },
19
23
  });
20
24
 
21
25
  export const { increment, decrement, incrementByAmount } = counterSlice.actions;
26
+ export const { selectCounterState, selectCounterValue } = counterSlice.selectors;
22
27
  export const counterReducer = counterSlice.reducer;
23
28
  export const counterSliceName = counterSlice.name;
@@ -2,13 +2,17 @@ import { configureStore, combineReducers } from '@reduxjs/toolkit';
2
2
  import { counterReducer } from './counter/slice';
3
3
 
4
4
  const rootReducer = combineReducers({
5
- counter: counterReducer
5
+ counter: counterReducer,
6
6
  });
7
7
 
8
- const Store = configureStore({
8
+ export const createStore = (preloadedState?: RootState) => configureStore({
9
9
  reducer: rootReducer,
10
+ preloadedState,
10
11
  });
11
12
 
13
+ const store = createStore();
14
+
12
15
  export type RootState = ReturnType<typeof rootReducer>;
13
- export type AppDispatch = typeof Store.dispatch;
14
- export default Store;
16
+ export type AppDispatch = ReturnType<typeof createStore>["dispatch"];
17
+
18
+ export default store;
@@ -1,7 +1,7 @@
1
1
  declare namespace NodeJS {
2
2
  interface ProcessEnv {
3
- PUBLIC_BUILD_ENV: string;
4
- PUBLIC_BUILD_VERSION: string;
3
+ BUILD_ENV: string;
4
+ BUILD_VERSION: string;
5
5
 
6
6
  /* add custom env variables here */
7
7
  PUBLIC_YOUR_WEBAPI_URL: string;
@@ -12,3 +12,8 @@ declare module '*.svg?url' {
12
12
  const value: string;
13
13
  export = value;
14
14
  }
15
+
16
+ declare module '*.json' {
17
+ const value: any;
18
+ export default value;
19
+ }
@@ -1,21 +1,19 @@
1
1
  {
2
- "compilerOptions": {
3
- "allowJs": true,
4
- "allowSyntheticDefaultImports": true,
5
- "baseUrl": "src",
6
- "checkJs": false,
7
- "esModuleInterop": true,
8
- "experimentalDecorators": true,
9
- "isolatedModules": true,
10
- "jsx": "react",
11
- "lib": [
12
- "DOM",
13
- "ESNext"
14
- ],
15
- "moduleResolution": "Node",
16
- "target": "ES2020",
17
- "noEmit": true,
18
- "skipLibCheck": true,
19
- "strict": true
20
- }
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "allowSyntheticDefaultImports": true,
5
+ "baseUrl": "src",
6
+ "checkJs": false,
7
+ "esModuleInterop": true,
8
+ "experimentalDecorators": true,
9
+ "isolatedModules": true,
10
+ "jsx": "react",
11
+ "lib": ["DOM", "ESNext"],
12
+ "moduleResolution": "Node",
13
+ "target": "ES2020",
14
+ "noEmit": true,
15
+ "resolveJsonModule": true,
16
+ "skipLibCheck": true,
17
+ "strict": true
18
+ }
21
19
  }
@@ -13,8 +13,7 @@
13
13
 
14
14
  ## Get Started
15
15
 
16
- To get started with working on the project first you have to install its
17
- dependencies:
16
+ To get started with working on the project first you have to install its dependencies:
18
17
 
19
18
  ```bash
20
19
  {{ install-command }}
@@ -24,16 +23,15 @@ Then you will have the following commands available:
24
23
 
25
24
  ### `{{ run-command }} dev`
26
25
 
27
- This starts the project with a local server for development. Typically this will
28
- be on [`http://localhost:1234/`](http://localhost:1234/), but this
26
+ This starts the project with a local server for development. Typically this will be on
27
+ [`http://localhost:1234/`](http://localhost:1234/), but this
29
28
  [can be adjusted](https://github.com/TobitSoftware/chayns-toolkit#development-options).
30
29
 
31
30
  ### `{{ run-command }} build`
32
31
 
33
32
  This builds your project for production.
34
33
 
35
- > If you want to analyze your bundle size you can do so by passing the `-a` flag
36
- > to this command.
34
+ > If you want to analyze your bundle size you can do so by passing the `-a` flag to this command.
37
35
 
38
36
  ### `{{ run-command }} lint`
39
37
 
@@ -45,7 +43,6 @@ Automatically formats all of the source code in your project.
45
43
 
46
44
  ---
47
45
 
48
- This project is based on
49
- [`chayns-toolkit`](https://github.com/TobitSoftware/chayns-toolkit). If you
46
+ This project is based on [`chayns-toolkit`](https://github.com/TobitSoftware/chayns-toolkit). If you
50
47
  encounter any issues with the toolchain and the commands, please
51
48
  [open an issue](https://github.com/TobitSoftware/chayns-toolkit/issues/new).
@@ -9,7 +9,7 @@
9
9
  <title>{{ readable-package-name }}</title>
10
10
  </head>
11
11
  <body>
12
- <div class="tapp" id="root" {{ tapp-style }}></div>
12
+ <div class="tapp" id="root"{{ tapp-style }}></div>
13
13
  <script src="https://api.chayns-static.space/js/v4.0/chayns.min.js"></script>
14
14
  </body>
15
15
  </html>
@@ -13,8 +13,7 @@
13
13
 
14
14
  ## Get Started
15
15
 
16
- To get started with working on the project first you have to install its
17
- dependencies:
16
+ To get started with working on the project first you have to install its dependencies:
18
17
 
19
18
  ```bash
20
19
  {{ install-command }}
@@ -24,16 +23,15 @@ Then you will have the following commands available:
24
23
 
25
24
  ### `{{ run-command }} dev`
26
25
 
27
- This starts the project with a local server for development. Typically this will
28
- be on [`http://localhost:1234/`](http://localhost:1234/), but this
26
+ This starts the project with a local server for development. Typically this will be on
27
+ [`http://localhost:1234/`](http://localhost:1234/), but this
29
28
  [can be adjusted](https://github.com/TobitSoftware/chayns-toolkit#development-options).
30
29
 
31
30
  ### `{{ run-command }} build`
32
31
 
33
32
  This builds your project for production.
34
33
 
35
- > If you want to analyze your bundle size you can do so by passing the `-a` flag
36
- > to this command.
34
+ > If you want to analyze your bundle size you can do so by passing the `-a` flag to this command.
37
35
 
38
36
  ### `{{ run-command }} lint`
39
37
 
@@ -45,7 +43,6 @@ Automatically formats all of the source code in your project.
45
43
 
46
44
  ---
47
45
 
48
- This project is based on
49
- [`chayns-toolkit`](https://github.com/TobitSoftware/chayns-toolkit). If you
46
+ This project is based on [`chayns-toolkit`](https://github.com/TobitSoftware/chayns-toolkit). If you
50
47
  encounter any issues with the toolchain and the commands, please
51
48
  [open an issue](https://github.com/TobitSoftware/chayns-toolkit/issues/new).
@@ -0,0 +1,9 @@
1
+ import { expect, afterEach } from 'vitest';
2
+ import { cleanup } from '@testing-library/react';
3
+ import * as matchers from '@testing-library/jest-dom/matchers';
4
+
5
+ expect.extend(matchers);
6
+
7
+ afterEach(() => {
8
+ cleanup();
9
+ });
@@ -0,0 +1,18 @@
1
+ import { defineConfig } from 'vitest/config';
2
+ import react from '@vitejs/plugin-react';
3
+
4
+ export default defineConfig({
5
+ plugins: [react()],
6
+ test: {
7
+ globals: true,
8
+ environment: 'jsdom',
9
+ setupFiles: './tests/setup.js',
10
+ coverage: {
11
+ enabled: true,
12
+ provider: 'v8',
13
+ reporter: ['text', 'json', 'html'],
14
+ include: ['src/**'],
15
+ all: true,
16
+ },
17
+ },
18
+ });
@@ -1,21 +0,0 @@
1
- name: Publish to NPM
2
-
3
- on:
4
- workflow_dispatch:
5
- push:
6
- tags:
7
- - 'v*'
8
-
9
- jobs:
10
- build:
11
- runs-on: ubuntu-latest
12
- steps:
13
- - uses: actions/checkout@v2
14
- - uses: actions/setup-node@v1
15
- with:
16
- node-version: '20'
17
- registry-url: https://registry.npmjs.org/
18
- - run: npm ci
19
- - run: npm publish
20
- env:
21
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}