From d5392eafb83625ae3feb46813c8d23f1385c906e Mon Sep 17 00:00:00 2001 From: Omar Brikaa Date: Fri, 11 Feb 2022 22:04:36 +0200 Subject: [PATCH] Naming refactor, remove id getter and use index --- api/src/api/v3.js | 4 ++-- api/src/bin/pistond.js | 12 ++++++++---- api/src/runtime.js | 12 ++++-------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/api/src/api/v3.js b/api/src/api/v3.js index aee5772..fb1b764 100644 --- a/api/src/api/v3.js +++ b/api/src/api/v3.js @@ -277,13 +277,13 @@ router.post('/execute', async (req, res) => { }); router.get('/runtimes', (req, res) => { - const runtimes = runtime.map(rt => { + const runtimes = runtime.map((rt, index) => { return { language: rt.language, version: rt.version.raw, aliases: rt.aliases, runtime: rt.runtime, - id: rt.id, + id: index, }; }); diff --git a/api/src/bin/pistond.js b/api/src/bin/pistond.js index c56cc99..9e1fca7 100755 --- a/api/src/bin/pistond.js +++ b/api/src/bin/pistond.js @@ -39,10 +39,14 @@ expressWs(app); logger.info('Loading packages'); - const runtimes_data = cp.execSync(`nix eval --json ${config.flake_path}#pistonRuntimeSets.${config.runtime_set} --apply builtins.attrNames`).toString(); - const runtimes = JSON.parse(runtimes_data); - - runtimes.for_each(pkg => runtime.load_runtime(pkg)); + const runtimes_data = cp + .execSync( + `nix eval --json ${config.flake_path}#pistonRuntimeSets.${config.runtime_set} --apply builtins.attrNames` + ) + .toString(); + const language_names = JSON.parse(runtimes_data); + + language_names.for_each(language_name => runtime.load_runtime(language_name)); logger.info('Starting API Server'); logger.debug('Constructing Express App'); diff --git a/api/src/runtime.js b/api/src/runtime.js index 554feed..a2cf0d9 100644 --- a/api/src/runtime.js +++ b/api/src/runtime.js @@ -120,9 +120,9 @@ class Runtime { logger.debug(`Finished ensuring ${this} is installed`); } - static load_runtime(flake_key) { - logger.info(`Loading ${flake_key}`); - const flake_path = `${config.flake_path}#pistonRuntimeSets.${config.runtime_set}.${flake_key}`; + static load_runtime(language_name) { + logger.info(`Loading ${language_name}`); + const flake_path = `${config.flake_path}#pistonRuntimeSets.${config.runtime_set}.${language_name}`; const metadata_command = `nix eval --json ${flake_path}.metadata`; const metadata = JSON.parse(cp.execSync(metadata_command)); @@ -139,17 +139,13 @@ class Runtime { runtimes.push(this_runtime); - logger.debug(`Package ${flake_key} was loaded`); + logger.debug(`Package ${language_name} was loaded`); } get compiled() { return this.compile !== null; } - get id() { - return runtimes.indexOf(this); - } - toString() { return `${this.language}-${this.version}`; }