[TestRunner] add base-path and shared-resources flags

This CL adds two flags to the new test runner for configuring the
components server and then updates the server to detect those values.

Note that whilst this CL adds yet-another-way to configure the
components server, this is only being done for backwards compat whilst
we roll out this change to all the various places. We will remove old
options towards the end of this work.

Bug: chromium:1186163
Change-Id: I4c9b85a5745b9fe36894e3c492952938a5b8f648
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2763875
Auto-Submit: Jack Franklin <jacktfranklin@chromium.org>
Reviewed-by: Paul Lewis <aerotwist@chromium.org>
Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
diff --git a/scripts/component_server/server.js b/scripts/component_server/server.js
index 77a4ec2..358179d 100644
--- a/scripts/component_server/server.js
+++ b/scripts/component_server/server.js
@@ -8,8 +8,20 @@
 const parseURL = require('url').parse;
 const {argv} = require('yargs');
 
-const serverPort = parseInt(process.env.PORT, 10) || 8090;
+function getTestRunnerConfig() {
+  try {
+    return JSON.parse(process.env.TEST_RUNNER_JSON_CONFIG);
+  } catch {
+    // Return an empty object so any lookups return undefined
+    return {};
+  }
+}
+function getTestRunnerConfigSetting(settingKey, fallbackValue) {
+  const config = getTestRunnerConfig();
+  return config[settingKey] === undefined ? fallbackValue : config[settingKey];
+}
 
+const serverPort = parseInt(process.env.PORT, 10) || 8090;
 const target = argv.target || process.env.TARGET || 'Default';
 
 /**
@@ -17,15 +29,17 @@
  * doc example to load. By default it's /, so that we load /front_end/..., but
  * this can be configured if you have a different file structure.
  */
-const sharedResourcesBase = argv.sharedResourcesBase || '/';
+const sharedResourcesBase =
+    argv.sharedResourcesBase || getTestRunnerConfigSetting('component-server-shared-resources-path', '/');
 
 /**
  * The server assumes that examples live in
- * devtoolsRoot/out/Target/front_end/component_docs, but if you need to add a
+ * devtoolsRoot/out/Target/gen/front_end/component_docs, but if you need to add a
  * prefix you can pass this argument. Passing `foo` will redirect the server to
- * look in devtoolsRoot/out/Target/foo/front_end/component_docs.
+ * look in devtoolsRoot/out/Target/gen/foo/front_end/component_docs.
  */
-const componentDocsBaseArg = argv.componentDocsBase || process.env.COMPONENT_DOCS_BASE || '';
+const componentDocsBaseArg = argv.componentDocsBase || process.env.COMPONENT_DOCS_BASE ||
+    getTestRunnerConfigSetting('component-server-base-path', '');
 
 /**
  * When you run npm run components-server we run the script as is from scripts/,