Skip to content

Commit

Permalink
Merge pull request #19 from nicolethoen/docs_scaffolding
Browse files Browse the repository at this point in the history
fix: clean up, add documentation scaffolding
  • Loading branch information
nicolethoen authored Feb 14, 2024
2 parents c6a767a + 2d97ee3 commit b791fd9
Show file tree
Hide file tree
Showing 29 changed files with 3,433 additions and 4,166 deletions.
49 changes: 46 additions & 3 deletions .github/workflows/build-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fi
- uses: actions/setup-node@v1
with:
node-version: '14'
node-version: '18'
- uses: actions/cache@v2
id: yarn-cache
name: Cache npm deps
Expand All @@ -35,7 +35,7 @@ jobs:
packages/*/dist
key: ${{ runner.os }}-dist-14-${{ secrets.CACHE_VERSION }}-${{ hashFiles('yarn.lock', 'package.json', 'packages/*/*', '!packages/*/dist', '!packages/*/node_modules') }}
- name: Build dist
run: yarn build:scss
run: yarn build
if: steps.dist.outputs.cache-hit != 'true'
lint:
runs-on: ubuntu-latest
Expand All @@ -52,7 +52,7 @@ jobs:
fi
- uses: actions/setup-node@v1
with:
node-version: '14'
node-version: '18'
- uses: actions/cache@v2
id: yarn-cache
name: Cache npm deps
Expand All @@ -71,3 +71,46 @@ jobs:
key: ${{ runner.os }}-lint-14-${{ secrets.CACHE_VERSION }}-${{ hashFiles('yarn.lock') }}
- name: MDLint
run: yarn lint:md
test_a11y:
runs-on: ubuntu-latest
env:
GH_PR_NUM: ${{ github.event.number }}
needs: build
steps:
- uses: actions/checkout@v2
# Yes, we really want to checkout the PR
- run: |
if [[ ! -z "${GH_PR_NUM}" ]]; then
echo "Checking out PR"
git fetch origin pull/$GH_PR_NUM/head:tmp
git checkout tmp
fi
- uses: actions/setup-node@v1
with:
node-version: '18'
- uses: actions/cache@v2
id: yarn-cache
name: Cache npm deps
with:
path: |
node_modules
**/node_modules
~/.cache/Cypress
key: ${{ runner.os }}-yarn-14-${{ secrets.CACHE_VERSION }}-${{ hashFiles('yarn.lock') }}
- run: yarn install --frozen-lockfile
if: steps.yarn-cache.outputs.cache-hit != 'true'
- uses: actions/cache@v2
id: dist
name: Cache dist
with:
path: |
packages/*/dist
packages/react-styles/css
key: ${{ runner.os }}-dist-14-${{ secrets.CACHE_VERSION }}-${{ hashFiles('yarn.lock', 'package.json', 'packages/*/*', '!packages/*/dist', '!packages/*/node_modules') }}
- name: Build dist
run: yarn build
if: steps.dist.outputs.cache-hit != 'true'
- name: Build docs
run: yarn build:docs
- name: A11y tests
run: yarn serve:docs & yarn test:a11y
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
if: steps.setup-cache.outputs.cache-hit != 'true'
- uses: actions/setup-node@v1
with:
node-version: '14'
node-version: '18'
- uses: actions/cache@v2
id: yarn-cache
name: Cache npm deps
Expand All @@ -52,4 +52,4 @@ jobs:
key: ${{ runner.os }}-dist-14-${{ secrets.CACHE_VERSION }}-${{ hashFiles('yarn.lock', 'package.json', 'packages/*/*', '!packages/*/dist', '!packages/*/node_modules') }}
- name: Build dist
run: yarn build
if: steps.dist.outputs.cache-hit != 'true'
if: steps.dist.outputs.cache-hit != 'true'
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '14'
node-version: '18'
- uses: actions/cache@v2
id: yarn-cache
name: Cache npm deps
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Javascript builds
node_modules
dist
tsc_out
.out
.changelog
Expand Down Expand Up @@ -30,4 +31,4 @@ lerna-debug.log
# For vim
*.swp

public
public
64 changes: 64 additions & 0 deletions fed-mini-modules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const fse = require('fs-extra');
const glob = require('glob');
const path = require('path');

const root = process.cwd();

const sourceFiles = glob
.sync(`${root}/src/*/`)
.map((name) => name.replace(/\/$/, ''));

const indexTypings = glob.sync(`${root}/src/index.d.ts`);

async function copyTypings(files, dest) {
const cmds = [];
files.forEach((file) => {
const fileName = file.split('/').pop();
cmds.push(fse.copyFile(file, `${dest}/${fileName}`));
});
return Promise.all(cmds);
}

