diff --git a/scripts/build-binaries.js b/scripts/build-binaries.js index eb3d3c3f..f09884ec 100644 --- a/scripts/build-binaries.js +++ b/scripts/build-binaries.js @@ -5,6 +5,15 @@ import { command } from 'execa' import archiver from 'archiver' import prettyBytes from 'pretty-bytes' +import { + PYTHON_BRIDGE_SRC_PATH, + TCP_SERVER_SRC_PATH, + BINARIES_FOLDER_NAME, + PYTHON_BRIDGE_DIST_PATH, + TCP_SERVER_DIST_PATH, + PYTHON_BRIDGE_BIN_NAME, + TCP_SERVER_BIN_NAME +} from '@/constants' import { LogHelper } from '@/helpers/log-helper' import { LoaderHelper } from '@/helpers/loader-helper' import { OSHelper, OSTypes } from '@/helpers/os-helper' @@ -18,24 +27,20 @@ import { OSHelper, OSTypes } from '@/helpers/os-helper' */ const BUILD_TARGETS = new Map() -const PYTHON_BRIDGE_SRC_PATH = 'bridges/python/src' -const TCP_SERVER_SRC_PATH = 'tcp_server/src' - -const BINARIES_FOLDER_NAME = OSHelper.getBinariesFolderName() BUILD_TARGETS.set('python-bridge', { name: 'Python bridge', pipfilePath: path.join(PYTHON_BRIDGE_SRC_PATH, 'Pipfile'), setupFilePath: path.join(PYTHON_BRIDGE_SRC_PATH, 'setup.py'), - distPath: 'bridges/python/dist', - archiveName: `leon-python-bridge-${BINARIES_FOLDER_NAME}.zip` + distPath: PYTHON_BRIDGE_DIST_PATH, + archiveName: `${PYTHON_BRIDGE_BIN_NAME}-${BINARIES_FOLDER_NAME}.zip` }) BUILD_TARGETS.set('tcp-server', { name: 'TCP server', pipfilePath: path.join(TCP_SERVER_SRC_PATH, 'Pipfile'), setupFilePath: path.join(TCP_SERVER_SRC_PATH, 'setup.py'), - distPath: 'tcp_server/dist', - archiveName: `leon-tcp-server-${BINARIES_FOLDER_NAME}.zip` + distPath: TCP_SERVER_DIST_PATH, + archiveName: `${TCP_SERVER_BIN_NAME}-${BINARIES_FOLDER_NAME}.zip` }) ;(async () => { LoaderHelper.start() diff --git a/scripts/check.js b/scripts/check.js index cb137da0..2dc0eddf 100644 --- a/scripts/check.js +++ b/scripts/check.js @@ -7,6 +7,7 @@ import semver from 'semver' import { version } from '@@/package.json' import { LogHelper } from '@/helpers/log-helper' +import { PYTHON_BRIDGE_BIN_PATH } from '@/constants' dotenv.config() @@ -171,7 +172,7 @@ export default () => try { LogHelper.time('Skill execution time') const p = await command( - './bridges/python/dist/python-bridge/leon-python-bridge scripts/assets/intent-object.json', + `${PYTHON_BRIDGE_BIN_PATH} scripts/assets/intent-object.json`, { shell: true } ) LogHelper.timeEnd('Skill execution time') diff --git a/scripts/setup/setup-python-dev-env.js b/scripts/setup/setup-python-dev-env.js index 4d99e1e3..6dab4ad2 100644 --- a/scripts/setup/setup-python-dev-env.js +++ b/scripts/setup/setup-python-dev-env.js @@ -3,6 +3,7 @@ import path from 'node:path' import { command } from 'execa' +import { PYTHON_BRIDGE_SRC_PATH, TCP_SERVER_SRC_PATH } from '@/constants' import { LogHelper } from '@/helpers/log-helper' import { LoaderHelper } from '@/helpers/loader-helper' @@ -18,8 +19,6 @@ import { LoaderHelper } from '@/helpers/loader-helper' const SETUP_TARGETS = new Map() // Find new spaCy models: https://github.com/explosion/spacy-models/releases const SPACY_MODELS = ['en_core_web_trf-3.4.0', 'fr_core_news_md-3.4.0'] -const PYTHON_BRIDGE_SRC_PATH = 'bridges/python/src' -const TCP_SERVER_SRC_PATH = 'tcp_server/src' SETUP_TARGETS.set('python-bridge', { name: 'Python bridge', diff --git a/server/src/constants.ts b/server/src/constants.ts index 3b163a68..4e7759a8 100644 --- a/server/src/constants.ts +++ b/server/src/constants.ts @@ -1,6 +1,9 @@ +import path from 'node:path' + import dotenv from 'dotenv' import type { LongLanguageCode } from '@/helpers/lang-helper' +import { OSHelper } from '@/helpers/os-helper' dotenv.config() @@ -8,6 +11,16 @@ const PRODUCTION_ENV = 'production' const DEVELOPMENT_ENV = 'development' const TESTING_ENV = 'testing' +export const BINARIES_FOLDER_NAME = OSHelper.getBinariesFolderName() +export const PYTHON_BRIDGE_DIST_PATH = path.join('bridges', 'python', 'dist') +export const TCP_SERVER_DIST_PATH = path.join('tcp_server', 'dist') + +export const PYTHON_BRIDGE_SRC_PATH = path.join('bridges', 'python', 'src') +export const TCP_SERVER_SRC_PATH = path.join('tcp_server', 'src') + +export const PYTHON_BRIDGE_BIN_NAME = 'leon-python-bridge' +export const TCP_SERVER_BIN_NAME = 'leon-tcp-server' + export const IS_PRODUCTION_ENV = process.env['LEON_NODE_ENV'] === PRODUCTION_ENV export const IS_DEVELOPMENT_ENV = process.env['LEON_NODE_ENV'] === DEVELOPMENT_ENV @@ -35,3 +48,14 @@ export const HAS_LOGGER = process.env['LEON_LOGGER'] === 'true' export const TCP_SERVER_HOST = process.env['LEON_PY_TCP_SERVER_HOST'] export const TCP_SERVER_PORT = process.env['LEON_PY_TCP_SERVER_PORT'] + +export const TCP_SERVER_BIN_PATH = path.join( + TCP_SERVER_DIST_PATH, + BINARIES_FOLDER_NAME, + TCP_SERVER_BIN_NAME +) +export const PYTHON_BRIDGE_BIN_PATH = path.join( + PYTHON_BRIDGE_DIST_PATH, + BINARIES_FOLDER_NAME, + PYTHON_BRIDGE_BIN_NAME +) diff --git a/server/src/core/brain.js b/server/src/core/brain.js index e342c893..ab2ff95f 100644 --- a/server/src/core/brain.js +++ b/server/src/core/brain.js @@ -3,7 +3,7 @@ import path from 'node:path' import { spawn } from 'node:child_process' import { langs } from '@@/core/langs.json' -import { HAS_TTS } from '@/constants' +import { HAS_TTS, PYTHON_BRIDGE_BIN_PATH } from '@/constants' import { LangHelper } from '@/helpers/lang-helper' import { LogHelper } from '@/helpers/log-helper' import { SkillDomainHelper } from '@/helpers/skill-domain-helper' @@ -225,7 +225,7 @@ class Brain { try { fs.writeFileSync(intentObjectPath, JSON.stringify(intentObj)) this.process = spawn( - `./bridges/python/dist/python-bridge/leon-python-bridge ${intentObjectPath}`, + `${PYTHON_BRIDGE_BIN_PATH} ${intentObjectPath}`, { shell: true } ) } catch (e) { diff --git a/server/src/core/nlu.js b/server/src/core/nlu.js index 8aa72abc..b1a6b8f8 100644 --- a/server/src/core/nlu.js +++ b/server/src/core/nlu.js @@ -14,6 +14,7 @@ import { version } from '@@/package.json' import { HAS_LOGGER, IS_TESTING_ENV, + TCP_SERVER_BIN_PATH, TCP_SERVER_HOST, TCP_SERVER_PORT } from '@/constants' @@ -223,10 +224,9 @@ class Nlu { // Recreate a new TCP server process and reconnect the TCP client kill(global.tcpServerProcess.pid, () => { - global.tcpServerProcess = spawn( - `./bridges/python/dist/tcp-server/leon-tcp-server ${locale}`, - { shell: true } - ) + global.tcpServerProcess = spawn(`${TCP_SERVER_BIN_PATH} ${locale}`, { + shell: true + }) global.tcpClient = new TcpClient(TCP_SERVER_HOST, TCP_SERVER_PORT) diff --git a/server/src/index.ts b/server/src/index.ts index fcb99f8c..44739fb5 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -4,7 +4,8 @@ import { TCP_SERVER_HOST, TCP_SERVER_PORT, IS_DEVELOPMENT_ENV, - LANG as LEON_LANG + LANG as LEON_LANG, + TCP_SERVER_BIN_PATH } from '@/constants' import { LangHelper } from '@/helpers/lang-helper' import TcpClient from '@/core/tcp-client' @@ -13,9 +14,7 @@ import server from '@/core/http-server/server' process.title = 'leon' global.tcpServerProcess = spawn( - `./bridges/python/dist/tcp-server/leon-tcp-server ${LangHelper.getShortCode( - LEON_LANG - )}`, + `${TCP_SERVER_BIN_PATH} ${LangHelper.getShortCode(LEON_LANG)}`, { shell: true, detached: IS_DEVELOPMENT_ENV