diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..6ebae6b8e --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + - package-ecosystem: "npm" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..1add94409 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,80 @@ +name: CI + +on: push + +jobs: + lint: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - uses: actions/cache@v2 + with: + path: '**/node_modules' + key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-modules- + - name: Use Node.js + uses: actions/setup-node@v2.1.4 + with: + node-version: 14 + - run: yarn + - run: yarn run lint + test: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - uses: actions/cache@v2 + with: + path: '**/node_modules' + key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-modules- + - name: Use Node.js + uses: actions/setup-node@v2.1.4 + with: + node-version: 14 + - run: yarn + - run: yarn run test:coverage + - uses: codecov/codecov-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + build: + runs-on: ubuntu-20.04 + needs: [lint, test] + steps: + - uses: actions/checkout@v2 + - name: Use Node.js + uses: actions/setup-node@v2.1.4 + with: + node-version: 14 + - run: yarn --pure-lockfile + - run: yarn run build + deploy: + runs-on: ubuntu-20.04 + needs: [build] + if: github.ref == 'refs/heads/master' + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: "0" + - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* + - name: Git Identity + run: | + git config --global user.name 'Scaleway Bot' + git config --global user.email 'github@scaleway.com' + git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/$GITHUB_REPOSITORY + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Use Node.js + uses: actions/setup-node@v2.1.4 + with: + node-version: 14 + - run: yarn --pure-lockfile + - run: yarn run build + - run: echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + - run: yarn run lerna publish -y --create-release github --ignore-scripts + env: + NPM_TOKEN: ${{secrets.NPM_TOKEN}} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pull_request_title.yml b/.github/workflows/pull_request_title.yml new file mode 100644 index 000000000..e4f959d74 --- /dev/null +++ b/.github/workflows/pull_request_title.yml @@ -0,0 +1,23 @@ + +name: Pull Request +on: + pull_request: + types: ['opened', 'edited', 'reopened', 'synchronize'] + +jobs: + check-title: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - uses: actions/cache@v2 + with: + path: '**/node_modules' + key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-modules- + - name: Use Node.js + uses: actions/setup-node@v2.1.4 + with: + node-version: 14 + - run: yarn + - run: echo '${{ github.event.pull_request.title }}' | yarn run commitlint diff --git a/README.md b/README.md index 57dd5c76c..727b67bec 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # scaleway-lib -scaleway-lib is a set of NPM packgages used at Scaleway. These libraries are available on our [private NPM registry](https://***REMOVED***). +scaleway-lib is a set of NPM packages used at Scaleway. --- @@ -28,14 +28,13 @@ scaleway-lib is a set of NPM packgages used at Scaleway. These libraries are ava - [`@scaleway/eslint-config-react`](./packages/eslint-config-react/README.md): A shared eslint react opiniated configuration - [`@scaleway/random-name`](./packages/random-name/README.md): A tiny utility to generate random names - [`@scaleway/regex`](./packages/regex/README.md): usefull regex named -- [`@scaleway/didiff-lib`](./packages/didiff-lib/README.md): diffing-s3-compatible lib for visual testing ## Development ### Locally ```bash -$ git clone git@***REMOVED***/scaleway-lib.git +$ git clone git@github.com:scaleway/scaleway-lib.git $ cd scaleway-lib $ yarn $ # ... do your changes ... diff --git a/lerna.json b/lerna.json index 62f27c9b5..83789b2be 100644 --- a/lerna.json +++ b/lerna.json @@ -8,7 +8,7 @@ "conventionalCommits": true }, "version": { - "message": "chore(release): publish [skip-ci]" + "message": "chore(release): publish" } } } diff --git a/package.json b/package.json index ec7362468..f93224020 100644 --- a/package.json +++ b/package.json @@ -63,8 +63,7 @@ }, "jest": { "collectCoverageFrom": [ - "packages/*/src/*.{js,jsx}", - "!packages/didiff-lib/capture/screenshot.js" + "packages/*/src/*.{js,jsx}" ], "coverageReporters": [ "text", diff --git a/packages/countries/package.json b/packages/countries/package.json index 4a07b1b29..82e313e51 100644 --- a/packages/countries/package.json +++ b/packages/countries/package.json @@ -3,6 +3,9 @@ "version": "1.1.1", "description": "A package containing ISO 3166 and ISO 3166-2 codes", "main": "./countries.json", + "publishConfig": { + "access": "public" + }, "repository": { "type": "git", "url": "https://github.com/scaleway/scaleway-lib", diff --git a/packages/didiff-lib/CHANGELOG.md b/packages/didiff-lib/CHANGELOG.md deleted file mode 100644 index 1ee327e78..000000000 --- a/packages/didiff-lib/CHANGELOG.md +++ /dev/null @@ -1,54 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [1.1.5](https://github.com/scaleway/scaleway-lib/compare/@scaleway/didiff-lib@1.1.4...@scaleway/didiff-lib@1.1.5) (2020-12-08) - -**Note:** Version bump only for package @scaleway/didiff-lib - - - - - -## [1.1.4](https://github.com/scaleway/scaleway-lib/compare/@scaleway/didiff-lib@1.1.3...@scaleway/didiff-lib@1.1.4) (2020-12-08) - -**Note:** Version bump only for package @scaleway/didiff-lib - - - - - -## [1.1.3](https://github.com/scaleway/scaleway-lib/compare/@scaleway/didiff-lib@1.1.2...@scaleway/didiff-lib@1.1.3) (2020-12-07) - -**Note:** Version bump only for package @scaleway/didiff-lib - - - - - -## [1.1.2](https://github.com/scaleway/scaleway-lib/compare/@scaleway/didiff-lib@1.1.1...@scaleway/didiff-lib@1.1.2) (2020-12-07) - -**Note:** Version bump only for package @scaleway/didiff-lib - - - - - -## [1.1.1](https://github.com/scaleway/scaleway-lib/compare/@scaleway/didiff-lib@1.1.0...@scaleway/didiff-lib@1.1.1) (2020-11-26) - - -### Bug Fixes - -* add lang to pathname ([980141c](https://github.com/scaleway/scaleway-lib/commit/980141c72336649628b4236ac089aa5f58f92192)) - - - - - -# 1.1.0 (2020-11-19) - - -### Features - -* add didiff-lib package SGW-1292 ([d07e263](https://github.com/scaleway/scaleway-lib/commit/d07e2637c53d3c21209f99a3586dd8bd00b3f72e)) diff --git a/packages/didiff-lib/README.md b/packages/didiff-lib/README.md deleted file mode 100644 index ae210ae7e..000000000 --- a/packages/didiff-lib/README.md +++ /dev/null @@ -1,68 +0,0 @@ -# Didiff 📸, the Scaleway pages diffing tool - -## Of what is the project composed? - -There are two parts: - -- The `lib` which contains the process of taking website captures, diff it and then upload it to s3. This is this repo. You're in the `lib` actually! -- The `UI` which contains the web UI to view the diff files. You can found the code of the `UI` [here](https://***REMOVED***/front/scaleway-global-differ). - -### To use - -- Add the package on your project with `yarn add @scaleway/didiff-lib` -- You must have the `vips` library installed on your system. Please see the [install process](https://libvips.github.io/libvips/install.html). -- Use it with `yarn run didiff capture file` -- `file` is a mandatory argument which is a path to a file with a list of url in it. See the section `File format` for more information. -- You can follow track of the process by watching logs on your terminal. -- You can also wait on the `UI` and start to examine the diff, if any! -- Please note that the lib uses s3 for the storage of files. You need to add to your `env` the correct value. See more on `Config env`. - -## The functioning ? - -Actually, the script process is: - -- Get the urls from the `file` argument and parse them -- Then, a loop starts - * captures urls page by peer - * generate PNGs based on the captures - * diff those PNGs - * if there is a diff, generate the diff PNG - * upload to s3 the 3 PNGs to human-comparison purpose - * clean the generated PNGs from file-system - -## File format - -The `file` passed to the script must be a simple text file with a list of urls, separeted by a new line `("\n")` -We need two urls to make a diff so each line must be two urls, separated by a comma `(",")` - -e.g. - -``` -https://www.scaleway.com/en/saas/,https://global-website.stg.frt.internal.scaleway.com/en/saas/ -https://www.scaleway.com/en/betas/,https://global-website.stg.frt.internal.scaleway.com/en/betas/ -https://www.scaleway.com/en/startup-program/,https://global-website.stg.frt.internal.scaleway.com/en/startup-program/ -``` - -In the output, the first url of the line will be called the `original` and the second the `sample` - -## Config env - -Since `Didiff` uses s3, you must log in to it. You have to add your credentials in your env (or `.env`). The keys are: - -#### Mandatory - -- `REACT_APP_DIDIFF_S3_ENDPOINT` e.g. "s3.fr-par.scw.cloud" -- `REACT_APP_DIDIFF_S3_SECRET_KEY` -- `REACT_APP_DIDIFF_S3_ACCESS_KEY` -- `REACT_APP_DIDIFF_S3_BUCKET_NAME` - -#### Optional - -- `REACT_APP_DIDIFF_HIDE_ELEMENTS`: CSS selectors which will be hided in your page, separated by a comma e.g. "iframe,section" will apply a `visibility: hidden` on all `iframe` and `section` of the page -- `REACT_APP_DIDIFF_VIEWPORT_WIDTH`: width of the viewport used for the screenshot. By default, will be `990` - -## Contact - -Please contact @teamfrontweb on Slack for any inquiries - -![logo](logo.png) diff --git a/packages/didiff-lib/logo.png b/packages/didiff-lib/logo.png deleted file mode 100644 index cf208487b..000000000 Binary files a/packages/didiff-lib/logo.png and /dev/null differ diff --git a/packages/didiff-lib/package.json b/packages/didiff-lib/package.json deleted file mode 100644 index 1ad34c630..000000000 --- a/packages/didiff-lib/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "@scaleway/didiff-lib", - "version": "1.1.5", - "author": "@teamfrontweb", - "description": "Lib comparing, diffing and uploading screenshots", - "main": "dist/index.js", - "license": "UNLICENSED", - "repository": { - "type": "git", - "url": "https://github.com/scaleway/scaleway-lib", - "directory": "packages/didiff-lib" - }, - "bin": { - "didiff": "./dist/index.js" - }, - "dependencies": { - "aws-sdk": "^2.804.0", - "dotenv": "^8.2.0", - "lookpath": "^1.1.0", - "node-fetch": "^2.6.1", - "path": "^0.12.7", - "pixelmatch": "^5.2.1", - "pngjs": "^6.0.0", - "puppeteer": "^5.5.0", - "sharp": "^0.26.3" - }, - "scripts": { - "start": "node src/" - } -} diff --git a/packages/didiff-lib/src/__mocks__/lookpath.js b/packages/didiff-lib/src/__mocks__/lookpath.js deleted file mode 100644 index 5bd74bece..000000000 --- a/packages/didiff-lib/src/__mocks__/lookpath.js +++ /dev/null @@ -1,11 +0,0 @@ -// __mocks__/lookpath.js - -const lookpath = jest.createMockFromModule('lookpath') - -function lp() { - return 'undefined' -} - -lookpath.lookpath = lp - -module.exports = lookpath diff --git a/packages/didiff-lib/src/__tests__/failedCapture.js b/packages/didiff-lib/src/__tests__/failedCapture.js deleted file mode 100644 index 4f050c65c..000000000 --- a/packages/didiff-lib/src/__tests__/failedCapture.js +++ /dev/null @@ -1,26 +0,0 @@ -/* eslint-disable no-console */ - -// This test is in another file because we use the mock of lookpath - -import capturesPages from '../capture' - -const mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {}) - -// Comment these two lines if you want to have logs during the tests -jest.spyOn(console, 'info').mockImplementation(() => {}) -jest.spyOn(console, 'error').mockImplementation(() => {}) - -describe('capture', () => { - it.only('should not detect vips on system and exit', async () => { - await capturesPages({ - original: {}, - sample: {}, - }) - - expect(mockExit).toHaveBeenCalledWith(1) - }) -}) - -afterEach(() => { - jest.clearAllMocks() -}) diff --git a/packages/didiff-lib/src/__tests__/index.js b/packages/didiff-lib/src/__tests__/index.js deleted file mode 100644 index 0bdb475e2..000000000 --- a/packages/didiff-lib/src/__tests__/index.js +++ /dev/null @@ -1,216 +0,0 @@ -/* eslint-disable no-console */ - -import fs from 'fs' -import nodePath from 'path' -import capturesPages from '../capture' -import isCapturesDifferent from '../diff' -import { - getPathnameFromUrl, - getImageInformations, - getImageData, - getFile, - removeFiles, -} from '../helpers' -import log from '../log' -import s3 from '../s3' -import urls from '../urls' - -jest.unmock('lookpath') - -const mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {}) - -// Comment these two lines if you want to have logs during the tests -jest.spyOn(console, 'info').mockImplementation(() => {}) -jest.spyOn(console, 'error').mockImplementation(() => {}) - -describe('didiff-lib', () => { - describe('log', () => { - it('should call console.info one time', () => { - log.info('hello') - expect(console.info.mock.calls.length).toBe(1) - }) - it('should call console.error one time', () => { - log.err('hello') - expect(console.error.mock.calls.length).toBe(1) - }) - }) - - describe('urls', () => { - it('should return one pair of urls', () => { - const res = urls(`${__dirname}/simple-urls.txt`) - expect(res.length).toBe(1) - }) - it('should return three pair of urls', () => { - const res = urls(`${__dirname}/multiple-urls.txt`) - expect(res.length).toBe(3) - }) - it('should throw an error if no file', () => { - urls() - expect(mockExit).toHaveBeenCalledWith(1) - }) - }) - - describe('s3', () => { - it('should create s3 client', () => { - s3.init() - }) - it('should get s3 client with default config', () => { - s3.init() - const client = s3.getClient() - expect(client.config.endpoint).toMatch('s3.fr-par.amazonaws.com') - }) - it('should get s3 client with ENV config', () => { - const endpoint = 's3.fr-par.scw.cloud' - process.env = Object.assign(process.env, { - REACT_APP_DIDIFF_S3_ENDPOINT: endpoint, - }) - s3.init() - const client = s3.getClient() - expect(client.config.endpoint).toMatch(endpoint) - }) - it('should upload 3 files', async () => { - s3.init() - const client = s3.getClient() - client.upload = jest.fn(() => {}) - s3.setClient(client) - - const files = ['file1', 'file2', 'file3'] - await s3.uploadBatch(files) - expect(client.upload.mock.calls.length).toBe(3) - }) - }) - - describe('diff', () => { - it('should not detect a diff', async () => { - const fsPathTestImage = nodePath.resolve(__dirname, './test.png') - const hasDetectedDiff = await isCapturesDifferent({ - original: { fullPath: fsPathTestImage }, - sample: { fullPath: fsPathTestImage }, - diff: { fullPath: '' }, - }) - - expect(hasDetectedDiff).toBe(false) - }) - it('should detect a diff', async () => { - const fsPathTestImage = nodePath.resolve(__dirname, './test.png') - const fsPathTest2Image = nodePath.resolve(__dirname, './test2.png') - const fsPathFinalImage = nodePath.resolve(__dirname, './final.png') - - const hasDetectedDiff = await isCapturesDifferent({ - original: { fullPath: fsPathTestImage }, - sample: { fullPath: fsPathTest2Image }, - diff: { fullPath: fsPathFinalImage }, - }) - const file = getFile(fsPathTestImage) - - expect(hasDetectedDiff).toBe(true) - expect(file).toBeDefined() - - removeFiles([fsPathFinalImage]) - }) - }) - - describe('helpers', () => { - describe('getPathnameFromUrl', () => { - it('should get slug from basic url', () => { - expect(getPathnameFromUrl('https://scaleway.com/en/saas')).toMatch( - 'en-saas', - ) - }) - it('should get slug from complex url', () => { - expect( - getPathnameFromUrl('https://scaleway.com/fr/dedibox/start'), - ).toMatch('fr-dedibox-start') - }) - it('should get slug from home url', () => { - expect(getPathnameFromUrl('https://scaleway.com/en/')).toMatch( - 'en-index', - ) - }) - }) - describe('getImageInformations', () => { - it('should get informations about image', () => { - const infos = getImageInformations({ - url: 'https://scaleway.com/en/saas', - pathname: 'en-saas', - name: 'original', - }) - const fsPath = nodePath.resolve(__dirname, '../screenshots') - - expect(infos).toMatchObject({ - url: 'https://scaleway.com/en/saas', - name: 'original', - fullName: 'en-saas-original.png', - fullPath: `${fsPath}/en-saas-original.png`, - path: `${fsPath}/en-saas`, - }) - }) - }) - describe('getFile', () => { - it('should get file data from fs', () => { - const fsPathTestImage = nodePath.resolve(__dirname, './test.png') - const file = getFile(fsPathTestImage) - - expect(file).toBeDefined() - }) - }) - describe('getImageData', () => { - it('should get PNG from fs', () => { - const fsPathTestImage = nodePath.resolve(__dirname, './test.png') - const png = getImageData(fsPathTestImage) - - expect(png.image).toBeDefined() - expect(png.png).toBeDefined() - }) - }) - describe('removeFiles', () => { - it('should remove 3 files', () => { - fs.unlinkSync = jest.fn(() => {}) - - const fsPathTestImage = nodePath.resolve(__dirname, './test.png') - - removeFiles([fsPathTestImage, fsPathTestImage, fsPathTestImage]) - expect(fs.unlinkSync.mock.calls.length).toBe(3) - fs.unlinkSync.mockClear() - }) - }) - }) - - describe.skip('capture', () => { - it('should capture two pages', async () => { - jest.setTimeout(50000) - jest.retryTimes(3) - - const fsCapturesPath = `${nodePath.resolve(__dirname, './screenshots')}` - - if (!fs.existsSync(fsCapturesPath)) { - fs.mkdirSync(fsCapturesPath) - } - - await capturesPages({ - original: { - url: 'https://scaleway.com/en/saas', - name: 'original', - fullName: 'saas-original.png', - fullPath: `${fsCapturesPath}/saas-original.png`, - path: `${fsCapturesPath}/saas`, - }, - sample: { - url: 'https://scaleway.com/en/saas', - name: 'sample', - fullName: 'saas-sample.png', - fullPath: `${fsCapturesPath}/saas-sample.png`, - path: `${fsCapturesPath}/saas`, - }, - }) - - const originalFile = getFile(`${fsCapturesPath}/saas-original.png`) - const sampleFile = getFile(`${fsCapturesPath}/saas-sample.png`) - - expect(originalFile).toBeDefined() - expect(sampleFile).toBeDefined() - - fs.rmdirSync(fsCapturesPath, { recursive: true }) - }) - }) -}) diff --git a/packages/didiff-lib/src/__tests__/multiple-urls.txt b/packages/didiff-lib/src/__tests__/multiple-urls.txt deleted file mode 100644 index e5730e6bf..000000000 --- a/packages/didiff-lib/src/__tests__/multiple-urls.txt +++ /dev/null @@ -1,3 +0,0 @@ -https://scaleway.com/en/saas,https://scaleway.com/en/saas -https://scaleway.com/en/betas,https://scaleway.com/en/betas -https://scaleway.com/en/startup,https://scaleway.com/en/startup \ No newline at end of file diff --git a/packages/didiff-lib/src/__tests__/simple-urls.txt b/packages/didiff-lib/src/__tests__/simple-urls.txt deleted file mode 100644 index a973c43c2..000000000 --- a/packages/didiff-lib/src/__tests__/simple-urls.txt +++ /dev/null @@ -1 +0,0 @@ -https://scaleway.com/en/saas,https://scaleway.com/en/saas \ No newline at end of file diff --git a/packages/didiff-lib/src/__tests__/test.png b/packages/didiff-lib/src/__tests__/test.png deleted file mode 100644 index e25c696be..000000000 Binary files a/packages/didiff-lib/src/__tests__/test.png and /dev/null differ diff --git a/packages/didiff-lib/src/__tests__/test2.png b/packages/didiff-lib/src/__tests__/test2.png deleted file mode 100644 index cf208487b..000000000 Binary files a/packages/didiff-lib/src/__tests__/test2.png and /dev/null differ diff --git a/packages/didiff-lib/src/capture/index.js b/packages/didiff-lib/src/capture/index.js deleted file mode 100644 index 11f2084de..000000000 --- a/packages/didiff-lib/src/capture/index.js +++ /dev/null @@ -1,88 +0,0 @@ -import { execSync } from 'child_process' -import { lookpath } from 'lookpath' -import puppeteer from 'puppeteer' -import { removeFiles } from '../helpers' -import log from '../log' -import screenshot from './screenshot' - -const NB_SCREEN_PER_PAGE = 3 - -async function detectIfVipsExist() { - const isVipsPresent = await lookpath('vips') - - if (isVipsPresent === 'undefined') { - log.err('vips library seems to not be installed on your system.') - log.err('Didiff need it to process screenshots. Please install it.') - return false - } - return true -} - -async function capturePages({ original, sample }) { - log.info('Capturing...') - const isVipsInstalled = await detectIfVipsExist() - if (!isVipsInstalled) { - process.exit(1) - return - } - try { - const viewportWidth = - parseInt(process.env.REACT_APP_DIDIFF_VIEWPORT_WIDTH || '', 10) || 990 - - const browser = await puppeteer.launch({ - args: [ - '--no-sandbox', - '--disable-setuid-sandbox', - '--ignore-certificate-errors', - ], - }) - - await Promise.all( - [original, sample].map(async infos => { - const page = await browser.newPage() - - await page.setViewport({ - height: 800, - width: viewportWidth, - }) - await page.goto(infos.url) - - const pageHeight = await page.evaluate( - () => document.getElementsByTagName('html')[0].scrollHeight, - ) - const partHeight = Math.round(pageHeight / NB_SCREEN_PER_PAGE) - - const filesPath = Array.from({ length: NB_SCREEN_PER_PAGE }).map( - (_, index) => `${infos.path}-${infos.name}-${index}.png`, - ) - - await Promise.all( - filesPath.map((path, index) => - screenshot(page, { - path, - viewportWidth, - viewportHeight: partHeight * (index + 1), - screeshotHeight: partHeight, - offset: partHeight * index, - }), - ), - ) - - execSync( - `vips arrayjoin "${filesPath.join(' ')}" ${ - infos.fullPath - } --across 1`, - { stdio: 'inherit' }, - ) - removeFiles(filesPath) - }), - ) - - browser.close() - } catch (error) { - log.err('Fail during the screenshoting process ❌', error) - process.exit(1) - } -} - -export default capturePages diff --git a/packages/didiff-lib/src/capture/screenshot.js b/packages/didiff-lib/src/capture/screenshot.js deleted file mode 100644 index 72ee21ff3..000000000 --- a/packages/didiff-lib/src/capture/screenshot.js +++ /dev/null @@ -1,35 +0,0 @@ -async function screenshot( - page, - { path, viewportHeight, screeshotHeight, viewportWidth, offset }, -) { - await page.setViewport({ - height: viewportHeight, - width: viewportWidth, - }) - - // eslint-disable-next-line no-restricted-syntax - for (const element of ( - process.env.REACT_APP_DIDIFF_HIDE_ELEMENTS || '' - ).split(',')) { - try { - // eslint-disable-next-line no-await-in-loop - await page.$$eval(element, elements => - elements.forEach(e => e.style.setProperty('visibility', 'hidden')), - ) - } catch (err) { - // eslint-disable-next-line no-empty - } - } - - return page.screenshot({ - path, - clip: { - x: 0, - y: offset, - height: screeshotHeight, - width: viewportWidth, - }, - }) -} - -export default screenshot diff --git a/packages/didiff-lib/src/diff.js b/packages/didiff-lib/src/diff.js deleted file mode 100644 index 10037fe5c..000000000 --- a/packages/didiff-lib/src/diff.js +++ /dev/null @@ -1,95 +0,0 @@ -import pixelmatch from 'pixelmatch' -import { PNG } from 'pngjs' -import sharp from 'sharp' -import { createPNG, getImageData } from './helpers' -import log from './log' - -const diffingOptions = { - includeAA: true, - threshold: 0.7, -} - -function crop(image, path, options) { - return sharp(image).extract(options).toFile(path) -} -async function cropBiggerImage({ image, path }, dimensions) { - log.info('Cropping...') - await crop(image, path, { - left: 0, - top: 0, - width: dimensions.width, - height: dimensions.height, - }) -} -function getSmallestDimensions({ originalData, sampleData }) { - if (sampleData.png.height > originalData.png.height) { - return { - source: 'original', - width: originalData.png.width, - height: originalData.png.height, - } - } - if (sampleData.png.height < originalData.png.height) { - return { - source: 'sample', - width: sampleData.png.width, - height: sampleData.png.height, - } - } - return undefined -} - -async function isCapturesDifferents({ original = {}, sample = {}, diff = {} }) { - log.info('Diffing...') - let originalData = getImageData(original.fullPath) - let sampleData = getImageData(sample.fullPath) - - const smallestDimensions = - getSmallestDimensions({ - originalData, - sampleData, - }) || {} - - if (smallestDimensions.source) { - const { source, ...dimensions } = smallestDimensions - const data = - source === 'original' - ? { image: sampleData.image, path: sample.fullPath } - : { image: originalData.image, path: original.fullPath } - await cropBiggerImage(data, dimensions) - if (source === 'original') { - sampleData = getImageData(sample.fullPath) - } else { - originalData = getImageData(original.fullPath) - } - } - - const diffPNG = new PNG({ - width: smallestDimensions.width || originalData.png.width, - height: smallestDimensions.height || originalData.png.height, - }) - - try { - const nbUnmatchedPx = pixelmatch( - originalData.png.data, - sampleData.png.data, - diffPNG.data, - diffPNG.width, - diffPNG.height, - diffingOptions, - ) - if (nbUnmatchedPx > 0) { - createPNG(diff.fullPath, diffPNG) - log.info('Diff was found ❗️') - return true - } - log.info('No diff, skipping') - return false - } catch (error) { - log.err('Fail during the diffing process ❌', error) - process.exit(1) - } - return undefined -} - -export default isCapturesDifferents diff --git a/packages/didiff-lib/src/helpers.js b/packages/didiff-lib/src/helpers.js deleted file mode 100644 index d1ea22aad..000000000 --- a/packages/didiff-lib/src/helpers.js +++ /dev/null @@ -1,54 +0,0 @@ -import fs from 'fs' -import nodePath from 'path' -import { PNG } from 'pngjs' - -function removeFile(path) { - fs.unlinkSync(path) -} -function removeFiles(paths = []) { - paths.forEach(path => removeFile(path)) -} -function getFile(path) { - return fs.readFileSync(path) -} -function toPNG(data) { - return PNG.sync.read(data) -} -function createPNG(path, data) { - fs.writeFileSync(path, PNG.sync.write(data)) -} -function getImageData(path) { - const image = getFile(path) - const png = toPNG(image) - return { image, png } -} -function getImageInformations({ url = '', pathname = '', name = '' }) { - const nameWithExtension = `${name}.png` - const fullName = `${pathname}-${nameWithExtension}` - const fsPath = `${nodePath.resolve(__dirname, './screenshots')}` - - return { - url, - name, - fullName, - fullPath: `${fsPath}/${fullName}`, - path: `${fsPath}/${pathname}`, - } -} -function getPathnameFromUrl(url = '') { - const urlParts = url.split('/').filter(Boolean) - const langIndex = urlParts.findIndex(v => v === 'en' || v === 'fr') - const slicedName = urlParts.slice(langIndex, urlParts.length) || [] - return (slicedName.length > 1 ? slicedName : [...slicedName, 'index']).join( - '-', - ) -} - -export { - createPNG, - getFile, - getImageData, - getImageInformations, - getPathnameFromUrl, - removeFiles, -} diff --git a/packages/didiff-lib/src/index.js b/packages/didiff-lib/src/index.js deleted file mode 100644 index 91a1c6f7f..000000000 --- a/packages/didiff-lib/src/index.js +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env node -import log from './log' -import didiff from './run' - -const cmds = { - capture: didiff, - help: () => { - log.info(` -Didiff 📸 comes with three commands: - - "capture": start the capturing and diffing process. Accept one mandatory argument, a file which contains a list of url. - - "help": print this help. - -For more info, please read the docs: - - about the lib: https://github.com/scaleway/scaleway-lib/-/tree/add-didiff-lib/packages/didiff-lib - - about the UI: https://***REMOVED***/front/scaleway-global-differ - `) - }, -} - -const cmd = process.argv[2] - -const fn = cmds[cmd || 'help'] -if (!fn) { - log.err('❌ Error: only two commands are available on Didiff.') - log.err('Use Didiff with "capture" or "help" command') -} - -fn() diff --git a/packages/didiff-lib/src/log.js b/packages/didiff-lib/src/log.js deleted file mode 100644 index 22fcfc9a1..000000000 --- a/packages/didiff-lib/src/log.js +++ /dev/null @@ -1,5 +0,0 @@ -/* eslint-disable no-console */ -export default { - info: (...args) => console.info(...args), - err: (...args) => console.error('⚠️', ...args), -} diff --git a/packages/didiff-lib/src/run.js b/packages/didiff-lib/src/run.js deleted file mode 100644 index d83a8def7..000000000 --- a/packages/didiff-lib/src/run.js +++ /dev/null @@ -1,132 +0,0 @@ -import dotenv from 'dotenv' -import fs from 'fs' -import nodePath from 'path' -import capture from './capture' -import isCapturesDifferents from './diff' -import { - getPathnameFromUrl, - getImageInformations, - getFile, - removeFiles, -} from './helpers' -import log from './log' -import s3 from './s3' -import getUrls from './urls' - -dotenv.config() - -const TEST_DATE = new Date() - -function cleanCaptures(fsPaths = []) { - removeFiles(fsPaths) -} -function upload(pathname, { original, sample, diff }) { - const dateString = TEST_DATE.toLocaleDateString('fr').replace(/\//g, '-') - const timeString = TEST_DATE.toLocaleTimeString('fr').replace(/:/g, '-') - const s3path = `${dateString}!${timeString}/${pathname}` - - s3.uploadBatch([ - { - key: `${s3path}/${original.name}`, - body: getFile(original.fullPath), - }, - { - key: `${s3path}/${sample.name}`, - body: getFile(sample.fullPath), - }, - { - key: `${s3path}/${diff.name}`, - body: getFile(diff.fullPath), - }, - ]) -} -function groupImagesInformations(pathname, { original, sample }) { - return { - originalInfos: getImageInformations({ - url: original, - pathname, - name: 'original', - }), - sampleInfos: getImageInformations({ - url: sample, - pathname, - name: 'sample', - }), - diffInfos: getImageInformations({ - pathname, - name: 'diff', - }), - } -} - -async function startLoop(urls) { - const nbUrls = urls.length - let totalDiff = 0 - - log.info(`Didiff will now check ${nbUrls} urls 📸 \n`) - for (let i = 0; i < nbUrls; i += 1) { - const [original, sample] = urls[i] - const pathname = getPathnameFromUrl(original) - - const { originalInfos, sampleInfos, diffInfos } = groupImagesInformations( - pathname, - { - original, - sample, - }, - ) - - // eslint-disable-next-line no-await-in-loop - await capture({ - original: originalInfos, - sample: sampleInfos, - }) - - // eslint-disable-next-line no-await-in-loop - const isDifferent = await isCapturesDifferents({ - original: originalInfos, - sample: sampleInfos, - diff: diffInfos, - }) - - const imagesPaths = [originalInfos.fullPath, sampleInfos.fullPath] - if (isDifferent) { - totalDiff += 1 - imagesPaths.push(diffInfos.fullPath) - - upload(pathname, { - original: originalInfos, - sample: sampleInfos, - diff: diffInfos, - }) - } - cleanCaptures(imagesPaths) - - log.info(`Process for /${pathname} done.`) - if (nbUrls - (i + 1) === 0) { - log.info(`\nAll urls have been handled! (${nbUrls}) 📸`) - log.info(`Didiff found ${totalDiff} diffs.`) - log.info(`Shutting down...`) - } else { - log.info(`Still ${nbUrls - (i + 1)} check to do.`) - log.info('---') - } - } -} - -function handleCapturesPath() { - const capturesPath = `${nodePath.resolve(__dirname, './screenshots/')}` - if (!fs.existsSync(capturesPath)) { - fs.mkdirSync(capturesPath) - } -} -function run() { - s3.init() - const urls = getUrls(process.argv[process.argv.length - 1]) - startLoop(urls) -} - -export default () => { - handleCapturesPath() - run() -} diff --git a/packages/didiff-lib/src/s3.js b/packages/didiff-lib/src/s3.js deleted file mode 100644 index 0f27e8e20..000000000 --- a/packages/didiff-lib/src/s3.js +++ /dev/null @@ -1,49 +0,0 @@ -import S3 from 'aws-sdk/clients/s3' -import log from './log' - -let s3Client = null -function setClient(client) { - s3Client = client -} -function getClient() { - return s3Client -} - -function init() { - const client = new S3({ - endpoint: process.env.REACT_APP_DIDIFF_S3_ENDPOINT, - secretAccessKey: process.env.REACT_APP_DIDIFF_S3_SECRET_KEY, - accessKeyId: process.env.REACT_APP_DIDIFF_S3_ACCESS_KEY, - signatureVersion: 'v4', - region: 'fr-par', - }) - setClient(client) -} - -function upload({ key, body }) { - const client = getClient() - client.upload( - { - Key: key, - Body: body, - Bucket: process.env.REACT_APP_DIDIFF_S3_BUCKET_NAME, - }, - error => { - if (error) { - log.err('Error uploading ⚠️', { error }) - } - }, - ) -} - -async function uploadBatch(batch = []) { - log.info('Uploading...') - batch.forEach(data => upload(data)) -} - -export default { - init, - uploadBatch, - setClient, - getClient, -} diff --git a/packages/didiff-lib/src/urls.js b/packages/didiff-lib/src/urls.js deleted file mode 100644 index 807e2d212..000000000 --- a/packages/didiff-lib/src/urls.js +++ /dev/null @@ -1,29 +0,0 @@ -import fs from 'fs' -import log from './log' - -function getUrls(file = '') { - log.info('Getting urls...') - try { - const data = fs.readFileSync(file, { - encoding: 'utf8', - flag: 'r', - }) - const urls = data - .split('\n') - .filter(Boolean) - .reduce((acc, curr) => { - const [o, s] = curr.split(',') - return [...acc, [o, s]] - }, []) - return urls || [] - } catch (error) { - log.err( - 'Fail while parsing urls file. Did you submit a file in argument of Didiff ?', - error, - ) - process.exit(1) - } - return [] -} - -export default getUrls diff --git a/packages/eslint-config-react/package.json b/packages/eslint-config-react/package.json index 95ccae58f..63d48d8da 100644 --- a/packages/eslint-config-react/package.json +++ b/packages/eslint-config-react/package.json @@ -3,6 +3,9 @@ "version": "1.1.16", "description": "Scaleway React eslint shared config", "main": "index.js", + "publishConfig": { + "access": "public" + }, "repository": { "type": "git", "url": "https://github.com/scaleway/scaleway-lib", diff --git a/packages/example_package/.npmignore b/packages/example_package/.npmignore deleted file mode 100644 index d1811b877..000000000 --- a/packages/example_package/.npmignore +++ /dev/null @@ -1,3 +0,0 @@ -**/__tests__/** -src -!.npmignore diff --git a/packages/example_package/CHANGELOG.md b/packages/example_package/CHANGELOG.md deleted file mode 100644 index 657b45d39..000000000 --- a/packages/example_package/CHANGELOG.md +++ /dev/null @@ -1,43 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.2.3](https://github.com/scaleway/scaleway-lib/compare/@scaleway/example_package@0.2.2...@scaleway/example_package@0.2.3) (2020-10-28) - - -### Bug Fixes - -* correct browser entrypoints ([8a7d0b5](https://github.com/scaleway/scaleway-lib/commit/8a7d0b503ee22eedb07d5021b3a3fd4e059e627a)) - - - - - -## [0.2.2](https://github.com/scaleway/scaleway-lib/compare/@scaleway/example_package@0.2.1...@scaleway/example_package@0.2.2) (2020-10-24) - -**Note:** Version bump only for package @scaleway/example_package - - - - - -## [0.2.1](https://github.com/scaleway/scaleway-lib/compare/@scaleway/example_package@0.2.0...@scaleway/example_package@0.2.1) (2020-10-24) - -**Note:** Version bump only for package @scaleway/example_package - - - - - -# 0.2.0 (2020-10-24) - - -### Features - -* first commit ([8a5dad6](https://github.com/scaleway/scaleway-lib/commit/8a5dad6d3c2f44d1302590185b6bc1aef08553a9)) - - -### BREAKING CHANGES - -* first release diff --git a/packages/example_package/package.json b/packages/example_package/package.json deleted file mode 100644 index 9756d500f..000000000 --- a/packages/example_package/package.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "@scaleway/example_package", - "version": "0.2.3", - "description": "Sample package", - "main": "dist/index.js", - "module": "dist/module.js", - "browser": { - "dist/index.js": "./dist/index.browser.js", - "dist/module.js": "./dist/module.browser.js" - }, - "repository": { - "type": "git", - "url": "https://github.com/scaleway/scaleway-lib", - "directory": "packages/example_package" - }, - "license": "UNLICENSED", - "dependencies": { - "lodash": "4.17.20" - } -} diff --git a/packages/example_package/src/__tests__/__snapshots__/index.js.snap b/packages/example_package/src/__tests__/__snapshots__/index.js.snap deleted file mode 100644 index 5fe3e3466..000000000 --- a/packages/example_package/src/__tests__/__snapshots__/index.js.snap +++ /dev/null @@ -1,5 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should calc 1`] = `4`; - -exports[`should pad 1`] = `" hello "`; diff --git a/packages/example_package/src/__tests__/index.js b/packages/example_package/src/__tests__/index.js deleted file mode 100644 index 379f33079..000000000 --- a/packages/example_package/src/__tests__/index.js +++ /dev/null @@ -1,9 +0,0 @@ -import { pad, calc } from '..' - -it('should calc', () => { - expect(calc(2, 2)).toMatchSnapshot() -}) - -it('should pad', () => { - expect(pad('hello', 10)).toMatchSnapshot() -}) diff --git a/packages/example_package/src/index.js b/packages/example_package/src/index.js deleted file mode 100644 index be7c58008..000000000 --- a/packages/example_package/src/index.js +++ /dev/null @@ -1,4 +0,0 @@ -import { pad as lodashPad } from 'lodash' - -export const calc = (a, b) => a + b -export const pad = (str, length) => lodashPad(str, length) diff --git a/packages/random-name/package.json b/packages/random-name/package.json index e4f42e01a..a85fdc698 100644 --- a/packages/random-name/package.json +++ b/packages/random-name/package.json @@ -8,6 +8,9 @@ "dist/index.js": "./dist/index.browser.js", "dist/module.js": "./dist/module.browser.js" }, + "publishConfig": { + "access": "public" + }, "repository": { "type": "git", "url": "https://github.com/scaleway/scaleway-lib", diff --git a/packages/regex/package.json b/packages/regex/package.json index 0a26a9aae..9272e6dec 100644 --- a/packages/regex/package.json +++ b/packages/regex/package.json @@ -8,6 +8,9 @@ "dist/index.js": "./dist/index.browser.js", "dist/module.js": "./dist/module.browser.js" }, + "publishConfig": { + "access": "public" + }, "repository": { "type": "git", "url": "https://github.com/scaleway/scaleway-lib", diff --git a/renovate.json b/renovate.json deleted file mode 100644 index ea0623b6e..000000000 --- a/renovate.json +++ /dev/null @@ -1,84 +0,0 @@ -{ - "extends": [ - ":combinePatchMinorReleases", - ":separateMultipleMajorReleases", - "group:monorepos", - "group:recommended", - "helpers:disableTypesNodeMajor", - "packages:linters" - ], - "assignees": ["dmaliszewski", "mprost", "vaudebert", "echambon", "thuart"], - "assigneesSampleSize": 1, - "reviewers": ["dmaliszewski", "mprost", "vaudebert", "echambon", "thuart"], - "reviewersSampleSize": 2, - "branchPrefix": "renovate/", - "updateNotScheduled": true, - "lockFileMaintenance": { "enabled": false }, - "docker": { "enabled": true }, - "meteor": { "enabled": false }, - "prCreation": "not-pending", - "prHourlyLimit": 5, - "prConcurrentLimit": 10, - "automerge": false, - "semanticCommits": true, - "semanticCommitType": "chore", - "semanticCommitScope": "deps", - "rangeStrategy": "bump", - "rebaseWhen": "auto", - "masterIssue": true, - "hostRules": [ - { - "domainName": "github.com", - "token": "5dcef816e2c915c94bd691faf0633cfdaa2d2d70" - } - ], - "packageRules": [ - { - "labels": ["UPDATE-MAJOR"], - "stabilityDays": 14, - "updateTypes": ["major"] - }, - { - "labels": ["UPDATE-MINOR"], - "stabilityDays": 5, - "updateTypes": ["minor"] - }, - { - "labels": ["UPDATE-PATCH"], - "stabilityDays": 1, - "updateTypes": ["patch"] - }, - { - "packagePatterns": [ - "commitlint", - "cz-conventional-changelog", - "eslint", - "husky", - "lint-staged" - ], - "automerge": true, - "automergeType": "branch", - "semanticCommits": true, - "semanticCommitScope": "minor-deps", - "semanticCommitType": "chore", - "stabilityDays": 5, - "updateTypes": ["minor"] - }, - { - "packagePatterns": [ - "commitlint", - "cz-conventional-changelog", - "eslint", - "husky", - "lint-staged" - ], - "automerge": true, - "automergeType": "branch", - "semanticCommits": true, - "semanticCommitScope": "patch-deps", - "semanticCommitType": "chore", - "stabilityDays": 1, - "updateTypes": ["patch"] - } - ] -}