mirror of
https://github.com/mozilla/fxa.git
synced 2025-12-13 20:36:41 +01:00
Because: - We want need a standalone library that can be used to send emails This Commit: - Ports the email sending code from auth-server into libs task(libs/accounts): Port email sending code to libs Because: - We want need a standalone library that can be used to send emails This Commit: - Ports the email sending code from auth-server into libs task(libs/accounts): Port email rendering code to libs Because: - We need a standalone library that can be used to render emails This Commit: - Ports the email rendering code from auth-server to libs - Converts to typescript - Cleans up code and improves consistency - Creates work around for copying nxignored l10n assets
60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
// Inspired by: https://github.com/Lisba/prevent-file-changes
|
|
|
|
import { execSync } from 'child_process';
|
|
|
|
// Maintain List of frozen files here!
|
|
const frozen: Array<{ pattern: string; reason: string }> = [
|
|
{
|
|
pattern: 'packages/fxa-auth-server/(lib|lib/oauth)/error.js',
|
|
reason: 'Files moved to libs/accounts/errors',
|
|
},
|
|
{
|
|
pattern: 'packages/fxa-auth-server/lib/senders/email.js',
|
|
reason: 'Files moved to libs/accounts/email-sender',
|
|
},
|
|
{
|
|
pattern: 'packages/fxa-auth-server/lib/senders/(emails|renderer)/.*',
|
|
reason: 'Files moved to libs/accounts/email-renderer',
|
|
},
|
|
];
|
|
|
|
export const getChangedFiles = () => {
|
|
const referenceToCompare = execSync(
|
|
'git rev-parse --verify HEAD >/dev/null 2>&1 && echo HEAD || echo 4b825dc642cb6eb9a060e54bf8d69288fbee4904'
|
|
);
|
|
return execSync(`git diff --cached --name-only ${referenceToCompare}`)
|
|
.toString()
|
|
.trim()
|
|
.split('\n');
|
|
};
|
|
|
|
try {
|
|
let violations = false;
|
|
for (const x of frozen) {
|
|
const re = new RegExp(x.pattern);
|
|
const changedFiles = getChangedFiles();
|
|
for (const file of changedFiles) {
|
|
if (re.test(file)) {
|
|
console.error(
|
|
`🚫 Error: Cannot modify frozen file: ${file}\n Reason: ${x.reason}.\n`
|
|
);
|
|
violations = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (violations) {
|
|
process.exit(1);
|
|
} else {
|
|
console.log('✨ Successful Execution!');
|
|
process.exit(0);
|
|
}
|
|
} catch (error: any) {
|
|
console.error('🚫 Execution Error:', error.message);
|
|
process.exit(1);
|
|
}
|