Skip to content

Commit b31aa04

Browse files
committed
Add changepacks
1 parent 97eaf81 commit b31aa04

File tree

14 files changed

+3059
-2975
lines changed

14 files changed

+3059
-2975
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"changes": { "package.json": "Patch" },
3+
"note": "Publish",
4+
"date": "2025-11-11T22:29:18.464629400Z"
5+
}

.changepacks/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"ignore": [],
33
"baseBranch": "main",
44
"latestPackage": null
5-
}
5+
}

.github/workflows/publish.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Publish Package to npm
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
permissions: write-all
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: false
15+
16+
jobs:
17+
check:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
23+
- uses: oven-sh/setup-bun@v2
24+
with:
25+
bun-version: latest
26+
- run: bun test
27+
- run: bun lint
28+
- run: bun run build
29+
30+
changepacks:
31+
name: changepacks
32+
runs-on: ubuntu-latest
33+
permissions:
34+
# create pull request comments
35+
pull-requests: write
36+
37+
# Actions > General > Workflow permissions for creating pull request
38+
# Create brench to create pull request
39+
contents: write
40+
needs:
41+
- check
42+
steps:
43+
- uses: actions/checkout@v5
44+
- uses: changepacks/action@main
45+
id: changepacks
46+
outputs:
47+
changepacks: ${{ steps.changepacks.outputs.changepacks }}
48+
49+
publish:
50+
runs-on: ubuntu-latest
51+
if: contains(needs.changepacks.outputs.changepacks, 'package.json')
52+
steps:
53+
- name: Checkout
54+
uses: actions/checkout@v4
55+
56+
- uses: oven-sh/setup-bun@v2
57+
with:
58+
bun-version: latest
59+
- run: bun i
60+
- run: bun test
61+
- run: bun run build
62+
- name: Upload to codecov.io
63+
uses: codecov/codecov-action@v5
64+
with:
65+
token: ${{ secrets.CODECOV_TOKEN }}
66+
fail_ci_if_error: true
67+
- run: bun publish --access public

__tests__/convert-type.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { expect, test } from "bun:test";
1+
import { expect, test } from 'bun:test'
22

3-
import { convertType } from "../convert-type";
3+
import { convertType } from '../convert-type'
44

5-
test.each([["string", '"string"']])("convertType", (type, expected) => {
6-
expect(convertType(type)).toEqual(expected);
7-
});
5+
test.each([['string', '"string"']])('convertType', (type, expected) => {
6+
expect(convertType(type)).toEqual(expected)
7+
})

__tests__/split-type.test.ts

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
1-
import { expect, test } from "bun:test";
1+
import { expect, test } from 'bun:test'
22

3-
import { splitType } from "../split-type";
3+
import { splitType } from '../split-type'
44

