-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e91025
commit 4ecbbad
Showing
14 changed files
with
201 additions
and
918 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,4 @@ | |
/**/.rts2_cache_umd | ||
/**/node_modules | ||
/app | ||
/hooks | ||
/hooks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.task-edit{ | ||
display: block; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.task-list{ | ||
display: block; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Controller, Get } from 'nger-core' | ||
|
||
// 首页 | ||
@Controller({ | ||
path: '/api' | ||
}) | ||
export class NgerHome { | ||
@Get() | ||
getSystemInfo() { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { createPlatformFactory, NgModule } from 'nger-core' | ||
import ngerPlatformNode from 'nger-platform-node' | ||
import providers from '../lib' | ||
@NgModule() | ||
export class NgerCompilerTestModule { } | ||
createPlatformFactory(ngerPlatformNode, 'test', providers)([]).bootstrapModule(NgerCompilerTestModule) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { NgModuleBootstrap, NgModuleRef, FileSystem,Logger } from 'nger-core'; | ||
import chokidar from 'chokidar'; | ||
import { join, relative, extname } from 'path' | ||
import { Stats } from 'fs-extra' | ||
import { NgerCompilerNgMetadata } from './helper/ng_metadata' | ||
const root = process.cwd(); | ||
import { NgerUtil } from 'nger-util' | ||
import { NgerCompilerBabel } from './ts/babel' | ||
export class NgerCompilerBootstrap extends NgModuleBootstrap { | ||
constructor( | ||
public metadata: NgerCompilerNgMetadata, | ||
public fs: FileSystem, | ||
public util: NgerUtil, | ||
public babel: NgerCompilerBabel, | ||
public logger: Logger | ||
) { | ||
super(); | ||
} | ||
async run(ref: NgModuleRef<any>) { | ||
await this.watchTsx(); | ||
} | ||
async watchTsx() { | ||
// 监听ts文件变更并生成metadata.json文件 | ||
const framework = join(root, 'framework'); | ||
const addon = join(root, 'addon'); | ||
await this.util.rimraf(join(root, '.temp')); | ||
chokidar.watch([`${addon}/**/*.(ts|tsx)`, `${framework}/**/*.(ts|tsx)`]) | ||
.on('add', (file, stats) => this.handlerTsxFile('add', file, stats)) | ||
.on('change', (file, stats) => this.handlerTsxFile('change', file, stats)) | ||
.on('error', () => { }); | ||
} | ||
metadataCache: Map<string, string> = new Map(); | ||
ngModuleMetadataCache: Map<string, any> = new Map(); | ||
handlerTsxFile(opt: 'add' | 'change', file: string, stats: Stats) { | ||
const metadata = this.metadata.getMetadata(file); | ||
const relativePath = relative(root, file) | ||
const ext = extname(relativePath); | ||
const noExtPath = relativePath.replace(ext, '') | ||
const metadataPath = join(root, '.temp', `${noExtPath}.metadata.json`); | ||
this.fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2)) | ||
this.metadataCache.set(file, metadataPath) | ||
// 解析Controller成浏览器端接口 | ||
if (metadata) { | ||
this.logger.info(`compiler controller`) | ||
const config = this.metadata.getControllerConfig(metadata); | ||
if (config) { | ||
// 是controller | ||
const code = this.babel.compile(file); | ||
const controllerPath = join(root, '.temp', `${noExtPath}.js`); | ||
this.fs.writeFileSync(controllerPath, code) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Visitor, NodePath } from '@babel/traverse'; | ||
import t from '@babel/types'; | ||
|
||
export const controllerVisitor: Visitor = { | ||
// 转义Controller里面的Get/Post等,删除Injector | ||
ClassMethod(path: NodePath<t.ClassMethod>) { } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.