async function createPackage(file) {
const fileName = file.split('/').pop();
const esmSource = glob.sync(`${root}/esm/${fileName}/**/index.js`)[0];
/**
* Prevent creating package.json for directories with no JS files (like CSS directories)
*/
if (!esmSource) {
return;
}

const destFile = `${path.resolve(root, file.split('/src/').pop())}/package.json`;

const esmRelative = path.relative(file.replace('/src', ''), esmSource);
const content = {
main: 'index.js',
module: esmRelative,
};
const typings = glob.sync(`${root}/src/${fileName}/*.d.ts`);
let cmds = [];
content.typings = 'index.d.ts';
cmds.push(copyTypings(typings, `${root}/${fileName}`));
cmds.push(fse.writeJSON(destFile, content));
return Promise.all(cmds);
}

async function generatePackages(files) {
const cmds = files.map((file) => createPackage(file));
return Promise.all(cmds);
}

async function run(files) {
try {
await generatePackages(files);
if (indexTypings.length === 1) {
copyTypings(indexTypings, root);
}
} catch (error) {
console.error(error);
process.exit(1);
}
}

run(sourceFiles);
17 changes: 0 additions & 17 deletions jest.config.js

This file was deleted.

36 changes: 20 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@patternfly/style-dictionary-root",
"name": "@patternfly/design-tokens-root",
"private": true,
"version": "0.0.0",
"description": "This library provides patternfly extensions",
Expand All @@ -8,23 +8,24 @@
"packages/*"
],
"scripts": {
"build:docs": "yarn workspace @patternfly/style-dictionary docs:build",
"build:scss": "yarn workspace @patternfly/style-dictionary build:scss",
"start": "yarn build && concurrently --kill-others \"yarn workspace @patternfly/style-dictionary docs:develop\"",
"serve:docs": "yarn workspace @patternfly/style-dictionary docs:serve",
"clean": "yarn workspace @patternfly/style-dictionary clean",
"lint:js": "node --max-old-space-size=4096 node_modules/.bin/eslint packages --ext js,jsx,ts,tsx --cache",
"build": "yarn workspace @patternfly/design-tokens build",
"build:docs": "yarn workspace @patternfly/design-tokens docs:build",
"build:fed:packages": "yarn workspace @patternfly/design-tokens build:fed:packages",
"build:scss": "yarn workspace @patternfly/design-tokens build:scss",
"start": "yarn build && concurrently --kill-others \"yarn workspace @patternfly/design-tokens docs:develop\"",
"serve:docs": "yarn workspace @patternfly/design-tokens docs:serve",
"clean": "yarn workspace @patternfly/design-tokens clean",
"lint:md": "yarn eslint packages --ext md --no-eslintrc --config .eslintrc-md.json --cache",
"lint": "yarn lint:js && yarn lint:md",
"test:a11y": "yarn workspace @patternfly/style-dictionary test:a11y",
"serve:a11y": "yarn workspace @patternfly/style-dictionary serve:a11y"
"lint": "yarn lint:md",
"test:a11y": "yarn workspace @patternfly/design-tokens test:a11y",
"serve:a11y": "yarn workspace @patternfly/design-tokens serve:a11y"
},
"devDependencies": {
"react": "^17",
"react-dom": "^17",
"react": "^18",
"react-dom": "^18",
"typescript": "^4.7.4",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"concurrently": "^5.3.0",
"eslint": "^8.0.1",
"eslint-plugin-import": "^2.25.2",
Expand All @@ -36,9 +37,12 @@
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-config-prettier": "8.5.0",
"@typescript-eslint/eslint-plugin": "^5.42.0",
"@typescript-eslint/parser": "^5.42.0",
"prettier": "2.7.1",
"@babel/core": "^7.19.6",
"@babel/preset-env": "^7.19.4",
"@babel/preset-react": "^7.18.6",
"@babel/preset-flow": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"serve": "^14.1.2"
}
}
38 changes: 38 additions & 0 deletions packages/module/build-js-for-docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const fs = require('fs');
const fse = require('fs-extra');
const path = require('path');

const charts_scss = path.join(__dirname, 'build/css/_tokens-charts.scss');
const dark_scss = path.join(__dirname, 'build/css/_tokens-dark.scss');
const default_scss = path.join(__dirname, 'build/css/_tokens-default.scss');
const palette_scss = path.join(__dirname, 'build/css/_tokens-palette.scss');

const chartFileContents = fs.readFileSync(charts_scss, 'utf-8');
const darkFileContents = fs.readFileSync(dark_scss, 'utf-8');
const defaultFileContents = fs.readFileSync(default_scss, 'utf-8');
const paletteFileContents = fs.readFileSync(palette_scss, 'utf-8');

const scssAsJson = {}

