Skip to content

Commit

Permalink
update templates
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSergey committed Oct 24, 2024
1 parent b825093 commit c34503f
Show file tree
Hide file tree
Showing 40 changed files with 292 additions and 325 deletions.
11 changes: 1 addition & 10 deletions packages/starter/lib/packageJSONPreparing.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,19 @@ export const packageJSONPreparing = async (packageJSON, { appType, tester, nogit
dependencies: [
{ name: 'react', version: '18' },
{ name: 'redux-thunk', version: '3' },
{ name: 'history', version: '5' },
{ name: 'react-dom', version: '18' },
{ name: 'react-redux', version: '9' },
{ name: 'react-router', version: '6' },
{ name: 'react-router-dom', version: '6' },
{ name: 'history', version: '5' },
{ name: 'react-helmet', version: '6' },
{ name: 'redux', version: '5' },
{ name: '@reduxjs/toolkit', version: '2' },
{ name: '@loadable/component', version: '5' },
],
devDependencies: [
{ name: '@rockpack/compiler', version: packageJson.version },
{ name: '@types/react', version: '18' },
{ name: '@types/react-dom', version: '18' },
{ name: '@types/react-helmet', version: '6' },
{ name: '@types/loadable__component', version: '5' },
{ name: '@types/webpack-env', version: '1' },
],
});
break;
Expand All @@ -38,20 +33,18 @@ export const packageJSONPreparing = async (packageJSON, { appType, tester, nogit
{ name: 'koa', version: '2' },
{ name: 'koa-compress', version: '5' },
{ name: 'redux-thunk', version: '3' },
{ name: 'history', version: '5' },
{ name: 'koa-static', version: '5' },
{ name: 'react', version: '18' },
{ name: 'react-dom', version: '18' },
{ name: 'react-redux', version: '9' },
{ name: 'react-router', version: '6' },
{ name: 'react-router-dom', version: '6' },
{ name: 'entities', version: '3' },
{ name: 'redux', version: '5' },
{ name: 'react-helmet-async', version: '1' },
{ name: '@issr/core', version: '2.2.0' },
{ name: 'node-fetch', version: '3' },
{ name: '@reduxjs/toolkit', version: '2' },
{ name: 'serialize-javascript', version: '5' },
{ name: 'entities', version: '2' },
{ name: 'pretty-error', version: '4' },
{ name: '@koa/router', version: '12' },
{ name: '@loadable/component', version: '5' },
Expand All @@ -69,7 +62,6 @@ export const packageJSONPreparing = async (packageJSON, { appType, tester, nogit
{ name: '@types/koa-static', version: '4' },
{ name: '@types/loadable__server', version: '5' },
{ name: '@types/node', version: '20' },
{ name: '@types/webpack-env', version: '1' },
{ name: '@types/serialize-javascript', version: '5' },
],
});
Expand All @@ -85,7 +77,6 @@ export const packageJSONPreparing = async (packageJSON, { appType, tester, nogit
{ name: '@rockpack/compiler', version: packageJson.version },
{ name: '@types/react', version: '18' },
{ name: '@types/react-dom', version: '18' },
{ name: '@types/webpack-env', version: '1' },
],
});
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createMemoryHistory } from 'history';
import { ReactNode } from 'react';
import { Provider } from 'react-redux';
import { createMemoryRouter } from 'react-router';
import { RouterProvider } from 'react-router-dom';

import { Router } from '../components/router';
import { createStore } from '../store';
import { createMockServices } from './mock-services';

Expand All @@ -12,21 +12,25 @@ export const createAppWrapper = ({
}: {
initialState?: Record<string, unknown>;
url?: string;
} = {}): (({ children }: { children: ReactNode }) => JSX.Element) => {
const history = createMemoryHistory({
initialEntries: [url],
});

} = {}): (({ children }: { children: ReactNode }) => ReactNode) => {
const store = createStore({
history,
initialState,
services: createMockServices(),
});

// eslint-disable-next-line react/display-name
return ({ children }): JSX.Element => (
<Provider store={store}>
<Router history={history}>{children}</Router>
</Provider>
);
return ({ children }): ReactNode => {
const router = createMemoryRouter([
{
element: children,
path: url,
},
]);

return (
<Provider store={store}>
<RouterProvider router={router} />
</Provider>
);
};
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createSsr } from '@issr/core';
import { createMemoryHistory } from 'history';
import { ReactNode } from 'react';
import { Provider } from 'react-redux';
import { createMemoryRouter } from 'react-router';
import { RouterProvider } from 'react-router-dom';

import { Router } from '../components/router';
import { createStore } from '../store';
import { createMockServices } from './mock-services';

