Skip to content

Commit f530999

Browse files
committed
0.22.9 - simplify setup process, bump bun version
1 parent 8eda8f7 commit f530999

5 files changed

Lines changed: 92 additions & 17 deletions

File tree

.github/workflows/build-test-and-publish.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88
permissions:
99
packages: write
1010

11+
env:
12+
BUN_VERSION: 1.2.22
13+
1114
jobs:
1215
build-test-and-publish:
1316
name: "Build, test, & publish package"
@@ -18,7 +21,7 @@ jobs:
1821
- name: Setup Bun
1922
uses: oven-sh/setup-bun@v2
2023
with:
21-
bun-version: 1.2.21
24+
bun-version: ${{ env.BUN_VERSION }}
2225
- name: Install dependencies with Bun
2326
run: bun install
2427
- name: Build package with Bun

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,25 @@ Package containing code for building TailwindCSS themes that contain SchemaVault
1111
The generated TailwindCSS config sets colors based on CSS variables. It's important that `globals.css` is imported, so that these colors can be resolved. E.g. `var(--foreground)` and `var(--card)` become functional after this CSS import.
1212

1313
```javascript
14-
import "@schemavaults/theme/dist/globals.css"
14+
import "@schemavaults/theme/globals.css"
1515
```
1616

1717
### Import and run the TailwindCSS Config Factory from your `tailwind.config.mjs` or `tailwind.config.ts`
1818

19-
```javascript
19+
#### Simple Example
20+
```typescript
21+
import { SchemaVaultsTailwindConfigFactory } from "@schemavaults/theme";
22+
const config = new SchemaVaultsTailwindConfigFactory().createConfig({
23+
content: [
24+
"./src/**/*.tsx|jsx|js|ts",
25+
"@schemavaults/ui", // resolved and converted to an absolute path to the schemavaults package in the node_modules folder
26+
],
27+
});
28+
export default config;
29+
```
30+
31+
#### More complex example
32+
```typescript
2033
// Import the config factory
2134
import { SchemaVaultsTailwindConfigFactory } from "@schemavaults/theme";
2235
import { join } from "path";

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@schemavaults/theme",
33
"description": "TailwindCSS theme shared by different SchemaVaults applications",
4-
"version": "0.22.8",
4+
"version": "0.22.9",
55
"private": false,
66
"license": "UNLICENSED",
77
"repository": {
@@ -19,8 +19,8 @@
1919
"@types/react": "19.0.0",
2020
"@types/react-dom": "19.0.0",
2121
"tsc-alias": "1.8.16",
22-
"bun-types": "1.2.21",
23-
"typescript": "5.9.2",
22+
"bun-types": "1.2.22",
23+
"typescript": "5.9.3",
2424
"ignore-loader": "0.1.2",
2525
"tailwindcss": "3.4.17"
2626
},
@@ -69,5 +69,5 @@
6969
"publishConfig": {
7070
"access": "public"
7171
},
72-
"packageManager": "bun@1.2.21"
72+
"packageManager": "bun@1.2.22"
7373
}

src/TailwindConfigFactory.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,12 @@ describe("SchemaVaultsTailwindConfigFactory", () => {
5858
});
5959
expect(typeof config === "object").toBeTrue();
6060
});
61+
62+
test("can create a config factory without any options", () => {
63+
const factory = new SchemaVaultsTailwindConfigFactory();
64+
const config = factory.createConfig({
65+
content: ["./src/**/*.ts|tsx|js|jsx"],
66+
});
67+
expect(typeof config === "object").toBeTrue();
68+
});
6169
});

src/TailwindConfigFactory.ts

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@ type OsJoinFn = (
1212
path_segment: string,
1313
...remaining_path_segments: string[]
1414
) => string;
15+
import { lstatSync } from "fs";
1516

1617
// TailwindCSS Plugins:
1718
import tailwindAnimatePlugin from "@/plugins/tailwindcss-animate";
1819

