Skip to content

Commit

Permalink
功能模块及编译器初步实现
Browse files Browse the repository at this point in the history
  • Loading branch information
meepobrother committed May 3, 2019
1 parent 27de5a9 commit 169fb0b
Show file tree
Hide file tree
Showing 48 changed files with 513 additions and 280 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
/**/node_modules
/app
/hooks
/platforms
/cloud
1 change: 1 addition & 0 deletions addon/nger-addon/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## 模块管理
3 changes: 3 additions & 0 deletions addon/nger-install/inc/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


export default [];
23 changes: 23 additions & 0 deletions addon/nger-install/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { NgModule } from 'nger-core';
import pages, { NgerInstallPage } from './template';
import incs from './inc';
import { NgerInstallTypeorm } from './typeorm';

@NgModule({
declarations: [
// 模板
...pages,
// 控制器
...incs
],
providers: [],
bootstrap: [
// 默认跳转页面
NgerInstallPage
],
imports: [
// 数据库
NgerInstallTypeorm
]
})
export class NgerInstallModule { }
3 changes: 3 additions & 0 deletions addon/nger-install/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "nger-install"
}
26 changes: 26 additions & 0 deletions addon/nger-install/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## 系统安装配置

## 源码
- [x] `addon`
- [x] `ims-install`
- [ ] `inc` 控制器,服务端
- [ ] `template` 模板
- [ ] `typeorm` 数据库
- [ ] `index.ts` 模块入口
- [ ] `package.json` 插件描述

## 编译后
- [x] `addon`
- [x] `ims-install`
- [ ] `pc` pc网站
- [ ] `admin` 管理
- [ ] `ttapp` 字节跳动
- [ ] `aliapp` 支付宝
- [ ] `weapp` 微信小程序
- [ ] `wechat` 微信浏览器
- [ ] `h5` 手机网站
- [ ] `ios` ios端
- [ ] `android` 安卓端
- [ ] `index.js` // 插件,可安装卸载更新
- [ ] `server.js` // 可独立运行,nger start addon/ims-install/server.js -p 4200
- [ ] `package.json` // 插件描述
7 changes: 7 additions & 0 deletions addon/nger-install/template/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { NgerInstallPage } from './install/index';

export default [
NgerInstallPage
];

export { NgerInstallPage }
36 changes: 36 additions & 0 deletions addon/nger-install/template/install/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Page } from 'nger-core';

@Page({
path: '/install',
title: 'nger系统安装',
type: ['pc']
})
export class NgerInstallPage {

render() {
return <div>
<h2 className="title">欢迎使用Nger平台</h2>
<div className="step1">
<h4 className="title">管理员</h4>
<input type="text" placeholder="站长用户名" />
<input type="text" placeholder="站长密码" />
</div>
<div className="step2">
<h4 className="title">数据库配置</h4>
<input type="text" placeholder="数据库地址" />
<input type="text" placeholder="数据库端口" />
<input type="text" placeholder="数据库用户名" />
<input type="text" placeholder="数据库密码" />
</div>
<div className="step3">
<h4 className="title">挑选模块</h4>
<ul>
<li>商城</li>
<li>社区</li>
<li>bbs</li>
<li>官网</li>
</ul>
</div>
</div>
}
}
4 changes: 4 additions & 0 deletions addon/nger-install/typeorm/entities/addon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Entity } from 'nger-core'

@Entity()
export class NgerAddon { }
4 changes: 4 additions & 0 deletions addon/nger-install/typeorm/entities/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { NgerAddon } from './addon'
export default [
NgerAddon
];
10 changes: 10 additions & 0 deletions addon/nger-install/typeorm/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Typeorm } from 'nger-core'
import entities from './entities'
@Typeorm({
entities: [
...entities
],
migrations: [],
subscribers: []
})
export class NgerInstallTypeorm { }
7 changes: 4 additions & 3 deletions framework/inc/home.ts → addon/nger-welcome/inc/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Controller, Get } from 'nger-core'

// 首页
@Controller({
path: '/api'
})
export class NgerHome {
export class NgerWelcomeController {
@Get()
getSystemInfo() { }
getAllInstalled() {
return [];
}
}
10 changes: 10 additions & 0 deletions addon/nger-welcome/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { NgModule } from 'nger-core'
import pages from './template'
import { NgerWelcomeController } from './inc'
@NgModule({
declarations: [
...pages,
NgerWelcomeController
]
})
export class NgerWelcomeModule { }
32 changes: 32 additions & 0 deletions addon/nger-welcome/template/home/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Page } from 'nger-core';

