refactor: migrate standalone scripts to the new DI architecture
Bug: twpowertools:226
Change-Id: Ie32b0200a31626bde06f3bdb0655790bb5a76802
diff --git a/src/common/architecture/entrypoint/EntrypointScriptRunner.ts b/src/common/architecture/entrypoint/EntrypointScriptRunner.ts
index e839168..f4d5f5c 100644
--- a/src/common/architecture/entrypoint/EntrypointScriptRunner.ts
+++ b/src/common/architecture/entrypoint/EntrypointScriptRunner.ts
@@ -1,5 +1,5 @@
import Features from '../../../features/Features';
-import StandaloneScripts from '../../../scripts/Scripts';
+import StandaloneScripts from '../../../presentation/standaloneScripts/Scripts';
import ScriptProvider from '../scripts/ScriptProvider';
import LegacyScriptRunner from '../scripts/LegacyScriptRunner';
import { Context } from './Context';
diff --git a/src/entryPoints/communityConsole/contentScripts/main.ts b/src/entryPoints/communityConsole/contentScripts/main.ts
index 4812d53..c4f994f 100644
--- a/src/entryPoints/communityConsole/contentScripts/main.ts
+++ b/src/entryPoints/communityConsole/contentScripts/main.ts
@@ -5,6 +5,7 @@
AutoRefreshDependency,
ExtraInfoDependency,
OptionsProviderDependency,
+ StartupDataStorageDependency,
WorkflowsImportDependency,
} from '../../../common/architecture/dependenciesProvider/DependenciesProvider';
import { Context } from '../../../common/architecture/entrypoint/Context';
@@ -28,7 +29,7 @@
import ScriptSorterAdapter from '../../../infrastructure/presentation/scripts/ScriptSorter.adapter';
import { SortedScriptsProviderAdapter } from '../../../infrastructure/presentation/scripts/SortedScriptsProvider.adapter';
import { NodeWatcherHandler } from '../../../presentation/nodeWatcher/NodeWatcherHandler';
-import StandaloneScripts from '../../../scripts/Scripts';
+import StandaloneScripts from '../../../presentation/standaloneScripts/Scripts';
import CCInfiniteScrollSetUpHandler from '../../../features/infiniteScroll/presentation/nodeWatcherHandlers/ccInfiniteScrollSetUp.handler';
import CCInfiniteScrollLoadMoreBarHandler from '../../../features/infiniteScroll/presentation/nodeWatcherHandlers/ccInfiniteScrollLoadMoreBar.handler';
import CCInfiniteScrollLoadMoreBtnHandler from '../../../features/infiniteScroll/presentation/nodeWatcherHandlers/ccInfiniteScrollLoadMoreBtn.handler';
@@ -45,6 +46,8 @@
import CCExtraInfoThreadReplyHandler from '../../../features/extraInfo/presentation/nodeWatcherHandlers/thread/ccExtraInfoThreadReply.handler';
import CCExtraInfoInjectScript from '../../../features/extraInfo/presentation/scripts/ccExtraInfoInject.script';
import CCExtraInfoStylesScript from '../../../features/extraInfo/presentation/scripts/ccExtraInfoStyles.script';
+import InjectLitComponentsScript from '../../../presentation/standaloneScripts/litComponents/injectLitComponents.script';
+import ApplyStartupDataModificationsOnMainScript from '../../../presentation/standaloneScripts/startupDataStorage/applyStartupDataModificationsOnMain.script';
const scriptRunner = createScriptRunner();
scriptRunner.run();
@@ -56,6 +59,9 @@
const optionsProvider = dependenciesProvider.getDependency(
OptionsProviderDependency,
);
+ const startupDataStorage = dependenciesProvider.getDependency(
+ StartupDataStorageDependency,
+ );
const workflowsImport = dependenciesProvider.getDependency(
WorkflowsImportDependency,
);
@@ -152,6 +158,10 @@
new CCExtraInfoStylesScript(),
new WorkflowsImportStylesheetScript(),
+ // Standalone scripts
+ new ApplyStartupDataModificationsOnMainScript(startupDataStorage),
+ new InjectLitComponentsScript(),
+
// Non-DI scripts (legacy, should be migrated to use a DI approach)
...new Features().getScripts(context),
...new StandaloneScripts().getScripts(context),
diff --git a/src/entryPoints/communityConsole/contentScripts/start.ts b/src/entryPoints/communityConsole/contentScripts/start.ts
index 4cbfd9d..e7023a2 100644
--- a/src/entryPoints/communityConsole/contentScripts/start.ts
+++ b/src/entryPoints/communityConsole/contentScripts/start.ts
@@ -22,10 +22,14 @@
import ScriptRunner from '../../../infrastructure/presentation/scripts/ScriptRunner';
import ScriptSorterAdapter from '../../../infrastructure/presentation/scripts/ScriptSorter.adapter';
import { SortedScriptsProviderAdapter } from '../../../infrastructure/presentation/scripts/SortedScriptsProvider.adapter';
-import StandaloneScripts from '../../../scripts/Scripts';
+import StandaloneScripts from '../../../presentation/standaloneScripts/Scripts';
import LoadDraftsSetupScript from '../../../features/loadDrafts/presentation/scripts/setup.script';
import WorkflowsImportSetUpScript from '../../../features/workflows/presentation/scripts/importSetUp.script';
import CCExtraInfoSetUpScript from '../../../features/extraInfo/presentation/scripts/ccExtraInfoSetUp.script';
+import MWI18nServerScript from '../../../presentation/standaloneScripts/mainWorldServers/MWI18nServerScript.script';
+import MWOptionsWatcherServerScript from '../../../presentation/standaloneScripts/mainWorldServers/MWOptionsWatcherServerScript.script';
+import ApplyStartupDataModificationsOnStartScript from '../../../presentation/standaloneScripts/startupDataStorage/applyStartupDataModificationsOnStart.script';
+import XHRInterceptorScript from '../../../presentation/standaloneScripts/xhrInterceptor/xhrInterceptor.script';
const scriptRunner = createScriptRunner();
scriptRunner.run();
@@ -62,6 +66,12 @@
new LoadDraftsSetupScript(optionsProvider, startupDataStorage),
new WorkflowsImportSetUpScript(workflowsImport),
+ // Standalone scripts
+ new ApplyStartupDataModificationsOnStartScript(startupDataStorage),
+ new MWI18nServerScript(),
+ new MWOptionsWatcherServerScript(),
+ new XHRInterceptorScript(),
+
// Non-DI scripts (legacy, should be migrated to use a DI approach)
...new Features().getScripts(context),
...new StandaloneScripts().getScripts(context),
diff --git a/src/presentation/standaloneScripts/Scripts.ts b/src/presentation/standaloneScripts/Scripts.ts
new file mode 100644
index 0000000..7f3b602
--- /dev/null
+++ b/src/presentation/standaloneScripts/Scripts.ts
@@ -0,0 +1,16 @@
+import Script, {
+ ConcreteScript,
+} from '../../common/architecture/scripts/Script';
+import ScriptFilterListProvider from '../../common/architecture/scripts/ScriptFilterListProvider';
+
+export default class StandaloneScripts extends ScriptFilterListProvider {
+ private scripts: ConcreteScript[] = [];
+ private initializedScripts: Script[];
+
+ protected getUnfilteredScriptsList() {
+ if (this.initializedScripts === undefined) {
+ this.initializedScripts = this.scripts.map((script) => new script());
+ }
+ return this.initializedScripts;
+ }
+}
diff --git a/src/scripts/litComponents/injectLitComponents.script.ts b/src/presentation/standaloneScripts/litComponents/injectLitComponents.script.ts
similarity index 74%
rename from src/scripts/litComponents/injectLitComponents.script.ts
rename to src/presentation/standaloneScripts/litComponents/injectLitComponents.script.ts
index 7040b45..a34c8b9 100644
--- a/src/scripts/litComponents/injectLitComponents.script.ts
+++ b/src/presentation/standaloneScripts/litComponents/injectLitComponents.script.ts
@@ -1,5 +1,5 @@
-import Script, { ScriptEnvironment, ScriptPage, ScriptRunPhase } from "../../common/architecture/scripts/Script"
-import { injectScript } from "../../common/contentScriptsUtils";
+import Script, { ScriptEnvironment, ScriptPage, ScriptRunPhase } from "../../../common/architecture/scripts/Script"
+import { injectScript } from "../../../common/contentScriptsUtils";
export default class InjectLitComponentsScript extends Script {
page = ScriptPage.CommunityConsole;
diff --git a/src/scripts/mainWorldServers/MWI18nServerScript.script.ts b/src/presentation/standaloneScripts/mainWorldServers/MWI18nServerScript.script.ts
similarity index 80%
rename from src/scripts/mainWorldServers/MWI18nServerScript.script.ts
rename to src/presentation/standaloneScripts/mainWorldServers/MWI18nServerScript.script.ts
index dbd87fe..86d28fa 100644
--- a/src/scripts/mainWorldServers/MWI18nServerScript.script.ts
+++ b/src/presentation/standaloneScripts/mainWorldServers/MWI18nServerScript.script.ts
@@ -1,5 +1,5 @@
-import Script, { ScriptEnvironment, ScriptPage, ScriptRunPhase } from "../../common/architecture/scripts/Script"
-import MWI18nServer from "../../common/mainWorldI18n/Server";
+import Script, { ScriptEnvironment, ScriptPage, ScriptRunPhase } from "../../../common/architecture/scripts/Script"
+import MWI18nServer from "../../../common/mainWorldI18n/Server";
export default class MWI18nServerScript extends Script {
// The server should be available as soon as possible, since e.g. the
diff --git a/src/scripts/mainWorldServers/MWOptionsWatcherServerScript.script.ts b/src/presentation/standaloneScripts/mainWorldServers/MWOptionsWatcherServerScript.script.ts
similarity index 70%
rename from src/scripts/mainWorldServers/MWOptionsWatcherServerScript.script.ts
rename to src/presentation/standaloneScripts/mainWorldServers/MWOptionsWatcherServerScript.script.ts
index a7aa405..464a7fa 100644
--- a/src/scripts/mainWorldServers/MWOptionsWatcherServerScript.script.ts
+++ b/src/presentation/standaloneScripts/mainWorldServers/MWOptionsWatcherServerScript.script.ts
@@ -1,6 +1,6 @@
-import Script, { ScriptEnvironment, ScriptPage, ScriptRunPhase } from "../../common/architecture/scripts/Script"
-import MWOptionsWatcherServer from "../../common/mainWorldOptionsWatcher/Server"
-import { kCSTarget, kMWTarget } from "../../xhrInterceptor/responseModifiers"
+import Script, { ScriptEnvironment, ScriptPage, ScriptRunPhase } from "../../../common/architecture/scripts/Script"
+import MWOptionsWatcherServer from "../../../common/mainWorldOptionsWatcher/Server"
+import { kCSTarget, kMWTarget } from "../../../xhrInterceptor/responseModifiers"
export default class MWOptionsWatcherServerScript extends Script {
// The server should be available as soon as possible, since e.g. the
diff --git a/src/presentation/standaloneScripts/startupDataStorage/applyStartupDataModificationsOnMain.script.ts b/src/presentation/standaloneScripts/startupDataStorage/applyStartupDataModificationsOnMain.script.ts
new file mode 100644
index 0000000..de58a11
--- /dev/null
+++ b/src/presentation/standaloneScripts/startupDataStorage/applyStartupDataModificationsOnMain.script.ts
@@ -0,0 +1,15 @@
+import { ScriptRunPhase } from '../../../common/architecture/scripts/Script';
+import { StartupDataStoragePort } from '../../../services/communityConsole/StartupDataStorage.port';
+import BaseApplyStartupDataModificationsScript from './baseApplyStartupDataModifications.script';
+
+/**
+ * Applies pending startup data modifications which have been added by other
+ * scripts at the main run phase.
+ */
+export default class ApplyStartupDataModificationsOnMainScript extends BaseApplyStartupDataModificationsScript {
+ runPhase = ScriptRunPhase.Main;
+
+ constructor(startupDataStorage: StartupDataStoragePort) {
+ super(startupDataStorage);
+ }
+}
diff --git a/src/presentation/standaloneScripts/startupDataStorage/applyStartupDataModificationsOnStart.script.ts b/src/presentation/standaloneScripts/startupDataStorage/applyStartupDataModificationsOnStart.script.ts
new file mode 100644
index 0000000..473f29c
--- /dev/null
+++ b/src/presentation/standaloneScripts/startupDataStorage/applyStartupDataModificationsOnStart.script.ts
@@ -0,0 +1,15 @@
+import { ScriptRunPhase } from '../../../common/architecture/scripts/Script';
+import { StartupDataStoragePort } from '../../../services/communityConsole/StartupDataStorage.port';
+import BaseApplyStartupDataModificationsScript from './baseApplyStartupDataModifications.script';
+
+/**
+ * Applies pending startup data modifications which have been added by other
+ * scripts at the start run phase.
+ */
+export default class ApplyStartupDataModificationsOnStartScript extends BaseApplyStartupDataModificationsScript {
+ runPhase = ScriptRunPhase.Start;
+
+ constructor(startupDataStorage: StartupDataStoragePort) {
+ super(startupDataStorage);
+ }
+}
diff --git a/src/presentation/standaloneScripts/startupDataStorage/baseApplyStartupDataModifications.script.ts b/src/presentation/standaloneScripts/startupDataStorage/baseApplyStartupDataModifications.script.ts
new file mode 100644
index 0000000..8244382
--- /dev/null
+++ b/src/presentation/standaloneScripts/startupDataStorage/baseApplyStartupDataModifications.script.ts
@@ -0,0 +1,24 @@
+import Script, {
+ ScriptEnvironment,
+ ScriptPage,
+} from '../../../common/architecture/scripts/Script';
+import { StartupDataStoragePort } from '../../../services/communityConsole/StartupDataStorage.port';
+
+/**
+ * Base class which applies pending startup data modifications which have been
+ * added by other scripts.
+ */
+export default abstract class BaseApplyStartupDataModificationsScript extends Script {
+ priority = 2 ** 32;
+
+ page = ScriptPage.CommunityConsole;
+ environment = ScriptEnvironment.ContentScript;
+
+ constructor(private startupDataStorage: StartupDataStoragePort) {
+ super();
+ }
+
+ execute() {
+ this.startupDataStorage.applyModifications();
+ }
+}
diff --git a/src/scripts/xhrInterceptor/xhrInterceptor.script.ts b/src/presentation/standaloneScripts/xhrInterceptor/xhrInterceptor.script.ts
similarity index 76%
rename from src/scripts/xhrInterceptor/xhrInterceptor.script.ts
rename to src/presentation/standaloneScripts/xhrInterceptor/xhrInterceptor.script.ts
index 551c85f..d2b146f 100644
--- a/src/scripts/xhrInterceptor/xhrInterceptor.script.ts
+++ b/src/presentation/standaloneScripts/xhrInterceptor/xhrInterceptor.script.ts
@@ -2,8 +2,8 @@
ScriptEnvironment,
ScriptPage,
ScriptRunPhase,
-} from '../../common/architecture/scripts/Script';
-import { injectScript } from '../../common/contentScriptsUtils';
+} from '../../../common/architecture/scripts/Script';
+import { injectScript } from '../../../common/contentScriptsUtils';
export default class XHRInterceptorScript extends Script {
priority = 10;
diff --git a/src/scripts/Scripts.ts b/src/scripts/Scripts.ts
deleted file mode 100644
index 2f4db19..0000000
--- a/src/scripts/Scripts.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-import Script, { ConcreteScript } from '../common/architecture/scripts/Script';
-import ScriptFilterListProvider from '../common/architecture/scripts/ScriptFilterListProvider';
-import InjectLitComponentsScript from './litComponents/injectLitComponents.script';
-import MWI18nServerScript from './mainWorldServers/MWI18nServerScript.script';
-import MWOptionsWatcherServerScript from './mainWorldServers/MWOptionsWatcherServerScript.script';
-import OptionsProviderSetUpScript from './optionsProvider/optionsProvider.script';
-import ApplyStartupDataModificationsOnMainScript from './startupDataStorage/applyStartupDataModificationsOnMain.script';
-import ApplyStartupDataModificationsOnStartScript from './startupDataStorage/applyStartupDataModificationsOnStart.script';
-import XHRInterceptorScript from './xhrInterceptor/xhrInterceptor.script';
-
-export default class StandaloneScripts extends ScriptFilterListProvider {
- private scripts: ConcreteScript[] = [
- ApplyStartupDataModificationsOnMainScript,
- ApplyStartupDataModificationsOnStartScript,
- InjectLitComponentsScript,
- MWI18nServerScript,
- MWOptionsWatcherServerScript,
- OptionsProviderSetUpScript,
- XHRInterceptorScript,
- ];
- private initializedScripts: Script[];
-
- protected getUnfilteredScriptsList() {
- if (this.initializedScripts === undefined) {
- this.initializedScripts = this.scripts.map((script) => new script());
- }
- return this.initializedScripts;
- }
-}
diff --git a/src/scripts/optionsProvider/optionsProvider.script.ts b/src/scripts/optionsProvider/optionsProvider.script.ts
deleted file mode 100644
index d468a06..0000000
--- a/src/scripts/optionsProvider/optionsProvider.script.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-import { Dependency, OptionsProviderDependency } from "../../common/architecture/dependenciesProvider/DependenciesProvider";
-import { ScriptEnvironment, ScriptPage, ScriptRunPhase } from "../../common/architecture/scripts/Script";
-import SetUpDependenciesScript from "../../common/architecture/scripts/setUpDependencies/SetUpDependenciesScript";
-
-export default class OptionsProviderSetUpScript extends SetUpDependenciesScript {
- public priority = 99;
- public page = ScriptPage.CommunityConsole;
- public environment = ScriptEnvironment.ContentScript;
- public runPhase = ScriptRunPhase.Start;
- public dependencies: Dependency[] = [OptionsProviderDependency];
-}
diff --git a/src/scripts/startupDataStorage/applyStartupDataModificationsOnMain.script.ts b/src/scripts/startupDataStorage/applyStartupDataModificationsOnMain.script.ts
deleted file mode 100644
index 2b9642d..0000000
--- a/src/scripts/startupDataStorage/applyStartupDataModificationsOnMain.script.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import { ScriptRunPhase } from '../../common/architecture/scripts/Script';
-import BaseApplyStartupDataModificationsScript from './baseApplyStartupDataModifications.script';
-
-/**
- * Applies pending startup data modifications which have been added by other
- * scripts at the main run phase.
- */
-export default class ApplyStartupDataModificationsOnMainScript extends BaseApplyStartupDataModificationsScript {
- runPhase = ScriptRunPhase.Main;
-}
diff --git a/src/scripts/startupDataStorage/applyStartupDataModificationsOnStart.script.ts b/src/scripts/startupDataStorage/applyStartupDataModificationsOnStart.script.ts
deleted file mode 100644
index 0903e1b..0000000
--- a/src/scripts/startupDataStorage/applyStartupDataModificationsOnStart.script.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import { ScriptRunPhase } from '../../common/architecture/scripts/Script';
-import BaseApplyStartupDataModificationsScript from './baseApplyStartupDataModifications.script';
-
-/**
- * Applies pending startup data modifications which have been added by other
- * scripts at the start run phase.
- */
-export default class ApplyStartupDataModificationsOnStartScript extends BaseApplyStartupDataModificationsScript {
- runPhase = ScriptRunPhase.Start;
-}
diff --git a/src/scripts/startupDataStorage/baseApplyStartupDataModifications.script.ts b/src/scripts/startupDataStorage/baseApplyStartupDataModifications.script.ts
deleted file mode 100644
index 1686b77..0000000
--- a/src/scripts/startupDataStorage/baseApplyStartupDataModifications.script.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-import DependenciesProviderSingleton, {
- StartupDataStorageDependency,
-} from '../../common/architecture/dependenciesProvider/DependenciesProvider';
-import Script, {
- ScriptEnvironment,
- ScriptPage,
-} from '../../common/architecture/scripts/Script';
-
-/**
- * Base class which applies pending startup data modifications which have been
- * added by other scripts.
- */
-export default abstract class BaseApplyStartupDataModificationsScript extends Script {
- priority = 2 ** 32;
-
- page = ScriptPage.CommunityConsole;
- environment = ScriptEnvironment.ContentScript;
-
- execute() {
- const dependenciesProvider = DependenciesProviderSingleton.getInstance();
- const startupDataStoarge = dependenciesProvider.getDependency(
- StartupDataStorageDependency,
- );
- startupDataStoarge.applyModifications();
- }
-}