diff --git a/firebase.json b/firebase.json deleted file mode 100644 index 99982980b6..0000000000 --- a/firebase.json +++ /dev/null @@ -1,111 +0,0 @@ -{ - "hosting": { - "public": "./dist", - "ignore": ["firebase.json", "**/.*", "**/node_modules/**"], - "redirects": [ - { - "source": "/", - "destination": "/en/index.html", - "type": 301 - } - ], - "rewrites": [ - { - "source": "/en/**", - "destination": "/en/index.html" - }, - { - "source": "/ar/**", - "destination": "/ar/index.rtl.html" - }, - { - "source": "/es/**", - "destination": "/es/index.html" - }, - { - "source": "/ca/**", - "destination": "/ca/index.html" - }, - { - "source": "/cs/**", - "destination": "/cs/index.html" - }, - { - "source": "/fr/**", - "destination": "/fr/index.html" - }, - { - "source": "/it/**", - "destination": "/it/index.html" - }, - { - "source": "/ja/**", - "destination": "/ja/index.html" - }, - { - "source": "/ko/**", - "destination": "/ko/index.html" - }, - { - "source": "/lr/**", - "destination": "/lr/index.html" - }, - { - "source": "/pt/**", - "destination": "/pt/index.html" - }, - { - "source": "/rl/**", - "destination": "/rl/index.html" - }, - { - "source": "/ru/**", - "destination": "/ru/index.html" - }, - { - "source": "/uk/**", - "destination": "/uk/index.html" - }, - { - "source": "/xx/**", - "destination": "/xx/index.html" - }, - { - "source": "/source/**", - "destination": "/source/index.html" - }, - { - "source": "/zh_CN/**", - "destination": "/zh_TW/index.html" - }, - { - "source": "/zh_TW/**", - "destination": "/zh_TW/index.html" - }, - { - "source": "/storybook/**", - "destination": "/storybook/index.html" - } - ], - "headers": [ - { - "source": "**/*.@(eot|otf|ttf|ttc|woff|font.css|woff|svg|js|woff2)", - "headers": [ - { - "key": "Cache-Control", - "value": "max-age=31536000" - } - ] - }, - { - "source": "**/*.@(jpg|jpeg|gif|png)", - "headers": [ - { - "key": "Cache-Control", - "value": "max-age=7200" - } - ] - } - ] - } -} diff --git a/scripts/lighthouse/firebase.ts b/scripts/lighthouse/firebase.ts deleted file mode 100644 index 7d82ad5ea6..0000000000 --- a/scripts/lighthouse/firebase.ts +++ /dev/null @@ -1,88 +0,0 @@ -import * as firebase from 'firebase' -import { environment } from './environment' -import { Result, ResultFile, MetadataFile } from './types' -const fse = require('fs-extra') - -export class FirebaseManager { - firebaseDB - - constructor() {} - - async initializeFirebase() { - this.firebaseDB = await firebase.initializeApp(environment.firebaseConfig) - this.firebaseDB = await firebase.firestore() - return this.firebaseDB - } - - async saveOnFirebase(result, id) { - await this.firebaseDB - .collection(environment.testPrefix || 'no-prefix') - .doc(id) - .set(result) - .then(function (docRef) { - console.debug('Document written with ID: ', JSON.stringify(docRef)) - }) - .catch(function (error) { - console.error('Error adding document: ', error) - }) - } - - saveFile(file: string, id: string): string { - const fileName = `${id}.json` - fse.outputFileSync(`${id}.json`, file) - return fileName - } - - generateRecordId(result: Result, date: Date): string { - const user = // A third user - result.auditDefinition.loggedAs || - // Admin user - (result.auditDefinition.auth && environment.ORCID_ADMIN_USER) || - // Without auth - 'no-auth' - - const id = `${result.auditDefinition.url || 'root'}.${user}.${date - .toISOString() - .replace(/:/g, '.')}` - - return id - } - - generateFilePath(date: Date): string { - const environmentContext = environment.testPrefix || 'no-prefix' - return `audits/${environmentContext}/${date - .toISOString() - .replace(/:/g, '.')}/` - } - - async saveFileResults(results: Result[], date: Date) { - const metadata: MetadataFile = { - resultFiles: [], - date: date.toISOString(), - executedBy: environment.ORCID_ADMIN_USER, - environmentPrefix: environment.prefix, - } - for (const result of results) { - const filePath = this.saveFileResult(result, date) - const resultFile: ResultFile = { - auditDefinition: result.auditDefinition, - filePath, - } - metadata.resultFiles.push(resultFile) - } - return this.saveFileMetadata(metadata, date) - } - - private saveFileMetadata(metadata: MetadataFile, date: Date) { - const path = this.generateFilePath(date) - const fileName = `metaData-${date.toISOString().replace(':', '.')}` - return this.saveFile(JSON.stringify(metadata), path + fileName) - } - - private saveFileResult(result: Result, date: Date) { - const fileName = this.generateRecordId(result, date) - const path = this.generateFilePath(date) - const filePath = this.saveFile(result.result, path + fileName) - return filePath - } -} diff --git a/scripts/lighthouse/main.ts b/scripts/lighthouse/main.ts deleted file mode 100644 index 60779650fc..0000000000 --- a/scripts/lighthouse/main.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { FirebaseManager } from './firebase' -import { Puppeteer } from './puppeteer' -import { environment } from './environment' -import { Result } from './types' - -class AuditManager { - firebase: FirebaseManager - puppeteer: Puppeteer - - constructor() { - this.puppeteer = new Puppeteer() - this.firebase = new FirebaseManager() - } - - async initFirebase() { - if (this.firebase.firebaseDB) { - await this.firebase.initializeFirebase() - } - } - - async runAudit(): Promise { - const audits: Result[] = [] - for (let audit of environment.ORCID_URLS_TO_AUDIT) { - await this.puppeteer.launch() - try { - if (audit.auth || audit.loggedAs) { - await this.puppeteer.login() - } - if (audit.loggedAs) { - await this.puppeteer.loginAs(audit.loggedAs) - } - const result = await this.puppeteer.runAudit(audit.url) - - audits.push({ auditDefinition: audit, result: JSON.stringify(result) }) - } catch (e) { - throw e - } finally { - await this.puppeteer.kill() - } - } - - return audits - } -} - -;(async () => { - const audit = new AuditManager() - audit.initFirebase() - const result: Result[] = await audit.runAudit() - const date = new Date() - await audit.firebase.saveFileResults(result, date) -})() diff --git a/scripts/lighthouse/puppeteer.ts b/scripts/lighthouse/puppeteer.ts deleted file mode 100644 index e2848da882..0000000000 --- a/scripts/lighthouse/puppeteer.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { environment } from './environment' -import * as puppeteer from 'puppeteer' -import { Page, Browser } from 'puppeteer' -import * as lighthouse from 'lighthouse' - -const log = require('lighthouse-logger') - -const LOGIN_URL = 'signin' - -export class Puppeteer { - PORT = 8041 - browser: Browser - page: Page - opts = { - port: this.PORT, - enableErrorReporting: true, - logLevel: 'info', - chromeFlags: ['--show-paint-rects'], - } - constructor() {} - - async launch() { - this.browser = await puppeteer.launch({ - args: [`--remote-debugging-port=${this.PORT}`], - headless: false, - }) - } - - async login() { - this.page = await this.browser.newPage() - await this.page.goto( - `${environment.protocol}${environment.prefix}${environment.baseURL}/${LOGIN_URL}` - ) - const emailInput = await this.page.$('input[id="userId"]') - await emailInput.type(environment.ORCID_ADMIN_USER) - const passwordInput = await this.page.$('input[type="password"]') - await passwordInput.type(environment.ORCID_ADMIN_PASSWORD) - - await Promise.all([ - await this.page.$eval('#form-sign-in-button', (form) => { - return (form as HTMLElement).click() - }), - this.page.waitForNavigation(), - ]) - this.page.close() - } - - async loginAs(orcidId) { - this.page = await this.browser.newPage() - await this.page.goto( - `${environment.protocol}${environment.prefix}${environment.baseURL}/switch-user?username=${orcidId}` - ) - this.page.close() - } - - async runAudit(url) { - await log.setLevel(this.opts.logLevel) - const result = await lighthouse( - `${environment.protocol}${environment.prefix}${environment.baseURL}/${url}`, - this.opts - ) - return result.lhr - } - - kill() { - this.browser.close() - } -} diff --git a/scripts/lighthouse/readme.md b/scripts/lighthouse/readme.md deleted file mode 100644 index 80f094d572..0000000000 --- a/scripts/lighthouse/readme.md +++ /dev/null @@ -1,50 +0,0 @@ -## Lighthouse - -This project uses [Puppeteer](https://github.com/puppeteer/puppeteer) and [Lighthouse](https://github.com/GoogleChrome/lighthouse), to automatically run performance, accessibility and best practices audits on the production application. - -#### How to run - -First make sure to have npm and yarn - -Clone and install orcid-angular - -``` -git clone https://github.com/ORCID/orcid-angular -cd orcid-angular -yarn -``` - -Define an `environment.ts` file on `scripts/lighthouse`. With the following content: - -``` -import { Environment } from './types' - -export const environment: Environment = { - protocol: 'https://', - prefix: '', - baseURL: 'orcid.org', - testPrefix: 'sample', - ORCID_URLS_TO_AUDIT: [ - { - url: 'orcid.org', - auth: false, - } - ] -} -``` - -Run the test - -``` -yarn lighthouse -``` - -This will save the lighthouse reports on the audits folder at the root of the project, for a graphical display of this report you can use [Lighthouse Report Viewer](https://googlechrome.github.io/lighthouse/viewer/) - -#### How to test pages that require authentication - -... in development - -#### How to generate a report - -... in development diff --git a/scripts/lighthouse/sample.environment.ts b/scripts/lighthouse/sample.environment.ts deleted file mode 100644 index a3236ea62e..0000000000 --- a/scripts/lighthouse/sample.environment.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { Environment } from './types' - -export const environment: Environment = { - protocol: 'https://', - prefix: '', - baseURL: 'orcid.org', - testPrefix: 'sample', - firebaseConfig: { - apiKey: '****', - authDomain: '****', - databaseURL: '****', - projectId: '****', - storageBucket: '****', - messagingSenderId: '****', - appId: '****', - measurementId: '****', - }, - ORCID_URLS_TO_AUDIT: [ - { - url: 'orcid.org', - auth: false, - }, - { - url: 'my-orcid', - auth: true, - loggedAs: '****-****-****-****', - }, - ], - ORCID_ADMIN_USER: '****', - ORCID_ADMIN_PASSWORD: '****', -} diff --git a/scripts/lighthouse/types.ts b/scripts/lighthouse/types.ts deleted file mode 100644 index b68384681a..0000000000 --- a/scripts/lighthouse/types.ts +++ /dev/null @@ -1,41 +0,0 @@ -export interface Audit { - url: string - auth?: boolean - loggedAs?: string -} - -export interface Environment { - protocol: string - prefix: string - baseURL: string - testPrefix: string - firebaseConfig?: { - apiKey: string - authDomain: string - databaseURL: string - projectId: string - storageBucket: string - messagingSenderId: string - appId: string - measurementId: string - } - ORCID_URLS_TO_AUDIT?: Audit[] - ORCID_ADMIN_USER?: string - ORCID_ADMIN_PASSWORD?: string -} - -export interface Result { - auditDefinition: Audit - result: string -} - -export interface ResultFile { - auditDefinition: Audit - filePath: string -} -export interface MetadataFile { - date: string - environmentPrefix: string - executedBy: string - resultFiles: ResultFile[] -}