Begin work on the localization cycle prevention and add newline to existing scripts

This commit is contained in:
Oliver-Akins 2024-02-24 13:40:25 -07:00
parent bbd96d3b45
commit 19588bb137
4 changed files with 85 additions and 2 deletions

View file

@ -4,3 +4,73 @@ that there are no cycles in them to prevent infinite recursion. This must pull
the pattern to match subkeys on via the config, otherwise this could result in
inconsistencies with the localizer logic.
*/
import { readFile } from "fs/promises";
class Node {
/** @type {Array<Node>} */
connectsTo = [];
/** @type {boolean} */
visited = false;
/** @type {boolean} */
finished = false;
id;
constructor(data) { this.id = data; };
};
/**
* @param {object | string} lang The localization object to convert into a graph
* @returns {Promise<Array<Node> | Node>}
*/
async function createGraph(data) {
throw new Error(`createGraph not Implemented Yet`);
};
/**
* @param {Node} from
* @returns {Promise<boolean|void>}
*/
async function depthFirstSearch(from) {
if (from.finished) return false;
if (from.visited) return true;
from.visited = true;
for (const neighbour of from.connectsTo) {
if (depthFirstSearch(neighbour)) return true;
};
from.finished = true;
return false;
};
/**
* @param {Array<Node>} graph
*/
async function checkForCycles(graph) {
for (const node of graph) {
if (node.finished) {
console.log(`skipping node: ${node.id}`);
continue;
}
if (depthFirstSearch(node)) {
console.log(`cycle found in node: ${node.id}`);
};
};
};
async function main() {
/*
Process:
- Load the system.json to identify all lang files
- Iterate through defined languages
- Construct a graph from the language file
- Iterate through nodes checking for a cycle
*/
const lang = JSON.parse(await readFile("test.lang") ?? "{}");
const graph = await createGraph(lang);
console.log(graph)
// await checkForCycles(graph);
};
main();

13
scripts/updateSystem.mjs Normal file
View file

@ -0,0 +1,13 @@
/*
Takes the system.json and updates all the release-specific properties in it to
help prevent erroneous updates from being made when using the local package for
development.
---
Set the "manifest" property to:
"url" property + "/releases/latest/download/system.json"
Set the "download" property to:
"url" property + "/releases/download/{version number}/{zip_name}.zip"
*/