From 9a670877669b8bccd9d6ebc6fcfc39729230c1c8 Mon Sep 17 00:00:00 2001
From: Daniel Scalzi <d_scalzi@yahoo.com>
Date: Sun, 24 May 2020 15:44:16 -0400
Subject: [PATCH] Move code to common. Renderer will be only react/redux code.
 Common code can be used in both main and renderer.

---
 src/{main => common}/asset/assetguardnew.ts              | 0
 src/{main => common}/asset/model/engine/Asset.ts         | 0
 .../asset/model/engine/AssetGuardError.ts                | 0
 .../asset/model/engine/IndexProcessor.ts                 | 0
 src/{main => common}/asset/model/mojang/LauncherJson.ts  | 0
 src/{main => common}/asset/model/mojang/VersionJson.ts   | 0
 .../asset/model/mojang/VersionManifest.ts                | 0
 .../asset/processor/MojangIndexProcessor.ts              | 6 +++---
 src/{main => common}/config/configmanager.ts             | 0
 src/{main => common}/config/model/LauncherConfig.ts      | 0
 src/{main => common}/config/model/ModConfig.ts           | 0
 src/{main => common}/config/model/NewsCache.ts           | 0
 src/{main => common}/config/model/SavedAccount.ts        | 0
 src/{main => common}/logging/loggerutil.ts               | 0
 src/{main => common}/mojang/model/auth/Agent.ts          | 0
 src/{main => common}/mojang/model/auth/AuthPayload.ts    | 0
 src/{main => common}/mojang/model/auth/Session.ts        | 0
 src/{main => common}/mojang/model/internal/Response.ts   | 0
 src/{main => common}/mojang/model/internal/Status.ts     | 0
 src/{main => common}/mojang/mojang.ts                    | 0
 src/{main => common}/util/FileUtils.ts                   | 0
 src/{main => common}/util/MojangUtils.ts                 | 2 +-
 src/{main => common}/util/isdev.ts                       | 0
 src/main/index.ts                                        | 2 +-
 src/main/old/assetguard.ts                               | 8 ++++----
 src/main/old/authmanager.ts                              | 6 +++---
 src/main/old/distromanager.ts                            | 2 +-
 src/main/old/preloader.ts                                | 2 +-
 src/main/old/processbuilder.ts                           | 6 +++---
 test/assets/MojangIndexProcessorTest.ts                  | 4 ++--
 test/mojang/mojangTest.ts                                | 6 +++---
 tsconfig.json                                            | 9 +++++----
 32 files changed, 27 insertions(+), 26 deletions(-)
 rename src/{main => common}/asset/assetguardnew.ts (100%)
 rename src/{main => common}/asset/model/engine/Asset.ts (100%)
 rename src/{main => common}/asset/model/engine/AssetGuardError.ts (100%)
 rename src/{main => common}/asset/model/engine/IndexProcessor.ts (100%)
 rename src/{main => common}/asset/model/mojang/LauncherJson.ts (100%)
 rename src/{main => common}/asset/model/mojang/VersionJson.ts (100%)
 rename src/{main => common}/asset/model/mojang/VersionManifest.ts (100%)
 rename src/{main => common}/asset/processor/MojangIndexProcessor.ts (98%)
 rename src/{main => common}/config/configmanager.ts (100%)
 rename src/{main => common}/config/model/LauncherConfig.ts (100%)
 rename src/{main => common}/config/model/ModConfig.ts (100%)
 rename src/{main => common}/config/model/NewsCache.ts (100%)
 rename src/{main => common}/config/model/SavedAccount.ts (100%)
 rename src/{main => common}/logging/loggerutil.ts (100%)
 rename src/{main => common}/mojang/model/auth/Agent.ts (100%)
 rename src/{main => common}/mojang/model/auth/AuthPayload.ts (100%)
 rename src/{main => common}/mojang/model/auth/Session.ts (100%)
 rename src/{main => common}/mojang/model/internal/Response.ts (100%)
 rename src/{main => common}/mojang/model/internal/Status.ts (100%)
 rename src/{main => common}/mojang/mojang.ts (100%)
 rename src/{main => common}/util/FileUtils.ts (100%)
 rename src/{main => common}/util/MojangUtils.ts (95%)
 rename src/{main => common}/util/isdev.ts (100%)

