🔧(packages) make scripts cross platform friendly

Some scripts had errors when running on windows.
We now use some cross platform cli tools to be
able to run the scripts on every platform.
This commit is contained in:
Anthony Le Courric
2023-08-03 10:42:31 +02:00
committed by Jean-Baptiste PENRATH
parent 956e6f2367
commit 4f4f1682a6
5 changed files with 168 additions and 30 deletions

View File

@@ -1,3 +1,4 @@
import { dirname, sep } from "path";
import { defaultTokenRefs } from "@openfun/cunningham-tokens";
import { globSync } from "glob";
@@ -11,21 +12,23 @@ import { globSync } from "glob";
const components: any = {};
const files = globSync("src/components/**/tokens.ts");
files.forEach((file) => {
const importPath = "./" + file.replace(/\.ts$/, "");
const matches = /^.+components\/(.+)\/tokens$/gm.exec(importPath);
let componentName = matches && matches[1];
if (!componentName) {
throw new Error("Could not find component name from file path " + file);
}
componentName = componentName.toLowerCase();
const importPath = "." + sep + file.replace(/\.ts$/, "");
const res = require(importPath);
if (!res.tokens) {
throw new Error("Tokens file does not export tokens " + file);
}
componentName = componentName.replace("/", "-");
components[componentName] = res.tokens(defaultTokenRefs);
try {
const componentName = dirname(importPath)
.split(`${sep}components${sep}`)[1]
.toLocaleLowerCase()
.replace(sep, "-");
components[componentName] = res.tokens(defaultTokenRefs);
} catch (error) {
throw new Error("Could not find component name from file path " + file);
}
});
export default {

View File

@@ -27,13 +27,13 @@
"scripts": {
"lint": "eslint . 'src/**/*.{ts,tsx}'",
"dev": "yarn storybook & nodemon --watch src --ext '*' --ignore src/cunningham-tokens.ts --ignore src/cunningham-tokens.js --ignore src/cunningham-tokens.css --exec npm run build",
"build": "./build",
"build-fonts": "vite build -c vite.fonts.config.ts && rm -rf dist/fonts.js && mkdir -p dist/sass && cp src/fonts.scss dist/sass/",
"build-icons": "vite build -c vite.icons.config.ts && rm -rf dist/icons.js && mkdir -p dist/sass && cp src/icons.scss dist/sass/",
"build": "bash ./build",
"build-fonts": "vite build -c vite.fonts.config.ts && rm -rf dist/fonts.js && make-dir dist/sass && cp src/fonts.scss dist/sass/",
"build-icons": "vite build -c vite.icons.config.ts && rm -rf dist/icons.js && make-dir dist/sass && cp src/icons.scss dist/sass/",
"build-theme": "cunningham -o src -g css,ts,js",
"preview": "vite preview",
"test": "FORCE_COLOR=1 vitest run",
"test-ci": "VITEST_MIN_THREADS=1 VITEST_MAX_THREADS=3 FORCE_COLOR=1 vitest run --shard $(($CIRCLE_NODE_INDEX + 1))/$CIRCLE_NODE_TOTAL",
"test": "cross-env FORCE_COLOR=1 vitest run",
"test-ci": "cross-env VITEST_MIN_THREADS=1 cross-env VITEST_MAX_THREADS=3 cross-env FORCE_COLOR=1 vitest run --shard $(($CIRCLE_NODE_INDEX + 1))/$CIRCLE_NODE_TOTAL",
"test-watch": "vitest",
"coverage": "vitest run --coverage",
"storybook": "storybook dev -p 6006",

View File

@@ -28,9 +28,9 @@
"build-bin": "cd src/bin && rm -rf ../../dist/bin && tsc -p tsconfig.build.json && tsc-alias && chmod +x ../../dist/bin/Main.js",
"build-lib": "cp dist/cunningham-tokens.ts src/lib && cd src/lib && tsc -p tsconfig.json",
"build": "yarn build-bin && yarn build-default-theme && yarn build-lib && cd ../.. && ln -sf ../../packages/tokens/dist/bin/Main.js node_modules/.bin/cunningham",
"build-default-theme": "./dist/bin/Main.js -o dist -s html -g scss,css,js,ts --utility-classes",
"test": "FORCE_COLOR=1 jest --runInBand --verbose src",
"test-ci": "FORCE_COLOR=1 jest --runInBand src"
"build-default-theme": "node ./dist/bin/Main.js -o dist -s html -g scss,css,js,ts --utility-classes",
"test": "cross-env FORCE_COLOR=1 jest --runInBand --verbose src",
"test-ci": "cross-env FORCE_COLOR=1 jest --runInBand src"
},
"dependencies": {
"chalk": "4.1.2",