Expand All @@ -13,11 +13,7 @@ export const createAppWrapper = ({
}: {
initialState?: Record<string, unknown>;
url?: string;
} = {}): (({ children }: { children: ReactNode }) => JSX.Element) => {
const history = createMemoryHistory({
initialEntries: [url],
});

} = {}): (({ children }: { children: ReactNode }) => ReactNode) => {
const SSR = createSsr(
{},
{
Expand All @@ -26,17 +22,25 @@ export const createAppWrapper = ({
);

const store = createStore({
history,
initialState,
services: createMockServices(),
});

// eslint-disable-next-line react/display-name
return ({ children }): JSX.Element => (
<SSR>
<Provider store={store}>
<Router history={history}>{children}</Router>
</Provider>
</SSR>
);
return ({ children }): ReactNode => {
const router = createMemoryRouter([
{
element: children,
path: url,
},
]);

return (
<SSR>
<Provider store={store}>
<RouterProvider router={router} />
</Provider>
</SSR>
);
};
};
19 changes: 0 additions & 19 deletions packages/starter/templates/backbone/csr/src/app.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
declare namespace StyleModulesScssNamespace {
export interface IStyleModulesScss {
declare namespace StylesModuleScssNamespace {
export interface IStylesModuleScss {
img: string;
}
}

declare const StyleModulesScssModule: StyleModulesScssNamespace.IStyleModulesScss & {
declare const StylesModuleScssModule: StylesModuleScssNamespace.IStylesModuleScss & {
/** WARNING: Only available when `css-loader` is used without `style-loader` or `mini-css-extract-plugin` */
locals: StyleModulesScssNamespace.IStyleModulesScss;
locals: StylesModuleScssNamespace.IStylesModuleScss;
};

export = StyleModulesScssModule;
export = StylesModuleScssModule;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
declare namespace StyleModulesScssNamespace {
export interface IStyleModulesScss {
'image-holder': string;
declare namespace StylesModuleScssNamespace {
export interface IStylesModuleScss {
"image-holder": string;
}
}

declare const StyleModulesScssModule: StyleModulesScssNamespace.IStyleModulesScss & {
declare const StylesModuleScssModule: StylesModuleScssNamespace.IStylesModuleScss & {
/** WARNING: Only available when `css-loader` is used without `style-loader` or `mini-css-extract-plugin` */
locals: StyleModulesScssNamespace.IStyleModulesScss;
locals: StylesModuleScssNamespace.IStylesModuleScss;
};

export = StyleModulesScssModule;
export = StylesModuleScssModule;
12 changes: 4 additions & 8 deletions packages/starter/templates/backbone/csr/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { createBrowserHistory } from 'history';
import { createRoot } from 'react-dom/client';
import { Provider } from 'react-redux';
import { createBrowserRouter, RouterProvider } from 'react-router-dom';

import { App } from './app';
import { Router } from './components/router';
import { routes } from './routes';
import { createServices } from './services';
import { createStore } from './store';
import './types/global.declaration';

const history = createBrowserHistory();
const router = createBrowserRouter(routes);

const store = createStore({
history,
services: createServices(fetch),
});

Expand All @@ -21,9 +19,7 @@ const root = createRoot(container as HTMLElement);

root.render(
<Provider store={store}>
<Router history={history}>
<App />
</Router>
<RouterProvider router={router} />
</Provider>,
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
declare namespace StyleModulesScssNamespace {
export interface IStyleModulesScss {
'nav-holder': string;
declare namespace StylesModuleScssNamespace {
export interface IStylesModuleScss {
"nav-holder": string;
}
}

declare const StyleModulesScssModule: StyleModulesScssNamespace.IStyleModulesScss & {
declare const StylesModuleScssModule: StylesModuleScssNamespace.IStylesModuleScss & {
/** WARNING: Only available when `css-loader` is used without `style-loader` or `mini-css-extract-plugin` */
locals: StyleModulesScssNamespace.IStyleModulesScss;
locals: StylesModuleScssNamespace.IStylesModuleScss;
};

export = StyleModulesScssModule;
export = StylesModuleScssModule;
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { ReactElement } from 'react';
import { Outlet } from 'react-router';

import { Navigation } from './components/navigation';
import styles from './styles.module.scss';

export const MainPage = ({ children }: { children: ReactElement }): ReactElement => (
export const MainPage = (): ReactElement => (
<div>
<Navigation />
<div className={styles.wrapper}>{children}</div>
<div className={styles.wrapper}>
<Outlet />
</div>
</div>
);
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
declare namespace StyleModulesScssNamespace {
export interface IStyleModulesScss {
declare namespace StylesModuleScssNamespace {
export interface IStylesModuleScss {
wrapper: string;
}
}

declare const StyleModulesScssModule: StyleModulesScssNamespace.IStyleModulesScss & {
declare const StylesModuleScssModule: StylesModuleScssNamespace.IStylesModuleScss & {
/** WARNING: Only available when `css-loader` is used without `style-loader` or `mini-css-extract-plugin` */
locals: StyleModulesScssNamespace.IStyleModulesScss;
locals: StylesModuleScssNamespace.IStylesModuleScss;
};

export = StyleModulesScssModule;
export = StylesModuleScssModule;
37 changes: 37 additions & 0 deletions packages/starter/templates/backbone/csr/src/routes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { lazy, Suspense } from 'react';
import { Navigate } from 'react-router-dom';

import './assets/styles/global.scss';
import { MainPage } from './pages/main-page';

const Home = lazy(() => import('./pages/home/home.lazy'));
const Image = lazy(() => import('./pages/image/image.lazy'));

export const routes = [
{
children: [
{
element: (
<Suspense fallback={<div>Loading</div>}>
<Home />
</Suspense>
),
path: '/',
},
{
element: (
<Suspense fallback={<div>Loading</div>}>
<Image />
</Suspense>
),
path: '/image',
},
{
element: <Navigate to="/" />,
path: '*',
},
],
element: <MainPage />,
path: '/',
},
];
3 changes: 1 addition & 2 deletions packages/starter/templates/backbone/csr/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const rootReducer = combineReducers({
image: imageReducer,
});

export const createStore = ({ history, initialState, services }: IStoreProps): Store<IRootState> =>
export const createStore = ({ initialState, services }: IStoreProps): Store<IRootState> =>
configureStore({
devTools: isDevelopment(),
middleware: (getDefaultMiddleware) =>
Expand All @@ -17,7 +17,6 @@ export const createStore = ({ history, initialState, services }: IStoreProps): S
serializableCheck: false,
thunk: {
extraArgument: {
history,
services,
},
},
Expand Down
Loading

0 comments on commit c34503f

Please sign in to comment.