diff --git a/src/main/asset/assetguardnew.ts b/src/common/asset/assetguardnew.ts
similarity index 100%
rename from src/main/asset/assetguardnew.ts
rename to src/common/asset/assetguardnew.ts
diff --git a/src/main/asset/model/engine/Asset.ts b/src/common/asset/model/engine/Asset.ts
similarity index 100%
rename from src/main/asset/model/engine/Asset.ts
rename to src/common/asset/model/engine/Asset.ts
diff --git a/src/main/asset/model/engine/AssetGuardError.ts b/src/common/asset/model/engine/AssetGuardError.ts
similarity index 100%
rename from src/main/asset/model/engine/AssetGuardError.ts
rename to src/common/asset/model/engine/AssetGuardError.ts
diff --git a/src/main/asset/model/engine/IndexProcessor.ts b/src/common/asset/model/engine/IndexProcessor.ts
similarity index 100%
rename from src/main/asset/model/engine/IndexProcessor.ts
rename to src/common/asset/model/engine/IndexProcessor.ts
diff --git a/src/main/asset/model/mojang/LauncherJson.ts b/src/common/asset/model/mojang/LauncherJson.ts
similarity index 100%
rename from src/main/asset/model/mojang/LauncherJson.ts
rename to src/common/asset/model/mojang/LauncherJson.ts
diff --git a/src/main/asset/model/mojang/VersionJson.ts b/src/common/asset/model/mojang/VersionJson.ts
similarity index 100%
rename from src/main/asset/model/mojang/VersionJson.ts
rename to src/common/asset/model/mojang/VersionJson.ts
diff --git a/src/main/asset/model/mojang/VersionManifest.ts b/src/common/asset/model/mojang/VersionManifest.ts
similarity index 100%
rename from src/main/asset/model/mojang/VersionManifest.ts
rename to src/common/asset/model/mojang/VersionManifest.ts
diff --git a/src/main/asset/processor/MojangIndexProcessor.ts b/src/common/asset/processor/MojangIndexProcessor.ts
similarity index 98%
rename from src/main/asset/processor/MojangIndexProcessor.ts
rename to src/common/asset/processor/MojangIndexProcessor.ts
index da4f6928..674cffba 100644
--- a/src/main/asset/processor/MojangIndexProcessor.ts
+++ b/src/common/asset/processor/MojangIndexProcessor.ts
@@ -1,14 +1,14 @@
 import { IndexProcessor } from '../model/engine/IndexProcessor'
 import got, { HTTPError, RequestError, ParseError, TimeoutError } from 'got'
-import { LoggerUtil } from '../../logging/loggerutil'
+import { LoggerUtil } from 'common/logging/loggerutil'
 import { pathExists, readFile, ensureDir, writeFile, readJson } from 'fs-extra'
 import { MojangVersionManifest } from '../model/mojang/VersionManifest'
-import { calculateHash, getVersionJsonPath, validateLocalFile, getLibraryDir, getVersionJarPath } from '../../util/FileUtils'
+import { calculateHash, getVersionJsonPath, validateLocalFile, getLibraryDir, getVersionJarPath } from 'common/util/FileUtils'
 import { dirname, join } from 'path'
 import { VersionJson, AssetIndex, LibraryArtifact } from '../model/mojang/VersionJson'
 import { AssetGuardError } from '../model/engine/AssetGuardError'
 import { Asset } from '../model/engine/Asset'
