Skip to content

Commit

Permalink
[chore] directoryPath 를 외부주입방법으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
extracold1209 authored and entrydev committed Sep 2, 2020
1 parent 7f9c6f0 commit 170c0da
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"new-cap": ["warn", { "capIsNewExceptionPattern": "^Entry." }],
"curly": "warn",
"keyword-spacing": "warn",
"indent": ["warn", 4]
"indent": ["warn", 4, { "SwitchCase": 1 }]
},
"overrides": [
{
Expand Down
27 changes: 7 additions & 20 deletions app/src/main/core/directoryPaths.ts
Original file line number Diff line number Diff line change
@@ -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'),
};

2 changes: 1 addition & 1 deletion app/src/main/core/functions/downloadModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
11 changes: 4 additions & 7 deletions app/src/main/core/hardwareListManager.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -44,9 +44,6 @@ export default class {
constructor(router: MainRouter) {
this.router = router;
logger.verbose('hardwareListManager created');
// 두번 하는 이유는, 먼저 유저에게 로컬 모듈 목록을 보여주기 위함
this.updateHardwareList();
this.updateHardwareListWithOnline();
}

async updateHardwareListWithOnline() {
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/core/serial/flasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Flasher {
this.flasherProcess = exec(
cmd.join(''),
{
cwd: directoryPaths.firmware,
cwd: directoryPaths.firmware(),
},
(...args) => {
resolve(args);
Expand All @@ -69,7 +69,7 @@ class Flasher {

private async _flashCopy(firmware: ICopyTypeFirmware): Promise<any[]> {
return new Promise((resolve, reject) => {
const firmwareDirectory = directoryPaths.firmware;
const firmwareDirectory = directoryPaths.firmware();
const destPath = dialog.showOpenDialogSync({
properties: ['openDirectory'],
});
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/electron/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
14 changes: 11 additions & 3 deletions app/src/main/mainRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -73,6 +77,10 @@ class MainRouter {

this.resetIpcEvents();
this.registerIpcEvents();

this.hardwareListManager.updateHardwareList();
this.hardwareListManager.updateHardwareListWithOnline();

logger.verbose('mainRouter created');
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit 170c0da

Please sign in to comment.