Skip to content

Commit

Permalink
feature/issue 23 Styleguide and Design System (#36)
Browse files Browse the repository at this point in the history
Co-authored-by: Owen Buckley <owenbuckley13@gmail.com>
  • Loading branch information
Auhseh and thescientist13 authored Apr 26, 2024
1 parent fbbdeca commit 2cf45b3
Show file tree
Hide file tree
Showing 30 changed files with 1,003 additions and 127 deletions.
597 changes: 476 additions & 121 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
"story:build": "storybook build",
"story:serve": "npm run clean && npm run story:build && http-server ./storybook-static",
"test": "wtr",
"test:tdd": "npm run test -- --watch"
"test:tdd": "npm run test -- --watch",
"postinstall": "patch-package"
},
"dependencies": {
"geist": "^1.2.0"
},
"devDependencies": {
"@chromatic-com/storybook": "^1.3.1",
Expand All @@ -39,6 +43,7 @@
"@web/test-runner-junit-reporter": "^0.7.1",
"http-server": "^14.1.1",
"lit": "^3.1.2",
"patch-package": "^8.0.0",
"rimraf": "^5.0.5",
"storybook": "^8.0.6",
"vite": "^5.2.8"
Expand Down
71 changes: 71 additions & 0 deletions patches/@greenwood+cli+0.29.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
diff --git a/node_modules/@greenwood/cli/src/plugins/resource/plugin-standard-css.js b/node_modules/@greenwood/cli/src/plugins/resource/plugin-standard-css.js
index d52c723..2aedcc3 100644
--- a/node_modules/@greenwood/cli/src/plugins/resource/plugin-standard-css.js
+++ b/node_modules/@greenwood/cli/src/plugins/resource/plugin-standard-css.js
@@ -5,10 +5,14 @@
*
*/
import fs from 'fs';
+import path from 'path';
import { parse, walk } from 'css-tree';
import { ResourceInterface } from '../../lib/resource-interface.js';
+import { normalizePathnameForWindows } from '../../lib/resource-utils.js';
+import { hashString } from '../../lib/hashing-utils.js';

-function bundleCss(body, url, projectDirectory) {
+function bundleCss(body, url, compilation) {
+ const { projectDirectory, outputDir, userWorkspace } = compilation.context;
const ast = parse(body, {
onParseError(error) {
console.log(error.formattedMessage);
@@ -29,10 +33,40 @@ function bundleCss(body, url, projectDirectory) {
: new URL(value, url);
const importContents = fs.readFileSync(resolvedUrl, 'utf-8');

- optimizedCss += bundleCss(importContents, url, projectDirectory);
+ optimizedCss += bundleCss(importContents, url, compilation);
} else {
optimizedCss += `@import url('${value}');`;
}
+ } else if (type === 'Url' && this.atrule?.name !== 'import') {
+ if (value.startsWith('http') || value.startsWith('//')) {
+ optimizedCss += `url('${value}')`;
+ return;
+ }
+
+ const basePath = compilation.config.basePath === '' ? '/' : `${compilation.config.basePath}/`;
+ let barePath = value.replace(/\.\.\//g, '').replace('./', '');
+
+ if (barePath.startsWith('/')) {
+ barePath = barePath.replace('/', '');
+ }
+
+ const locationUrl = barePath.startsWith('node_modules')
+ ? new URL(`./${barePath}`, projectDirectory)
+ : new URL(`./${barePath}`, userWorkspace);
+ const hash = hashString(fs.readFileSync(locationUrl, 'utf-8'));
+ const ext = barePath.split('.').pop();
+ const hashedRoot = barePath.replace(`.${ext}`, `.${hash}.${ext}`);
+
+ fs.mkdirSync(normalizePathnameForWindows(new URL(`./${path.dirname(barePath)}/`, outputDir)), {
+ recursive: true
+ });
+
+ fs.promises.copyFile(
+ locationUrl,
+ new URL(`./${hashedRoot}`, outputDir)
+ );
+
+ optimizedCss += `url('${basePath}${hashedRoot}')`;
} else if (type === 'Atrule' && name !== 'import') {
optimizedCss += `@${name} `;
} else if (type === 'TypeSelector') {
@@ -238,7 +272,7 @@ class StandardCssResource extends ResourceInterface {

async optimize(url, response) {
const body = await response.text();
- const optimizedBody = bundleCss(body, url, this.compilation.context.projectDirectory);
+ const optimizedBody = bundleCss(body, url, this.compilation);

return new Response(optimizedBody);
}
7 changes: 7 additions & 0 deletions src/assets/api-routes.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/assets/build-ssg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/assets/center-grid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/assets/copy-button.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/discord.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/assets/emphasis-corner.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2cf45b3

Please sign in to comment.