const addToMap = (line) => {
const trimmedLine = line.trimStart();
if (trimmedLine.startsWith("--")) {
const varName = trimmedLine.substring(0, trimmedLine.indexOf(':'));

// value should have var( ) stripped from it, so it's just the variable name
// if no var ( ) then just the value should be stored in the map
let value = trimmedLine.substring(trimmedLine.indexOf(':')+1, trimmedLine.indexOf(';')).trimStart();
if (value.startsWith('var(')) {
value = value.substring(value.indexOf('(')+1, value.indexOf(')'));
}
scssAsJson[varName] = value
}
}

paletteFileContents.split(/\r?\n/).forEach(line => addToMap(line));
defaultFileContents.split(/\r?\n/).forEach(line => addToMap(line));
darkFileContents.split(/\r?\n/).forEach(line => addToMap(line));
chartFileContents.split(/\r?\n/).forEach(line => addToMap(line));

fse.writeJson(path.join(__dirname, 'patternfly-docs/scssAsJson.json'), scssAsJson);

18 changes: 9 additions & 9 deletions packages/module/build/css/_tokens-charts.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// /**
// * Do not edit directly
// * Generated on Thu, 01 Feb 2024 18:21:44 GMT
// */
/**
* Do not edit directly
* Generated on Wed, 14 Feb 2024 00:59:20 GMT
*/

:root {
--pf-t--chart--stroke--width--sm: 2px;
--pf-t--chart--stroke--width--xs: 1px;
--pf-t--chart--BorderWidth--lg: 8px;
--pf-t--chart--BorderWidth--sm: 2px;
--pf-t--chart--BorderWidth--xs: 1px;
--pf-t--chart--stroke--width--sm: 2;
--pf-t--chart--stroke--width--xs: 1;
--pf-t--chart--BorderWidth--lg: 8;
--pf-t--chart--BorderWidth--sm: 2;
--pf-t--chart--BorderWidth--xs: 1;
--pf-t--chart--color--fills-and-strokes--fill--color--white: var(--pf-t--color--white);
--pf-t--chart--color--fills-and-strokes--fill--color--900: var(--pf-t--color--gray--90);
--pf-t--chart--color--fills-and-strokes--fill--color--700: var(--pf-t--color--gray--70);
Expand Down
8 changes: 4 additions & 4 deletions packages/module/build/css/_tokens-dark.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// /**
// * Do not edit directly
// * Generated on Thu, 01 Feb 2024 18:21:44 GMT
// */
/**
* Do not edit directly
* Generated on Wed, 14 Feb 2024 00:59:20 GMT
*/

:root {
--pf-t--global--background--color--action--plain--default: rgba(0, 0, 0, 0.0000);
Expand Down
20 changes: 10 additions & 10 deletions packages/module/build/css/_tokens-default.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// /**
// * Do not edit directly
// * Generated on Thu, 01 Feb 2024 18:21:44 GMT
// */
/**
* Do not edit directly
* Generated on Wed, 14 Feb 2024 00:59:19 GMT
*/

:root {
--pf-t--global--background--color--action--plain--default: rgba(255, 255, 255, 0.0000);
Expand Down Expand Up @@ -103,12 +103,12 @@
--pf-t--global--background--color--300: var(--pf-t--color--gray--20);
--pf-t--global--background--color--200: var(--pf-t--color--gray--10);
--pf-t--global--background--color--100: var(--pf-t--color--white);
--pf-t--global--Zindex--2xl: 600;
--pf-t--global--Zindex--xl: 500;
--pf-t--global--Zindex--lg: 400;
--pf-t--global--Zindex--md: 300;
--pf-t--global--Zindex--sm: 200;
--pf-t--global--Zindex--xs: 100;
--pf-t--global--Zindex--2xl: var(--pf-t--global--Zindex--600);
--pf-t--global--Zindex--xl: var(--pf-t--global--Zindex--500);
--pf-t--global--Zindex--lg: var(--pf-t--global--Zindex--400);
--pf-t--global--Zindex--md: var(--pf-t--global--Zindex--300);
--pf-t--global--Zindex--sm: var(--pf-t--global--Zindex--200);
--pf-t--global--Zindex--xs: var(--pf-t--global--Zindex--100);
--pf-t--global--font--size--4xl: var(--pf-t--global--font--size--800);
--pf-t--global--font--size--3xl: var(--pf-t--global--font--size--700);
--pf-t--global--font--size--2xl: var(--pf-t--global--font--size--600);
Expand Down
8 changes: 4 additions & 4 deletions packages/module/build/css/_tokens-palette.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// /**
// * Do not edit directly
// * Generated on Thu, 01 Feb 2024 18:21:44 GMT
// */
/**
* Do not edit directly
* Generated on Wed, 14 Feb 2024 00:59:20 GMT
*/

:root {
--pf-t--color--red--70: #5f0000;
Expand Down
Loading

0 comments on commit b791fd9

Please sign in to comment.