55
test.each([
6-
["string | number", ["string", "number"]],
7-
["string | number | boolean", ["string", "number", "boolean"]],
8-
[
9-
"string | number | boolean | object",
10-
["string", "number", "boolean", "object"],
11-
],
12-
[
13-
"string | number | boolean | object | array",
14-
["string", "number", "boolean", "object", "array"],
15-
],
16-
[
17-
"string | number | boolean | object | array | function",
18-
["string", "number", "boolean", "object", "array", "function"],
19-
],
20-
[
21-
"[ left | right ] || [ top | bottom ]",
22-
["[ left | right ] || [ top | bottom ]"],
23-
],
24-
[
25-
"[ <coord-box> | no-clip | border | padding | content | text ]#",
26-
["[ <coord-box> | no-clip | border | padding | content | text ]#"],
27-
],
28-
[
29-
"normal | <baseline-position> | <content-distribution> | <overflow-position>? <content-position>",
30-
[
31-
"normal",
32-
"<baseline-position>",
33-
"<content-distribution>",
34-
"<overflow-position>? <content-position>",
35-
],
36-
],
37-
["[ auto | <time [0s,∞]> ]#", ["[ auto | <time [0s,∞]> ]#"]],
38-
[
39-
"[ center | [ [ left | right | x-start | x-end ]? <length-percentage>? ]! ]#",
40-
[
41-
"[ center | [ [ left | right | x-start | x-end ]? <length-percentage>? ]! ]#",
42-
],
43-
],
44-
])("splitType", (type, expected) => {
45-
expect(splitType(type)).toEqual(expected);
46-
});
6+
['string | number', ['string', 'number']],
7+
['string | number | boolean', ['string', 'number', 'boolean']],
8+
[
9+
'string | number | boolean | object',
10+
['string', 'number', 'boolean', 'object'],
11+
],
12+
[
13+
'string | number | boolean | object | array',
14+
['string', 'number', 'boolean', 'object', 'array'],
15+
],
16+
[
17+
'string | number | boolean | object | array | function',
18+
['string', 'number', 'boolean', 'object', 'array', 'function'],
19+
],
20+
[
21+
'[ left | right ] || [ top | bottom ]',
22+
['[ left | right ] || [ top | bottom ]'],
23+
],
24+
[
25+
'[ <coord-box> | no-clip | border | padding | content | text ]#',
26+
['[ <coord-box> | no-clip | border | padding | content | text ]#'],
27+
],
28+
[
29+
'normal | <baseline-position> | <content-distribution> | <overflow-position>? <content-position>',
30+
[
31+
'normal',
32+
'<baseline-position>',
33+
'<content-distribution>',
34+
'<overflow-position>? <content-position>',
35+
],
36+
],
37+
['[ auto | <time [0s,∞]> ]#', ['[ auto | <time [0s,∞]> ]#']],
38+
[
39+
'[ center | [ [ left | right | x-start | x-end ]? <length-percentage>? ]! ]#',
40+
[
41+
'[ center | [ [ left | right | x-start | x-end ]? <length-percentage>? ]! ]#',
42+
],
43+
],
44+
])('splitType', (type, expected) => {
45+
expect(splitType(type)).toEqual(expected)
46+
})

biome.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
3+
"vcs": {
4+
"enabled": true,
5+
"clientKind": "git",
6+
"useIgnoreFile": true
7+
},
8+
"files": {
9+
"includes": ["**", "!**/dist"]
10+
},
11+
"javascript": {
12+
"formatter": {
13+
"semicolons": "asNeeded",
14+
"quoteStyle": "single",
15+
"indentStyle": "space",
16+
"indentWidth": 2
17+
}
18+
},
19+
"json": {
20+
"formatter": {
21+
"indentStyle": "space",
22+
"indentWidth": 2
23+
}
24+
}
25+
}

build.ts

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,94 @@
1-
import { convertType } from "./convert-type";
2-
import { toCamelCase } from "./to-camelcase";
3-
import { toPascalCase } from "./to-pascalcase";
1+
import { convertType } from './convert-type'
2+
import { toCamelCase } from './to-camelcase'
3+
import { toPascalCase } from './to-pascalcase'
44

5-
let output = `export as namespace CSS;\nexport interface CustomColors{}\n`;
5+
let output = `/** biome-ignore-all lint/complexity/noBannedTypes: <this is a generated file> */\nexport as namespace CSS;\nexport interface CustomColors{}\n`
66

77
const syntaxes = (await fetch(
8-
"https://raw.githubusercontent.com/mdn/data/refs/heads/main/css/syntaxes.json",
8+
'https://raw.githubusercontent.com/mdn/data/refs/heads/main/css/syntaxes.json',
99
).then((res) => res.json())) as Record<
10-
string,
11-
{
12-
syntax: string;
13-
primitive?: boolean;
14-
}
15-
>;
10+
string,
11+
{
12+
syntax: string
13+
primitive?: boolean
14+
}
15+
>
1616

1717
const properties = (await fetch(
18-
"https://raw.githubusercontent.com/mdn/data/refs/heads/main/css/properties.json",
18+
'https://raw.githubusercontent.com/mdn/data/refs/heads/main/css/properties.json',
1919
).then((res) => res.json())) as Record<
20-
string,
21-
{
22-
syntax: string;
23-
status: string;
24-
}
25-
>;
20+
string,
21+
{
22+
syntax: string
23+
status: string
24+
}
25+
>
2626

