From 8b826fce818f8986f159fdc1b606503b7ea214e8 Mon Sep 17 00:00:00 2001 From: Josh-Walker-GM <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Sat, 11 Feb 2023 19:00:10 +0000 Subject: [PATCH 1/7] telemetry ci which listens for redirected telemetry packets from crwa --- .../actions/telemetry_check_crwa/action.yaml | 5 ++ .../telemetry_check_crwa.mjs | 76 +++++++++++++++++++ .github/workflows/ci.yml | 37 +++++++++ packages/telemetry/src/sendTelemetry.ts | 4 +- 4 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 .github/actions/telemetry_check_crwa/action.yaml create mode 100644 .github/actions/telemetry_check_crwa/telemetry_check_crwa.mjs diff --git a/.github/actions/telemetry_check_crwa/action.yaml b/.github/actions/telemetry_check_crwa/action.yaml new file mode 100644 index 000000000000..eb661a0cae7d --- /dev/null +++ b/.github/actions/telemetry_check_crwa/action.yaml @@ -0,0 +1,5 @@ +name: 'Listen for CRWA telemetry' +description: 'Builds and executes the CRWA while listening for redirected telemetry' +runs: + using: 'node16' + main: 'telemetry_check_crwa.mjs' diff --git a/.github/actions/telemetry_check_crwa/telemetry_check_crwa.mjs b/.github/actions/telemetry_check_crwa/telemetry_check_crwa.mjs new file mode 100644 index 000000000000..ef7ba28a9dd2 --- /dev/null +++ b/.github/actions/telemetry_check_crwa/telemetry_check_crwa.mjs @@ -0,0 +1,76 @@ +import { exec } from '@actions/exec' + +import http from "http" + +console.log(`Telemetry is being redirected to ${process.env.REDWOOD_REDIRECT_TELEMETRY}`) +const port = parseInt(process.env.REDWOOD_REDIRECT_TELEMETRY.split(":")[2]) + +// All the fields we expect inside a telemetry packet +const expectedPacketFields = [ + "type", + "command", + "duration", + "uid", + "ci", + "redwoodCi", + "NODE_ENV", + "os", + "osVersion", + // "shell", // Not expected on windows + "nodeVersion", + "yarnVersion", + "npmVersion", + "redwoodVersion", + "system", + "complexity", + "sides", + // "bundler" // TODO: Should we add the experimental bundler option? +] + +// Setup fake telemetry server +const server = http.createServer((req, res) => { + let data = "" + req.on("data", (chunk) => { + data += chunk + }) + req.on("end", () => { + res.writeHead(200) + res.end() + + const packet = JSON.parse(data) + + let hasAllFields = true + for (const field of expectedPacketFields) { + if(packet[field] === undefined){ + hasAllFields = false + console.error(`Telemetry packet is missing field "${field}"`) + } + } + + const isCI = packet.ci ?? false + + if((hasAllFields && isCI)){ + console.log("Valid telemetry received") + process.exit(0) + }else{ + console.error("Invalid telemetry received") + console.error(packet) + process.exit(1) + } + }) +}); +server.listen(port, "127.0.0.1", () => { + console.log(`Telemetry listener is running on http://127.0.0.1:${port}`); +}); + +// Run create-redwood-app +try { + await exec(`yarn node ./packages/create-redwood-app/dist/create-redwood-app.js ../crwa-telemetry --typescript false --git false --yarn-install false`) +} catch (error) { + console.error(error) +} + +// If we didn't hear the telemetry after 2 mins since running crwa then let's fail +await new Promise(r => setTimeout(r, 120_000)); +console.error("No telemetry response within 120 seconds. Failing...") +process.exit(1) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 867ee6a19388..8f6824d27922 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -324,3 +324,40 @@ jobs: runs-on: ${{ matrix.os }} steps: - run: echo "Only doc changes" + + telemetry-crwa: + needs: check + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + node-version: [16, 18] + fail-fast: true + name: ๐Ÿ”ญ Telemetry check - CRWA / ${{ matrix.os }} / node ${{ matrix.node-version }} latest + runs-on: ${{ matrix.os }} + env: + REDWOOD_REDIRECT_TELEMETRY: "http://127.0.0.1:48619" # Random port + steps: + - uses: actions/checkout@v3 + - name: ๐Ÿงถ Set up job + uses: ./.github/actions/set-up-job + with: + node-version: ${{ matrix.node-version }} + + - name: โš’๏ธ Build the framework packages + run: yarn build + working-directory: . + + - name: ๐Ÿ“ข Listen for telemetry + uses: ./.github/actions/telemetry_check_crwa + + telemetry-crwa-docs: + needs: only-doc-changes + if: needs.only-doc-changes.outputs.only-doc-changes == 'true' + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + node-version: [16, 18] + name: ๐Ÿ”ญ Telemetry check - CRWA / ${{ matrix.os }} / node ${{ matrix.node-version }} latest + runs-on: ${{ matrix.os }} + steps: + - run: echo "Only doc changes" diff --git a/packages/telemetry/src/sendTelemetry.ts b/packages/telemetry/src/sendTelemetry.ts index bd2a2eab4fbc..1ea71ff0c888 100644 --- a/packages/telemetry/src/sendTelemetry.ts +++ b/packages/telemetry/src/sendTelemetry.ts @@ -234,7 +234,9 @@ const uniqueId = (rootDir: string | null) => { // actually call the API with telemetry data export const sendTelemetry = async () => { - const telemetryUrl = 'https://telemetry.redwoodjs.com/api/v1/telemetry' + const telemetryUrl = + process.env.REDWOOD_REDIRECT_TELEMETRY || + 'https://telemetry.redwoodjs.com/api/v1/telemetry' try { const payload = await buildPayload() From a67f9ea56d4a6f5e93dad598ea0fba5fabbbf14a Mon Sep 17 00:00:00 2001 From: Dominic Saadi Date: Mon, 13 Feb 2023 14:56:44 -0800 Subject: [PATCH 2/7] chore: run lint and formatting changes --- .../telemetry_check_crwa.mjs | 76 ++++++++++--------- .github/workflows/ci.yml | 3 +- 2 files changed, 42 insertions(+), 37 deletions(-) diff --git a/.github/actions/telemetry_check_crwa/telemetry_check_crwa.mjs b/.github/actions/telemetry_check_crwa/telemetry_check_crwa.mjs index ef7ba28a9dd2..98a5d31e1abd 100644 --- a/.github/actions/telemetry_check_crwa/telemetry_check_crwa.mjs +++ b/.github/actions/telemetry_check_crwa/telemetry_check_crwa.mjs @@ -1,39 +1,43 @@ -import { exec } from '@actions/exec' +/* eslint-env node */ + +import http from 'node:http' -import http from "http" +import { exec } from '@actions/exec' -console.log(`Telemetry is being redirected to ${process.env.REDWOOD_REDIRECT_TELEMETRY}`) -const port = parseInt(process.env.REDWOOD_REDIRECT_TELEMETRY.split(":")[2]) +console.log( + `Telemetry is being redirected to ${process.env.REDWOOD_REDIRECT_TELEMETRY}` +) +const port = parseInt(process.env.REDWOOD_REDIRECT_TELEMETRY.split(':')[2]) // All the fields we expect inside a telemetry packet const expectedPacketFields = [ - "type", - "command", - "duration", - "uid", - "ci", - "redwoodCi", - "NODE_ENV", - "os", - "osVersion", + 'type', + 'command', + 'duration', + 'uid', + 'ci', + 'redwoodCi', + 'NODE_ENV', + 'os', + 'osVersion', // "shell", // Not expected on windows - "nodeVersion", - "yarnVersion", - "npmVersion", - "redwoodVersion", - "system", - "complexity", - "sides", + 'nodeVersion', + 'yarnVersion', + 'npmVersion', + 'redwoodVersion', + 'system', + 'complexity', + 'sides', // "bundler" // TODO: Should we add the experimental bundler option? ] // Setup fake telemetry server const server = http.createServer((req, res) => { - let data = "" - req.on("data", (chunk) => { + let data = '' + req.on('data', (chunk) => { data += chunk }) - req.on("end", () => { + req.on('end', () => { res.writeHead(200) res.end() @@ -41,7 +45,7 @@ const server = http.createServer((req, res) => { let hasAllFields = true for (const field of expectedPacketFields) { - if(packet[field] === undefined){ + if (packet[field] === undefined) { hasAllFields = false console.error(`Telemetry packet is missing field "${field}"`) } @@ -49,28 +53,30 @@ const server = http.createServer((req, res) => { const isCI = packet.ci ?? false - if((hasAllFields && isCI)){ - console.log("Valid telemetry received") + if (hasAllFields && isCI) { + console.log('Valid telemetry received') process.exit(0) - }else{ - console.error("Invalid telemetry received") + } else { + console.error('Invalid telemetry received') console.error(packet) process.exit(1) } }) -}); -server.listen(port, "127.0.0.1", () => { - console.log(`Telemetry listener is running on http://127.0.0.1:${port}`); -}); +}) +server.listen(port, '127.0.0.1', () => { + console.log(`Telemetry listener is running on http://127.0.0.1:${port}`) +}) // Run create-redwood-app try { - await exec(`yarn node ./packages/create-redwood-app/dist/create-redwood-app.js ../crwa-telemetry --typescript false --git false --yarn-install false`) + await exec( + `yarn node ./packages/create-redwood-app/dist/create-redwood-app.js ../crwa-telemetry --typescript false --git false --yarn-install false` + ) } catch (error) { console.error(error) } // If we didn't hear the telemetry after 2 mins since running crwa then let's fail -await new Promise(r => setTimeout(r, 120_000)); -console.error("No telemetry response within 120 seconds. Failing...") +await new Promise((r) => setTimeout(r, 120_000)) +console.error('No telemetry response within 120 seconds. Failing...') process.exit(1) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8f6824d27922..11edec608d1d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -343,9 +343,8 @@ jobs: with: node-version: ${{ matrix.node-version }} - - name: โš’๏ธ Build the framework packages + - name: ๐Ÿ”จ Build run: yarn build - working-directory: . - name: ๐Ÿ“ข Listen for telemetry uses: ./.github/actions/telemetry_check_crwa From 358f41ec0d5e09ddfd80c6e93b18f63fe2ce16ba Mon Sep 17 00:00:00 2001 From: Josh-Walker-GM <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Tue, 14 Feb 2023 15:06:40 +0000 Subject: [PATCH 3/7] refactor and test the cli too --- .github/actions/telemetry_check/check.mjs | 97 +++++++++++++++++++ .../actions/telemetry_check_crwa/action.yaml | 5 - .../telemetry_check_crwa.mjs | 82 ---------------- .github/workflows/ci.yml | 19 ++-- 4 files changed, 109 insertions(+), 94 deletions(-) create mode 100644 .github/actions/telemetry_check/check.mjs delete mode 100644 .github/actions/telemetry_check_crwa/action.yaml delete mode 100644 .github/actions/telemetry_check_crwa/telemetry_check_crwa.mjs diff --git a/.github/actions/telemetry_check/check.mjs b/.github/actions/telemetry_check/check.mjs new file mode 100644 index 000000000000..b799ff123bd8 --- /dev/null +++ b/.github/actions/telemetry_check/check.mjs @@ -0,0 +1,97 @@ +import { exec } from '@actions/exec' + +import http from "http" + +console.log(`Telemetry is being redirected to ${process.env.REDWOOD_REDIRECT_TELEMETRY}`) + +// All the fields we expect inside a telemetry packet +const expectedPacketFields = [ + "type", + "command", + "duration", + "uid", + "ci", + "redwoodCi", + "NODE_ENV", + "os", + "osVersion", + // "shell", // Not expected on windows + "nodeVersion", + "yarnVersion", + "npmVersion", + "redwoodVersion", + "system", + "complexity", + "sides", + "bundler" +] + +// Setup fake telemetry server +const server = http.createServer((req, res) => { + let data = "" + req.on("data", (chunk) => { + data += chunk + }) + req.on("end", () => { + res.writeHead(200) + res.end() + + const packet = JSON.parse(data) + + let hasAllFields = true + for (const field of expectedPacketFields) { + if(packet[field] === undefined){ + hasAllFields = false + console.error(`Telemetry packet is missing field "${field}"`) + } + } + + const isCI = packet.ci ?? false + + if((hasAllFields && isCI)){ + console.log("Valid telemetry received") + process.exit(0) + }else{ + console.error("Invalid telemetry received") + console.error(packet) + process.exit(1) + } + }) +}); + +// Run the fake telemetry server at the redirected location +const host = process.env.REDWOOD_REDIRECT_TELEMETRY.split(":")[1].slice(2) +const port = parseInt(process.env.REDWOOD_REDIRECT_TELEMETRY.split(":")[2]) +server.listen(port, host, () => { + console.log(`Telemetry listener is running on http://${host}:${port}`); +}); + +// Run a command and await output +try { + const mode = process.argv[process.argv.indexOf("--mode") + 1] + let exitCode = 0 + switch (mode) { + case "crwa": + exitCode = await exec(`yarn node ./packages/create-redwood-app/dist/create-redwood-app.js ../project-for-telemetry --typescript false --git false --yarn-install true`) + if(exitCode){ + process.exit(1) + } + break; + case "cli": + exitCode = await exec(`yarn --cwd ../project-for-telemetry node ../redwood-test/packages/cli/dist/index.js info`) + if(exitCode){ + process.exit(1) + } + break; + default: + console.error(`Unknown mode: ${mode}`) + process.exit(1) + } +} catch (error) { + console.error(error) +} + +// If we didn't hear the telemetry after 2 mins then let's fail +await new Promise(r => setTimeout(r, 120_000)); +console.error("No telemetry response within 120 seconds. Failing...") +process.exit(1) diff --git a/.github/actions/telemetry_check_crwa/action.yaml b/.github/actions/telemetry_check_crwa/action.yaml deleted file mode 100644 index eb661a0cae7d..000000000000 --- a/.github/actions/telemetry_check_crwa/action.yaml +++ /dev/null @@ -1,5 +0,0 @@ -name: 'Listen for CRWA telemetry' -description: 'Builds and executes the CRWA while listening for redirected telemetry' -runs: - using: 'node16' - main: 'telemetry_check_crwa.mjs' diff --git a/.github/actions/telemetry_check_crwa/telemetry_check_crwa.mjs b/.github/actions/telemetry_check_crwa/telemetry_check_crwa.mjs deleted file mode 100644 index 98a5d31e1abd..000000000000 --- a/.github/actions/telemetry_check_crwa/telemetry_check_crwa.mjs +++ /dev/null @@ -1,82 +0,0 @@ -/* eslint-env node */ - -import http from 'node:http' - -import { exec } from '@actions/exec' - -console.log( - `Telemetry is being redirected to ${process.env.REDWOOD_REDIRECT_TELEMETRY}` -) -const port = parseInt(process.env.REDWOOD_REDIRECT_TELEMETRY.split(':')[2]) - -// All the fields we expect inside a telemetry packet -const expectedPacketFields = [ - 'type', - 'command', - 'duration', - 'uid', - 'ci', - 'redwoodCi', - 'NODE_ENV', - 'os', - 'osVersion', - // "shell", // Not expected on windows - 'nodeVersion', - 'yarnVersion', - 'npmVersion', - 'redwoodVersion', - 'system', - 'complexity', - 'sides', - // "bundler" // TODO: Should we add the experimental bundler option? -] - -// Setup fake telemetry server -const server = http.createServer((req, res) => { - let data = '' - req.on('data', (chunk) => { - data += chunk - }) - req.on('end', () => { - res.writeHead(200) - res.end() - - const packet = JSON.parse(data) - - let hasAllFields = true - for (const field of expectedPacketFields) { - if (packet[field] === undefined) { - hasAllFields = false - console.error(`Telemetry packet is missing field "${field}"`) - } - } - - const isCI = packet.ci ?? false - - if (hasAllFields && isCI) { - console.log('Valid telemetry received') - process.exit(0) - } else { - console.error('Invalid telemetry received') - console.error(packet) - process.exit(1) - } - }) -}) -server.listen(port, '127.0.0.1', () => { - console.log(`Telemetry listener is running on http://127.0.0.1:${port}`) -}) - -// Run create-redwood-app -try { - await exec( - `yarn node ./packages/create-redwood-app/dist/create-redwood-app.js ../crwa-telemetry --typescript false --git false --yarn-install false` - ) -} catch (error) { - console.error(error) -} - -// If we didn't hear the telemetry after 2 mins since running crwa then let's fail -await new Promise((r) => setTimeout(r, 120_000)) -console.error('No telemetry response within 120 seconds. Failing...') -process.exit(1) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 11edec608d1d..06c202f21ef2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -325,14 +325,14 @@ jobs: steps: - run: echo "Only doc changes" - telemetry-crwa: + telemetry-check: needs: check strategy: matrix: os: [ubuntu-latest, windows-latest] node-version: [16, 18] fail-fast: true - name: ๐Ÿ”ญ Telemetry check - CRWA / ${{ matrix.os }} / node ${{ matrix.node-version }} latest + name: ๐Ÿ”ญ Telemetry check / ${{ matrix.os }} / node ${{ matrix.node-version }} latest runs-on: ${{ matrix.os }} env: REDWOOD_REDIRECT_TELEMETRY: "http://127.0.0.1:48619" # Random port @@ -343,20 +343,25 @@ jobs: with: node-version: ${{ matrix.node-version }} - - name: ๐Ÿ”จ Build + - name: โš’๏ธ Build the framework packages run: yarn build - - name: ๐Ÿ“ข Listen for telemetry - uses: ./.github/actions/telemetry_check_crwa + - name: ๐Ÿ“ข Listen for telemetry (CRWA) + run: node ./.github/actions/telemetry_check/check.mjs --mode crwa + env: + YARN_ENABLE_IMMUTABLE_INSTALLS: false + + - name: ๐Ÿ“ข Listen for telemetry (CLI) + run: node ./.github/actions/telemetry_check/check.mjs --mode cli - telemetry-crwa-docs: + telemetry-check-docs: needs: only-doc-changes if: needs.only-doc-changes.outputs.only-doc-changes == 'true' strategy: matrix: os: [ubuntu-latest, windows-latest] node-version: [16, 18] - name: ๐Ÿ”ญ Telemetry check - CRWA / ${{ matrix.os }} / node ${{ matrix.node-version }} latest + name: ๐Ÿ”ญ Telemetry check / ${{ matrix.os }} / node ${{ matrix.node-version }} latest runs-on: ${{ matrix.os }} steps: - run: echo "Only doc changes" From 8632705be42277deb5663e069178237c132b42ad Mon Sep 17 00:00:00 2001 From: Josh-Walker-GM <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Tue, 14 Feb 2023 15:13:57 +0000 Subject: [PATCH 4/7] restore build emoji change --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 06c202f21ef2..313876592f16 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -343,7 +343,7 @@ jobs: with: node-version: ${{ matrix.node-version }} - - name: โš’๏ธ Build the framework packages + - name: ๐Ÿ”จ Build run: yarn build - name: ๐Ÿ“ข Listen for telemetry (CRWA) From 09a27ec0b44d807a442f4b11f2ff58be9859b81d Mon Sep 17 00:00:00 2001 From: Josh-Walker-GM <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Tue, 14 Feb 2023 15:16:04 +0000 Subject: [PATCH 5/7] fix field bundler to webBundler --- .github/actions/telemetry_check/check.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/telemetry_check/check.mjs b/.github/actions/telemetry_check/check.mjs index b799ff123bd8..c9ac0b9f07b0 100644 --- a/.github/actions/telemetry_check/check.mjs +++ b/.github/actions/telemetry_check/check.mjs @@ -23,7 +23,7 @@ const expectedPacketFields = [ "system", "complexity", "sides", - "bundler" + "webBundler" ] // Setup fake telemetry server From f516bc026d8ecfd2cc52b5a7a3b4866752c467ec Mon Sep 17 00:00:00 2001 From: Josh-Walker-GM <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Tue, 14 Feb 2023 15:24:45 +0000 Subject: [PATCH 6/7] attempt to fix directory --- .github/actions/telemetry_check/check.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/telemetry_check/check.mjs b/.github/actions/telemetry_check/check.mjs index c9ac0b9f07b0..01bf882c4c86 100644 --- a/.github/actions/telemetry_check/check.mjs +++ b/.github/actions/telemetry_check/check.mjs @@ -78,7 +78,7 @@ try { } break; case "cli": - exitCode = await exec(`yarn --cwd ../project-for-telemetry node ../redwood-test/packages/cli/dist/index.js info`) + exitCode = await exec(`yarn --cwd ../project-for-telemetry node ../redwood/packages/cli/dist/index.js info`) if(exitCode){ process.exit(1) } From c8718a8e69d6af6274001626fe0898aae88ee063 Mon Sep 17 00:00:00 2001 From: Dominic Saadi Date: Tue, 14 Feb 2023 08:26:44 -0800 Subject: [PATCH 7/7] chore: lint fix --- .github/actions/telemetry_check/check.mjs | 96 ++++++++++++----------- 1 file changed, 52 insertions(+), 44 deletions(-) diff --git a/.github/actions/telemetry_check/check.mjs b/.github/actions/telemetry_check/check.mjs index 01bf882c4c86..52837b76f7f5 100644 --- a/.github/actions/telemetry_check/check.mjs +++ b/.github/actions/telemetry_check/check.mjs @@ -1,38 +1,42 @@ -import { exec } from '@actions/exec' +/* eslint-env node */ + +import http from 'http' -import http from "http" +import { exec } from '@actions/exec' -console.log(`Telemetry is being redirected to ${process.env.REDWOOD_REDIRECT_TELEMETRY}`) +console.log( + `Telemetry is being redirected to ${process.env.REDWOOD_REDIRECT_TELEMETRY}` +) // All the fields we expect inside a telemetry packet const expectedPacketFields = [ - "type", - "command", - "duration", - "uid", - "ci", - "redwoodCi", - "NODE_ENV", - "os", - "osVersion", + 'type', + 'command', + 'duration', + 'uid', + 'ci', + 'redwoodCi', + 'NODE_ENV', + 'os', + 'osVersion', // "shell", // Not expected on windows - "nodeVersion", - "yarnVersion", - "npmVersion", - "redwoodVersion", - "system", - "complexity", - "sides", - "webBundler" + 'nodeVersion', + 'yarnVersion', + 'npmVersion', + 'redwoodVersion', + 'system', + 'complexity', + 'sides', + 'webBundler', ] // Setup fake telemetry server const server = http.createServer((req, res) => { - let data = "" - req.on("data", (chunk) => { + let data = '' + req.on('data', (chunk) => { data += chunk }) - req.on("end", () => { + req.on('end', () => { res.writeHead(200) res.end() @@ -40,7 +44,7 @@ const server = http.createServer((req, res) => { let hasAllFields = true for (const field of expectedPacketFields) { - if(packet[field] === undefined){ + if (packet[field] === undefined) { hasAllFields = false console.error(`Telemetry packet is missing field "${field}"`) } @@ -48,41 +52,45 @@ const server = http.createServer((req, res) => { const isCI = packet.ci ?? false - if((hasAllFields && isCI)){ - console.log("Valid telemetry received") + if (hasAllFields && isCI) { + console.log('Valid telemetry received') process.exit(0) - }else{ - console.error("Invalid telemetry received") + } else { + console.error('Invalid telemetry received') console.error(packet) process.exit(1) } }) -}); +}) // Run the fake telemetry server at the redirected location -const host = process.env.REDWOOD_REDIRECT_TELEMETRY.split(":")[1].slice(2) -const port = parseInt(process.env.REDWOOD_REDIRECT_TELEMETRY.split(":")[2]) +const host = process.env.REDWOOD_REDIRECT_TELEMETRY.split(':')[1].slice(2) +const port = parseInt(process.env.REDWOOD_REDIRECT_TELEMETRY.split(':')[2]) server.listen(port, host, () => { - console.log(`Telemetry listener is running on http://${host}:${port}`); -}); + console.log(`Telemetry listener is running on http://${host}:${port}`) +}) // Run a command and await output try { - const mode = process.argv[process.argv.indexOf("--mode") + 1] + const mode = process.argv[process.argv.indexOf('--mode') + 1] let exitCode = 0 switch (mode) { - case "crwa": - exitCode = await exec(`yarn node ./packages/create-redwood-app/dist/create-redwood-app.js ../project-for-telemetry --typescript false --git false --yarn-install true`) - if(exitCode){ + case 'crwa': + exitCode = await exec( + `yarn node ./packages/create-redwood-app/dist/create-redwood-app.js ../project-for-telemetry --typescript false --git false --yarn-install true` + ) + if (exitCode) { process.exit(1) } - break; - case "cli": - exitCode = await exec(`yarn --cwd ../project-for-telemetry node ../redwood/packages/cli/dist/index.js info`) - if(exitCode){ + break + case 'cli': + exitCode = await exec( + `yarn --cwd ../project-for-telemetry node ../redwood/packages/cli/dist/index.js info` + ) + if (exitCode) { process.exit(1) } - break; + break default: console.error(`Unknown mode: ${mode}`) process.exit(1) @@ -92,6 +100,6 @@ try { } // If we didn't hear the telemetry after 2 mins then let's fail -await new Promise(r => setTimeout(r, 120_000)); -console.error("No telemetry response within 120 seconds. Failing...") +await new Promise((r) => setTimeout(r, 120_000)) +console.error('No telemetry response within 120 seconds. Failing...') process.exit(1)