Updated settings and script compilnig

This commit is contained in:
ex61wi
2026-04-07 10:46:17 +02:00
parent 3083cf4b0b
commit fddf8e3946
4 changed files with 57 additions and 21 deletions
+20 -3
View File
@@ -55,7 +55,7 @@ export class ScriptCompiler {
} }
} }
public async compile(): Promise<void> { public async compile(includeDevScript: boolean): Promise<void> {
const start = Date.now(); const start = Date.now();
const metricsMeter = new Metrics(); const metricsMeter = new Metrics();
const entries = fs.readdirSync(this.options.sourcePath, { recursive: true, withFileTypes: true }); const entries = fs.readdirSync(this.options.sourcePath, { recursive: true, withFileTypes: true });
@@ -84,7 +84,7 @@ export class ScriptCompiler {
); );
const writeStart = Date.now(); const writeStart = Date.now();
writer.write(metricsMeter); writer.write(includeDevScript, metricsMeter);
const writeEnd = Date.now(); const writeEnd = Date.now();
metricsMeter.writeTimeMs = (writeEnd - writeStart); metricsMeter.writeTimeMs = (writeEnd - writeStart);
@@ -394,7 +394,7 @@ class Writer {
} }
}; };
write(metrics: Metrics): void { write(includeDevScript: boolean, metrics: Metrics): void {
const writtenFiles: Set<string> = new Set(); const writtenFiles: Set<string> = new Set();
const outputLines: string[] = []; const outputLines: string[] = [];
@@ -475,5 +475,22 @@ class Writer {
fs.mkdirSync(path.dirname(this.location), { recursive: true }); fs.mkdirSync(path.dirname(this.location), { recursive: true });
fs.writeFileSync(this.location, outputLines.join('\n'), 'utf-8'); fs.writeFileSync(this.location, outputLines.join('\n'), 'utf-8');
if(includeDevScript) {
const devFileLocation = this.location.replace('.lua', '.dev.lua');
this.writeDevScript(devFileLocation, this.location);
}
}
private writeDevScript(devFileLocation: string, actualFileLocation: string){
const devLines = [
`-- DEV SCRIPT - NOT FOR PRODUCTION USE`,
`-- This script can be referenced in DCS. Compiled script will then be loaded dynamically.`,
`-- This way you can test the compiled output without having to re-import the script into the mission every time.`,
`-- This file will only have to be re-imported when the name or location of the compiled script file changes.`,
`assert(loadfile("${actualFileLocation}"))()`
];
fs.writeFileSync(devFileLocation, devLines.join('\n'), 'utf-8');
this.logger.info(`Development script written to ${devFileLocation}`);
} }
} }
+5
View File
@@ -11,6 +11,11 @@ Direct DCS API checking and a Transpiler that can help keep huge complex scripts
## Release Notes ## Release Notes
### 0.0.2
- Improved error handling and reporting in the script compiler.
- Added Output channel for compilation logs and errors.
- Improved Settings for better user experience.
### 0.0.1 ### 0.0.1
+11 -2
View File
@@ -49,8 +49,17 @@
"type": "boolean", "type": "boolean",
"default": false, "default": false,
"description": "Adds an additional script. This can be referenced from DCS through doScriptFile. This will then execute the compiles script. This way you don't have to reinsert the script on each change, but can just hit 'restart'." "description": "Adds an additional script. This can be referenced from DCS through doScriptFile. This will then execute the compiles script. This way you don't have to reinsert the script on each change, but can just hit 'restart'."
} },
"dutchies-dcs-scripting-tools.luaSrcDirectory" : {
"type":"string",
"default": "${workspaceFolder}/src",
"description": "Where the source files start. default: ${workspaceFolder}/src"
},
"dutchies-dcs-scripting-tools.luaOutputPath" : {
"type":"string",
"default": "${workspaceFolder}/dist",
"description": "Where the compiled Lua files will be output. default: ${workspaceFolder}/dist"
}
} }
}, },
"grammars": [ "grammars": [
+21 -16
View File
@@ -27,21 +27,13 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push( context.subscriptions.push(
vscode.commands.registerCommand('dutchies-dcs-scripting-tools.enable', async () => { vscode.commands.registerCommand('dutchies-dcs-scripting-tools.enable', async () => {
addPluginPathToSettings(); enableIntellisense();
await vscode.commands.executeCommand(
"lua.startServer"
);
vscode.window.showInformationMessage('Dutchies DCS Scripting Tools enabled.');
}) })
); );
context.subscriptions.push( context.subscriptions.push(
vscode.commands.registerCommand('dutchies-dcs-scripting-tools.disable', async () => { vscode.commands.registerCommand('dutchies-dcs-scripting-tools.disable', async () => {
removePluginPathFromSettings(); disableIntellisense();
await vscode.commands.executeCommand(
"lua.startServer"
);
vscode.window.showInformationMessage('Dutchies DCS Scripting Tools disabled.');
}) })
); );
@@ -116,11 +108,10 @@ async function compileLuaScripts() {
logger.clear(); logger.clear();
logger.info("Compiling..."); logger.info("Compiling...");
const config = vscode.workspace.getConfiguration('dcsScriptingTools'); const config = vscode.workspace.getConfiguration(extensionName);
const sourcePath = config.get<string>('luaSourcePath') || '${workspaceFolder}/src'; const sourcePath = config.get<string>('luaSrcDirectory') || '${workspaceFolder}/src';
const outputPath = config.get<string>('luaOutputPath') || '${workspaceFolder}/dist'; const outputPath = config.get<string>('luaOutputPath') || '${workspaceFolder}/dist';
const minify = config.get<boolean>('minifyLuaScripts') || false;
const resolvedSourcePath = sourcePath.replace('${workspaceFolder}', vscode.workspace.workspaceFolders?.[0].uri.fsPath || ''); const resolvedSourcePath = sourcePath.replace('${workspaceFolder}', vscode.workspace.workspaceFolders?.[0].uri.fsPath || '');
const resolvedOutputPath = outputPath.replace('${workspaceFolder}', vscode.workspace.workspaceFolders?.[0].uri.fsPath || ''); const resolvedOutputPath = outputPath.replace('${workspaceFolder}', vscode.workspace.workspaceFolders?.[0].uri.fsPath || '');
@@ -130,7 +121,7 @@ async function compileLuaScripts() {
const options: ScriptCompilerOptions = { const options: ScriptCompilerOptions = {
sourcePath: resolvedSourcePath, sourcePath: resolvedSourcePath,
outputPath: resolvedOutputPath, outputPath: resolvedOutputPath,
minify: minify, minify: false,
onError: (error: CompilationError) => { onError: (error: CompilationError) => {
const errors = errorsByFile.get(error.filePath) || []; const errors = errorsByFile.get(error.filePath) || [];
errors.push(error); errors.push(error);
@@ -140,8 +131,11 @@ async function compileLuaScripts() {
const compilationLogger = new CompilationLogger(logger); const compilationLogger = new CompilationLogger(logger);
const compiler = new ScriptCompiler(options, compilationLogger); const compiler = new ScriptCompiler(options, compilationLogger);
const includeDevScript = config.get<boolean>('includeDevelopmentScript') || false;
try { try {
await compiler.compile(); await compiler.compile(includeDevScript);
} catch (err) { } catch (err) {
vscode.window.showErrorMessage('Compilation failed: ' + (err as Error).message); vscode.window.showErrorMessage('Compilation failed: ' + (err as Error).message);
} }
@@ -161,6 +155,12 @@ async function compileLuaScripts() {
} }
async function enableIntellisense() { async function enableIntellisense() {
const config = vscode.workspace.getConfiguration(extensionName);
if (config.get<boolean>("dcsTypes") === false) {
config.update("dcsTypes", true, vscode.ConfigurationTarget.Workspace);
}
addPluginPathToSettings(); addPluginPathToSettings();
await vscode.commands.executeCommand( await vscode.commands.executeCommand(
"lua.startServer" "lua.startServer"
@@ -169,6 +169,11 @@ async function enableIntellisense() {
} }
async function disableIntellisense() { async function disableIntellisense() {
const config = vscode.workspace.getConfiguration(extensionName);
if (config.get<boolean>("dcsTypes") === true) {
config.update("dcsTypes", false, vscode.ConfigurationTarget.Workspace);
}
removePluginPathFromSettings(); removePluginPathFromSettings();
await vscode.commands.executeCommand( await vscode.commands.executeCommand(
"lua.startServer" "lua.startServer"