diff --git a/.eslintrc b/.eslintrc index 8d4a8da83..ec4322c17 100644 --- a/.eslintrc +++ b/.eslintrc @@ -72,7 +72,7 @@ "new-cap": ["warn", { "capIsNewExceptionPattern": "^Entry." }], "curly": "warn", "keyword-spacing": "warn", - "indent": ["warn", 4] + "indent": ["warn", 4, { "SwitchCase": 1 }] }, "overrides": [ { diff --git a/app/src/main/core/directoryPaths.ts b/app/src/main/core/directoryPaths.ts index 83ab038d7..dd783cccf 100644 --- a/app/src/main/core/directoryPaths.ts +++ b/app/src/main/core/directoryPaths.ts @@ -1,26 +1,13 @@ import path from 'path'; -const isProduction = process.env.NODE_ENV === 'production'; -const isForStandalone = process.env.STANDALONE === 'true'; -// project's app directory path -// development: /Users/user/entry_projects/entry-hw/app -// production: /Users/user/entry_projects/entry-hw/dist/mac/Entry_HW.app/Contents/Resources -const rootAppPath = (() => { - if (isProduction) { - if (isForStandalone) { - return path.join(__dirname, '..', '..', '..', '..'); - } else { - return path.join(__dirname, '..', '..', '..', '..', '..', '..'); - } - } else { - return path.join(__dirname, '..', '..'); - } -})(); - +let rootAppPath = path.join(__dirname, '..', '..'); export default { - driver: path.join(rootAppPath, 'drivers'), - firmware: path.join(rootAppPath, 'firmwares'), - modules: path.join(rootAppPath, 'modules'), + setRootAppPath: (nextPath: string) => { + rootAppPath = nextPath; + }, + driver: () => path.join(rootAppPath, 'drivers'), + firmware: () => path.join(rootAppPath, 'firmwares'), + modules: () => path.join(rootAppPath, 'modules'), }; diff --git a/app/src/main/core/functions/downloadModule.ts b/app/src/main/core/functions/downloadModule.ts index e08680fab..2043acf90 100644 --- a/app/src/main/core/functions/downloadModule.ts +++ b/app/src/main/core/functions/downloadModule.ts @@ -24,7 +24,7 @@ const downloadModuleFunction = (moduleName: string) => request.on('response', (response) => { response.on('error', reject); if (response.statusCode === 200) { - const moduleDirPath = directoryPaths.modules; + const moduleDirPath = directoryPaths.modules(); logger.verbose('hardware module zip extract..'); const zipStream = new NetworkZipHandlerStream(moduleDirPath); zipStream.on('done', () => { diff --git a/app/src/main/core/hardwareListManager.ts b/app/src/main/core/hardwareListManager.ts index 8b6075f46..53b38d87f 100644 --- a/app/src/main/core/hardwareListManager.ts +++ b/app/src/main/core/hardwareListManager.ts @@ -1,9 +1,9 @@ import fs from 'fs'; import path from 'path'; -import {cloneDeep, merge, unionWith} from 'lodash'; +import { cloneDeep, merge, unionWith } from 'lodash'; import lt from 'semver/functions/lt'; import valid from 'semver/functions/valid'; -import {AvailableTypes} from '../../common/constants'; +import { AvailableTypes } from '../../common/constants'; import getModuleList from './functions/getModuleList'; import createLogger from '../electron/functions/createLogger'; import directoryPaths from './directoryPaths'; @@ -44,9 +44,6 @@ export default class { constructor(router: MainRouter) { this.router = router; logger.verbose('hardwareListManager created'); - // 두번 하는 이유는, 먼저 유저에게 로컬 모듈 목록을 보여주기 위함 - this.updateHardwareList(); - this.updateHardwareListWithOnline(); } async updateHardwareListWithOnline() { @@ -97,10 +94,10 @@ export default class { private getAllHardwareModulesFromDisk() { try { - return fs.readdirSync(directoryPaths.modules) + return fs.readdirSync(directoryPaths.modules()) .filter((file) => !!file.match(/\.json$/)) .map((file) => { - const bufferData = fs.readFileSync(path.join(directoryPaths.modules, file)); + const bufferData = fs.readFileSync(path.join(directoryPaths.modules(), file)); const configJson = JSON.parse(bufferData.toString()); configJson.availableType = AvailableTypes.available; return configJson; diff --git a/app/src/main/core/serial/flasher.ts b/app/src/main/core/serial/flasher.ts index 79c684f53..2cc9919bc 100644 --- a/app/src/main/core/serial/flasher.ts +++ b/app/src/main/core/serial/flasher.ts @@ -58,7 +58,7 @@ class Flasher { this.flasherProcess = exec( cmd.join(''), { - cwd: directoryPaths.firmware, + cwd: directoryPaths.firmware(), }, (...args) => { resolve(args); @@ -69,7 +69,7 @@ class Flasher { private async _flashCopy(firmware: ICopyTypeFirmware): Promise { return new Promise((resolve, reject) => { - const firmwareDirectory = directoryPaths.firmware; + const firmwareDirectory = directoryPaths.firmware(); const destPath = dialog.showOpenDialogSync({ properties: ['openDirectory'], }); diff --git a/app/src/main/electron/index.ts b/app/src/main/electron/index.ts index d9b2ffe22..a5a68ff9e 100644 --- a/app/src/main/electron/index.ts +++ b/app/src/main/electron/index.ts @@ -115,7 +115,9 @@ if (!app.requestSingleInstanceLock()) { entryServer = new EntryServer(); // @ts-ignore - mainRouter = new MainRouter(mainWindow, entryServer); + mainRouter = new MainRouter(mainWindow, entryServer, { + rootAppPath: process.env.NODE_ENV === 'production' && path.join(__dirname, '..', '..', '..'), + }); if (autoOpenHardwareId) { setTimeout(() => { diff --git a/app/src/main/mainRouter.ts b/app/src/main/mainRouter.ts index 15752c2d1..6dba4bc6c 100644 --- a/app/src/main/mainRouter.ts +++ b/app/src/main/mainRouter.ts @@ -58,8 +58,12 @@ class MainRouter { return global.sharedObject.roomIds || []; } - constructor(mainWindow: BrowserWindow, entryServer: IEntryServer) { + constructor(mainWindow: BrowserWindow, entryServer: IEntryServer, options: {rootAppPath?: string}) { global.$ = require('lodash'); + if (options.rootAppPath) { + directoryPaths.setRootAppPath(options.rootAppPath); + } + rendererConsole.initialize(mainWindow); this.ipcManager = new IpcManager(mainWindow.webContents); this.browser = mainWindow; @@ -73,6 +77,10 @@ class MainRouter { this.resetIpcEvents(); this.registerIpcEvents(); + + this.hardwareListManager.updateHardwareList(); + this.hardwareListManager.updateHardwareListWithOnline(); + logger.verbose('mainRouter created'); } @@ -213,7 +221,7 @@ class MainRouter { const { type = 'serial' } = hardware; this.scanner = this.scannerManager.getScanner(type); if (this.scanner) { - const moduleFilePath = directoryPaths.modules; + const moduleFilePath = directoryPaths.modules(); this.hwModule = nativeNodeRequire(path.join(moduleFilePath, config.module)) as IHardwareModule; this.sendState(HardwareStatement.scan); this.scanner.stopScan(); @@ -436,7 +444,7 @@ class MainRouter { return; } - const driverFullPath = path.join(directoryPaths.driver, driverPath); + const driverFullPath = path.join(directoryPaths.driver(), driverPath); logger.info(`execute driver requested. filePath : ${driverFullPath}`); shell.openItem(driverFullPath); } diff --git a/package.json b/package.json index 34fdb2a2f..1a895f6a6 100644 --- a/package.json +++ b/package.json @@ -14,9 +14,10 @@ "webpack:prod": "cross-env NODE_ENV=production webpack", "webpack:watch": "cross-env NODE_ENV=development webpack -w", "update:licence": "lcdoc make -o app/OPENSOURCE.md -d 1", - "dist:win32": "npm run webpack:prod && electron-builder --win --ia32", - "dist:mac:notarize": "npm run webpack:prod && cross-env NOTARIZE=true CSC_NAME=\"Connect Foundation (DLFUSDA3L5)\" electron-builder", - "dist:mac": "npm run webpack:prod && cross-env NOTARIZE=false CSC_NAME=\"Connect Foundation (DLFUSDA3L5)\" electron-builder", + "dist:win32": "cross-env BUILD_MODE=STANDALONE npm run webpack:prod && electron-builder --win --ia32", + "dist:mac:notarize": "cross-env BUILD_MODE=STANDALONE npm run webpack:prod && cross-env NOTARIZE=true CSC_NAME=\"Connect Foundation (DLFUSDA3L5)\" electron-builder", + "dist:mac": "cross-env BUILD_MODE=STANDALONE npm run webpack:prod && cross-env NOTARIZE=false CSC_NAME=\"Connect Foundation (DLFUSDA3L5)\" electron-builder", + "dist:offline": "cross-env BUILD_MODE=OFFLINE npm run webpack:prod", "rebuild": "electron-rebuild -f -w serialport,node-hid", "setting": "npm run rebuild && npm run webpack:dev" },