From 03c277996ada23e0c8cffb2decb43bb249872132 Mon Sep 17 00:00:00 2001 From: CyberCookie Date: Tue, 19 Nov 2024 23:39:29 +0200 Subject: [PATCH] fix mini proj init script --- README.md | 31 +++++++++++++++++++++++-------- bin/index.ts | 2 +- bin/init_minimal.ts | 4 +++- bin/init_project.ts | 3 +++ 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1a073b8..e8dac3b 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ npm i siegel
-Create **app.js** file:
+Create **app.ts** file:
```ts import { createRoot } from 'react-dom/client' @@ -106,24 +106,39 @@ You may also define **NodeJS dev server** using `--server` flag: ```ts -// server.js +// server.ts -function appServer(app, { express }) { - console.log('Custom server is ready') +import type { ServerExtenderFn, ExpressExtenderParams } from '../core' + +const appServer: ServerExtenderFn = params => { + const { express, staticServer } = params as ExpressExtenderParams + + staticServer + .use(express.json()) } -module.exports = appServer +export default appServer +``` + +
+ +To bootstrap the app with server defined - run the next command: + +```sh +npx siegel run --server server.ts ``` -In console run: +
+ +Siegel provides a command to initialize mini project along with `server` and `app` files we created above:
```sh -npx siegel run --server server.js +npx siegel init -s ```
-Run `npx siegel` To get list of Siegel CLI commands +To list all the available Siegel CLI commands and flags: `npx siegel`

diff --git a/bin/index.ts b/bin/index.ts index 392d95f..f7c522f 100755 --- a/bin/index.ts +++ b/bin/index.ts @@ -184,7 +184,7 @@ const COMMANDS_TREE: CommanTree = { }, { flagLong: '--mini-serv', - flag: '-ms', + flag: '-s', defaultValue: false, description: 'Creates mini zero-config react TS project with preconfigured TS express server', paramAction({ result }) { diff --git a/bin/init_minimal.ts b/bin/init_minimal.ts index a6554a9..d9e9f9a 100644 --- a/bin/init_minimal.ts +++ b/bin/init_minimal.ts @@ -95,7 +95,9 @@ function init(isMiniServ: boolean) { path.relative(PATHS.cwd, PATHS.binOutput) ) .replace(`${LOC_NAMES.DEMO_MINI_APP_DIR_NAME}/`, '') - .replace(/\s--c.*$/g, '') + .replace(/\s--c.*$/g, ''), + + start_client: 'npx siegel run' } fs.writeFileSync(INIT_PATHS.userPackageJson, JSON.stringify(clientPackageJson, null, 4)) diff --git a/bin/init_project.ts b/bin/init_project.ts index 1164edc..a8af403 100644 --- a/bin/init_project.ts +++ b/bin/init_project.ts @@ -55,6 +55,7 @@ function main(isGlobal?: boolean) { siegelDemoAppServerPath: join(PATHS.demoProject, INIT_LOC_NAMES.DEMO_APP_SERVER_DIR_NAME), siegelDemoAppPathShift: relative(PATHS.demoProject, PATHS.packageRoot), siegelLibPath: join(pathToSiegelRelative, LOC_NAMES.LIB_OUTPUT_DIRNAME), + siegelTSConfigPath: join(PATHS.packageRoot, LOC_NAMES.TS_JSON), userServerEntryPath, userServerExtenderPath: join(userServerPath, INIT_LOC_NAMES.DEMO_APP_SERVER_EXTENDER), @@ -113,6 +114,8 @@ function main(isGlobal?: boolean) { INIT_PATHS.pathToSiegelRelative ) + clientTSConfig.compilerOptions.plugins = requireJSON(INIT_PATHS.siegelTSConfigPath).compilerOptions.plugins + const paths = clientTSConfig.compilerOptions.paths for (const alias in paths) { paths[alias][0] = paths[alias][0].replace(