Skip to content

Commit

Permalink
feat: add application skeleton (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
imdhemy authored Dec 30, 2024
2 parents b489daa + 83d7a15 commit c284820
Show file tree
Hide file tree
Showing 14 changed files with 181 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
node_modules/
coverage/
dist/
stub/package-lock.json
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions src/command/create-app.command.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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);
}
});
}
3 changes: 3 additions & 0 deletions stub/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
coverage/
dist/
39 changes: 39 additions & 0 deletions stub/README.md
Original file line number Diff line number Diff line change
@@ -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/).
Empty file removed stub/index.ts
Empty file.
31 changes: 31 additions & 0 deletions stub/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"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",
"serve": "node dist/index.js"
},
"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"
}
}
8 changes: 8 additions & 0 deletions stub/src/config/app.ts
Original file line number Diff line number Diff line change
@@ -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,
]
};
8 changes: 8 additions & 0 deletions stub/src/controller/HomeController.ts
Original file line number Diff line number Diff line change
@@ -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. 🎩🐨';
}
}
8 changes: 8 additions & 0 deletions stub/src/index.ts
Original file line number Diff line number Diff line change
@@ -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');
15 changes: 15 additions & 0 deletions stub/tests/home-page.test.ts
Original file line number Diff line number Diff line change
@@ -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. 🎩🐨');
});
});
36 changes: 36 additions & 0 deletions stub/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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": [
]
}
15 changes: 15 additions & 0 deletions stub/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -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',
],
},
},
});
6 changes: 4 additions & 2 deletions tests/create-app.command.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
}
});
Expand Down

0 comments on commit c284820

Please sign in to comment.