Skip to content

Commit

Permalink
终于能动态加载了
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Jun 26, 2024
1 parent 156f695 commit 722ae12
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,15 @@
"fs-extra": "^11.2.0",
"iconv-lite": "^0.6.3",
"jszip": "^3.10.1",
"module-alias": "2.2.3",
"uuid": "^9.0.1",
"winreg": "^1.2.5"
},
"devDependencies": {
"@types/exceljs": "^1.3.0",
"@types/fs-extra": "^11.0.4",
"@types/mocha": "^10.0.3",
"@types/module-alias": "^2.0.4",
"@types/node": "^18.19.18",
"@types/uuid": "^9.0.8",
"@types/vscode": "^1.83.0",
Expand Down
15 changes: 8 additions & 7 deletions src/editorTable/EXCEL/excelExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,15 @@ export class excelExporter extends tableExpoter{
try {
this.importRules = [];
// 读取目录中的所有.mjs文件
const files = fs.readdirSync(this.rulePath.fsPath).filter(file => file.endsWith('.mjs'));
const files = fs.readdirSync(this.rulePath.fsPath).filter(file => file.endsWith('.js'));
for (const file of files) {
let src = vscode.Uri.joinPath(this.rulePath, file);
let tar = vscode.Uri.joinPath(vscode.Uri.file(__dirname+'../../EXCEL'), file);
fs.copySync(src.fsPath, tar.fsPath, { overwrite: true });
let filePath = './' + file;
const dynamicPath = `${filePath}?t=${new Date().getTime()}`; // 使用不同的动态路径
let ImportRulesModule = await import(dynamicPath);
//let tar = vscode.Uri.joinPath(vscode.Uri.file(__dirname+'../../EXCEL'), file);
//fs.copySync(src.fsPath, tar.fsPath, { overwrite: true });
//let filePath = './' + file;
//const dynamicPath = `${filePath}?t=${new Date().getTime()}`; // 使用不同的动态路径
delete require.cache[src.fsPath];
let ImportRulesModule = require(src.fsPath);
for(let ruleName in ImportRulesModule){
if(ImportRulesModule[ruleName] instanceof ImportRule){
this.importRules.push(ImportRulesModule[ruleName]);
Expand All @@ -122,4 +123,4 @@ export class excelExporter extends tableExpoter{
}
return {};
}
}
}
7 changes: 7 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import moduleAlias from 'module-alias';

moduleAlias.addAliases({
'y3helper': __dirname + '/y3helper'
});

import * as fs from 'fs';
import * as tools from "./tools";
import * as vscode from 'vscode';
Expand All @@ -22,6 +28,7 @@ import { excelExporter } from './editorTable/EXCEL/excelExporter';
import * as debug from './debug';
import { EditorLauncher } from './launchEditor';


class Helper {
private context: vscode.ExtensionContext;

Expand Down
16 changes: 7 additions & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@
"lib": [
"ES2022"
],
"baseUrl": ".",
"sourceMap": true,
"rootDir": "src",
"strict": true /* enable all strict type-checking options */
/* Additional Checks */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
"strict": true,
"paths": {
"y3helper": ["./src/y3helper"],
},
},
//"include": [
// "src/**/*.ts"
//]

// 忽略对template/excel/importRules.ts的编译 因为它只是个模板 生成给用户用
"exclude": [
"template/excel"
"template",
"tmp",
]
}

0 comments on commit 722ae12

Please sign in to comment.