From 8d6bb739a29330e912eba83abe2ac930dbc758ce Mon Sep 17 00:00:00 2001 From: imdhemy Date: Mon, 30 Dec 2024 12:57:19 +0100 Subject: [PATCH 1/4] feat(stub): add skeleton application --- .gitignore | 1 + stub/.gitignore | 3 +++ stub/index.ts | 0 stub/package.json | 30 ++++++++++++++++++++++ stub/src/config/app.ts | 8 ++++++ stub/src/controller/HomeController.ts | 8 ++++++ stub/src/index.ts | 8 ++++++ stub/tests/home-page.test.ts | 15 +++++++++++ stub/tsconfig.json | 36 +++++++++++++++++++++++++++ stub/vitest.config.ts | 15 +++++++++++ 10 files changed, 124 insertions(+) create mode 100644 stub/.gitignore delete mode 100644 stub/index.ts create mode 100644 stub/package.json create mode 100644 stub/src/config/app.ts create mode 100644 stub/src/controller/HomeController.ts create mode 100644 stub/src/index.ts create mode 100644 stub/tests/home-page.test.ts create mode 100644 stub/tsconfig.json create mode 100644 stub/vitest.config.ts diff --git a/.gitignore b/.gitignore index 1988291..a3258c1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules/ coverage/ dist/ +stub/package-lock.json diff --git a/stub/.gitignore b/stub/.gitignore new file mode 100644 index 0000000..06c3eac --- /dev/null +++ b/stub/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +coverage/ +dist/ diff --git a/stub/index.ts b/stub/index.ts deleted file mode 100644 index e69de29..0000000 diff --git a/stub/package.json b/stub/package.json new file mode 100644 index 0000000..6a1d56f --- /dev/null +++ b/stub/package.json @@ -0,0 +1,30 @@ +{ + "name": "koala-app", + "version": "1.0.0", + "description": "The skeleton application for Koala-Ts application", + "keywords": [ + "Koalats", + "Framework" + ], + "license": "ISC", + "author": "", + "type": "module", + "main": "dist/index.js", + "scripts": { + "start": "tsx watch src/index.ts", + "test": "vitest run --coverage", + "build": "tsc && tsc-alias" + }, + "dependencies": { + "@koala-ts/framework": "^0.1.0" + }, + "devDependencies": { + "tsc-alias": "^1.8.10", + "typescript": "^5.7.2", + "vitest": "^2.1.8", + "@vitest/coverage-v8": "^2.1.8", + "tsx": "^4.19.2", + "supertest": "^7.0.0", + "@types/supertest": "^6.0.2" + } +} diff --git a/stub/src/config/app.ts b/stub/src/config/app.ts new file mode 100644 index 0000000..b46ea35 --- /dev/null +++ b/stub/src/config/app.ts @@ -0,0 +1,8 @@ +import { HomeController } from '../controller/HomeController'; +import { type IKoalaConfig } from '@koala-ts/framework/dist/config/types'; + +export const appConfig: IKoalaConfig = { + controllers: [ + HomeController, + ] +}; diff --git a/stub/src/controller/HomeController.ts b/stub/src/controller/HomeController.ts new file mode 100644 index 0000000..29e1552 --- /dev/null +++ b/stub/src/controller/HomeController.ts @@ -0,0 +1,8 @@ +import { type IScope, Route } from '@koala-ts/framework'; + +export class HomeController { + @Route({ method: 'GET', path: '/' }) + index(scope: IScope): void { + scope.response.body = 'KoalaTS: Effortlessly elegant, relentlessly efficient. 🎩🐨'; + } +} diff --git a/stub/src/index.ts b/stub/src/index.ts new file mode 100644 index 0000000..84b7c7b --- /dev/null +++ b/stub/src/index.ts @@ -0,0 +1,8 @@ +import { create } from '@koala-ts/framework'; +import { appConfig } from './config/app'; + +const app = create(appConfig); + +app.listen(3000); + +console.log('Server is running on http://localhost:3000'); diff --git a/stub/tests/home-page.test.ts b/stub/tests/home-page.test.ts new file mode 100644 index 0000000..e904baa --- /dev/null +++ b/stub/tests/home-page.test.ts @@ -0,0 +1,15 @@ +import { beforeEach, describe, test } from 'vitest'; +import { ITestAgent, testAgent } from '@koala-ts/framework'; +import { appConfig } from '../src/config/app'; + +describe('Home Page', function () { + let agent: ITestAgent; + + beforeEach(function () { + agent = testAgent(appConfig); + }); + + test('it should return welcome message', function () { + return agent.get('/').expect(200, 'KoalaTS: Effortlessly elegant, relentlessly efficient. 🎩🐨'); + }); +}); diff --git a/stub/tsconfig.json b/stub/tsconfig.json new file mode 100644 index 0000000..47ae8c2 --- /dev/null +++ b/stub/tsconfig.json @@ -0,0 +1,36 @@ +{ + "compilerOptions": { + "esModuleInterop": true, + "target": "ESNext", + "allowJs": false, + "resolveJsonModule": true, + "moduleDetection": "force", + "isolatedModules": true, + "module": "Preserve", + "moduleResolution": "Node", + "strict": true, + "noUncheckedIndexedAccess": true, + "noImplicitOverride": true, + "noImplicitAny": true, + "rootDir": "./src", + "outDir": "./dist", + "strictNullChecks": true, + "allowSyntheticDefaultImports": true, + "baseUrl": ".", + "experimentalDecorators": true, + "emitDecoratorMetadata": true + }, + "include": [ + "src/**/*.ts" + ], + "exclude": [ + "node_modules", + "dist" + ], + "tsc-alias": { + "resolveFullPaths": true, + "verbose": false + }, + "types": [ + ] +} diff --git a/stub/vitest.config.ts b/stub/vitest.config.ts new file mode 100644 index 0000000..6987177 --- /dev/null +++ b/stub/vitest.config.ts @@ -0,0 +1,15 @@ +import { configDefaults, defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + coverage: { + exclude: [ + ...configDefaults.exclude, + '**/config/**', + 'src/index.ts', + '**/tests/**', + '**/types.ts', + ], + }, + }, +}); From 87c9e34af4238536c6bea2ef12b211dbcab1b169 Mon Sep 17 00:00:00 2001 From: imdhemy Date: Mon, 30 Dec 2024 13:09:47 +0100 Subject: [PATCH 2/4] fix(stub): fix copy command --- src/command/create-app.command.ts | 13 +++++++++++-- stub/package.json | 3 ++- tests/create-app.command.test.ts | 6 ++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/command/create-app.command.ts b/src/command/create-app.command.ts index 6c64575..50f5e6e 100644 --- a/src/command/create-app.command.ts +++ b/src/command/create-app.command.ts @@ -1,5 +1,5 @@ import { dirname, join } from 'path'; -import { copyFileSync, existsSync, mkdirSync, readdirSync } from 'fs'; +import { copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync } from 'fs'; import { fileURLToPath } from 'url'; import logger from '../util/logger'; @@ -39,10 +39,19 @@ function isEmptyDir(dirPath: string): boolean { } export function copyDirectoryContents(srcDir: string, destDir: string) { + if (!existsSync(destDir)) { + mkdirSync(destDir, { recursive: true }); + } + const files = readdirSync(srcDir); files.forEach(file => { const srcFile = join(srcDir, file); const destFile = join(destDir, file); - copyFileSync(srcFile, destFile); + + if (lstatSync(srcFile).isDirectory()) { + copyDirectoryContents(srcFile, destFile); + } else { + copyFileSync(srcFile, destFile); + } }); } diff --git a/stub/package.json b/stub/package.json index 6a1d56f..a89af69 100644 --- a/stub/package.json +++ b/stub/package.json @@ -13,7 +13,8 @@ "scripts": { "start": "tsx watch src/index.ts", "test": "vitest run --coverage", - "build": "tsc && tsc-alias" + "build": "tsc && tsc-alias", + "serve": "node dist/index.js" }, "dependencies": { "@koala-ts/framework": "^0.1.0" diff --git a/tests/create-app.command.test.ts b/tests/create-app.command.test.ts index cddcfa6..472811a 100644 --- a/tests/create-app.command.test.ts +++ b/tests/create-app.command.test.ts @@ -1,6 +1,6 @@ import { afterEach, describe, expect, test } from 'vitest'; import { action, copyDirectoryContents, createDir, description, signature } from '../src/command/create-app.command'; -import { readdirSync, rmdirSync, unlinkSync } from 'node:fs'; +import { lstatSync, readdirSync, rmdirSync, unlinkSync } from 'node:fs'; import { existsSync } from 'fs'; import { dirname, join } from 'path'; import { fileURLToPath } from 'url'; @@ -9,7 +9,9 @@ function removeDirectory(dirPath: string) { if (existsSync(dirPath)) { readdirSync(dirPath).forEach((file) => { const currentPath = join(dirPath, file); - if (existsSync(currentPath)) { + if (lstatSync(currentPath).isDirectory()) { + removeDirectory(currentPath); + } else { unlinkSync(currentPath); } }); From 667241eefc30b8c495fbe7f39b6a5f33ceff26e2 Mon Sep 17 00:00:00 2001 From: imdhemy Date: Mon, 30 Dec 2024 13:13:27 +0100 Subject: [PATCH 3/4] Create README.md --- stub/README.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 stub/README.md diff --git a/stub/README.md b/stub/README.md new file mode 100644 index 0000000..8314145 --- /dev/null +++ b/stub/README.md @@ -0,0 +1,39 @@ +# KoalaTs + +This is the skeleton for a new KoalaTs project. + +## Getting Started + +Install the dependencies: + +```bash +npm install +``` + +Start the development server: + +```bash +npm start +``` + +To run the tests: + +```bash +npm test +``` + +To build the project: + +```bash +npm run build +``` + +Then you can serve the `dist` folder with any static server. + +```bash +npm run serve +``` + +## Documentation + +You can find the KoalaTs documentation [here](https://koala-ts.github.io/docs/). From 83d7a15ca48f580a8eef329550692b33e86205e6 Mon Sep 17 00:00:00 2001 From: imdhemy Date: Mon, 30 Dec 2024 13:14:05 +0100 Subject: [PATCH 4/4] Update package-lock.json --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3fc4d92..a5335e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@koala-ts/cli", - "version": "0.1.0", + "version": "0.1.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@koala-ts/cli", - "version": "0.1.0", + "version": "0.1.3", "license": "MIT", "dependencies": { "commander": "^12.1.0",