2727
const customSyntaxes = {
28-
string: {
29-
syntax: "(string & {})",
30-
primitive: true,
31-
},
32-
number: {
33-
syntax: "number",
34-
primitive: true,
35-
},
36-
percentage: {
37-
syntax: "number",
38-
primitive: true,
39-
},
40-
integer: {
41-
syntax: "number",
42-
primitive: true,
43-
},
44-
};
28+
string: {
29+
syntax: '(string & {})',
30+
primitive: true,
31+
},
32+
number: {
33+
syntax: 'number',
34+
primitive: true,
35+
},
36+
percentage: {
37+
syntax: 'number',
38+
primitive: true,
39+
},
40+
integer: {
41+
syntax: 'number',
42+
primitive: true,
43+
},
44+
}
4545

46-
Object.assign(syntaxes, customSyntaxes);
46+
Object.assign(syntaxes, customSyntaxes)
4747

48-
const standardProperties: string[] = [];
49-
const vendorProperties: [string, { syntax: string; status: string }][] = [];
48+
const standardProperties: string[] = []
49+
const vendorProperties: [string, { syntax: string; status: string }][] = []
5050
for (const [property, value] of Object.entries(properties)) {
51-
// skip vendor prefixed properties
52-
if (property.startsWith("--")) continue;
53-
if (
54-
property.startsWith("-ms-") ||
55-
property.startsWith("-webkit-") ||
56-
property.startsWith("-moz-")
57-
) {
58-
vendorProperties.push([property, value]);
59-
continue;
60-
}
61-
if (value.status !== "standard") continue;
62-
output += `export type ${toPascalCase(property)} = ${convertType(value.syntax, syntaxes)};\n`;
63-
standardProperties.push(property);
51+
// skip vendor prefixed properties
52+
if (property.startsWith('--')) continue
53+
if (
54+
property.startsWith('-ms-') ||
55+
property.startsWith('-webkit-') ||
56+
property.startsWith('-moz-')
57+
) {
58+
vendorProperties.push([property, value])
59+
continue
60+
}
61+
if (value.status !== 'standard') continue
62+
output += `export type ${toPascalCase(property)} = ${convertType(value.syntax, syntaxes)};\n`
63+
standardProperties.push(property)
6464
}
6565

6666
output += `export interface StandardProperties {
67-
${standardProperties.map((p) => ` ${toCamelCase(p)}: ${toPascalCase(p)}`).join("\n")}
68-
}\n`;
67+
${standardProperties.map((p) => ` ${toCamelCase(p)}: ${toPascalCase(p)}`).join('\n')}
68+
}\n`
6969

7070
for (const [property, value] of vendorProperties) {
71-
output += `export type ${toPascalCase(property)} = ${convertType(value.syntax, syntaxes)};\n`;
71+
output += `export type ${toPascalCase(property)} = ${convertType(value.syntax, syntaxes)};\n`
7272
}
7373

7474
output += `export interface VendorProperties {
75-
${vendorProperties.map(([p, _]) => ` ${toCamelCase(p)}: ${toPascalCase(p)}`).join("\n")}
76-
}\n`;
75+
${vendorProperties.map(([p, _]) => ` ${toCamelCase(p)}: ${toPascalCase(p)}`).join('\n')}
76+
}\n`
7777

7878
for (const [property, value] of Object.entries(syntaxes)) {
79-
if (
80-
property.endsWith(")") ||
81-
property.includes("+") ||
82-
value.syntax.includes("@")
83-
)
84-
continue;
85-
if (property in customSyntaxes) {
86-
continue;
87-
}
88-
output += `export type T${toPascalCase(property)} = ${convertType(value.syntax.replace("<image |", "<image> |"), syntaxes)}${property === "color" ? " | keyof CustomColors" : ""};\n`;
79+
if (
80+
property.endsWith(')') ||
81+
property.includes('+') ||
82+
value.syntax.includes('@')
83+
)
84+
continue
85+
if (property in customSyntaxes) {
86+
continue
87+
}
88+
output += `export type T${toPascalCase(property)} = ${convertType(value.syntax.replace('<image |', '<image> |'), syntaxes)}${property === 'color' ? ' | keyof CustomColors' : ''};\n`
8989
}
9090

91-
Bun.write("src/index.d.ts", output);
91+
Bun.write('src/index.d.ts', output)
9292

9393
// declare module "./src" {
9494
// interface CustomColors {

0 commit comments

Comments
 (0)