mirror of
https://github.com/leon-ai/leon.git
synced 2024-08-17 06:00:33 +03:00
chore: rename config.json to settings.json
This commit is contained in:
parent
30e405bbe3
commit
4f5b385fd7
4
.gitignore
vendored
4
.gitignore
vendored
@ -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
|
||||
|
@ -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`
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
77
scripts/setup/setup-skills/setup-skills-settings.js
Normal file
77
scripts/setup/setup-skills/setup-skills-settings.js
Normal file
@ -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`
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -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`)
|
||||
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"configurations": {
|
||||
"options": {},
|
||||
"credentials": {}
|
||||
}
|
||||
}
|
1
skills/games/akinator/src/settings.sample.json
Normal file
1
skills/games/akinator/src/settings.sample.json
Normal file
@ -0,0 +1 @@
|
||||
{}
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"configurations": {
|
||||
"options": {},
|
||||
"credentials": {}
|
||||
}
|
||||
}
|
1
skills/games/guess_the_number/src/settings.sample.json
Normal file
1
skills/games/guess_the_number/src/settings.sample.json
Normal file
@ -0,0 +1 @@
|
||||
{}
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"configurations": {
|
||||
"options": {},
|
||||
"credentials": {}
|
||||
}
|
||||
}
|
1
skills/games/rochambeau/src/settings.sample.json
Normal file
1
skills/games/rochambeau/src/settings.sample.json
Normal file
@ -0,0 +1 @@
|
||||
{}
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"configurations": {
|
||||
"options": {},
|
||||
"credentials": {}
|
||||
}
|
||||
}
|
1
skills/leon/greeting/src/settings.sample.json
Normal file
1
skills/leon/greeting/src/settings.sample.json
Normal file
@ -0,0 +1 @@
|
||||
{}
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"configurations": {
|
||||
"options": {},
|
||||
"credentials": {}
|
||||
}
|
||||
}
|
1
skills/leon/introduction/src/settings.sample.json
Normal file
1
skills/leon/introduction/src/settings.sample.json
Normal file
@ -0,0 +1 @@
|
||||
{}
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"configurations": {
|
||||
"options": {},
|
||||
"credentials": {}
|
||||
}
|
||||
}
|
1
skills/leon/random_number/src/settings.sample.json
Normal file
1
skills/leon/random_number/src/settings.sample.json
Normal file
@ -0,0 +1 @@
|
||||
{}
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"configurations": {
|
||||
"options": {},
|
||||
"credentials": {}
|
||||
}
|
||||
}
|
1
skills/news/github_trends/src/settings.sample.json
Normal file
1
skills/news/github_trends/src/settings.sample.json
Normal file
@ -0,0 +1 @@
|
||||
{}
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"configurations": {
|
||||
"options": {},
|
||||
"credentials": {}
|
||||
}
|
||||
}
|
1
skills/productivity/todo_list/src/settings.sample.json
Normal file
1
skills/productivity/todo_list/src/settings.sample.json
Normal file
@ -0,0 +1 @@
|
||||
{}
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"configurations": {
|
||||
"options": {},
|
||||
"credentials": {}
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
{}
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"configurations": {
|
||||
"options": {},
|
||||
"credentials": {}
|
||||
}
|
||||
}
|
1
skills/utilities/is_it_down/src/settings.sample.json
Normal file
1
skills/utilities/is_it_down/src/settings.sample.json
Normal file
@ -0,0 +1 @@
|
||||
{}
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"configurations": {
|
||||
"options": {},
|
||||
"credentials": {}
|
||||
}
|
||||
}
|
1
skills/utilities/speed_test/src/settings.sample.json
Normal file
1
skills/utilities/speed_test/src/settings.sample.json
Normal file
@ -0,0 +1 @@
|
||||
{}
|
@ -1,15 +0,0 @@
|
||||
{
|
||||
"configurations": {
|
||||
"options": {
|
||||
"playlist_id": "PLAYLIST_ID",
|
||||
"synchronization": {
|
||||
"enabled": true,
|
||||
"method": "direct",
|
||||
"email": ""
|
||||
}
|
||||
},
|
||||
"credentials": {
|
||||
"api_key": "YOUR_GOOGLE_API_KEY"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user