refactor(autorefresh): migrate to the new DI architecture

The presentation layer has been updated to use DI for the Autorefresh
feature.

Since it's the first feature using DI, this commit also refactors the
main and start entry points to set up the script runner using DI.
Compatibility with the old feature architecture (what we used to call
"new architecture") has been provided as well, so other features which
haven't migrated yet to use DI continue to work properly.

Bug: twpowertools:226
Change-Id: Icf97bebe761693571f3aa915a4935bc002e7c0ca
diff --git a/src/entryPoints/communityConsole/contentScripts/main.ts b/src/entryPoints/communityConsole/contentScripts/main.ts
new file mode 100644
index 0000000..ff70c11
--- /dev/null
+++ b/src/entryPoints/communityConsole/contentScripts/main.ts
@@ -0,0 +1,66 @@
+import DependenciesProviderSingleton, {
+  AutoRefreshDependency,
+} from '../../../common/architecture/dependenciesProvider/DependenciesProvider';
+import { Context } from '../../../common/architecture/entrypoint/Context';
+import {
+  ScriptEnvironment,
+  ScriptPage,
+  ScriptRunPhase,
+} from '../../../common/architecture/scripts/Script';
+import AutoRefreshThreadListHideHandler from '../../../features/autoRefresh/presentation/nodeWatcherHandlers/threadListHide.handler';
+import AutoRefreshThreadListSetUpHandler from '../../../features/autoRefresh/presentation/nodeWatcherHandlers/threadListSetUp.handler';
+import AutoRefreshStylesScript from '../../../features/autoRefresh/presentation/scripts/styles.script';
+import Features from '../../../features/Features';
+import { NodeWatcherAdapter } from '../../../infrastructure/presentation/nodeWatcher/NodeWatcher.adapter';
+import NodeWatcherScriptAdapter from '../../../infrastructure/presentation/scripts/NodeWatcherScript.adapter';
+import ScriptRunner from '../../../infrastructure/presentation/scripts/ScriptRunner';
+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';
+
+// Run legacy Javascript entry point
+import '../../../contentScripts/communityConsole/main';
+
+const scriptRunner = createScriptRunner();
+scriptRunner.run();
+
+function createScriptRunner() {
+  const dependenciesProvider = DependenciesProviderSingleton.getInstance();
+  const autoRefresh = dependenciesProvider.getDependency(AutoRefreshDependency);
+
+  const context: Context = {
+    page: ScriptPage.CommunityConsole,
+    environment: ScriptEnvironment.ContentScript,
+    runPhase: ScriptRunPhase.Main,
+  };
+
+  return new ScriptRunner(
+    new SortedScriptsProviderAdapter(
+      [
+        // Node watcher script with handlers
+        new NodeWatcherScriptAdapter(
+          new NodeWatcherAdapter(),
+          new Map<string, NodeWatcherHandler>([
+            [
+              'autoRefreshThreadListSetUp',
+              new AutoRefreshThreadListSetUpHandler(autoRefresh),
+            ],
+            [
+              'autoRefreshThreadListHide',
+              new AutoRefreshThreadListHideHandler(autoRefresh),
+            ],
+          ]),
+        ),
+
+        // Individual feature scripts
+        new AutoRefreshStylesScript(),
+
+        // Non-DI scripts (legacy, should be migrated to use a DI approach)
+        ...new Features().getScripts(context),
+        ...new StandaloneScripts().getScripts(context),
+      ],
+      new ScriptSorterAdapter(),
+    ).getScripts(),
+  );
+}
diff --git a/src/entryPoints/communityConsole/contentScripts/start.ts b/src/entryPoints/communityConsole/contentScripts/start.ts
new file mode 100644
index 0000000..5e11a87
--- /dev/null
+++ b/src/entryPoints/communityConsole/contentScripts/start.ts
@@ -0,0 +1,46 @@
+import DependenciesProviderSingleton, {
+  AutoRefreshDependency,
+} from '../../../common/architecture/dependenciesProvider/DependenciesProvider';
+import { Context } from '../../../common/architecture/entrypoint/Context';
+import {
+  ScriptEnvironment,
+  ScriptPage,
+  ScriptRunPhase,
+} from '../../../common/architecture/scripts/Script';
+import AutoRefreshSetUpScript from '../../../features/autoRefresh/presentation/scripts/setUp.script';
+import Features from '../../../features/Features';
+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';
+
+// Run legacy Javascript entry point
+import '../../../contentScripts/communityConsole/start';
+
+const scriptRunner = createScriptRunner();
+scriptRunner.run();
+
+function createScriptRunner() {
+  const dependenciesProvider = DependenciesProviderSingleton.getInstance();
+  const autoRefresh = dependenciesProvider.getDependency(AutoRefreshDependency);
+
+  const context: Context = {
+    page: ScriptPage.CommunityConsole,
+    environment: ScriptEnvironment.ContentScript,
+    runPhase: ScriptRunPhase.Start,
+  };
+
+  return new ScriptRunner(
+    new SortedScriptsProviderAdapter(
+      [
+        // Individual feature scripts
+        new AutoRefreshSetUpScript(autoRefresh),
+
+        // Non-DI scripts (legacy, should be migrated to use a DI approach)
+        ...new Features().getScripts(context),
+        ...new StandaloneScripts().getScripts(context),
+      ],
+      new ScriptSorterAdapter(),
+    ).getScripts(),
+  );
+}