chore: rename runtime Lib/Module.lua & Lib/Class.lua to lowercase lib/module.lua & lib/class.lua (v0.3.1)
This commit is contained in:
1 parent
b1a53d8660
commit
1e2a0b7546
13 files changed
+42
-37
No files matched your search
+5
-5
@@ -32,26 +32,26 @@ import {
|
||||
export interface UnLuaPluginOptions {
|
||||
/**
|
||||
* 模块化编译模式:
|
||||
* - `"hot-reload"`(默认):基于 `Lib/Module.lua` + `Lib/Class.lua` 生成支持单文件热更的 `__MODULE__.Import` / `__TS__DefineClass` 产物;
|
||||
* - `"hot-reload"`(默认):基于 `lib/module.lua` + `lib/class.lua` 生成支持单文件热更的 `__MODULE__.Import` / `__TS__DefineClass` 产物;
|
||||
* - `"standard"`:沿用 TSTL 标准 `require` 与 `local ____exports = {}` 产物。
|
||||
*/
|
||||
moduleSystem?: "hot-reload" | "standard";
|
||||
/** 是否在 `beforeEmit` 自动产出 `Lib/Module.lua` 与 `Lib/Class.lua`(默认 `true`,仅 `hot-reload` 模式生效)。 */
|
||||
/** 是否在 `beforeEmit` 自动产出 `lib/module.lua` 与 `lib/class.lua`(默认 `true`,仅 `hot-reload` 模式生效)。 */
|
||||
emitRuntime?: boolean;
|
||||
/** 运行时基础库输出相对目录(默认 `"Lib"`)。 */
|
||||
/** 运行时基础库输出相对目录(默认 `"lib"`)。 */
|
||||
runtimeDir?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* TypeScriptToLua (TSTL) UnLua 定制插件:
|
||||
* 1. 编译期强制执行 ts2lua-unreal 语言子集约束(禁用 get/set、async/await、try/catch 等);
|
||||
* 2. 支持自定义模块化单文件运行时热更(`Lib/Module.lua` + `Lib/Class.lua` + `@module_data`);
|
||||
* 2. 支持自定义模块化单文件运行时热更(`lib/module.lua` + `lib/class.lua` + `@module_data`);
|
||||
* 3. 将全局 `@unlua` 标记的绑定类转译为原生 UnLua 风格(UnLua.Class / return M / self.Overridden)。
|
||||
*/
|
||||
export function createUnLuaPlugin(options?: UnLuaPluginOptions): tstl.Plugin {
|
||||
const moduleSystem = options?.moduleSystem ?? "hot-reload";
|
||||
const emitRuntime = options?.emitRuntime ?? true;
|
||||
const runtimeDir = options?.runtimeDir ?? "Lib";
|
||||
const runtimeDir = options?.runtimeDir ?? "lib";
|
||||
const isHotReload = moduleSystem === "hot-reload";
|
||||
|
||||
const simpleValidators = createSimpleValidationVisitors();
|
||||
|
||||
@@ -57,17 +57,17 @@ const fileModuleStates = new WeakMap<ts.SourceFile, FileModuleState>();
|
||||
let cachedRuntimeModuleLua: string | undefined;
|
||||
let cachedRuntimeClassLua: string | undefined;
|
||||
|
||||
function getRuntimeFileContent(fileName: "Module.lua" | "Class.lua"): string {
|
||||
if (fileName === "Module.lua" && cachedRuntimeModuleLua !== undefined) {
|
||||
function getRuntimeFileContent(fileName: "module.lua" | "class.lua"): string {
|
||||
if (fileName === "module.lua" && cachedRuntimeModuleLua !== undefined) {
|
||||
return cachedRuntimeModuleLua;
|
||||
}
|
||||
if (fileName === "Class.lua" && cachedRuntimeClassLua !== undefined) {
|
||||
if (fileName === "class.lua" && cachedRuntimeClassLua !== undefined) {
|
||||
return cachedRuntimeClassLua;
|
||||
}
|
||||
// dist/plugin/module-transform.js -> ../../runtime/Lib/<fileName>
|
||||
const filePath = path.resolve(__dirname, "..", "..", "runtime", "Lib", fileName);
|
||||
// dist/plugin/module-transform.js -> ../../runtime/lib/<fileName>
|
||||
const filePath = path.resolve(__dirname, "..", "..", "runtime", "lib", fileName);
|
||||
const content = fs.readFileSync(filePath, "utf8");
|
||||
if (fileName === "Module.lua") {
|
||||
if (fileName === "module.lua") {
|
||||
cachedRuntimeModuleLua = content;
|
||||
} else {
|
||||
cachedRuntimeClassLua = content;
|
||||
@@ -875,7 +875,7 @@ export function transformHotReloadSourceFile(
|
||||
}
|
||||
|
||||
/**
|
||||
* 在 `beforeEmit` 阶段自动向编译产物目录输出 `Lib/Module.lua` 与 `Lib/Class.lua`(不覆盖已有同名产物)。
|
||||
* 在 `beforeEmit` 阶段自动向编译产物目录输出 `lib/module.lua` 与 `lib/class.lua`(不覆盖已有同名产物)。
|
||||
*/
|
||||
export function emitModuleRuntimeFiles(
|
||||
_program: ts.Program,
|
||||
@@ -888,7 +888,7 @@ export function emitModuleRuntimeFiles(
|
||||
result.map((f) => path.normalize(f.outputPath).replace(/\\/g, "/"))
|
||||
);
|
||||
|
||||
const filesToEmit: Array<"Module.lua" | "Class.lua"> = ["Module.lua", "Class.lua"];
|
||||
const filesToEmit: Array<"module.lua" | "class.lua"> = ["module.lua", "class.lua"];
|
||||
for (const fileName of filesToEmit) {
|
||||
const outputPath = path.join(outDir, runtimeDir, fileName);
|
||||
const normalized = path.normalize(outputPath).replace(/\\/g, "/");
|
||||
|
||||
Reference in new issue
Block a user