Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions packages/cli/generator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@unioc/generator",
"type": "module",
"version": "0.0.9",
"description": "Template generator engine for unioc.",
"author": "Naily Zero <zero@naily.cc> (https://naily.cc)",
"license": "MIT",
"homepage": "https://unioc.dev",
"repository": {
"type": "git",
"url": "https://github.com/uniocjs/core.git",
"directory": "packages/cli/generator"
},
"bugs": {
"url": "https://github.com/uniocjs/core/issues"
},
"keywords": [
"unioc",
"generator",
"template"
],
"files": [
"dist",
"templates"
],
"scripts": {
"build": "tsdown",
"watch": "tsdown -w",
"prepublishOnly": "tsdown"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@types/prompts": "^2.4.9",
"@unioc/shared": "workspace:*",
"hbs": "^4.2.0",
"prompts": "^2.4.2"
}
}
38 changes: 38 additions & 0 deletions packages/cli/generator/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export interface IGeneratorTemplateCollection {
files: string[] | string
baseDir: string
}

export interface IGeneratorOptions {
templateCollections: IGeneratorTemplateCollection[]
}

export interface IGeneratorDestination {
baseDir: string
outDir: string
}

export interface IGenerateOptions {
destinations: IGeneratorDestination[]
}

export interface IEjectOptions {}

export interface IGeneratorService {
generate(generateOptions: IGenerateOptions): Promise<void>
eject(ejectOptions: IEjectOptions): Promise<void>
}

export async function createGenerator(_generatorOptions: IGeneratorOptions): Promise<IGeneratorService> {
async function generate(_generateOptions: IGenerateOptions): Promise<void> {

}

async function eject(_ejectOptions: IEjectOptions): Promise<void> {
}

return {
generate,
eject,
}
}
16 changes: 16 additions & 0 deletions packages/cli/generator/templates/vite-nestjs/package.json.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "{{name}}",
"version": "0.0.1",
"private": true,
"description": "",
"type": "module",
"scripts": {
"dev": "vite build --watch",
"build": "vite build",
"preview": "node ./dist/main.js"
},
"devDependencies": {
"vite": "^6.3.3",
"unioc": "latest"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Controller, Get } from '@nestjs/common'
import { AppService } from './app.service'

@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}

@Get()
getHello(): string {
return this.appService.getHello()
}
}
10 changes: 10 additions & 0 deletions packages/cli/generator/templates/vite-nestjs/src/app.module.ts.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common'
import { AppController } from './app.controller'
import { AppService } from './app.service'

@Module({
imports: [],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Injectable } from '@nestjs/common'

@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!'
}
}
15 changes: 15 additions & 0 deletions packages/cli/generator/templates/vite-nestjs/src/main.ts.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ExpressApp } from 'unioc/web-express'
import process from 'node:process'
import { NestJS } from 'unioc/adapter-nestjs'
import { AppModule } from './app.module'

async function main(): Promise<void> {
const app = new ExpressApp()

app.use(NestJS, {
imports: [AppModule],
})

await app.run(process.env.PORT ?? 3000)
}
main()
13 changes: 13 additions & 0 deletions packages/cli/generator/templates/vite-nestjs/tsconfig.json.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"strict": true,
"moduleResolution": "bundler",
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"include": ["src/**/*.ts"]
}
11 changes: 11 additions & 0 deletions packages/cli/generator/templates/vite-nestjs/vite.config.ts.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from 'vite'
import { NodeRunner } from 'vite-plugin-node-runner'

export default defineConfig({
plugins: [
NodeRunner({
entry: './dist/main.js',
sourceMap: true,
}),
],
})
11 changes: 11 additions & 0 deletions packages/cli/generator/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ESNext"],
"module": "ES2022",
"moduleResolution": "Bundler",
"strict": true,
"strictPropertyInitialization": false
},
"include": ["src", "test"]
}
14 changes: 14 additions & 0 deletions packages/cli/generator/tsdown.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from 'tsdown'
import swc from 'unplugin-swc'

export default defineConfig({
entry: {
index: './src/index.ts',
},
sourcemap: true,
clean: true,
format: ['esm', 'cjs'],
plugins: [
swc.rolldown(),
],
})
58 changes: 58 additions & 0 deletions pnpm-lock.yaml

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