mirror of
https://github.com/leon-ai/leon.git
synced 2024-09-11 10:25:40 +03:00
refactor(server): loader helper to static class
This commit is contained in:
parent
f4d625500f
commit
88d86117ac
@ -1,7 +1,7 @@
|
||||
import { command } from 'execa'
|
||||
|
||||
import { LOG } from '@/helpers/log'
|
||||
import { LOADER } from '@/helpers/loader'
|
||||
import { LoaderHelper } from '@/helpers/loader-helper'
|
||||
|
||||
const globs = [
|
||||
'"app/src/js/*.{ts,js}"',
|
||||
@ -33,7 +33,7 @@ async function prettier() {
|
||||
* This script ensures the correct coding syntax of the whole project
|
||||
*/
|
||||
;(async () => {
|
||||
LOADER.start()
|
||||
LoaderHelper.start()
|
||||
LOG.info('Linting...')
|
||||
|
||||
try {
|
||||
@ -46,10 +46,10 @@ async function prettier() {
|
||||
])
|
||||
|
||||
LOG.success('Looks great')
|
||||
LOADER.stop()
|
||||
LoaderHelper.stop()
|
||||
} catch (e) {
|
||||
LOG.error(`Does not look great: ${e.message}`)
|
||||
LOADER.stop()
|
||||
LoaderHelper.stop()
|
||||
process.exit(1)
|
||||
}
|
||||
})()
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { LOG } from '@/helpers/log'
|
||||
import { LOADER } from '@/helpers/loader'
|
||||
import { LoaderHelper } from '@/helpers/loader-helper'
|
||||
|
||||
import updateVersion from './update-version'
|
||||
import generateChangelog from './generate-changelog'
|
||||
@ -8,7 +8,7 @@ import generateChangelog from './generate-changelog'
|
||||
* Main entry of the release preparation
|
||||
*/
|
||||
;(async () => {
|
||||
LOADER.start()
|
||||
LoaderHelper.start()
|
||||
LOG.info('Preparing for release...')
|
||||
|
||||
const { argv } = process
|
||||
@ -22,15 +22,15 @@ import generateChangelog from './generate-changelog'
|
||||
await generateChangelog(version)
|
||||
|
||||
LOG.success('Hooray! Leon is ready to be released!')
|
||||
LOADER.stop()
|
||||
LoaderHelper.stop()
|
||||
} catch (e) {
|
||||
LOG.error(e)
|
||||
LOADER.stop()
|
||||
LoaderHelper.stop()
|
||||
}
|
||||
} else {
|
||||
LOG.error(
|
||||
'The version number does match the Semantic Versioning rules (https://semver.org)'
|
||||
)
|
||||
LOADER.stop()
|
||||
LoaderHelper.stop()
|
||||
}
|
||||
})()
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { LOADER } from '@/helpers/loader'
|
||||
import { LoaderHelper } from '@/helpers/loader-helper'
|
||||
|
||||
import check from './check'
|
||||
|
||||
@ -7,10 +7,10 @@ import check from './check'
|
||||
*/
|
||||
;(async () => {
|
||||
try {
|
||||
LOADER.start()
|
||||
LoaderHelper.start()
|
||||
await check()
|
||||
LOADER.stop()
|
||||
LoaderHelper.stop()
|
||||
} catch (e) {
|
||||
LOADER.stop()
|
||||
LoaderHelper.stop()
|
||||
}
|
||||
})()
|
||||
|
@ -1,6 +1,6 @@
|
||||
import dotenv from 'dotenv'
|
||||
|
||||
import { LOADER } from '@/helpers/loader'
|
||||
import { LoaderHelper } from '@/helpers/loader-helper'
|
||||
import { LOG } from '@/helpers/log'
|
||||
|
||||
import checkOs from '../check-os'
|
||||
@ -15,18 +15,18 @@ dotenv.config()
|
||||
*/
|
||||
;(async () => {
|
||||
try {
|
||||
LOADER.start()
|
||||
LoaderHelper.start()
|
||||
await checkOs()
|
||||
LOADER.stop()
|
||||
LoaderHelper.stop()
|
||||
await setupHotword()
|
||||
LOADER.start()
|
||||
LoaderHelper.start()
|
||||
await setupTts()
|
||||
await setupStt()
|
||||
|
||||
LOADER.stop()
|
||||
LoaderHelper.stop()
|
||||
LOG.success('Hooray! Offline components are installed!')
|
||||
} catch (e) {
|
||||
LOG.error(e)
|
||||
LOADER.stop()
|
||||
LoaderHelper.stop()
|
||||
}
|
||||
})()
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { LOADER } from '@/helpers/loader'
|
||||
import { LoaderHelper } from '@/helpers/loader-helper'
|
||||
import { LOG } from '@/helpers/log'
|
||||
|
||||
import train from '../train/train'
|
||||
@ -20,19 +20,19 @@ import setupPythonPackages from './setup-python-packages'
|
||||
process.env.PIPENV_VENV_IN_PROJECT = 'true'
|
||||
|
||||
await setupDotenv()
|
||||
LOADER.start()
|
||||
LoaderHelper.start()
|
||||
await Promise.all([setupCore(), setupSkillsConfig()])
|
||||
await setupPythonPackages()
|
||||
LOADER.stop()
|
||||
LoaderHelper.stop()
|
||||
await generateHttpApiKey()
|
||||
LOADER.start()
|
||||
LoaderHelper.start()
|
||||
await train()
|
||||
|
||||
LOG.default('')
|
||||
LOG.success('Hooray! Leon is installed and ready to go!')
|
||||
LOADER.stop()
|
||||
LoaderHelper.stop()
|
||||
} catch (e) {
|
||||
LOG.error(e)
|
||||
LOADER.stop()
|
||||
LoaderHelper.stop()
|
||||
}
|
||||
})()
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { command } from 'execa'
|
||||
|
||||
import { LOG } from '@/helpers/log'
|
||||
import { LOADER } from '@/helpers/loader'
|
||||
import { LoaderHelper } from '@/helpers/loader-helper'
|
||||
|
||||
/**
|
||||
* Specific module testing script
|
||||
@ -15,7 +15,7 @@ import { LOADER } from '@/helpers/loader'
|
||||
const [pkg, module] = arr
|
||||
|
||||
try {
|
||||
LOADER.start()
|
||||
LoaderHelper.start()
|
||||
await command('npm run train en', { shell: true })
|
||||
const cmd = await command(
|
||||
`cross-env PIPENV_PIPFILE=bridges/python/Pipfile LEON_NODE_ENV=testing jest --silent --config=./test/e2e/modules/e2e.modules.jest.json packages/${pkg}/test/${module}.spec.js && npm run train`,
|
||||
@ -24,9 +24,9 @@ import { LOADER } from '@/helpers/loader'
|
||||
|
||||
LOG.default(cmd.stdout)
|
||||
LOG.default(cmd.stderr)
|
||||
LOADER.stop()
|
||||
LoaderHelper.stop()
|
||||
} catch (e) {
|
||||
LOG.default(e.message)
|
||||
LOADER.stop()
|
||||
LoaderHelper.stop()
|
||||
}
|
||||
})()
|
||||
|
@ -6,7 +6,7 @@ function randomNumber(min: number, max: number) {
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min
|
||||
}
|
||||
|
||||
class LoaderHelper {
|
||||
export class LoaderHelper {
|
||||
static readonly SENTENCES = [
|
||||
'This process takes time, please go for a coffee (or a fruit juice)',
|
||||
'This may take a while, grab a drink and come back later',
|
||||
@ -15,22 +15,16 @@ class LoaderHelper {
|
||||
'Leon will be ready for you in a moment'
|
||||
]
|
||||
|
||||
private static instance: LoaderHelper
|
||||
private static spinner = new Spinner('\x1b[95m%s\x1b[0m\r').setSpinnerString(
|
||||
18
|
||||
)
|
||||
|
||||
private spinner = new Spinner('\x1b[95m%s\x1b[0m\r').setSpinnerString(18)
|
||||
|
||||
private interval: NodeJS.Timer | undefined
|
||||
|
||||
constructor() {
|
||||
if (LoaderHelper.instance == null) {
|
||||
LoaderHelper.instance = this
|
||||
}
|
||||
}
|
||||
private static interval: NodeJS.Timer | undefined
|
||||
|
||||
/**
|
||||
* Start the loader
|
||||
*/
|
||||
public start() {
|
||||
public static start() {
|
||||
this.interval = setInterval(() => {
|
||||
if (this.spinner.isSpinning()) {
|
||||
const randomSentenceIndex = randomNumber(
|
||||
@ -49,11 +43,9 @@ class LoaderHelper {
|
||||
/**
|
||||
* Stop the loader
|
||||
*/
|
||||
public stop() {
|
||||
public static stop() {
|
||||
clearInterval(this.interval)
|
||||
|
||||
this.spinner.stop()
|
||||
}
|
||||
}
|
||||
|
||||
export const LOADER = new LoaderHelper()
|
@ -1,4 +1,4 @@
|
||||
import { LOADER } from '@/helpers/loader'
|
||||
import { LoaderHelper } from '@/helpers/loader-helper'
|
||||
|
||||
jest.useFakeTimers()
|
||||
|
||||
@ -8,14 +8,14 @@ describe('loader helper', () => {
|
||||
jest.spyOn(global, 'setInterval')
|
||||
|
||||
test('starts spinner', () => {
|
||||
expect(LOADER.start()).toBeObject()
|
||||
expect(LoaderHelper.start()).toBeObject()
|
||||
expect(setInterval).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('stop()', () => {
|
||||
test('stops spinner', () => {
|
||||
expect(LOADER.stop()).toBeObject()
|
||||
expect(LoaderHelper.stop()).toBeObject()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user