-import { isLibraryCompatible, getMojangOS } from '../../util/MojangUtils'
+import { isLibraryCompatible, getMojangOS } from 'common/util/MojangUtils'
 
 export class MojangIndexProcessor extends IndexProcessor {
 
diff --git a/src/main/config/configmanager.ts b/src/common/config/configmanager.ts
similarity index 100%
rename from src/main/config/configmanager.ts
rename to src/common/config/configmanager.ts
diff --git a/src/main/config/model/LauncherConfig.ts b/src/common/config/model/LauncherConfig.ts
similarity index 100%
rename from src/main/config/model/LauncherConfig.ts
rename to src/common/config/model/LauncherConfig.ts
diff --git a/src/main/config/model/ModConfig.ts b/src/common/config/model/ModConfig.ts
similarity index 100%
rename from src/main/config/model/ModConfig.ts
rename to src/common/config/model/ModConfig.ts
diff --git a/src/main/config/model/NewsCache.ts b/src/common/config/model/NewsCache.ts
similarity index 100%
rename from src/main/config/model/NewsCache.ts
rename to src/common/config/model/NewsCache.ts
diff --git a/src/main/config/model/SavedAccount.ts b/src/common/config/model/SavedAccount.ts
similarity index 100%
rename from src/main/config/model/SavedAccount.ts
rename to src/common/config/model/SavedAccount.ts
diff --git a/src/main/logging/loggerutil.ts b/src/common/logging/loggerutil.ts
similarity index 100%
rename from src/main/logging/loggerutil.ts
rename to src/common/logging/loggerutil.ts
diff --git a/src/main/mojang/model/auth/Agent.ts b/src/common/mojang/model/auth/Agent.ts
similarity index 100%
rename from src/main/mojang/model/auth/Agent.ts
rename to src/common/mojang/model/auth/Agent.ts
diff --git a/src/main/mojang/model/auth/AuthPayload.ts b/src/common/mojang/model/auth/AuthPayload.ts
similarity index 100%
rename from src/main/mojang/model/auth/AuthPayload.ts
rename to src/common/mojang/model/auth/AuthPayload.ts
diff --git a/src/main/mojang/model/auth/Session.ts b/src/common/mojang/model/auth/Session.ts
similarity index 100%
rename from src/main/mojang/model/auth/Session.ts
rename to src/common/mojang/model/auth/Session.ts
diff --git a/src/main/mojang/model/internal/Response.ts b/src/common/mojang/model/internal/Response.ts
similarity index 100%
rename from src/main/mojang/model/internal/Response.ts
rename to src/common/mojang/model/internal/Response.ts
diff --git a/src/main/mojang/model/internal/Status.ts b/src/common/mojang/model/internal/Status.ts
similarity index 100%
rename from src/main/mojang/model/internal/Status.ts
rename to src/common/mojang/model/internal/Status.ts
diff --git a/src/main/mojang/mojang.ts b/src/common/mojang/mojang.ts
similarity index 100%
rename from src/main/mojang/mojang.ts
rename to src/common/mojang/mojang.ts
diff --git a/src/main/util/FileUtils.ts b/src/common/util/FileUtils.ts
similarity index 100%
rename from src/main/util/FileUtils.ts
rename to src/common/util/FileUtils.ts
diff --git a/src/main/util/MojangUtils.ts b/src/common/util/MojangUtils.ts
similarity index 95%
rename from src/main/util/MojangUtils.ts
rename to src/common/util/MojangUtils.ts
index c9c619c8..f8664e47 100644
--- a/src/main/util/MojangUtils.ts
+++ b/src/common/util/MojangUtils.ts
@@ -1,4 +1,4 @@
-import { Rule, Natives } from "../asset/model/mojang/VersionJson"
+import { Rule, Natives } from "../../main/asset/model/mojang/VersionJson"
 
 export function getMojangOS(): string {
     const opSys = process.platform
diff --git a/src/main/util/isdev.ts b/src/common/util/isdev.ts
similarity index 100%
rename from src/main/util/isdev.ts
rename to src/common/util/isdev.ts
diff --git a/src/main/index.ts b/src/main/index.ts
index 3790a686..1a561fc0 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -4,7 +4,7 @@ import { join } from "path"
 import { readdirSync } from "fs-extra"
 import { format } from "url"
 import { autoUpdater } from 'electron-updater'
-import isdev from "./util/isdev"
+import isdev from "../common/util/isdev"
 
 const installExtensions = async () => {
     const installer = require('electron-devtools-installer');
diff --git a/src/main/old/assetguard.ts b/src/main/old/assetguard.ts
index 4fc1172f..2b3456a4 100644
--- a/src/main/old/assetguard.ts
+++ b/src/main/old/assetguard.ts
@@ -4,16 +4,16 @@ import { join } from 'path'
 import { pathExistsSync, pathExists, readdir, exists, readFileSync, createWriteStream, ensureDirSync, readFile, writeFileSync, unlink, createReadStream, readJsonSync } from 'fs-extra'
 import Registry from 'winreg'
 import { exec, spawn } from 'child_process'
-import { LauncherJson } from '../asset/model/mojang/LauncherJson'
+import { LauncherJson } from 'common/asset/model/mojang/LauncherJson'
 import { createHash } from 'crypto'
 import AdmZip from 'adm-zip'
 import { forEachOfLimit, eachLimit } from 'async'
 import { extract } from 'tar-fs'
 import { createGunzip } from 'zlib'
-import { VersionJson, AssetIndex, Rule, Natives, Library } from '../asset/model/mojang/VersionJson'
+import { VersionJson, AssetIndex, Rule, Natives, Library } from 'common/asset/model/mojang/VersionJson'
 
-import { ConfigManager } from '../config/configmanager'
-import isDev from '../util/isdev'
+import { ConfigManager } from 'common/config/configmanager'
+import isDev from 'common/util/isdev'
 const DistroManager = require('./distromanager')
 
 // Constants
diff --git a/src/main/old/authmanager.ts b/src/main/old/authmanager.ts
index 49f6f34d..de3b6d91 100644
--- a/src/main/old/authmanager.ts
+++ b/src/main/old/authmanager.ts
@@ -1,7 +1,7 @@
 import { LoggerUtil } from './loggerutil'
-import { ConfigManager } from '../config/configmanager'
-import { Mojang } from '../mojang/mojang'
-import { SavedAccount } from '../config/model/SavedAccount'
+import { ConfigManager } from '../../common/config/configmanager'
+import { Mojang } from '../../common/mojang/mojang'
+import { SavedAccount } from '../../common/config/model/SavedAccount'
 
 /**
  * AuthManager
diff --git a/src/main/old/distromanager.ts b/src/main/old/distromanager.ts
index b9022016..1c972b00 100644
--- a/src/main/old/distromanager.ts
+++ b/src/main/old/distromanager.ts
@@ -3,7 +3,7 @@ import { Distribution, Module, Type, TypeMetadata, Server } from 'helios-distrib
 import { readJson, writeJson } from 'fs-extra'
 import { join } from 'path'
 import { LoggerUtil } from './loggerutil'
-import { ConfigManager } from '../config/configmanager'
+import { ConfigManager } from '../../common/config/configmanager'
 
 const logger = new LoggerUtil('%c[DistroManager]', 'color: #a02d2a; font-weight: bold')
 
diff --git a/src/main/old/preloader.ts b/src/main/old/preloader.ts
index 096a0d2e..a7bd2ddc 100644
--- a/src/main/old/preloader.ts
+++ b/src/main/old/preloader.ts
@@ -1,4 +1,4 @@
-import { ConfigManager } from '../config/configmanager'
+import { ConfigManager } from '../../common/config/configmanager'
 import { DistroManager, DistributionWrapper } from './distromanager'
 import { join } from 'path'
 import { remove } from 'fs-extra'
diff --git a/src/main/old/processbuilder.ts b/src/main/old/processbuilder.ts
index 0e00e6e3..f37b7b19 100644
--- a/src/main/old/processbuilder.ts
+++ b/src/main/old/processbuilder.ts
@@ -4,11 +4,11 @@ import { join, basename } from 'path'
 import { ModuleWrapper, ServerWrapper } from './distromanager'
 import { Type, Required } from 'helios-distribution-types'
 import { LoggerUtil } from './loggerutil'
-import { ConfigManager } from '../config/configmanager'
+import { ConfigManager } from '../../common/config/configmanager'
 import { spawn } from 'child_process'
-import { SavedAccount } from '../config/model/SavedAccount'
+import { SavedAccount } from '../../common/config/model/SavedAccount'
 import { tmpdir, release } from 'os'
-import { SubModConfig } from '../config/model/ModConfig'
+import { SubModConfig } from '../../common/config/model/ModConfig'
 import { pseudoRandomBytes } from 'crypto'
 import { Util, LibraryInternal } from './assetguard'
 import { VersionJson, Rule } from '../asset/model/mojang/VersionJson'
diff --git a/test/assets/MojangIndexProcessorTest.ts b/test/assets/MojangIndexProcessorTest.ts
index c4c34cb2..9bef7804 100644
--- a/test/assets/MojangIndexProcessorTest.ts
+++ b/test/assets/MojangIndexProcessorTest.ts
@@ -1,10 +1,10 @@
 import nock from 'nock'
 import { URL } from 'url'
-import { MojangIndexProcessor } from '../../src/main/asset/processor/MojangIndexProcessor'
+import { MojangIndexProcessor } from 'common/asset/processor/MojangIndexProcessor'
 import { dirname, join } from 'path'
 import { expect } from 'chai'
 import { remove, pathExists } from 'fs-extra'
-import { getVersionJsonPath } from '../../src/main/util/FileUtils'
+import { getVersionJsonPath } from 'common/util/FileUtils'
 
 // @ts-ignore (JSON Modules enabled in tsconfig.test.json)
 import versionManifest from './files/version_manifest.json'
diff --git a/test/mojang/mojangTest.ts b/test/mojang/mojangTest.ts
index cdd50308..8283876c 100644
--- a/test/mojang/mojangTest.ts
+++ b/test/mojang/mojangTest.ts
@@ -1,8 +1,8 @@
-import { Mojang } from "../../src/main/mojang/mojang"
+import { Mojang } from "common/mojang/mojang"
 import { expect } from 'chai'
 import nock from 'nock'
-import { Session } from "../../src/main/mojang/model/auth/Session"
-import { MojangResponseCode } from "../../src/main/mojang/model/internal/Response"
+import { Session } from "common/mojang/model/auth/Session"
+import { MojangResponseCode } from "common/mojang/model/internal/Response"
 
 function expectMojangResponse(res: any, responseCode: MojangResponseCode, negate = false) {
     expect(res).to.not.be.an('error')
diff --git a/tsconfig.json b/tsconfig.json
index e9c4f7c3..ae0afd41 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -16,10 +16,11 @@
     // *"sourceMap": true,                        /* Generates corresponding '.map' file. */
     // *"outDir": "dist",                         /* Redirect output structure to the directory. */
     // *"strict": true,
-    // "baseUrl": ".",                           /* Base directory to resolve non-absolute module names. */
-    // "paths": {                                /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
-    //   "*": ["node_modules/*"]
-    // },
+    "baseUrl": ".",                           /* Base directory to resolve non-absolute module names. */
+    "paths": {
+      "@/*": ["src/main/*"],
+      "common/*": ["src/common/*"]
+    },
     // *"esModuleInterop": true                   /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
   },
   // *"include": [