-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
see read me (hover show path removed and some otehr stuff idk)
- Loading branch information
1 parent
da41533
commit 7499f5a
Showing
6 changed files
with
99 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const vscode = require('vscode'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const os = require('os'); | ||
const { raiseError, raiseInfo } = require('../support_files/log_utils'); | ||
const { getConfig, loadConfigFile, setModName, setConfig } = require('../support_files/config'); | ||
const builder = require('xmlbuilder'); | ||
|
||
async function indentXmlFiles() { | ||
const config = getConfig(); | ||
const rootModPath = config.rootModPath; | ||
const indentLevel = await vscode.window.showInputBox({ | ||
prompt: 'Enter the number of spaces for indentation', | ||
validateInput: (value) => { | ||
const num = parseInt(value, 10); | ||
return isNaN(num) || num < 0 ? 'Please enter a valid non-negative number' : null; | ||
} | ||
}); | ||
|
||
if (!indentLevel) { | ||
return; // User cancelled the input box | ||
} | ||
|
||
const findFiles = (dir, extensions, fileList = []) => { | ||
fs.readdirSync(dir).forEach(file => { | ||
const filePath = path.join(dir, file); | ||
if (fs.statSync(filePath).isDirectory()) { | ||
// Skip the Localization folder | ||
if (path.basename(filePath).toLowerCase() !== 'localization') { | ||
fileList = findFiles(filePath, extensions, fileList); | ||
} | ||
} else if (extensions.some(ext => filePath.endsWith(ext))) { | ||
fileList.push(filePath); | ||
} | ||
}); | ||
return fileList; | ||
}; | ||
|
||
const files = findFiles(rootModPath, ['.lsx', '.lsj']); | ||
|
||
for (const filePath of files) { | ||
let fileContent = fs.readFileSync(filePath, 'utf-8'); | ||
// Remove BOM if it exists | ||
if (fileContent.charCodeAt(0) === 0xFEFF) { | ||
fileContent = fileContent.slice(1); | ||
} | ||
try { | ||
const doc = builder.create(fileContent, { headless: true }); | ||
const formattedContent = doc.end({ pretty: true, indent: ' '.repeat(parseInt(indentLevel, 10)) }); | ||
fs.writeFileSync(filePath, formattedContent, 'utf-8'); | ||
raiseInfo(`File ${filePath} has been formatted with an indent level of ${indentLevel} spaces.`); | ||
} catch (error) { | ||
raiseError(`Failed to process file ${filePath}: ${error.message}`); | ||
} | ||
} | ||
|
||
raiseInfo('XML files formatting process completed.'); | ||
} | ||
|
||
const indentXmlFilesCommand = vscode.commands.registerCommand('bg3-mod-helper.indentXmlFilesCommand', async function () { | ||
await indentXmlFiles(); | ||
}); | ||
|
||
module.exports = { indentXmlFilesCommand }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters