From 4f5b385fd76df6345ef334d6c012e2dbd68cdd25 Mon Sep 17 00:00:00 2001 From: Divlo Date: Fri, 26 May 2023 23:31:25 +0200 Subject: [PATCH] chore: rename config.json to settings.json --- .gitignore | 4 +- .../setup/setup-skills/setup-skills-config.js | 79 ------------------- .../setup-skills/setup-skills-settings.js | 77 ++++++++++++++++++ scripts/setup/setup-skills/setup-skills.js | 4 +- skills/games/akinator/src/config.sample.json | 6 -- .../games/akinator/src/settings.sample.json | 1 + .../guess_the_number/src/config.sample.json | 6 -- .../guess_the_number/src/settings.sample.json | 1 + .../games/rochambeau/src/config.sample.json | 6 -- .../games/rochambeau/src/settings.sample.json | 1 + skills/leon/greeting/src/config.sample.json | 6 -- skills/leon/greeting/src/settings.sample.json | 1 + .../leon/introduction/src/config.sample.json | 6 -- .../introduction/src/settings.sample.json | 1 + .../leon/random_number/src/config.sample.json | 6 -- .../random_number/src/settings.sample.json | 1 + .../news/github_trends/src/config.sample.json | 6 -- .../github_trends/src/settings.sample.json | 1 + ...onfig.sample.json => settings.sample.json} | 0 .../todo_list/src/config.sample.json | 6 -- .../todo_list/src/settings.sample.json | 1 + .../mbti/src/config.sample.json | 6 -- .../mbti/src/settings.sample.json | 1 + ...onfig.sample.json => settings.sample.json} | 0 .../is_it_down/src/config.sample.json | 6 -- .../is_it_down/src/settings.sample.json | 1 + .../speed_test/src/config.sample.json | 6 -- .../speed_test/src/settings.sample.json | 1 + .../youtube_downloader/src/config.sample.json | 15 ---- 29 files changed, 91 insertions(+), 165 deletions(-) delete mode 100644 scripts/setup/setup-skills/setup-skills-config.js create mode 100644 scripts/setup/setup-skills/setup-skills-settings.js delete mode 100644 skills/games/akinator/src/config.sample.json create mode 100644 skills/games/akinator/src/settings.sample.json delete mode 100644 skills/games/guess_the_number/src/config.sample.json create mode 100644 skills/games/guess_the_number/src/settings.sample.json delete mode 100644 skills/games/rochambeau/src/config.sample.json create mode 100644 skills/games/rochambeau/src/settings.sample.json delete mode 100644 skills/leon/greeting/src/config.sample.json create mode 100644 skills/leon/greeting/src/settings.sample.json delete mode 100644 skills/leon/introduction/src/config.sample.json create mode 100644 skills/leon/introduction/src/settings.sample.json delete mode 100644 skills/leon/random_number/src/config.sample.json create mode 100644 skills/leon/random_number/src/settings.sample.json delete mode 100644 skills/news/github_trends/src/config.sample.json create mode 100644 skills/news/github_trends/src/settings.sample.json rename skills/news/product_hunt_trends/src/{config.sample.json => settings.sample.json} (100%) delete mode 100644 skills/productivity/todo_list/src/config.sample.json create mode 100644 skills/productivity/todo_list/src/settings.sample.json delete mode 100644 skills/social_communication/mbti/src/config.sample.json create mode 100644 skills/social_communication/mbti/src/settings.sample.json rename skills/utilities/have_i_been_pwned/src/{config.sample.json => settings.sample.json} (100%) delete mode 100644 skills/utilities/is_it_down/src/config.sample.json create mode 100644 skills/utilities/is_it_down/src/settings.sample.json delete mode 100644 skills/utilities/speed_test/src/config.sample.json create mode 100644 skills/utilities/speed_test/src/settings.sample.json delete mode 100644 skills/utilities/youtube_downloader/src/config.sample.json diff --git a/.gitignore b/.gitignore index c64960bf..ea65b6a1 100644 --- a/.gitignore +++ b/.gitignore @@ -29,9 +29,7 @@ tcp_server/src/Pipfile.lock !bridges/python/**/.gitkeep !bridges/nodejs/**/.gitkeep !**/*.sample* -packages/**/config/config.json -skills/**/src/config.json -packages/**/data/db/*.json +skills/**/src/settings.json skills/**/memory/*.json skills/**/memory/*.db* core/data/models/*.nlp diff --git a/scripts/setup/setup-skills/setup-skills-config.js b/scripts/setup/setup-skills/setup-skills-config.js deleted file mode 100644 index 7911c19c..00000000 --- a/scripts/setup/setup-skills/setup-skills-config.js +++ /dev/null @@ -1,79 +0,0 @@ -import fs from 'node:fs' -import path from 'node:path' - -import { commandSync } from 'execa' - -import { LogHelper } from '@/helpers/log-helper' - -/** - * Set up skills configuration - */ -export default async function (skillFriendlyName, currentSkill) { - const configDir = path.join(currentSkill.path, 'src') - const configFile = path.join(configDir, 'config.json') - const configSampleFile = path.join(configDir, 'config.sample.json') - - // If there is a bridge set from the skill config - if (currentSkill.bridge) { - // Check if the config and config.sample file exist - if (fs.existsSync(configFile) && fs.existsSync(configSampleFile)) { - const config = JSON.parse( - await fs.promises.readFile(configFile, 'utf8') - )?.configurations - const configSample = JSON.parse( - await fs.promises.readFile(configSampleFile, 'utf8') - )?.configurations - const configKeys = Object.keys(config) - const configSampleKeys = Object.keys(configSample) - - // Check if there is a new config key in the config sample compared to the config.json - if (JSON.stringify(configKeys) !== JSON.stringify(configSampleKeys)) { - // Browse config keys of the new skill config - for (let j = 0; j < configSampleKeys.length; j += 1) { - // Check if the current config key does not exist - if (configKeys.includes(configSampleKeys[j]) === false) { - LogHelper.info( - `Adding new configuration key "${configSampleKeys[j]}" for the ${skillFriendlyName} skill...` - ) - - // Prepare to inject the new config key object - const configKey = { - [configSampleKeys[j]]: configSample[configSampleKeys[j]] - } - - try { - // Add new skill configuration in the config.json file - commandSync( - `json -I -f ${configFile} -e 'this.configurations.${ - configSampleKeys[j] - }=${JSON.stringify(configKey[configSampleKeys[j]])}'`, - { shell: true } - ) - LogHelper.success( - `"${configSampleKeys[j]}" configuration key added to ${configFile}` - ) - } catch (e) { - LogHelper.error( - `Error while adding "${configSampleKeys[j]}" configuration key to ${configFile}: ${e}` - ) - } - } - } - } - } else if (!fs.existsSync(configSampleFile)) { - // Stop the setup if the config.sample.json of the current skill does not exist - LogHelper.error( - `The "${skillFriendlyName}" skill configuration file does not exist. Try to pull the project (git pull)` - ) - } else { - // Duplicate config.sample.json of the current skill to config.json - fs.createReadStream(configSampleFile).pipe( - fs.createWriteStream(`${configDir}/config.json`) - ) - - LogHelper.success( - `"${skillFriendlyName}" skill configuration file created` - ) - } - } -} diff --git a/scripts/setup/setup-skills/setup-skills-settings.js b/scripts/setup/setup-skills/setup-skills-settings.js new file mode 100644 index 00000000..660dabe8 --- /dev/null +++ b/scripts/setup/setup-skills/setup-skills-settings.js @@ -0,0 +1,77 @@ +import fs from 'node:fs' +import path from 'node:path' + +import { commandSync } from 'execa' + +import { LogHelper } from '@/helpers/log-helper' + +/** + * Set up skills settings + */ +export default async function (skillFriendlyName, currentSkill) { + const skillSrcPath = path.join(currentSkill.path, 'src') + const settingsPath = path.join(skillSrcPath, 'settings.json') + const settingsSamplePath = path.join(skillSrcPath, 'settings.sample.json') + + // If there is a bridge set from the skill settings + if (currentSkill.bridge) { + // Check if the settings and settings.sample file exist + if (fs.existsSync(settingsPath) && fs.existsSync(settingsSamplePath)) { + const settings = JSON.parse( + await fs.promises.readFile(settingsPath, 'utf8') + ) + const settingsSample = JSON.parse( + await fs.promises.readFile(settingsSamplePath, 'utf8') + ) + const settingsKeys = Object.keys(settings) + const settingsSampleKeys = Object.keys(settingsSample) + + // Check if there is a new settings key in the settings sample compared to the settings.json + if (JSON.stringify(settingsKeys) !== JSON.stringify(settingsSampleKeys)) { + // Browse settings keys of the new settings config + for (let j = 0; j < settingsSampleKeys.length; j += 1) { + // Check if the current settings key does not exist + if (!settingsKeys.includes(settingsSampleKeys[j])) { + LogHelper.info( + `Adding new settings key "${settingsSampleKeys[j]}" for the ${skillFriendlyName} skill...` + ) + + // Prepare to inject the new settings key object + const configKey = { + [settingsSampleKeys[j]]: settingsSample[settingsSampleKeys[j]] + } + + try { + // Add new skill settings in the settings.json file + commandSync( + `json -I -f ${settingsPath} -e 'this.${settingsSampleKeys[j]}=${JSON.stringify(configKey[settingsSampleKeys[j]])}'`, + { shell: true } + ) + LogHelper.success( + `"${settingsSampleKeys[j]}" settings key added to ${settingsPath}` + ) + } catch (e) { + LogHelper.error( + `Error while adding "${settingsSampleKeys[j]}" settings key to ${settingsPath}: ${e}` + ) + } + } + } + } + } else if (!fs.existsSync(settingsSamplePath)) { + // Stop the setup if the settings.sample.json of the current skill does not exist + LogHelper.error( + `The "${skillFriendlyName}" skill settings file does not exist. Try to pull the project (git pull)` + ) + } else { + // Duplicate settings.sample.json of the current skill to settings.json + fs.createReadStream(settingsSamplePath).pipe( + fs.createWriteStream(`${skillSrcPath}/settings.json`) + ) + + LogHelper.success( + `"${skillFriendlyName}" skill settings file created` + ) + } + } +} diff --git a/scripts/setup/setup-skills/setup-skills.js b/scripts/setup/setup-skills/setup-skills.js index bdade548..77af4493 100644 --- a/scripts/setup/setup-skills/setup-skills.js +++ b/scripts/setup/setup-skills/setup-skills.js @@ -1,7 +1,7 @@ import { LogHelper } from '@/helpers/log-helper' import { SkillDomainHelper } from '@/helpers/skill-domain-helper' -import setupSkillsConfig from './setup-skills-config' +import setupSkillsSettings from './setup-skills-settings' import installNodejsSkillsPackages from './install-nodejs-skills-packages' /** @@ -23,7 +23,7 @@ export default async function () { LogHelper.info(`Setting up "${skillFriendlyName}" skill...`) - await setupSkillsConfig(skillFriendlyName, currentSkill) + await setupSkillsSettings(skillFriendlyName, currentSkill) await installNodejsSkillsPackages(skillFriendlyName, currentSkill) LogHelper.success(`"${skillFriendlyName}" skill set up`) diff --git a/skills/games/akinator/src/config.sample.json b/skills/games/akinator/src/config.sample.json deleted file mode 100644 index 9e43d47e..00000000 --- a/skills/games/akinator/src/config.sample.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "configurations": { - "options": {}, - "credentials": {} - } -} diff --git a/skills/games/akinator/src/settings.sample.json b/skills/games/akinator/src/settings.sample.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/skills/games/akinator/src/settings.sample.json @@ -0,0 +1 @@ +{} diff --git a/skills/games/guess_the_number/src/config.sample.json b/skills/games/guess_the_number/src/config.sample.json deleted file mode 100644 index 9e43d47e..00000000 --- a/skills/games/guess_the_number/src/config.sample.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "configurations": { - "options": {}, - "credentials": {} - } -} diff --git a/skills/games/guess_the_number/src/settings.sample.json b/skills/games/guess_the_number/src/settings.sample.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/skills/games/guess_the_number/src/settings.sample.json @@ -0,0 +1 @@ +{} diff --git a/skills/games/rochambeau/src/config.sample.json b/skills/games/rochambeau/src/config.sample.json deleted file mode 100644 index 9e43d47e..00000000 --- a/skills/games/rochambeau/src/config.sample.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "configurations": { - "options": {}, - "credentials": {} - } -} diff --git a/skills/games/rochambeau/src/settings.sample.json b/skills/games/rochambeau/src/settings.sample.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/skills/games/rochambeau/src/settings.sample.json @@ -0,0 +1 @@ +{} diff --git a/skills/leon/greeting/src/config.sample.json b/skills/leon/greeting/src/config.sample.json deleted file mode 100644 index 9e43d47e..00000000 --- a/skills/leon/greeting/src/config.sample.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "configurations": { - "options": {}, - "credentials": {} - } -} diff --git a/skills/leon/greeting/src/settings.sample.json b/skills/leon/greeting/src/settings.sample.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/skills/leon/greeting/src/settings.sample.json @@ -0,0 +1 @@ +{} diff --git a/skills/leon/introduction/src/config.sample.json b/skills/leon/introduction/src/config.sample.json deleted file mode 100644 index 9e43d47e..00000000 --- a/skills/leon/introduction/src/config.sample.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "configurations": { - "options": {}, - "credentials": {} - } -} diff --git a/skills/leon/introduction/src/settings.sample.json b/skills/leon/introduction/src/settings.sample.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/skills/leon/introduction/src/settings.sample.json @@ -0,0 +1 @@ +{} diff --git a/skills/leon/random_number/src/config.sample.json b/skills/leon/random_number/src/config.sample.json deleted file mode 100644 index 9e43d47e..00000000 --- a/skills/leon/random_number/src/config.sample.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "configurations": { - "options": {}, - "credentials": {} - } -} diff --git a/skills/leon/random_number/src/settings.sample.json b/skills/leon/random_number/src/settings.sample.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/skills/leon/random_number/src/settings.sample.json @@ -0,0 +1 @@ +{} diff --git a/skills/news/github_trends/src/config.sample.json b/skills/news/github_trends/src/config.sample.json deleted file mode 100644 index 9e43d47e..00000000 --- a/skills/news/github_trends/src/config.sample.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "configurations": { - "options": {}, - "credentials": {} - } -} diff --git a/skills/news/github_trends/src/settings.sample.json b/skills/news/github_trends/src/settings.sample.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/skills/news/github_trends/src/settings.sample.json @@ -0,0 +1 @@ +{} diff --git a/skills/news/product_hunt_trends/src/config.sample.json b/skills/news/product_hunt_trends/src/settings.sample.json similarity index 100% rename from skills/news/product_hunt_trends/src/config.sample.json rename to skills/news/product_hunt_trends/src/settings.sample.json diff --git a/skills/productivity/todo_list/src/config.sample.json b/skills/productivity/todo_list/src/config.sample.json deleted file mode 100644 index 9e43d47e..00000000 --- a/skills/productivity/todo_list/src/config.sample.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "configurations": { - "options": {}, - "credentials": {} - } -} diff --git a/skills/productivity/todo_list/src/settings.sample.json b/skills/productivity/todo_list/src/settings.sample.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/skills/productivity/todo_list/src/settings.sample.json @@ -0,0 +1 @@ +{} diff --git a/skills/social_communication/mbti/src/config.sample.json b/skills/social_communication/mbti/src/config.sample.json deleted file mode 100644 index 9e43d47e..00000000 --- a/skills/social_communication/mbti/src/config.sample.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "configurations": { - "options": {}, - "credentials": {} - } -} diff --git a/skills/social_communication/mbti/src/settings.sample.json b/skills/social_communication/mbti/src/settings.sample.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/skills/social_communication/mbti/src/settings.sample.json @@ -0,0 +1 @@ +{} diff --git a/skills/utilities/have_i_been_pwned/src/config.sample.json b/skills/utilities/have_i_been_pwned/src/settings.sample.json similarity index 100% rename from skills/utilities/have_i_been_pwned/src/config.sample.json rename to skills/utilities/have_i_been_pwned/src/settings.sample.json diff --git a/skills/utilities/is_it_down/src/config.sample.json b/skills/utilities/is_it_down/src/config.sample.json deleted file mode 100644 index 9e43d47e..00000000 --- a/skills/utilities/is_it_down/src/config.sample.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "configurations": { - "options": {}, - "credentials": {} - } -} diff --git a/skills/utilities/is_it_down/src/settings.sample.json b/skills/utilities/is_it_down/src/settings.sample.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/skills/utilities/is_it_down/src/settings.sample.json @@ -0,0 +1 @@ +{} diff --git a/skills/utilities/speed_test/src/config.sample.json b/skills/utilities/speed_test/src/config.sample.json deleted file mode 100644 index 9e43d47e..00000000 --- a/skills/utilities/speed_test/src/config.sample.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "configurations": { - "options": {}, - "credentials": {} - } -} diff --git a/skills/utilities/speed_test/src/settings.sample.json b/skills/utilities/speed_test/src/settings.sample.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/skills/utilities/speed_test/src/settings.sample.json @@ -0,0 +1 @@ +{} diff --git a/skills/utilities/youtube_downloader/src/config.sample.json b/skills/utilities/youtube_downloader/src/config.sample.json deleted file mode 100644 index 2f1f1d68..00000000 --- a/skills/utilities/youtube_downloader/src/config.sample.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "configurations": { - "options": { - "playlist_id": "PLAYLIST_ID", - "synchronization": { - "enabled": true, - "method": "direct", - "email": "" - } - }, - "credentials": { - "api_key": "YOUR_GOOGLE_API_KEY" - } - } -}