-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
146 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,46 @@ | ||
import { getUrlsAsync } from '../shared/urls.js' | ||
import { exec } from 'node:child_process' | ||
import { sendEmail } from '../shared/email.js' | ||
import { ExecException, exec } from 'node:child_process' | ||
|
||
const urls = await getUrlsAsync() | ||
|
||
const output = [] as string[] | ||
|
||
function appendLog(url: string, stdout: string) { | ||
const txt = `${url} | ${stdout}` | ||
output.push(txt) | ||
console.log(txt) | ||
} | ||
|
||
function appendError(url: string, err: ExecException | string) { | ||
const txt = `${url} | ${err}` | ||
output.push(txt) | ||
console.error(txt) | ||
} | ||
|
||
const promises = [] as Promise<void>[] | ||
|
||
for (const url of urls) { | ||
console.log(`Processing ${url}...`) | ||
exec(`./node_modules/.bin/axe "${url}"`, (err, stdout, stderr) => { | ||
if (err) { | ||
console.error(`Error on ${url} | ${err}`) | ||
return | ||
} | ||
|
||
if (stderr) { | ||
console.error(`Error on ${url} | ${err}`) | ||
return | ||
} | ||
|
||
console.log(`${url} | ${stdout}`) | ||
}) | ||
promises.push( | ||
new Promise((resolve, reject) => { | ||
const process = exec(`./node_modules/.bin/axe "${url}"`, (err: ExecException | null, stdout: string, stderr: string) => { | ||
if (err) { | ||
appendError(url, err) | ||
return | ||
} | ||
|
||
if (stderr) { | ||
appendError(url, stderr) | ||
return | ||
} | ||
|
||
appendLog(url, stdout) | ||
}) | ||
|
||
process.on('close', resolve) | ||
}), | ||
) | ||
} | ||
|
||
await Promise.all(promises) | ||
await sendEmail('Axe Results - data-grid-vue', output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { EmailClient, EmailMessage, EmailSendResponse } from '@azure/communication-email' | ||
import { EnvironmentCredential } from '@azure/identity' | ||
import { SecretClient } from '@azure/keyvault-secrets' | ||
import { parse } from 'ansicolor' | ||
Check failure on line 4 in scripts/shared/email.ts
|
||
|
||
interface AzureEmailConfig { | ||
connectionString: string | ||
senderAddress: string | ||
toEmail: string | ||
} | ||
|
||
const credential = new EnvironmentCredential() | ||
const client = new SecretClient('https://data-grid-vue.vault.azure.net/', credential) | ||
|
||
const secret = await client.getSecret('EmailService') | ||
const config = JSON.parse(secret.value ?? '{}') as AzureEmailConfig | ||
|
||
const emailClient = new EmailClient(config.connectionString) | ||
|
||
export async function sendEmail(subject: string, ansiTexts: string[]): Promise<EmailSendResponse> { | ||
const parsed = parse(ansiTexts.join('\r\n')) | ||
const html = parsed.spans.map(s => s.text).join('<br />') | ||
|
||
const message: EmailMessage = { | ||
senderAddress: config.senderAddress, | ||
recipients: { | ||
to: [ | ||
{ | ||
address: config.toEmail, | ||
}, | ||
], | ||
}, | ||
content: { | ||
subject, | ||
html, | ||
}, | ||
} | ||
|
||
const poller = await emailClient.beginSend(message) | ||
const response = await poller.pollUntilDone() | ||
|
||
console.log('EMAIL RESPONSE', response) | ||
|
||
return response | ||
} |