first commit
This commit is contained in:
1
moehu/moehu_admin/bin/.pydio
Normal file
1
moehu/moehu_admin/bin/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
55d0c799-794b-47f5-b30f-2aeda081f5f4
|
||||
1
moehu/moehu_admin/bin/config/.pydio
Normal file
1
moehu/moehu_admin/bin/config/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
540faacb-8c40-430c-858c-b9cd6218e349
|
||||
94
moehu/moehu_admin/bin/config/index.js
Normal file
94
moehu/moehu_admin/bin/config/index.js
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2020. bmy
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
pageConfig: (name) => {
|
||||
return `
|
||||
import "@pageLess/${ name }.less";
|
||||
import { Component } from 'vue-property-decorator';
|
||||
import { ${ name }Logic } from "@logic/page/${ name }.logic";
|
||||
import { RouterMeta, VueCustomize } from "@logic/Base.type";
|
||||
import { Route, RawLocation } from 'vue-router';
|
||||
|
||||
@Component
|
||||
export default class ${ name } extends VueCustomize {
|
||||
private logic: ${ name }Logic<${ name }> = new ${ name }Logic(this);
|
||||
private RouterMeta: RouterMeta = {
|
||||
title: '${ name }',
|
||||
isLogin: true
|
||||
};
|
||||
|
||||
public async created() {
|
||||
await this.logic.StartUp();
|
||||
};
|
||||
|
||||
// 路由拦截器
|
||||
beforeRouteEnter(to: Route, from: Route, next: (to?: RawLocation | false | ((vm: Vue) => void)) => void) {
|
||||
next();
|
||||
}
|
||||
|
||||
protected render() {
|
||||
return (
|
||||
<div class="${ name }">
|
||||
${ name }
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
`
|
||||
},
|
||||
logicConfig: (name) => {
|
||||
return `
|
||||
import { BaseLogic } from "@logic/Base.logic";
|
||||
import { Autowired } from "@ann/Ioc.annotation";
|
||||
import { Methods, VueCustomize } from "@logic/Base.type";
|
||||
import { UserServiceImpl } from "@impl/User.service.impl";
|
||||
|
||||
export class ${ name }Logic<T extends VueCustomize> extends BaseLogic implements Methods {
|
||||
|
||||
@Autowired
|
||||
public readonly UserServiceImpl!: UserServiceImpl;
|
||||
|
||||
constructor(_: T) {
|
||||
super();
|
||||
this._ = _;
|
||||
}
|
||||
|
||||
public async StartUp(): Promise<void> {
|
||||
|
||||
}
|
||||
}
|
||||
`
|
||||
},
|
||||
serviceConfig: (name) => {
|
||||
return `
|
||||
export interface ${ name }Service {
|
||||
IndexClass(params: object): Promise<any>;
|
||||
}
|
||||
`
|
||||
},
|
||||
implPathConfig: (name) => {
|
||||
return `
|
||||
import { ${ name }Service } from "@service/${ name }.service";
|
||||
import { Injectable } from "@ann/Ioc.annotation";
|
||||
import { GET } from "@ann/Http.annotation";
|
||||
|
||||
@Injectable()
|
||||
export class ${ name }ServiceImpl implements ${ name }Service {
|
||||
|
||||
@GET({ useHandle: false })
|
||||
public async IndexClass(params: object): Promise<any> { }
|
||||
|
||||
}
|
||||
`
|
||||
},
|
||||
lessConfig: (name) => {
|
||||
return `
|
||||
@import "../mixin/index";
|
||||
|
||||
.${ name } {
|
||||
}
|
||||
`
|
||||
}
|
||||
}
|
||||
105
moehu/moehu_admin/bin/tinit
Executable file
105
moehu/moehu_admin/bin/tinit
Executable file
@@ -0,0 +1,105 @@
|
||||
#!/usr/bin/env node
|
||||
const { program } = require('commander');
|
||||
const packageConfig = require("../package.json");
|
||||
const fs = require("fs");
|
||||
const path = require('path');
|
||||
const Config = require("./config");
|
||||
|
||||
var isWin = /^win/.test(process.platform);
|
||||
const RootPath = process.cwd();
|
||||
|
||||
program
|
||||
.requiredOption('-t, --file-type <type>', '文件类型: [page,logic,service,impl,less]')
|
||||
.option('-n, --file-name <name>', '被创建的文件名称')
|
||||
.option('-i, --is-create <is>', '是否为 -t 参数自动创建相关文件类型', false);
|
||||
|
||||
program.version(packageConfig.version, '-v, --version', '显示当前的版本');
|
||||
|
||||
program.parse(process.argv);
|
||||
|
||||
// 存储终端的参数
|
||||
let programOptions = program.opts();
|
||||
let OtherFileType = program.parse(process.argv).args
|
||||
|
||||
// tsx 页面路径
|
||||
let PagePath = isWin ? `${RootPath}\\src\\application\\page\\${UpperCase(programOptions.fileName)}.tsx` :`${RootPath}/src/application/page/${UpperCase(programOptions.fileName)}.tsx`;
|
||||
// logic 页面路径
|
||||
let LogicPath = isWin ? `${RootPath}\\src\\application\\logic\\page\\${UpperCase(programOptions.fileName)}.logic.ts` : `${RootPath}/src/application/logic/page/${UpperCase(programOptions.fileName)}.logic.ts`;
|
||||
// service 页面路径
|
||||
let ServicePath = isWin ? `${RootPath}\\src\\core\\service\\${UpperCase(programOptions.fileName)}.service.ts` : `${RootPath}/src/core/service/${UpperCase(programOptions.fileName)}.service.ts`;
|
||||
// Impl 页面路径
|
||||
let ImplPath = isWin ? `${RootPath}\\src\\core\\service\\impl\\${UpperCase(programOptions.fileName)}.service.impl.ts` : `${RootPath}/src/core/service/impl/${UpperCase(programOptions.fileName)}.service.impl.ts`;
|
||||
// Less 页面路径
|
||||
let LessPath = isWin ? `${RootPath}\\src\\application\\assets\\less\\page\\${UpperCase(programOptions.fileName)}.less` : `${RootPath}/src/application/assets/less/page/${UpperCase(programOptions.fileName)}.less`;
|
||||
|
||||
// 需要创建的文件类型
|
||||
let FileList = ['page', 'logic', 'service', 'impl', 'less'];
|
||||
|
||||
// 是否需要为 controller 联合创建所有文件
|
||||
if (programOptions.isCreate) {
|
||||
FileList.forEach(val => replaceTplText(val));
|
||||
console.log("成功创建文件...");
|
||||
} else {
|
||||
// 循环创建多个文件
|
||||
if (OtherFileType.length !=0 ) {
|
||||
[...OtherFileType, programOptions.fileType].forEach(v => replaceTplText(v))
|
||||
} else {
|
||||
replaceTplText(programOptions.fileType)
|
||||
}
|
||||
console.log("成功创建文件...");
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换模板的内容,并将内容写入文件。
|
||||
*/
|
||||
let FileText = ""
|
||||
function replaceTplText (action) {
|
||||
switch (action) {
|
||||
case 'page':
|
||||
fs.writeFileSync(PagePath, Config.pageConfig(UpperCase(programOptions.fileName)));
|
||||
break;
|
||||
case 'logic':
|
||||
fs.writeFileSync(LogicPath, Config.logicConfig(UpperCase(programOptions.fileName)));
|
||||
break;
|
||||
case 'service':
|
||||
fs.writeFileSync(ServicePath, Config.serviceConfig(UpperCase(programOptions.fileName)));
|
||||
break;
|
||||
case 'impl':
|
||||
fs.writeFileSync(ImplPath, Config.implPathConfig(UpperCase(programOptions.fileName)));
|
||||
break;
|
||||
case 'less':
|
||||
fs.writeFileSync(LessPath, Config.lessConfig(UpperCase(programOptions.fileName)));
|
||||
break;
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 单词首字母大写
|
||||
* @param str
|
||||
* @returns {void | string | *}
|
||||
* @constructor
|
||||
*/
|
||||
function UpperCase (str) {
|
||||
return str.replace(str[0],str[0].toUpperCase())
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取文件内容
|
||||
* @param path
|
||||
* @returns {*}
|
||||
* @constructor
|
||||
*/
|
||||
function GetFileText (path) {
|
||||
return (fs.readFileSync( pathJoin(path), 'utf-8' )).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼接路径
|
||||
* @param paths
|
||||
* @returns {string}
|
||||
*/
|
||||
function pathJoin (paths) {
|
||||
return path.join(__dirname, paths)
|
||||
}
|
||||
Reference in New Issue
Block a user