Skip to content

Commit 6fffd04

Browse files
committed
Add build action
- also update to node 22 - remove css - update esbuild dependency
1 parent 8df8cdb commit 6fffd04

6 files changed

Lines changed: 239 additions & 191 deletions

File tree

.github/workflows/npm.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: NodeJS
2+
on:
3+
push:
4+
branches: [ "main" ]
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v3
11+
12+
- name: Use Node.js 22.x
13+
uses: actions/setup-node@v3
14+
with:
15+
node-version: 22.x
16+
- name: add package-version to environment
17+
run: node -p -e '`PACKAGE_VERSION=${require("./package.json").version}`' >> $GITHUB_ENV
18+
- name: Build
19+
run: |
20+
npm install
21+
npm run build
22+
- name: create package-version artifact
23+
run: node -p -e '`${require("./package.json").version}`' > dist/version.txt
24+
- name: package-version-to-git-tag
25+
uses: pkgdeps/git-tag-action@v2
26+
with:
27+
github_token: ${{ secrets.GITHUB_TOKEN }}
28+
github_repo: ${{ github.repository }}
29+
version: ${{ env.PACKAGE_VERSION }}
30+
git_commit_sha: ${{ github.sha }}
31+
git_tag_prefix: "v"
32+
- name: Upload Build Artifacts
33+
uses: actions/upload-artifact@v4
34+
with:
35+
name: build-artifact
36+
path: dist/*
37+
38+
release:
39+
runs-on: ubuntu-latest
40+
needs: build
41+
42+
steps:
43+
- name: Download Build Artifacts
44+
uses: actions/download-artifact@v5
45+
with:
46+
name: build-artifact
47+
- name: Set tagname
48+
shell: bash
49+
run: |
50+
version=`cat version.txt`
51+
echo "TAGNAME=$version" >> $GITHUB_ENV
52+
- name: Create Release
53+
id: create_release
54+
uses: actions/create-release@v1
55+
env:
56+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
with:
58+
tag_name: v${{ env.TAGNAME }}
59+
release_name: Release v${{ env.TAGNAME }}
60+
body: |
61+
Changes in this Release
62+
- First Change
63+
- Second Change
64+
draft: false
65+
prerelease: false
66+
- name: Upload bookmarklet
67+
id: upload-bookmarklet
68+
uses: actions/upload-release-asset@v1
69+
env:
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71+
with:
72+
upload_url: ${{ steps.create_release.outputs.upload_url }}
73+
asset_path: ./bookmarklet.txt
74+
asset_name: bookmarklet.txt
75+
asset_content_type: text/plain
76+
- name: Upload Bookmarklet Page
77+
id: upload-bookmark-export
78+
uses: actions/upload-release-asset@v1
79+
env:
80+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
81+
with:
82+
upload_url: ${{ steps.create_release.outputs.upload_url }}
83+
asset_path: ./ccc-bookmarklet.html
84+
asset_name: ccc-bookmarklet.html
85+
asset_content_type: text/html

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v22

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
With the CAAT Color Contrast Checker, you can easily check the color contrasts of website elements directly in your browser as a bookmarklet.
44
This tool evaluates the contrast conformity according to the W3C guidelines for small and large text, as well as non-text content.
55
Additionally, the color values and the calculated contrast ratio can be easily copied for further use.
6+
67
## Features
78

89
- Provides color contrast checks for websites
@@ -28,4 +29,4 @@ The default colors are controlled by the following variables:
2829

2930
The color picker function is not available in all browsers and operating systems.
3031

31-
if you have any questions or feedback, please open an issue.
32+
If you have any questions or feedback, please open an issue.

esbuild.mjs

Lines changed: 1 addition & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,6 @@ import { minifyCSS } from "./minifyCSS.js";
99
const bookmarkletPlugin = options => ({
1010
name: 'bookmarkletPlugin',
1111
setup(build) {
12-
build.onLoad({ filter: /\.(tsx|js)$/ }, async args => {
13-
let code = await fs.promises.readFile(args.path, 'utf8');
14-
15-
const cssRegex = /css`([^`]+)`/g;
16-
let match;
17-
let newCode = code;
18-
19-
while ((match = cssRegex.exec(code)) !== null) {
20-
const originalCSS = match[1];
21-
const minifiedCSS = minifyCSS(originalCSS);
22-
newCode = newCode.replace(originalCSS, minifiedCSS);
23-
}
24-
25-
return {
26-
loader: 'tsx',
27-
contents: newCode,
28-
};
29-
});
3012
build.onEnd(async (result) => {
3113
const { outputFiles } = result;
3214
if (!outputFiles) return;
@@ -53,7 +35,7 @@ await esbuild.build({
5335
entryPoints: ['src/bookmarklet.js'],
5436
bundle: true,
5537
minify: true,
56-
outfile: 'dist/bookmarkletConverted.js',
38+
outfile: 'dist/bookmarklet.txt',
5739
write: false,
5840
plugins: [
5941
bookmarkletPlugin()
@@ -71,7 +53,6 @@ await esbuild.build({
7153
<head>
7254
<meta charset="UTF-8">
7355
<meta name="viewport" content="width=device-width, initial-scale=1.0">
74-
<link rel="stylesheet" href="style.css"/>
7556
<title>CAAT Color Contrast Checker Bookmarklet</title>
7657
</head>
7758
<body>
@@ -89,65 +70,5 @@ await esbuild.build({
8970
</html>
9071
`;
9172

92-
const cssStyle = `
93-
html, body {
94-
margin: 0;
95-
padding: 0;
96-
background-color: #fff;
97-
}
98-
.row {
99-
margin: 0 auto;
100-
max-width: 45rem;
101-
padding: 0 1rem;
102-
}
103-
h1, h2, h3, h4, h5, h6 {
104-
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol;
105-
font-weight: 700;
106-
color: #111;
107-
}
108-
h1 {
109-
line-height: 1.2;
110-
font-size: 2rem;
111-
margin-bottom: 0;
112-
}
113-
@media screen and (min-width: 45em) {
114-
h1 {
115-
font-size: 3rem;
116-
}
117-
}
118-
h2 {
119-
line-height: 1.2;
120-
font-size: 1.5rem;
121-
}
122-
p, li {
123-
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol;
124-
color: #333;
125-
line-height: 1.6;
126-
font-size: 1.4rem;
127-
}
128-
p {
129-
margin: 0 0 1rem 0;
130-
}
131-
li {
132-
margin: 0 0 1rem 0;
133-
}
134-
ul, ol {
135-
margin: 0 0 1rem 2rem;
136-
padding: 0;
137-
list-style-position: outside;
138-
}
139-
a {
140-
color: #D7090E;
141-
}
142-
a:hover, a:focus {
143-
color: #fff;
144-
background-color: #ce171e;
145-
border-top: 3px solid #ce171e;
146-
text-decoration: none;
147-
outline: none;
148-
}
149-
`;
150-
15173
fs.writeFileSync(`${distDir}/ccc-bookmarklet.html`, htmlContent);
152-
fs.writeFileSync(`${distDir}/style.css`, cssStyle);
15374
});

0 commit comments

Comments
 (0)