styles and startmenuItems
This commit is contained in:
@@ -31,132 +31,131 @@ class FileSystemManager {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Liest rekursiv Dateien und gibt nur die gewünschten Attribute zurück.
|
||||
*
|
||||
* @param {string} dirPath - Startverzeichnis
|
||||
* @param {string[]} attributes - gewünschte Attribute:
|
||||
* ['name','fullPath','size','lastModified','isDirectory','extension', ...]
|
||||
* @param {string|null} sortBy - Attribut zum Sortieren (z.B. 'lastModified' oder 'name')
|
||||
* @param {string} order - 'asc' oder 'desc'
|
||||
*/
|
||||
readFiles(dirPath, attributes = ['name', 'fullPath'], sortBy = null, order = 'asc') {
|
||||
let results = [];
|
||||
/**
|
||||
* Liest rekursiv Dateien und gibt nur die gewünschten Attribute zurück.
|
||||
*
|
||||
* @param {string} dirPath - Startverzeichnis
|
||||
* @param {string[]} attributes - gewünschte Attribute:
|
||||
* ['name','fullPath','size','lastModified','isDirectory','extension', ...]
|
||||
* @param {string|null} sortBy - Attribut zum Sortieren (z.B. 'lastModified' oder 'name')
|
||||
* @param {string} order - 'asc' oder 'desc'
|
||||
*/
|
||||
readFiles(dirPath, attributes = ['name', 'fullPath'], sortBy = null, order = 'asc') {
|
||||
let results = [];
|
||||
|
||||
const items = fs.readdirSync(dirPath);
|
||||
const items = fs.readdirSync(dirPath);
|
||||
|
||||
for (const item of items) {
|
||||
const fullPath = path.join(dirPath, item);
|
||||
const stats = fs.statSync(fullPath);
|
||||
const isDir = stats.isDirectory();
|
||||
for (const item of items) {
|
||||
const fullPath = path.join(dirPath, item);
|
||||
const stats = fs.statSync(fullPath);
|
||||
const isDir = stats.isDirectory();
|
||||
|
||||
// Objekt mit ALLEN möglichen Infos
|
||||
const allInfo = {
|
||||
name: item,
|
||||
nameWithoutExt: item.substring(0, item.indexOf('.')),
|
||||
fullPath: fullPath,
|
||||
size: stats.size,
|
||||
lastModified: stats.mtime,
|
||||
created: stats.birthtime,
|
||||
isDirectory: isDir,
|
||||
extension: isDir ? null : path.extname(item)
|
||||
};
|
||||
// Objekt mit ALLEN möglichen Infos
|
||||
const allInfo = {
|
||||
name: item,
|
||||
nameWithoutExt: item.substring(0, item.indexOf('.')),
|
||||
fullPath: fullPath,
|
||||
size: stats.size,
|
||||
lastModified: stats.mtime,
|
||||
created: stats.birthtime,
|
||||
isDirectory: isDir,
|
||||
extension: isDir ? null : path.extname(item)
|
||||
};
|
||||
|
||||
if (isDir) {
|
||||
// rekursiv weitermachen
|
||||
results = results.concat(this.readFiles(fullPath, attributes, null, order));
|
||||
} else {
|
||||
// nur gewünschte Attribute ausgeben
|
||||
const filtered = {};
|
||||
for (const attr of attributes) {
|
||||
if (allInfo[attr] !== undefined) {
|
||||
filtered[attr] = allInfo[attr];
|
||||
if (isDir) {
|
||||
// rekursiv weitermachen
|
||||
results = results.concat(this.readFiles(fullPath, attributes, null, order));
|
||||
} else {
|
||||
// nur gewünschte Attribute ausgeben
|
||||
const filtered = {};
|
||||
for (const attr of attributes) {
|
||||
if (allInfo[attr] !== undefined) {
|
||||
filtered[attr] = allInfo[attr];
|
||||
}
|
||||
}
|
||||
results.push(filtered);
|
||||
}
|
||||
results.push(filtered);
|
||||
}
|
||||
|
||||
// Sortieren, falls gewünscht
|
||||
if (sortBy) {
|
||||
results.sort((a, b) => {
|
||||
if (a[sortBy] < b[sortBy]) return order === 'asc' ? -1 : 1;
|
||||
if (a[sortBy] > b[sortBy]) return order === 'asc' ? 1 : -1;
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
// Sortieren, falls gewünscht
|
||||
if (sortBy) {
|
||||
results.sort((a, b) => {
|
||||
if (a[sortBy] < b[sortBy]) return order === 'asc' ? -1 : 1;
|
||||
if (a[sortBy] > b[sortBy]) return order === 'asc' ? 1 : -1;
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sammelt verschiedene Pattern-Ergebnisse aus Dateien mehrerer Ordner.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {string|string[]} options.folderPaths - Pfad oder Array von Pfaden zu Ordnern
|
||||
* @param {string} [options.extension='.js'] - Dateiendung
|
||||
* @param {Array<{ name: string, pattern: RegExp, mapFn?: Function }>} options.patterns - Liste von Pattern-Definitionen
|
||||
* @param {boolean} [options.recursive=true] - Unterordner durchsuchen?
|
||||
* @returns {Array} - kombinierte Ergebnisse aller Pattern
|
||||
*/
|
||||
collectFromFiles({
|
||||
folderPaths,
|
||||
extension = '.js',
|
||||
patterns,
|
||||
recursive = true
|
||||
}) {
|
||||
const results = [];
|
||||
|
||||
// if only one path selected
|
||||
const paths = Array.isArray(folderPaths) ? folderPaths : [folderPaths];
|
||||
|
||||
function readDir(dir) {
|
||||
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
||||
|
||||
for (const entry of entries) {
|
||||
const fullPath = path.join(dir, entry.name);
|
||||
|
||||
/**
|
||||
* Sammelt verschiedene Pattern-Ergebnisse aus Dateien mehrerer Ordner.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {string|string[]} options.folderPaths - Pfad oder Array von Pfaden zu Ordnern
|
||||
* @param {string} [options.extension='.js'] - Dateiendung
|
||||
* @param {Array<{ name: string, pattern: RegExp, mapFn?: Function }>} options.patterns - Liste von Pattern-Definitionen
|
||||
* @param {boolean} [options.recursive=true] - Unterordner durchsuchen?
|
||||
* @returns {Array} - kombinierte Ergebnisse aller Pattern
|
||||
*/
|
||||
collectFromFiles({
|
||||
folderPaths,
|
||||
extension = '.js',
|
||||
patterns,
|
||||
recursive = true
|
||||
}) {
|
||||
const results = [];
|
||||
if (entry.isDirectory() && recursive) {
|
||||
readDir(fullPath);
|
||||
} else if (entry.isFile() && entry.name.endsWith(extension)) {
|
||||
const content = fs.readFileSync(fullPath, 'utf8');
|
||||
|
||||
// if only one path selected
|
||||
const paths = Array.isArray(folderPaths) ? folderPaths : [folderPaths];
|
||||
// 👉 NEU: fallback wenn keine patterns
|
||||
if (!patterns || patterns.length === 0) {
|
||||
results.push({
|
||||
file: entry.name,
|
||||
fullPath
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
function readDir(dir) {
|
||||
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
||||
|
||||
for (const entry of entries) {
|
||||
const fullPath = path.join(dir, entry.name);
|
||||
|
||||
if (entry.isDirectory() && recursive) {
|
||||
readDir(fullPath);
|
||||
} else if (entry.isFile() && entry.name.endsWith(extension)) {
|
||||
const content = fs.readFileSync(fullPath, 'utf8');
|
||||
|
||||
// 👉 NEU: fallback wenn keine patterns
|
||||
if (!patterns || patterns.length === 0) {
|
||||
results.push({
|
||||
file: entry.name,
|
||||
fullPath
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const { name, pattern, mapFn } of patterns) {
|
||||
let match;
|
||||
while ((match = pattern.exec(content)) !== null) {
|
||||
const mapped = mapFn
|
||||
? mapFn(match, entry.name, fullPath, name)
|
||||
: { file: entry.name, type: name, match: match[0] };
|
||||
results.push(mapped);
|
||||
for (const { name, pattern, mapFn } of patterns) {
|
||||
let match;
|
||||
while ((match = pattern.exec(content)) !== null) {
|
||||
const mapped = mapFn
|
||||
? mapFn(match, entry.name, fullPath, name)
|
||||
: { file: entry.name, type: name, match: match[0] };
|
||||
results.push(mapped);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Run through multiple paths
|
||||
for (const dir of paths) {
|
||||
if (fs.existsSync(dir)) {
|
||||
readDir(path.resolve(dir));
|
||||
} else {
|
||||
console.warn(`Ordner nicht gefunden: ${dir}`);
|
||||
// Run through multiple paths
|
||||
for (const dir of paths) {
|
||||
if (fs.existsSync(dir)) {
|
||||
readDir(path.resolve(dir));
|
||||
} else {
|
||||
console.warn(`Ordner nicht gefunden: ${dir}`);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -171,6 +170,16 @@ collectFromFiles({
|
||||
}
|
||||
}
|
||||
|
||||
loadFile(path) {
|
||||
try {
|
||||
const rawData = fs.readFileSync(path, 'utf8');
|
||||
return rawData;
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check file-/path
|
||||
exists(path) {
|
||||
|
||||
Reference in New Issue
Block a user