refactor: create reusable EntrypointScriptRunner class
Change-Id: I88e0fbc4118a28cafe1c9548583c4049036dfaa9
diff --git a/src/common/architecture/entrypoint/Context.ts b/src/common/architecture/entrypoint/Context.ts
new file mode 100644
index 0000000..0ebe29f
--- /dev/null
+++ b/src/common/architecture/entrypoint/Context.ts
@@ -0,0 +1,11 @@
+import {
+ ScriptEnvironment,
+ ScriptPage,
+ ScriptRunPhase,
+} from '../scripts/Script';
+
+export interface Context {
+ page: ScriptPage;
+ environment: ScriptEnvironment;
+ runPhase: ScriptRunPhase;
+}
diff --git a/src/common/architecture/entrypoint/EntrypointScriptRunner.ts b/src/common/architecture/entrypoint/EntrypointScriptRunner.ts
new file mode 100644
index 0000000..d47e947
--- /dev/null
+++ b/src/common/architecture/entrypoint/EntrypointScriptRunner.ts
@@ -0,0 +1,19 @@
+import Features from '../../../features/Features';
+import ScriptRunner from '../scripts/ScriptRunner';
+import { Context } from './Context';
+
+export default class EntrypointScriptRunner {
+ private features: Features;
+ private scriptRunner: ScriptRunner;
+
+ constructor(public context: Context) {
+ this.features = new Features();
+ this.scriptRunner = new ScriptRunner();
+ }
+
+ run() {
+ const scripts = this.features.getScripts(this.context);
+ this.scriptRunner.add(...scripts);
+ this.scriptRunner.run();
+ }
+}
diff --git a/src/features/Features.ts b/src/features/Features.ts
index 8a13700..7b563bd 100644
--- a/src/features/Features.ts
+++ b/src/features/Features.ts
@@ -1,21 +1,11 @@
import Feature from '../common/architecture/features/Feature';
-import {
- ScriptEnvironment,
- ScriptPage,
- ScriptRunPhase,
-} from '../common/architecture/scripts/Script';
import ScriptRunner from '../common/architecture/scripts/ScriptRunner';
import AutoRefreshFeature from './autoRefresh/autoRefresh.feature';
import InfiniteScrollFeature from './infiniteScroll/infiniteScroll.feature';
+import { Context } from '../common/architecture/entrypoint/Context';
export type ConcreteFeatureClass = { new (): Feature };
-export interface Context {
- page: ScriptPage;
- environment: ScriptEnvironment;
- runPhase: ScriptRunPhase;
-}
-
export default class Features {
private features: ConcreteFeatureClass[] = [
AutoRefreshFeature,
diff --git a/src/platforms/communityConsole/entryPoints/main.ts b/src/platforms/communityConsole/entryPoints/main.ts
index 03d5eba..1f59e20 100644
--- a/src/platforms/communityConsole/entryPoints/main.ts
+++ b/src/platforms/communityConsole/entryPoints/main.ts
@@ -1,21 +1,16 @@
+import EntrypointScriptRunner from '../../../common/architecture/entrypoint/EntrypointScriptRunner';
import {
ScriptEnvironment,
ScriptPage,
ScriptRunPhase,
} from '../../../common/architecture/scripts/Script';
-import Features from '../../../features/Features';
-import ScriptRunner from '../../../common/architecture/scripts/ScriptRunner';
// Run legacy Javascript entry point
import '../../../contentScripts/communityConsole/main';
-const features = new Features();
-const scripts = features.getScripts({
+const runner = new EntrypointScriptRunner({
page: ScriptPage.CommunityConsole,
environment: ScriptEnvironment.ContentScript,
runPhase: ScriptRunPhase.Main,
});
-
-const scriptRunner = new ScriptRunner();
-scriptRunner.add(...scripts);
-scriptRunner.run();
+runner.run();
diff --git a/src/platforms/communityConsole/entryPoints/start.ts b/src/platforms/communityConsole/entryPoints/start.ts
index 2410f2c..c1138a1 100644
--- a/src/platforms/communityConsole/entryPoints/start.ts
+++ b/src/platforms/communityConsole/entryPoints/start.ts
@@ -1,21 +1,16 @@
+import EntrypointScriptRunner from '../../../common/architecture/entrypoint/EntrypointScriptRunner';
import {
ScriptEnvironment,
ScriptPage,
ScriptRunPhase,
} from '../../../common/architecture/scripts/Script';
-import Features from '../../../features/Features';
-import ScriptRunner from '../../../common/architecture/scripts/ScriptRunner';
// Run legacy Javascript entry point
import '../../../contentScripts/communityConsole/start';
-const features = new Features();
-const scripts = features.getScripts({
+const runner = new EntrypointScriptRunner({
page: ScriptPage.CommunityConsole,
environment: ScriptEnvironment.ContentScript,
runPhase: ScriptRunPhase.Start,
});
-
-const scriptRunner = new ScriptRunner();
-scriptRunner.add(...scripts);
-scriptRunner.run();
+runner.run();