checkers中容错
This commit is contained in:
parent
0eaedad577
commit
70a8978996
|
|
@ -1,5 +1,21 @@
|
|||
type DepNode = {
|
||||
name: string;
|
||||
parent?: DepNode;
|
||||
};
|
||||
type DepGraph = {
|
||||
nodeDict: Record<string, DepNode>;
|
||||
roots: DepNode[];
|
||||
ascOrder: string[];
|
||||
};
|
||||
/**
|
||||
* 构建项目依赖关系图
|
||||
* @param cwd
|
||||
* @returns
|
||||
*/
|
||||
export declare function analyzeDepedency(cwd: string): DepGraph;
|
||||
/**
|
||||
* 本函数用于构建src/initialize.dev, src/initialize.prod, src/initializeFeatures, src/context/FrontendContext, src/contextBackendContext
|
||||
* 这些和dependency相关的项目文件
|
||||
*/
|
||||
export default function buildDependency(rebuild?: boolean): void;
|
||||
export {};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.analyzeDepedency = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const assert_1 = tslib_1.__importDefault(require("assert"));
|
||||
const path_1 = require("path");
|
||||
|
|
@ -8,6 +9,70 @@ const ts = tslib_1.__importStar(require("typescript"));
|
|||
const string_1 = require("../utils/string");
|
||||
const env_1 = require("./env");
|
||||
const { factory } = ts;
|
||||
/**
|
||||
* 构建项目依赖关系图
|
||||
* @param cwd
|
||||
* @returns
|
||||
*/
|
||||
function analyzeDepedency(cwd) {
|
||||
const depGraph = {
|
||||
nodeDict: {},
|
||||
roots: [],
|
||||
ascOrder: [],
|
||||
};
|
||||
function analyzeOne(dir, name, parent) {
|
||||
const node = {
|
||||
name,
|
||||
parent,
|
||||
};
|
||||
if (name) {
|
||||
depGraph.nodeDict[name] = node;
|
||||
if (!parent) {
|
||||
depGraph.roots.push(node);
|
||||
}
|
||||
}
|
||||
let dependencies = [];
|
||||
const depConfigTsFile = join(dir, 'src', 'configuration', 'dependency.ts');
|
||||
if ((0, fs_1.existsSync)(depConfigTsFile)) {
|
||||
// 这里依赖配置是ts文件,得翻译成js再读取
|
||||
const result = ts.transpileModule((0, fs_1.readFileSync)(depConfigTsFile, 'utf-8'), { compilerOptions: { module: ts.ModuleKind.CommonJS } });
|
||||
dependencies = eval(result.outputText);
|
||||
}
|
||||
else {
|
||||
const depConfigJsFile = join(dir, 'lib', 'configuration', 'dependency.js');
|
||||
if ((0, fs_1.existsSync)(depConfigJsFile)) {
|
||||
dependencies = require(depConfigJsFile);
|
||||
}
|
||||
else {
|
||||
// 没有依赖文件,直接返回
|
||||
return;
|
||||
}
|
||||
}
|
||||
dependencies.forEach((dep) => {
|
||||
const n2 = depGraph.nodeDict[dep];
|
||||
if (n2) {
|
||||
(0, assert_1.default)(name);
|
||||
}
|
||||
else {
|
||||
let dir2 = join(cwd, 'node_modules', dep);
|
||||
if (!(0, fs_1.existsSync)(dir2)) {
|
||||
dir2 = join(dir, 'node_modules', dep);
|
||||
if (!(0, fs_1.existsSync)(dir2)) {
|
||||
throw new Error(`找不到依赖包${dep}的安装位置,当前包是${dir}`);
|
||||
}
|
||||
}
|
||||
analyzeOne(dir2, dep, name ? node : undefined);
|
||||
}
|
||||
});
|
||||
}
|
||||
analyzeOne(cwd, '');
|
||||
// 输出一个从底向上的序列,因为当前的项目中最多只有一个依赖,所以暂时不写
|
||||
const deps = Object.keys(depGraph.nodeDict);
|
||||
(0, assert_1.default)(deps.length <= 1);
|
||||
depGraph.ascOrder = deps;
|
||||
return depGraph;
|
||||
}
|
||||
exports.analyzeDepedency = analyzeDepedency;
|
||||
function join(...paths) {
|
||||
const path = (0, path_1.join)(...paths);
|
||||
return path.replaceAll('\\', '/');
|
||||
|
|
@ -29,6 +94,20 @@ function destructVariableDeclaration(vd) {
|
|||
expression,
|
||||
};
|
||||
}
|
||||
function outputDependentContext(depGraph, printer, filename) {
|
||||
// 目前只支持单向依赖,未来可以利用mixin来实现多类的继承
|
||||
(0, assert_1.default)(depGraph.roots.length <= 1);
|
||||
let root = depGraph.roots[0] ? depGraph.roots[0].name : 'oak-frontend-base';
|
||||
const statements = [
|
||||
factory.createExportDeclaration(undefined, false, factory.createNamedExports([
|
||||
factory.createExportSpecifier(false, undefined, factory.createIdentifier("BackendRuntimeContext")),
|
||||
factory.createExportSpecifier(false, undefined, factory.createIdentifier("FrontendRuntimeContext"))
|
||||
]), factory.createStringLiteral(root), undefined)
|
||||
];
|
||||
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements), ts.createSourceFile("someFileName.ts", "", ts.ScriptTarget.Latest, false, ts.ScriptKind.TS));
|
||||
(0, fs_1.writeFileSync)(filename, result, { flag: 'w' });
|
||||
console.log('构建context/DependentContext.ts文件成功');
|
||||
}
|
||||
/**
|
||||
* 生成initialize.prod.ts
|
||||
* @param cwd
|
||||
|
|
@ -37,7 +116,7 @@ function destructVariableDeclaration(vd) {
|
|||
* @param sourceFile
|
||||
* @param printer
|
||||
*/
|
||||
function outputIntializeProd(cwd, dependencies, briefNames, sourceFile, printer) {
|
||||
function outputIntializeProd(cwd, dependencies, briefNames, sourceFile, printer, filename) {
|
||||
const { statements } = sourceFile;
|
||||
const objectDict = {};
|
||||
// 所有的import
|
||||
|
|
@ -154,7 +233,6 @@ function outputIntializeProd(cwd, dependencies, briefNames, sourceFile, printer)
|
|||
});
|
||||
}
|
||||
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
||||
const filename = join(cwd, 'src', 'initialize.prod.ts');
|
||||
(0, fs_1.writeFileSync)(filename, result, { flag: 'w' });
|
||||
console.log('构建initialize.prod.ts文件成功');
|
||||
}
|
||||
|
|
@ -166,7 +244,7 @@ function outputIntializeProd(cwd, dependencies, briefNames, sourceFile, printer)
|
|||
* @param sourceFile
|
||||
* @param printer
|
||||
*/
|
||||
function outputIntializeDev(cwd, dependencies, briefNames, sourceFile, printer) {
|
||||
function outputIntializeDev(cwd, dependencies, briefNames, sourceFile, printer, filename) {
|
||||
const { statements } = sourceFile;
|
||||
const objectDict = {};
|
||||
// 所有的import
|
||||
|
|
@ -315,11 +393,10 @@ function outputIntializeDev(cwd, dependencies, briefNames, sourceFile, printer)
|
|||
});
|
||||
}
|
||||
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
||||
const filename = join(cwd, 'src', 'initialize.dev.ts');
|
||||
(0, fs_1.writeFileSync)(filename, result, { flag: 'w' });
|
||||
console.log('构建initialize.dev.ts文件成功');
|
||||
}
|
||||
function outputIntializeFeatures(cwd, dependencies, briefNames, sourceFile, printer) {
|
||||
function outputIntializeFeatures(cwd, dependencies, briefNames, sourceFile, printer, filename) {
|
||||
const { statements } = sourceFile;
|
||||
const features = [];
|
||||
// 所有的import
|
||||
|
|
@ -385,7 +462,6 @@ function outputIntializeFeatures(cwd, dependencies, briefNames, sourceFile, prin
|
|||
});
|
||||
}
|
||||
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
||||
const filename = join(cwd, 'src', 'initializeFeatures.ts');
|
||||
(0, fs_1.writeFileSync)(filename, result, { flag: 'w' });
|
||||
console.log('构建initializeFeatures.ts文件成功');
|
||||
}
|
||||
|
|
@ -395,18 +471,13 @@ function outputIntializeFeatures(cwd, dependencies, briefNames, sourceFile, prin
|
|||
*/
|
||||
function buildDependency(rebuild) {
|
||||
const cwd = process.cwd();
|
||||
const initDevFile = join(cwd, 'src', 'initialize.dev.ts');
|
||||
if ((0, fs_1.existsSync)(initDevFile) && !rebuild) {
|
||||
console.log('src/initialize.dev.ts文件已经存在,无需构建启动文件');
|
||||
return;
|
||||
}
|
||||
const depConfigFile = join(cwd, 'src', 'configuration', 'dependency.ts');
|
||||
if (!(0, fs_1.existsSync)(depConfigFile)) {
|
||||
console.error(`${depConfigFile}不存在,无法构建启动文件`);
|
||||
}
|
||||
// 这里依赖配置是ts文件,得翻译成js再读取
|
||||
const result = ts.transpileModule((0, fs_1.readFileSync)(depConfigFile, 'utf-8'), { compilerOptions: { module: ts.ModuleKind.CommonJS } });
|
||||
const dependencies = eval(result.outputText);
|
||||
const depGraph = analyzeDepedency(cwd);
|
||||
// 依赖如果是树形关系,应当从底层的被依赖者开始初始化
|
||||
const dependencies = depGraph.ascOrder;
|
||||
const briefNames = dependencies.map((dep, idx) => `${dep.split('-').map(ele => ele[0]).join('')}${idx}`);
|
||||
const templateFileList = [
|
||||
join(cwd, 'node_modules', env_1.OAK_CLI_MODULE_NAME, 'templateFiles', 'initialize.dev.ts'),
|
||||
|
|
@ -415,8 +486,33 @@ function buildDependency(rebuild) {
|
|||
];
|
||||
const program = ts.createProgram(templateFileList, {});
|
||||
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
||||
outputIntializeDev(cwd, dependencies, briefNames, program.getSourceFile(templateFileList[0]), printer);
|
||||
outputIntializeProd(cwd, dependencies, briefNames, program.getSourceFile(templateFileList[1]), printer);
|
||||
outputIntializeFeatures(cwd, dependencies, briefNames, program.getSourceFile(templateFileList[2]), printer);
|
||||
const initDevFile = join(cwd, 'src', 'initialize.dev.ts');
|
||||
if ((0, fs_1.existsSync)(initDevFile) && !rebuild) {
|
||||
console.log(`[${initDevFile}]文件已经存在,无需构建启动文件`);
|
||||
}
|
||||
else {
|
||||
outputIntializeDev(cwd, dependencies, briefNames, program.getSourceFile(templateFileList[0]), printer, initDevFile);
|
||||
}
|
||||
const initProdFile = join(cwd, 'src', 'initialize.prod.ts');
|
||||
if ((0, fs_1.existsSync)(initProdFile) && !rebuild) {
|
||||
console.log(`[${initProdFile}]文件已经存在,无需构建启动文件`);
|
||||
}
|
||||
else {
|
||||
outputIntializeProd(cwd, dependencies, briefNames, program.getSourceFile(templateFileList[1]), printer, initProdFile);
|
||||
}
|
||||
const initFeaturesFile = join(cwd, 'src', 'initializeFeatures.ts');
|
||||
if ((0, fs_1.existsSync)(initFeaturesFile) && !rebuild) {
|
||||
console.log(`[${initFeaturesFile}]文件已经存在,无需构建启动文件`);
|
||||
}
|
||||
else {
|
||||
outputIntializeFeatures(cwd, dependencies, briefNames, program.getSourceFile(templateFileList[2]), printer, initFeaturesFile);
|
||||
}
|
||||
const dependentContextFile = join(cwd, 'src', 'context', 'DependentContext.ts');
|
||||
if ((0, fs_1.existsSync)(dependentContextFile) && !rebuild) {
|
||||
console.log(`[${dependentContextFile}]文件已经存在,无需构建启动文件`);
|
||||
}
|
||||
else {
|
||||
outputDependentContext(depGraph, printer, dependentContextFile);
|
||||
}
|
||||
}
|
||||
exports.default = buildDependency;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,5 @@ export declare const STRING_LITERAL_MAX_LENGTH = 24;
|
|||
export declare const NUMERICAL_LITERL_DEFAULT_PRECISION = 8;
|
||||
export declare const NUMERICAL_LITERL_DEFAULT_SCALE = 2;
|
||||
export declare const INT_LITERL_DEFAULT_WIDTH = 4;
|
||||
export declare const OAK_EXTERNAL_LIBS_FILEPATH: (path: string) => string;
|
||||
export * from './entities';
|
||||
export declare const OAK_CLI_MODULE_NAME = "@xuchangzju/oak-cli";
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.OAK_CLI_MODULE_NAME = exports.OAK_EXTERNAL_LIBS_FILEPATH = exports.INT_LITERL_DEFAULT_WIDTH = exports.NUMERICAL_LITERL_DEFAULT_SCALE = exports.NUMERICAL_LITERL_DEFAULT_PRECISION = exports.STRING_LITERAL_MAX_LENGTH = exports.ENTITY_NAME_MAX_LENGTH = exports.ACTION_CONSTANT_IN_OAK_DOMAIN = exports.TYPE_PATH_IN_OAK_DOMAIN = exports.ENTITY_PATH_IN_OAK_DOMAIN = exports.ENTITY_PATH_IN_OAK_GENERAL_BUSINESS = exports.LIB_PATH = exports.LIB_OAK_DOMAIN = void 0;
|
||||
exports.OAK_CLI_MODULE_NAME = exports.INT_LITERL_DEFAULT_WIDTH = exports.NUMERICAL_LITERL_DEFAULT_SCALE = exports.NUMERICAL_LITERL_DEFAULT_PRECISION = exports.STRING_LITERAL_MAX_LENGTH = exports.ENTITY_NAME_MAX_LENGTH = exports.ACTION_CONSTANT_IN_OAK_DOMAIN = exports.TYPE_PATH_IN_OAK_DOMAIN = exports.ENTITY_PATH_IN_OAK_DOMAIN = exports.ENTITY_PATH_IN_OAK_GENERAL_BUSINESS = exports.LIB_PATH = exports.LIB_OAK_DOMAIN = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const path_1 = tslib_1.__importDefault(require("path"));
|
||||
exports.LIB_OAK_DOMAIN = 'oak-domain';
|
||||
const LIB_OAK_GENERAL_BUSINESS = 'oak-general-business';
|
||||
const LIB_PATH = () => 'lib';
|
||||
|
|
@ -36,11 +35,5 @@ exports.STRING_LITERAL_MAX_LENGTH = 24;
|
|||
exports.NUMERICAL_LITERL_DEFAULT_PRECISION = 8;
|
||||
exports.NUMERICAL_LITERL_DEFAULT_SCALE = 2;
|
||||
exports.INT_LITERL_DEFAULT_WIDTH = 4;
|
||||
// 暂放在这儿
|
||||
// 项目依赖的第三方oak lib配置文件所在的固定路径
|
||||
const OAK_EXTERNAL_LIBS_FILEPATH = (path) => {
|
||||
return path_1.default.join(path, 'config/oakExternalLib.json');
|
||||
};
|
||||
exports.OAK_EXTERNAL_LIBS_FILEPATH = OAK_EXTERNAL_LIBS_FILEPATH;
|
||||
tslib_1.__exportStar(require("./entities"), exports);
|
||||
exports.OAK_CLI_MODULE_NAME = '@xuchangzju/oak-cli';
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ const { factory } = ts;
|
|||
const path_1 = require("path");
|
||||
const crypto_1 = require("crypto");
|
||||
const fs_1 = tslib_1.__importDefault(require("fs"));
|
||||
const env_1 = require("./env");
|
||||
const string_1 = require("../utils/string");
|
||||
const dependencyBuilder_1 = require("./dependencyBuilder");
|
||||
/**
|
||||
* 将一个object展开编译为一棵语法树,只有string和object两种键值对象
|
||||
* @param data
|
||||
|
|
@ -36,9 +36,10 @@ class LocaleBuilder {
|
|||
const pwd = process.cwd();
|
||||
this.pwd = pwd;
|
||||
this.asLib = !!asLib;
|
||||
const dependencyFile = (0, env_1.OAK_EXTERNAL_LIBS_FILEPATH)((0, path_1.join)(pwd, 'src'));
|
||||
if (fs_1.default.existsSync(dependencyFile)) {
|
||||
this.dependencies = require(dependencyFile);
|
||||
const dependencyConfigureFile = (0, path_1.join)(pwd, 'src', 'configuration', 'dependency.ts');
|
||||
if (fs_1.default.existsSync(dependencyConfigureFile)) {
|
||||
const depGraph = (0, dependencyBuilder_1.analyzeDepedency)(pwd);
|
||||
this.dependencies = depGraph.ascOrder;
|
||||
}
|
||||
else {
|
||||
this.dependencies = [];
|
||||
|
|
|
|||
|
|
@ -195,15 +195,17 @@ function createActionTransformerCheckers(actionDefDict) {
|
|||
entity,
|
||||
checker: (operation) => {
|
||||
const { data } = operation;
|
||||
if (data instanceof Array) {
|
||||
data.forEach((d) => Object.assign(d, {
|
||||
[attr]: stm[action][1],
|
||||
}));
|
||||
}
|
||||
else {
|
||||
Object.assign(data, {
|
||||
[attr]: stm[action][1],
|
||||
});
|
||||
if (data) {
|
||||
if (data instanceof Array) {
|
||||
data.forEach((d) => Object.assign(d, {
|
||||
[attr]: stm[action][1],
|
||||
}));
|
||||
}
|
||||
else {
|
||||
Object.assign(data, {
|
||||
[attr]: stm[action][1],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -225,7 +227,7 @@ function createActionTransformerCheckers(actionDefDict) {
|
|||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
else if (data) {
|
||||
if (!data[attr]) {
|
||||
Object.assign(data, {
|
||||
[attr]: is,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,89 @@ import { firstLetterLowerCase, firstLetterUpperCase } from '../utils/string';
|
|||
import { OAK_CLI_MODULE_NAME } from './env';
|
||||
const { factory } = ts;
|
||||
|
||||
type DepNode = {
|
||||
name: string;
|
||||
parent?: DepNode;
|
||||
};
|
||||
|
||||
type DepGraph = {
|
||||
nodeDict: Record<string, DepNode>;
|
||||
roots: DepNode[];
|
||||
ascOrder: string[];
|
||||
};
|
||||
|
||||
/**
|
||||
* 构建项目依赖关系图
|
||||
* @param cwd
|
||||
* @returns
|
||||
*/
|
||||
export function analyzeDepedency(cwd: string) {
|
||||
const depGraph: DepGraph = {
|
||||
nodeDict: {},
|
||||
roots: [],
|
||||
ascOrder: [],
|
||||
};
|
||||
|
||||
function analyzeOne(dir: string, name: string, parent?: DepNode) {
|
||||
const node: DepNode = {
|
||||
name,
|
||||
parent,
|
||||
};
|
||||
if (name) {
|
||||
depGraph.nodeDict[name] = node;
|
||||
if (!parent) {
|
||||
depGraph.roots.push(node);
|
||||
}
|
||||
}
|
||||
|
||||
let dependencies: string[] = [];
|
||||
const depConfigTsFile = join(dir, 'src', 'configuration', 'dependency.ts');
|
||||
|
||||
if (existsSync(depConfigTsFile)) {
|
||||
// 这里依赖配置是ts文件,得翻译成js再读取
|
||||
const result = ts.transpileModule(readFileSync(depConfigTsFile, 'utf-8'), { compilerOptions: { module: ts.ModuleKind.CommonJS } });
|
||||
dependencies = eval(result.outputText) as string[];
|
||||
}
|
||||
else {
|
||||
const depConfigJsFile = join(dir, 'lib', 'configuration', 'dependency.js');
|
||||
if (existsSync(depConfigJsFile)) {
|
||||
dependencies = require(depConfigJsFile);
|
||||
}
|
||||
else {
|
||||
// 没有依赖文件,直接返回
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
dependencies.forEach(
|
||||
(dep) => {
|
||||
const n2 = depGraph.nodeDict[dep];
|
||||
if (n2) {
|
||||
assert(name);
|
||||
}
|
||||
else {
|
||||
let dir2 = join(cwd, 'node_modules', dep);
|
||||
if (!existsSync(dir2)) {
|
||||
dir2 = join(dir, 'node_modules', dep);
|
||||
if (!existsSync(dir2)) {
|
||||
throw new Error(`找不到依赖包${dep}的安装位置,当前包是${dir}`);
|
||||
}
|
||||
}
|
||||
analyzeOne(dir2, dep, name ? node : undefined);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
analyzeOne(cwd, '');
|
||||
|
||||
// 输出一个从底向上的序列,因为当前的项目中最多只有一个依赖,所以暂时不写
|
||||
const deps = Object.keys(depGraph.nodeDict);
|
||||
assert(deps.length <= 1);
|
||||
depGraph.ascOrder = deps;
|
||||
return depGraph;
|
||||
}
|
||||
|
||||
function join(...paths: string[]) {
|
||||
const path = pathJoin(...paths);
|
||||
return path.replaceAll('\\', '/');
|
||||
|
|
@ -29,6 +112,42 @@ function destructVariableDeclaration(vd: ts.VariableDeclaration) {
|
|||
};
|
||||
}
|
||||
|
||||
function outputDependentContext(depGraph: DepGraph, printer: ts.Printer, filename: string) {
|
||||
// 目前只支持单向依赖,未来可以利用mixin来实现多类的继承
|
||||
assert(depGraph.roots.length <= 1);
|
||||
let root = depGraph.roots[0] ? depGraph.roots[0].name : 'oak-frontend-base';
|
||||
|
||||
const statements = [
|
||||
factory.createExportDeclaration(
|
||||
undefined,
|
||||
false,
|
||||
factory.createNamedExports([
|
||||
factory.createExportSpecifier(
|
||||
false,
|
||||
undefined,
|
||||
factory.createIdentifier("BackendRuntimeContext")
|
||||
),
|
||||
factory.createExportSpecifier(
|
||||
false,
|
||||
undefined,
|
||||
factory.createIdentifier("FrontendRuntimeContext")
|
||||
)
|
||||
]),
|
||||
factory.createStringLiteral(root),
|
||||
undefined
|
||||
)
|
||||
];
|
||||
|
||||
|
||||
const result = printer.printList(
|
||||
ts.ListFormat.SourceFileStatements,
|
||||
factory.createNodeArray(statements),
|
||||
ts.createSourceFile("someFileName.ts", "", ts.ScriptTarget.Latest, false, ts.ScriptKind.TS));
|
||||
|
||||
writeFileSync(filename, result, { flag: 'w' });
|
||||
console.log('构建context/DependentContext.ts文件成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成initialize.prod.ts
|
||||
* @param cwd
|
||||
|
|
@ -42,7 +161,8 @@ function outputIntializeProd(
|
|||
dependencies: string[],
|
||||
briefNames: string[],
|
||||
sourceFile: ts.SourceFile,
|
||||
printer: ts.Printer
|
||||
printer: ts.Printer,
|
||||
filename: string
|
||||
) {
|
||||
const { statements } = sourceFile;
|
||||
|
||||
|
|
@ -275,7 +395,7 @@ function outputIntializeProd(
|
|||
ts.ListFormat.SourceFileStatements,
|
||||
factory.createNodeArray(statements2),
|
||||
sourceFile);
|
||||
const filename = join(cwd, 'src', 'initialize.prod.ts');
|
||||
|
||||
writeFileSync(filename, result, { flag: 'w' });
|
||||
console.log('构建initialize.prod.ts文件成功');
|
||||
}
|
||||
|
|
@ -293,7 +413,8 @@ function outputIntializeDev(
|
|||
dependencies: string[],
|
||||
briefNames: string[],
|
||||
sourceFile: ts.SourceFile,
|
||||
printer: ts.Printer
|
||||
printer: ts.Printer,
|
||||
filename: string
|
||||
) {
|
||||
const { statements } = sourceFile;
|
||||
|
||||
|
|
@ -592,7 +713,7 @@ function outputIntializeDev(
|
|||
ts.ListFormat.SourceFileStatements,
|
||||
factory.createNodeArray(statements2),
|
||||
sourceFile);
|
||||
const filename = join(cwd, 'src', 'initialize.dev.ts');
|
||||
|
||||
writeFileSync(filename, result, { flag: 'w' });
|
||||
console.log('构建initialize.dev.ts文件成功');
|
||||
}
|
||||
|
|
@ -602,7 +723,8 @@ function outputIntializeFeatures(
|
|||
dependencies: string[],
|
||||
briefNames: string[],
|
||||
sourceFile: ts.SourceFile,
|
||||
printer: ts.Printer
|
||||
printer: ts.Printer,
|
||||
filename: string
|
||||
) {
|
||||
|
||||
const { statements } = sourceFile;
|
||||
|
|
@ -737,7 +859,7 @@ function outputIntializeFeatures(
|
|||
ts.ListFormat.SourceFileStatements,
|
||||
factory.createNodeArray(statements2),
|
||||
sourceFile);
|
||||
const filename = join(cwd, 'src', 'initializeFeatures.ts');
|
||||
|
||||
writeFileSync(filename, result, { flag: 'w' });
|
||||
console.log('构建initializeFeatures.ts文件成功');
|
||||
}
|
||||
|
|
@ -749,20 +871,15 @@ function outputIntializeFeatures(
|
|||
export default function buildDependency(rebuild?: boolean) {
|
||||
const cwd = process.cwd();
|
||||
|
||||
const initDevFile = join(cwd, 'src', 'initialize.dev.ts');
|
||||
if (existsSync(initDevFile) && !rebuild) {
|
||||
console.log('src/initialize.dev.ts文件已经存在,无需构建启动文件');
|
||||
return;
|
||||
}
|
||||
|
||||
const depConfigFile = join(cwd, 'src', 'configuration', 'dependency.ts');
|
||||
if (!existsSync(depConfigFile)) {
|
||||
console.error(`${depConfigFile}不存在,无法构建启动文件`);
|
||||
}
|
||||
|
||||
// 这里依赖配置是ts文件,得翻译成js再读取
|
||||
const result = ts.transpileModule(readFileSync(depConfigFile, 'utf-8'), { compilerOptions: { module: ts.ModuleKind.CommonJS } });
|
||||
const dependencies = eval(result.outputText) as string[];
|
||||
const depGraph = analyzeDepedency(cwd);
|
||||
// 依赖如果是树形关系,应当从底层的被依赖者开始初始化
|
||||
const dependencies = depGraph.ascOrder;
|
||||
|
||||
const briefNames = dependencies.map(
|
||||
(dep, idx) => `${dep.split('-').map(ele => ele[0]).join('')}${idx}`
|
||||
);
|
||||
|
|
@ -776,7 +893,37 @@ export default function buildDependency(rebuild?: boolean) {
|
|||
const program = ts.createProgram(templateFileList, {});
|
||||
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
||||
|
||||
outputIntializeDev(cwd, dependencies, briefNames, program.getSourceFile(templateFileList[0])!, printer);
|
||||
outputIntializeProd(cwd, dependencies, briefNames, program.getSourceFile(templateFileList[1])!, printer);
|
||||
outputIntializeFeatures(cwd, dependencies, briefNames, program.getSourceFile(templateFileList[2])!, printer);
|
||||
|
||||
const initDevFile = join(cwd, 'src', 'initialize.dev.ts');
|
||||
if (existsSync(initDevFile) && !rebuild) {
|
||||
console.log(`[${initDevFile}]文件已经存在,无需构建启动文件`);
|
||||
}
|
||||
else {
|
||||
outputIntializeDev(cwd, dependencies, briefNames, program.getSourceFile(templateFileList[0])!, printer, initDevFile);
|
||||
}
|
||||
|
||||
const initProdFile = join(cwd, 'src', 'initialize.prod.ts');
|
||||
if (existsSync(initProdFile) && !rebuild) {
|
||||
console.log(`[${initProdFile}]文件已经存在,无需构建启动文件`);
|
||||
}
|
||||
else {
|
||||
outputIntializeProd(cwd, dependencies, briefNames, program.getSourceFile(templateFileList[1])!, printer, initProdFile);
|
||||
}
|
||||
|
||||
|
||||
const initFeaturesFile = join(cwd, 'src', 'initializeFeatures.ts');
|
||||
if (existsSync(initFeaturesFile) && !rebuild) {
|
||||
console.log(`[${initFeaturesFile}]文件已经存在,无需构建启动文件`);
|
||||
}
|
||||
else {
|
||||
outputIntializeFeatures(cwd, dependencies, briefNames, program.getSourceFile(templateFileList[2])!, printer, initFeaturesFile);
|
||||
}
|
||||
|
||||
const dependentContextFile = join(cwd, 'src', 'context', 'DependentContext.ts');
|
||||
if (existsSync(dependentContextFile) && !rebuild) {
|
||||
console.log(`[${dependentContextFile}]文件已经存在,无需构建启动文件`);
|
||||
}
|
||||
else {
|
||||
outputDependentContext(depGraph, printer, dependentContextFile);
|
||||
}
|
||||
}
|
||||
|
|
@ -34,12 +34,6 @@ export const NUMERICAL_LITERL_DEFAULT_PRECISION = 8;
|
|||
export const NUMERICAL_LITERL_DEFAULT_SCALE = 2;
|
||||
export const INT_LITERL_DEFAULT_WIDTH = 4;
|
||||
|
||||
// 暂放在这儿
|
||||
|
||||
// 项目依赖的第三方oak lib配置文件所在的固定路径
|
||||
export const OAK_EXTERNAL_LIBS_FILEPATH = (path: string) => {
|
||||
return Path.join(path, 'config/oakExternalLib.json');
|
||||
}
|
||||
|
||||
export * from './entities';
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ const { factory } = ts;
|
|||
import { join } from 'path';
|
||||
import { Hash, createHash } from 'crypto';
|
||||
import fs from 'fs';
|
||||
import { OAK_EXTERNAL_LIBS_FILEPATH } from './env';
|
||||
import { firstLetterLowerCase, unescapeUnicode } from '../utils/string';
|
||||
import { analyzeDepedency } from './dependencyBuilder';
|
||||
|
||||
/**
|
||||
* 将一个object展开编译为一棵语法树,只有string和object两种键值对象
|
||||
|
|
@ -47,9 +47,10 @@ export default class LocaleBuilder {
|
|||
const pwd = process.cwd();
|
||||
this.pwd = pwd;
|
||||
this.asLib = !!asLib;
|
||||
const dependencyFile = OAK_EXTERNAL_LIBS_FILEPATH(join(pwd, 'src'));
|
||||
if (fs.existsSync(dependencyFile)) {
|
||||
this.dependencies = require(dependencyFile);
|
||||
const dependencyConfigureFile = join(pwd, 'src', 'configuration', 'dependency.ts');
|
||||
if (fs.existsSync(dependencyConfigureFile)) {
|
||||
const depGraph = analyzeDepedency(pwd);
|
||||
this.dependencies = depGraph.ascOrder;
|
||||
}
|
||||
else {
|
||||
this.dependencies = [];
|
||||
|
|
|
|||
|
|
@ -233,17 +233,19 @@ function createActionTransformerCheckers<ED extends EntityDict & BaseEntityDict,
|
|||
entity,
|
||||
checker: (operation) => {
|
||||
const { data } = operation;
|
||||
if (data instanceof Array) {
|
||||
data.forEach(
|
||||
(d) => Object.assign(d, {
|
||||
if (data) {
|
||||
if (data instanceof Array) {
|
||||
data.forEach(
|
||||
(d) => Object.assign(d, {
|
||||
[attr]: stm[action][1],
|
||||
})
|
||||
);
|
||||
}
|
||||
else {
|
||||
Object.assign(data, {
|
||||
[attr]: stm[action][1],
|
||||
})
|
||||
);
|
||||
}
|
||||
else {
|
||||
Object.assign(data, {
|
||||
[attr]: stm[action][1],
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -268,7 +270,7 @@ function createActionTransformerCheckers<ED extends EntityDict & BaseEntityDict,
|
|||
}
|
||||
);
|
||||
}
|
||||
else {
|
||||
else if (data){
|
||||
if (!(data as Readonly<ED[keyof ED]['CreateSingle']['data']>)[attr]) {
|
||||
Object.assign(data, {
|
||||
[attr]: is,
|
||||
|
|
|
|||
Loading…
Reference in New Issue