移除C#导出支持
支持针对表配置输出目录
This commit is contained in:
@@ -1,8 +1,16 @@
|
|||||||
|
# EditorConfig is awesome: https://EditorConfig.org
|
||||||
|
|
||||||
|
# top-most EditorConfig file
|
||||||
root = true
|
root = true
|
||||||
|
|
||||||
[*]
|
[*]
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
|
end_of_line = lf
|
||||||
charset = utf-8
|
charset = utf-8
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
insert_final_newline = false
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.{yml,yaml,tiny,yaml.txt,html}]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
|||||||
29
.vscode/settings.json
vendored
Normal file
29
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"*.tiny": "yaml",
|
||||||
|
"*.yaml.txt": "yaml",
|
||||||
|
"*.js.txt": "javascript",
|
||||||
|
"*.meta": "yaml",
|
||||||
|
"*.manifest": "yaml",
|
||||||
|
"*.asset": "yaml",
|
||||||
|
"project.tiny": "yaml"
|
||||||
|
},
|
||||||
|
"files.exclude": {
|
||||||
|
"Library": true,
|
||||||
|
"Logs": true,
|
||||||
|
"Temp": true,
|
||||||
|
"**/*.meta": true,
|
||||||
|
"Packages/packages-lock.json": true,
|
||||||
|
".temp": true,
|
||||||
|
"UI/.objs": true,
|
||||||
|
"yarn.lock": true,
|
||||||
|
"TextToolDatas": true,
|
||||||
|
"ProjectSettings": true,
|
||||||
|
"UserSettings": true,
|
||||||
|
"node_modules": true,
|
||||||
|
"qrcodes": true,
|
||||||
|
"obj": true,
|
||||||
|
"*.csproj": true,
|
||||||
|
"*.sln": true
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
input:
|
input:
|
||||||
- 配置表.xlsx
|
# - 配置表.xlsx
|
||||||
|
- 车辆.xlsx
|
||||||
parser:
|
parser:
|
||||||
first_column_as_id: true # 第一列用作 ID 列
|
first_column_as_id: true # 第一列用作 ID 列
|
||||||
constant_array_length: [
|
constant_array_length: [
|
||||||
# 这里填入需要固定数组长度的表名称
|
# 这里填入需要固定数组长度的表名称
|
||||||
]
|
]
|
||||||
|
|
||||||
output:
|
output:
|
||||||
json:
|
json:
|
||||||
enabled: true
|
enabled: true
|
||||||
@@ -14,13 +16,6 @@ output:
|
|||||||
enabled: true
|
enabled: true
|
||||||
directory: output/yaml
|
directory: output/yaml
|
||||||
indent: 2
|
indent: 2
|
||||||
csharp:
|
|
||||||
enabled: true
|
|
||||||
directory: output/csharp
|
|
||||||
namespace: game.data
|
|
||||||
base_type: tiny.data.UniqueIDObject
|
|
||||||
file_name: data
|
|
||||||
ignore_id: true
|
|
||||||
typescript:
|
typescript:
|
||||||
enabled: true
|
enabled: true
|
||||||
declaration: false
|
declaration: false
|
||||||
@@ -29,3 +24,6 @@ output:
|
|||||||
class_name_extension: Data
|
class_name_extension: Data
|
||||||
directory: output/typescript
|
directory: output/typescript
|
||||||
file_name: data
|
file_name: data
|
||||||
|
|
||||||
|
override:
|
||||||
|
车辆/Vehicle: output/车辆/Vehicle
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"colors": "^1.4.0",
|
"colors": "^1.4.0",
|
||||||
"js-yaml": "^3.14.0",
|
"js-yaml": "^3.14.0",
|
||||||
|
"source-map-support": "^0.5.21",
|
||||||
"xlsx": "^0.16.0"
|
"xlsx": "^0.16.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
project.tiny
Normal file
10
project.tiny
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
develop:
|
||||||
|
actions:
|
||||||
|
- name: dev
|
||||||
|
title: 脚本编译服务
|
||||||
|
description: 脚本编译服务
|
||||||
|
command: yarn dev
|
||||||
|
- name: test
|
||||||
|
title: 单元测试
|
||||||
|
description: 单元测试
|
||||||
|
command: node ./dist/binary.js ./excel-exporter.yaml
|
||||||
@@ -2,25 +2,28 @@ import { FileAccess, ModeFlags } from "tiny/io";
|
|||||||
import { ParserConfigs, TableParser, TableData } from "./TableParser";
|
import { ParserConfigs, TableParser, TableData } from "./TableParser";
|
||||||
import { ExporterConfigs, TableExporter } from "./TableExporter";
|
import { ExporterConfigs, TableExporter } from "./TableExporter";
|
||||||
import { JSONExporter } from "./exporters/JSONExporter";
|
import { JSONExporter } from "./exporters/JSONExporter";
|
||||||
import { CSharpExporter } from "./exporters/CSharpExporter";
|
|
||||||
import * as colors from "colors";
|
import * as colors from "colors";
|
||||||
import { TypeScriptExporter } from "./exporters/TypeScriptExporter";
|
import { TypeScriptExporter } from "./exporters/TypeScriptExporter";
|
||||||
import * as yaml from "js-yaml";
|
import * as yaml from "js-yaml";
|
||||||
import { YAMLExporter } from "./exporters/YAMLExporter";
|
import { YAMLExporter } from "./exporters/YAMLExporter";
|
||||||
|
import * as path from "path";
|
||||||
|
import * as fs from "fs";
|
||||||
|
|
||||||
export interface Configurations {
|
export interface Configurations {
|
||||||
/** 解析配置 */
|
/** 解析配置 */
|
||||||
parser?: ParserConfigs,
|
parser?: ParserConfigs,
|
||||||
/** 要读取的 XLSL 文档 */
|
/** 要读取的 XLSL 文档 */
|
||||||
input: {"file": string, encode: string}[],
|
input: string[],
|
||||||
/** 导出配置 */
|
/** 导出配置 */
|
||||||
output: { [key: string]: ExporterConfigs }
|
output: {
|
||||||
|
[key: string]: ExporterConfigs,
|
||||||
|
}
|
||||||
|
override: Record<string, string>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const exporters: {[key:string]: new(config: ExporterConfigs) => TableExporter } = {
|
const exporters: {[key:string]: new(config: ExporterConfigs) => TableExporter } = {
|
||||||
json: JSONExporter,
|
json: JSONExporter,
|
||||||
csharp: CSharpExporter,
|
|
||||||
typescript: TypeScriptExporter,
|
typescript: TypeScriptExporter,
|
||||||
yaml: YAMLExporter,
|
yaml: YAMLExporter,
|
||||||
}
|
}
|
||||||
@@ -53,8 +56,12 @@ export class ExcelExporterApplication {
|
|||||||
for (const file of this.configs.input) {
|
for (const file of this.configs.input) {
|
||||||
console.log(colors.grey(`解析配表文件: ${file}`));
|
console.log(colors.grey(`解析配表文件: ${file}`));
|
||||||
let sheets = this.parser.parse_xlsl(file);
|
let sheets = this.parser.parse_xlsl(file);
|
||||||
|
const base = path.basename(file).replace(/\.xlsx?$/, '');
|
||||||
for (const name in sheets) {
|
for (const name in sheets) {
|
||||||
this.tables[name] = sheets[name];
|
const override = this.configs.override[`${base}/${name}`];
|
||||||
|
const table = sheets[name];
|
||||||
|
table.output = override;
|
||||||
|
this.tables[name] = table;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(colors.green(`解析所有配表文件完成`));
|
console.log(colors.green(`解析所有配表文件完成`));
|
||||||
@@ -66,7 +73,18 @@ export class ExcelExporterApplication {
|
|||||||
if (exporter.configs.enabled) {
|
if (exporter.configs.enabled) {
|
||||||
console.log(colors.white(`执行 ${exporter.name} 导出:`));
|
console.log(colors.white(`执行 ${exporter.name} 导出:`));
|
||||||
for (const name in this.tables) {
|
for (const name in this.tables) {
|
||||||
exporter.export(name, this.tables[name]);
|
const table = this.tables[name];
|
||||||
|
const data = exporter.export(name, table);
|
||||||
|
if (data) {
|
||||||
|
let file = path.join(exporter.configs.directory, `${name}.${exporter.extension}`);
|
||||||
|
if (table.output) {
|
||||||
|
file = table.output + `.${exporter.extension}`;
|
||||||
|
}
|
||||||
|
const dir = path.dirname(file);
|
||||||
|
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
||||||
|
fs.writeFileSync(file, data);
|
||||||
|
console.log(colors.white(`\t ${name} => ${file}`));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exporter.finalize();
|
exporter.finalize();
|
||||||
console.log();
|
console.log();
|
||||||
|
|||||||
@@ -45,7 +45,9 @@ export class TableExporter {
|
|||||||
* @param name 表名称
|
* @param name 表名称
|
||||||
* @param table 表数据
|
* @param table 表数据
|
||||||
*/
|
*/
|
||||||
export(name: string, table: TableData) { }
|
export(name: string, table: TableData): string | Buffer {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/** 全部配置表导出完毕后保存文件 */
|
/** 全部配置表导出完毕后保存文件 */
|
||||||
finalize() {}
|
finalize() {}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import * as xlsl from "xlsx";
|
import * as xlsl from "xlsx";
|
||||||
import { FileAccess, ModeFlags } from "tiny/io";
|
import { FileAccess, ModeFlags } from "tiny/io";
|
||||||
import * as colors from "colors";
|
import * as colors from "colors";
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
export enum Keywords {
|
export enum Keywords {
|
||||||
SKIP = '@skip',
|
SKIP = '@skip',
|
||||||
@@ -32,6 +33,7 @@ type RawTableData = RawTableCell[][];
|
|||||||
export interface TableData {
|
export interface TableData {
|
||||||
struct: Field;
|
struct: Field;
|
||||||
data: {[key: string]: any}[];
|
data: {[key: string]: any}[];
|
||||||
|
output?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ParserConfigs {
|
export interface ParserConfigs {
|
||||||
@@ -230,8 +232,8 @@ export class TableParser {
|
|||||||
return this.load_raw_xlsl_data(path);
|
return this.load_raw_xlsl_data(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected load_raw_xlsl_data(path: string): { [key: string]: TableData } {
|
protected load_raw_xlsl_data(filePath: string): { [key: string]: TableData } {
|
||||||
var file = FileAccess.open(path, ModeFlags.READ);
|
var file = FileAccess.open(filePath, ModeFlags.READ);
|
||||||
let wb = xlsl.read(file.get_as_array());
|
let wb = xlsl.read(file.get_as_array());
|
||||||
file.close();
|
file.close();
|
||||||
let raw_tables: {[key: string]: RawTableData } = {};
|
let raw_tables: {[key: string]: RawTableData } = {};
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
import { TableExporter, ExporterConfigs } from "excel-exporter/TableExporter";
|
|
||||||
import { TableData, DataType } from "excel-exporter/TableParser";
|
|
||||||
import { path } from "tiny/path";
|
|
||||||
import * as colors from "colors";
|
|
||||||
|
|
||||||
interface CSharpExporterConfigs extends ExporterConfigs {
|
|
||||||
namespace: string,
|
|
||||||
base_type: string,
|
|
||||||
file_name: string,
|
|
||||||
ignore_id: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export class CSharpExporter extends TableExporter {
|
|
||||||
protected declear_content = "";
|
|
||||||
protected classes: string[] = [];
|
|
||||||
get extension(): string { return 'cs' }
|
|
||||||
|
|
||||||
constructor(configs: ExporterConfigs) {
|
|
||||||
super(configs);
|
|
||||||
if ( typeof ((this.configs as CSharpExporterConfigs).namespace) != 'string') {
|
|
||||||
(this.configs as CSharpExporterConfigs).namespace = "game.data";
|
|
||||||
}
|
|
||||||
if ( typeof ((this.configs as CSharpExporterConfigs).base_type) != 'string') {
|
|
||||||
(this.configs as CSharpExporterConfigs).namespace = "object";
|
|
||||||
}
|
|
||||||
if ( typeof ((this.configs as CSharpExporterConfigs).file_name) != 'string') {
|
|
||||||
(this.configs as CSharpExporterConfigs).file_name = "data";
|
|
||||||
}
|
|
||||||
|
|
||||||
this.declear_content += this.line("// Tool generated file DO NOT MODIFY");
|
|
||||||
this.declear_content += this.line("using System;");
|
|
||||||
this.declear_content += this.line();
|
|
||||||
this.declear_content += this.line("namespace " + (this.configs as CSharpExporterConfigs).namespace + " {")
|
|
||||||
this.declear_content += this.line("%CLASSES%");
|
|
||||||
this.declear_content += this.line("}");
|
|
||||||
}
|
|
||||||
|
|
||||||
export(name: string, table: TableData) {
|
|
||||||
const base_type = (this.configs as CSharpExporterConfigs).base_type;
|
|
||||||
let body = "";
|
|
||||||
for (const field of table.headers) {
|
|
||||||
if (field.name == 'id' && (this.configs as CSharpExporterConfigs).ignore_id) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let type = "object";
|
|
||||||
switch (field.type) {
|
|
||||||
case DataType.bool:
|
|
||||||
case DataType.float:
|
|
||||||
case DataType.string:
|
|
||||||
case DataType.int:
|
|
||||||
type = field.type;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
type = "object";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (field.is_array) {
|
|
||||||
type += "[]";
|
|
||||||
}
|
|
||||||
if (field.comment) {
|
|
||||||
let comment = field.comment.split("\r\n").join("\t");
|
|
||||||
comment = comment.split("\n").join("\t");
|
|
||||||
body += this.line(`/// <summary>${comment}</summary>`, 1);
|
|
||||||
}
|
|
||||||
body += this.line(`public ${type} ${field.name};`, 1);
|
|
||||||
}
|
|
||||||
let class_text = this.line(`public class ${name} : ${base_type} {\n${body}\n}`);
|
|
||||||
this.classes.push(class_text);
|
|
||||||
}
|
|
||||||
|
|
||||||
finalize() {
|
|
||||||
let class_text = "";
|
|
||||||
for (const cls of this.classes) {
|
|
||||||
class_text += cls;
|
|
||||||
class_text += this.line();
|
|
||||||
}
|
|
||||||
|
|
||||||
let file = path.join(this.configs.directory, (this.configs as CSharpExporterConfigs).file_name);
|
|
||||||
if (!file.endsWith(".cs")) {
|
|
||||||
file += "." + this.extension;
|
|
||||||
}
|
|
||||||
this.save_text(file, this.declear_content.replace("%CLASSES%", class_text));
|
|
||||||
console.log(colors.green(`\t${file}`));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -59,9 +59,7 @@ export class JSONExporter extends TableExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export(name: string, table: TableData) {
|
export(name: string, table: TableData) {
|
||||||
const file = path.join(this.configs.directory, `${name}.${this.extension}`);
|
|
||||||
const text = JSON.stringify(this.export_json_object(name, table), null, this.indent);
|
const text = JSON.stringify(this.export_json_object(name, table), null, this.indent);
|
||||||
this.save_text(file, text);
|
return text;
|
||||||
console.log(colors.green(`\t ${name} ==> ${file}`));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,6 +29,7 @@ export class TypeScriptExporter extends TableExporter {
|
|||||||
(this.configs as TypeScriptExporterConfigs).type,
|
(this.configs as TypeScriptExporterConfigs).type,
|
||||||
(this.configs as TypeScriptExporterConfigs).declaration,
|
(this.configs as TypeScriptExporterConfigs).declaration,
|
||||||
);
|
);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected export_field(field: Field, indent = 0, ignore_root = false) {
|
protected export_field(field: Field, indent = 0, ignore_root = false) {
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ export class YAMLExporter extends JSONExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export(name: string, table: TableData) {
|
export(name: string, table: TableData) {
|
||||||
const file = path.join(this.configs.directory, `${name}.${this.extension}`);
|
|
||||||
const text = yaml.dump(
|
const text = yaml.dump(
|
||||||
this.export_json_object(name, table),
|
this.export_json_object(name, table),
|
||||||
{
|
{
|
||||||
@@ -30,7 +29,6 @@ export class YAMLExporter extends JSONExporter {
|
|||||||
sortKeys: true,
|
sortKeys: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
this.save_text(file, text);
|
return text;
|
||||||
console.log(colors.green(`\t ${name} ==> ${file}`));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,10 @@ module.exports = (env) => {
|
|||||||
console.log("Compile environment:", env);
|
console.log("Compile environment:", env);
|
||||||
return ({
|
return ({
|
||||||
target: 'node',
|
target: 'node',
|
||||||
entry: path.join(workSpaceDir, 'src/main.ts'),
|
entry: [
|
||||||
|
'source-map-support/register',
|
||||||
|
path.join(workSpaceDir, 'src/main.ts'),
|
||||||
|
],
|
||||||
output: {
|
output: {
|
||||||
path: path.join(workSpaceDir, 'dist'),
|
path: path.join(workSpaceDir, 'dist'),
|
||||||
filename: 'binary.js'
|
filename: 'binary.js'
|
||||||
|
|||||||
Reference in New Issue
Block a user