1920
export interface ISchemaVaultsTailwindConfigFactoryInitOptions {
2021
debug?: boolean;
21-
join: OsJoinFn;
22+
join?: OsJoinFn;
2223
// Path (or fn that resolves to a path) to node_modules for application
23-
node_modules: string | (() => string);
24+
node_modules?: string | (() => string);
2425
// Checks whether a path is a directory (e.g. lstatSync(file).isDirectory())
25-
isdir: (path: string) => boolean;
26+
isdir?: (path: string) => boolean;
2627
scope?: string;
2728
// A list of file extensions that should be considered/searched for TailwindCSS className usage. Defaults to ts/tsx/js/jsx
2829
fileExtensions?: readonly string[];
@@ -66,26 +67,76 @@ export class SchemaVaultsTailwindConfigFactory
6667

6768
protected readonly fileExtensionsToIncludeInTailwindClassNamesSearch: readonly string[];
6869

69-
public constructor(opts: ISchemaVaultsTailwindConfigFactoryInitOptions) {
70+
private static defaultJoinImplementation(
71+
path_segment: string,
72+
...remaining_path_segments: string[]
73+
): string {
74+
const path_segments: readonly string[] = [
75+
path_segment,
76+
...remaining_path_segments,
77+
];
78+
return path_segments.join("/");
79+
}
80+
81+
private static defaultIsDirImplementation(maybeDirPath: string): boolean {
82+
return lstatSync(maybeDirPath).isDirectory();
83+
}
84+
85+
private static getDefaultResolveNodeModulesDirectoryPathImplementation(
86+
join: OsJoinFn,
87+
isdir: (dir: string) => boolean,
88+
): () => string {
89+
const cwd = process.cwd();
90+
91+
if (isdir(join(cwd, "node_modules"))) {
92+
return (): string => join(cwd, "node_modules");
93+
} else if (isdir(join(cwd, "..", "node_modules"))) {
94+
return (): string => join(cwd, "..", "node_modules");
95+
} else if (isdir(join(cwd, "..", "..", "node_modules"))) {
96+
return () => join(cwd, "..", "..", "node_modules");
97+
} else {
98+
console.error(
99+
"Failed to resolve path to 'node_modules' directory from SchemaVaultsTailwindConfigFactory!",
100+
);
101+
console.error(
102+
"You can pass a custom resolver function to the config factory constructor to fix this!",
103+
);
104+
process.exit(1);
105+
}
106+
}
107+
108+
public constructor(opts?: ISchemaVaultsTailwindConfigFactoryInitOptions) {
70109
this.debug = opts?.debug ?? false;
71110
if (this.debug) {
72111
console.log("[SchemaVaultsTailwindConfigFactory] constructor()");
73112
}
74-
this.join = opts.join;
113+
this.join =
114+
typeof opts?.join === "function"
115+
? opts.join
116+
: SchemaVaultsTailwindConfigFactory.defaultJoinImplementation;
117+
this.isdir =
118+
typeof opts?.isdir === "function"
119+
? opts.isdir
120+
: SchemaVaultsTailwindConfigFactory.defaultIsDirImplementation;
121+
75122
this.node_modules_path =
76-
typeof opts.node_modules === "string"
123+
typeof opts?.node_modules === "string"
77124
? opts.node_modules
78-
: opts.node_modules();
79-
this.isdir = opts.isdir;
80-
this.scope = opts.scope ?? DefaultOrgScope;
125+
: typeof opts?.node_modules === "function"
126+
? opts.node_modules()
127+
: SchemaVaultsTailwindConfigFactory.getDefaultResolveNodeModulesDirectoryPathImplementation(
128+
this.join,
129+
this.isdir,
130+
)();
131+
this.scope = opts?.scope ?? DefaultOrgScope;
81132
if (this.scope.startsWith("@")) {
82133
throw new Error(
83134
"Don't pass the @ in the scope, we'll handle adding passing that!",
84135
);
85136
}
86137

87138
this.fileExtensionsToIncludeInTailwindClassNamesSearch = Array.isArray(
88-
opts.fileExtensions,
139+
opts?.fileExtensions,
89140
)
90141
? opts.fileExtensions
91142
: SchemaVaultsTailwindConfigFactory.defaultFileExtensionsToSearch;

0 commit comments

Comments
 (0)