Skip to content

Instantly share code, notes, and snippets.

View jmfrancois's full-sized avatar

Jean-Michel FRANCOIS jmfrancois

  • Talend by Qlik
  • France
  • 07:37 (UTC +01:00)
View GitHub Profile
#!/usr/bin/env node
/**
* # Preview what would be renamed (dry run)
* node rename-jsx-files.mjs packages/components --dry-run
*
* # Actually rename files
* node rename-jsx-files.mjs packages/components
*
* # Verbose mode to see all files processed
* node rename-jsx-files.mjs packages/components --verbose
function generateContrastingColors(baseColor, numberOfColors, minContrastRatio = 4.5) {
const colors = [];
let attempts = 0;
const maxAttempts = numberOfColors * 100;
while (colors.length < numberOfColors && attempts < maxAttempts) {
const newColor = getRandomColor();
const contrastRatio = getContrastRatio(baseColor, newColor);
if (contrastRatio >= minContrastRatio) {
colors.push(newColor);
git config --global alias.lol "log --graph --pretty=format:'%s' --abbrev-commit"
/**
* Run `node css.js` from this package root to compile every `*.module.scss` to a sibling `*.module.css` and rewrite imports accordingly.
*
* - Scans the package for `*.module.scss` files (ignoring node_modules, lib, lib-esm, .turbo, .git, dist, build, etc.).
* - Compiles each of them with `sass` into a `*.module.css` that sits in the same folder.
* - Updates `.js`, `.jsx`, `.ts`, and `.tsx` files so `.module.scss` imports point to the new `.module.css` files.
* - Optionally deletes the original `*.module.scss` files after successful compilation (use --delete flag).
*
* Usage:
* node css.js # Compile and update imports (keep .scss files)
@jmfrancois
jmfrancois / merge-coverage.ts
Created March 14, 2024 08:25
ts-node utilities for frontend
#!/usr/bin/env ts-node
import * as fs from 'fs'
import * as path from 'path'
import * as glob from 'glob'
const CWD = process.cwd()
// describe coverage-final.json file
type Statement = {
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const CWD = process.cwd();
const EXTENSIONS = /\.(scss)$/;
const SASS_DATA = "@use '~@talend/bootstrap-theme/src/theme/guidelines' as *;\n";
function transform(filename) {
@jmfrancois
jmfrancois / screenshots.js
Created April 15, 2021 08:20
ui regression tester between two surge.sh websites
const program = require('commander');
const fs = require('fs');
const tmp = require('tmp-promise');
const PNG = require('pngjs').PNG;
const pixelmatch = require('pixelmatch');
const puppeteer = require('puppeteer');
program
.option('-p, --pullrequest [pr]', 'Pull request')
.option('-c, --config [config]', 'JSON config file')
@jmfrancois
jmfrancois / versions.js
Last active December 12, 2024 09:53
This gist is to help you to maintain your backstage app clean against a release
const os = require('os');
const fs = require('fs');
const versions = require('./versions.json');
function updatePart(dependencies) {
Object.keys(dependencies).forEach(dep => {
if (versions[dep]) {
dependencies[dep] = versions[dep];
}
})
@jmfrancois
jmfrancois / Webcomponent.jsx
Created April 6, 2020 20:37
how to render webcomponent in react
import React from 'react';
export default function WebComponent({ component, ...props }) {
const [myEl, setState] = React.useState(document.createElement(component));
const el = React.useRef(null);
React.useEffect(() => {
if (myEl.tagName.toLowerCase() !== component.toLowerCase() ) {
setState(document.createElement(component));
} else {
Object.keys(props).forEach(key => {
@jmfrancois
jmfrancois / pathShadowForReact.js
Last active March 24, 2020 08:56
This gist let you use React into shadowDOM
/**
* IMPORTANT NOTE.
* Because react use synthetic event we have to patch the shadowDOM
* The following patch has to be applied just after the attachShadow
* and you must ban the use document.createElement. Use shadowRoot.createElement instead.
* Source: https://github.com/facebook/react/issues/9242
*/
function changeOwnerDocumentToShadowRoot(element, shadowRoot) {
Object.defineProperty(element, 'ownerDocument', {value: shadowRoot});
}