@Page({
path: '/',
type: ['admin'],
title: '首页'
})
export class NgerWelcomeHomePage {

getLang() {
// 把这个当成规范
return {
[`客户1`]: {
'install_title': '模块安装'
},
[`客户2`]: {
'install_title': 'Nger模块安装'
}
}
}

render() {
return <div role="member">
<li>bbs</li>
<li>商城</li>
<li>官网</li>
<li>博客</li>
<button id="install">模块安装</button>
</div>
}
}

5 changes: 5 additions & 0 deletions addon/nger-welcome/template/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { NgerWelcomeHomePage } from './home'

export default [
NgerWelcomeHomePage
]
3 changes: 0 additions & 3 deletions framework/admin.ts

This file was deleted.

3 changes: 0 additions & 3 deletions framework/app.ts

This file was deleted.

4 changes: 0 additions & 4 deletions framework/pc.ts

This file was deleted.

2 changes: 0 additions & 2 deletions framework/readme.md

This file was deleted.

5 changes: 0 additions & 5 deletions framework/server.ts

This file was deleted.

7 changes: 0 additions & 7 deletions framework/template/admin/components/footer/index.tsx

This file was deleted.

12 changes: 0 additions & 12 deletions framework/template/admin/components/header/index.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions framework/template/admin/components/index.ts

This file was deleted.

3 changes: 0 additions & 3 deletions framework/template/admin/pages/home/index.scss

This file was deleted.

23 changes: 0 additions & 23 deletions framework/template/admin/pages/home/index.tsx

This file was deleted.

Empty file removed framework/template/app/index.ts
Empty file.
Empty file removed framework/template/pc/index.ts
Empty file.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"lerna": "3.13.1",
"packages": [
"dist/*"
"packages/*"
],
"command": {
"publish": {
Expand Down
3 changes: 3 additions & 0 deletions packages/nger-compiler-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `nger-compiler-client`

> 客户端编译
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

const ngerCompilerClient = require('..');

describe('nger-compiler-client', () => {
it('needs tests');
});
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { NgModuleBootstrap, NgModuleRef, FileSystem,Logger } from 'nger-core';
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'
import { NgerCompilerNgMetadata, NgerCompilerBabel, NgerCompilerBabelController } from 'nger-compiler'
const root = process.cwd();
import { NgerUtil } from 'nger-util'
import { NgerCompilerBabel } from './ts/babel'
export class NgerCompilerBootstrap extends NgModuleBootstrap {
export class NgerCompilerClientBootstrap extends NgModuleBootstrap {
constructor(
public metadata: NgerCompilerNgMetadata,
public fs: FileSystem,
public util: NgerUtil,
public babel: NgerCompilerBabel,
public logger: Logger
public logger: Logger,
public controller: NgerCompilerBabelController
) {
super();
}
Expand All @@ -21,10 +21,9 @@ export class NgerCompilerBootstrap extends NgModuleBootstrap {
}
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)`])
chokidar.watch([`${addon}/**/*.(ts|tsx)`])
.on('add', (file, stats) => this.handlerTsxFile('add', file, stats))
.on('change', (file, stats) => this.handlerTsxFile('change', file, stats))
.on('error', () => { });
Expand All @@ -41,14 +40,17 @@ export class NgerCompilerBootstrap extends NgModuleBootstrap {
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 code = this.controller.compile(file);
const controllerPath = join(root, '.temp', `${noExtPath}.js`);
this.fs.writeFileSync(controllerPath, code)
}
} else {
const code = this.babel.compile(file);
const controllerPath = join(root, '.temp', `${noExtPath}.js`);
this.fs.writeFileSync(controllerPath, code)
}
}
}
16 changes: 16 additions & 0 deletions packages/nger-compiler-client/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { NgModuleBootstrap, FileSystem, Logger } from 'nger-core'
import compilerProviders, { NgerCompilerNgMetadata, NgerCompilerBabel, NgerCompilerBabelController } from 'nger-compiler'
import { NgerCompilerClientBootstrap } from './bootstrap'
import { NgerUtil } from 'nger-util'
export default [
...compilerProviders,
{
provide: NgModuleBootstrap,
useClass: NgerCompilerClientBootstrap,
multi: true,
deps: [
NgerCompilerNgMetadata, FileSystem, NgerUtil,
NgerCompilerBabel, Logger, NgerCompilerBabelController
]
},
]
Loading

0 comments on commit 169fb0b

Please sign in to comment.