uitheme-web 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/dist/cli/index.js +311 -0
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -20,6 +20,24 @@ pnpm add uitheme-web
|
|
|
20
20
|
yarn add uitheme-web
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
+
## Migrating from `@ui-theme/web`
|
|
24
|
+
|
|
25
|
+
This package was published under the name `@ui-theme/web` before the rename. That name is deprecated. Run the migration command to move a project across:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npx uitheme-web migrate
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The command lists the files it will change and asks for confirmation. It then rewrites the import specifiers, the Tailwind `@source` path, and the dependency in `package.json`. The entry point names stay the same, so `/core`, `/react` and `/tanstack` are unchanged.
|
|
32
|
+
|
|
33
|
+
| Option | Effect |
|
|
34
|
+
| ------------- | --------------------------------------- |
|
|
35
|
+
| `--yes` | Rewrite without asking for confirmation |
|
|
36
|
+
| `--cwd <dir>` | Work on a project in another directory |
|
|
37
|
+
| `--help` | Show the help |
|
|
38
|
+
|
|
39
|
+
The command skips `node_modules`, `dist`, `.next` and other build output. It does not change prose in your markdown files.
|
|
40
|
+
|
|
23
41
|
## Tailwind Setup For Prebuilt Components
|
|
24
42
|
|
|
25
43
|
`UIThemeSwitcher`, `UIThemeSelector`, and the bundled select primitives use Tailwind utility classes. `uitheme-web` does not ship a compiled CSS file for those components, so the consuming app must include the package in Tailwind's source scan.
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { parseArgs } from 'util';
|
|
3
|
+
import { readFile, writeFile, readdir } from 'fs/promises';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { createInterface } from 'readline/promises';
|
|
6
|
+
|
|
7
|
+
// ../../node_modules/.pnpm/kleur@4.1.5/node_modules/kleur/colors.mjs
|
|
8
|
+
var FORCE_COLOR;
|
|
9
|
+
var NODE_DISABLE_COLORS;
|
|
10
|
+
var NO_COLOR;
|
|
11
|
+
var TERM;
|
|
12
|
+
var isTTY = true;
|
|
13
|
+
if (typeof process !== "undefined") {
|
|
14
|
+
({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env || {});
|
|
15
|
+
isTTY = process.stdout && process.stdout.isTTY;
|
|
16
|
+
}
|
|
17
|
+
var $ = {
|
|
18
|
+
enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== "dumb" && (FORCE_COLOR != null && FORCE_COLOR !== "0" || isTTY)
|
|
19
|
+
};
|
|
20
|
+
function init(x, y) {
|
|
21
|
+
let rgx = new RegExp(`\\x1b\\[${y}m`, "g");
|
|
22
|
+
let open = `\x1B[${x}m`, close = `\x1B[${y}m`;
|
|
23
|
+
return function(txt) {
|
|
24
|
+
if (!$.enabled || txt == null) return txt;
|
|
25
|
+
return open + (!!~("" + txt).indexOf(close) ? txt.replace(rgx, close + open) : txt) + close;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
var bold = init(1, 22);
|
|
29
|
+
var dim = init(2, 22);
|
|
30
|
+
var red = init(31, 39);
|
|
31
|
+
var green = init(32, 39);
|
|
32
|
+
var yellow = init(33, 39);
|
|
33
|
+
var blue = init(34, 39);
|
|
34
|
+
var cyan = init(36, 39);
|
|
35
|
+
|
|
36
|
+
// src/cli/rewrite.ts
|
|
37
|
+
var OLD_NAME = "@ui-theme/web";
|
|
38
|
+
var NEW_NAME = "uitheme-web";
|
|
39
|
+
var SPECIFIER = /(['"`])@ui-theme\/web(?![@\w-])(\/[^'"`\n]*)?\1/g;
|
|
40
|
+
var NODE_MODULES_PATH = /node_modules\/@ui-theme\/web(?![\w-])/g;
|
|
41
|
+
var PACKAGE_JSON_ENTRY = /"@ui-theme\/web"\s*:\s*"([^"]*)"/g;
|
|
42
|
+
function rewriteModuleSpecifier(source) {
|
|
43
|
+
return source.replace(
|
|
44
|
+
SPECIFIER,
|
|
45
|
+
(_match, quote, subpath) => `${quote}${NEW_NAME}${subpath ?? ""}${quote}`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
function rewriteNodeModulesPath(source) {
|
|
49
|
+
return source.replace(NODE_MODULES_PATH, `node_modules/${NEW_NAME}`);
|
|
50
|
+
}
|
|
51
|
+
function rewriteSource(source) {
|
|
52
|
+
return rewriteNodeModulesPath(rewriteModuleSpecifier(source));
|
|
53
|
+
}
|
|
54
|
+
function rewritePackageJson(source, version) {
|
|
55
|
+
let keptRange = false;
|
|
56
|
+
const text = source.replace(PACKAGE_JSON_ENTRY, (_match, range) => {
|
|
57
|
+
if (version === null) {
|
|
58
|
+
keptRange = true;
|
|
59
|
+
return `"${NEW_NAME}": "${range}"`;
|
|
60
|
+
}
|
|
61
|
+
return `"${NEW_NAME}": "^${version}"`;
|
|
62
|
+
});
|
|
63
|
+
return { text, changed: text !== source, keptRange };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// src/cli/migrate.ts
|
|
67
|
+
var SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
68
|
+
".ts",
|
|
69
|
+
".tsx",
|
|
70
|
+
".js",
|
|
71
|
+
".jsx",
|
|
72
|
+
".mjs",
|
|
73
|
+
".cjs",
|
|
74
|
+
".mts",
|
|
75
|
+
".cts",
|
|
76
|
+
".css"
|
|
77
|
+
]);
|
|
78
|
+
var IGNORED_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
79
|
+
"node_modules",
|
|
80
|
+
".git",
|
|
81
|
+
".next",
|
|
82
|
+
".output",
|
|
83
|
+
".svelte-kit",
|
|
84
|
+
".turbo",
|
|
85
|
+
".vercel",
|
|
86
|
+
".cache",
|
|
87
|
+
"build",
|
|
88
|
+
"coverage",
|
|
89
|
+
"dist",
|
|
90
|
+
"out"
|
|
91
|
+
]);
|
|
92
|
+
var MAX_DEPTH = 12;
|
|
93
|
+
async function readOwnVersion() {
|
|
94
|
+
try {
|
|
95
|
+
const manifestUrl = new URL("../../package.json", import.meta.url);
|
|
96
|
+
const manifest = JSON.parse(await readFile(manifestUrl, "utf8"));
|
|
97
|
+
return manifest.version ?? null;
|
|
98
|
+
} catch {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async function collectSourceFiles(root, directory, depth) {
|
|
103
|
+
if (depth > MAX_DEPTH) {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
107
|
+
const files = [];
|
|
108
|
+
for (const entry of entries) {
|
|
109
|
+
const full = path.join(directory, entry.name);
|
|
110
|
+
if (entry.isDirectory()) {
|
|
111
|
+
if (IGNORED_DIRECTORIES.has(entry.name)) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
files.push(...await collectSourceFiles(root, full, depth + 1));
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (!entry.isFile()) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (SOURCE_EXTENSIONS.has(path.extname(entry.name))) {
|
|
121
|
+
files.push(full);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return files;
|
|
125
|
+
}
|
|
126
|
+
async function planSourceChanges(root) {
|
|
127
|
+
const changes = [];
|
|
128
|
+
for (const file of await collectSourceFiles(root, root, 0)) {
|
|
129
|
+
const before = await readFile(file, "utf8");
|
|
130
|
+
const after = rewriteSource(before);
|
|
131
|
+
if (after !== before) {
|
|
132
|
+
changes.push({ file, before, after });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return changes;
|
|
136
|
+
}
|
|
137
|
+
async function planPackageJsonChange(root, version) {
|
|
138
|
+
const file = path.join(root, "package.json");
|
|
139
|
+
let before;
|
|
140
|
+
try {
|
|
141
|
+
before = await readFile(file, "utf8");
|
|
142
|
+
} catch {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
const {
|
|
146
|
+
text: after,
|
|
147
|
+
changed,
|
|
148
|
+
keptRange
|
|
149
|
+
} = rewritePackageJson(before, version);
|
|
150
|
+
if (!changed) {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
return { file, before, after, keptRange };
|
|
154
|
+
}
|
|
155
|
+
async function confirm(question) {
|
|
156
|
+
const prompt = createInterface({
|
|
157
|
+
input: process.stdin,
|
|
158
|
+
output: process.stdout
|
|
159
|
+
});
|
|
160
|
+
try {
|
|
161
|
+
const answer = await prompt.question(question);
|
|
162
|
+
return /^y(es)?$/i.test(answer.trim());
|
|
163
|
+
} finally {
|
|
164
|
+
prompt.close();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function reportPlan(root, source, manifest) {
|
|
168
|
+
process.stdout.write("\n");
|
|
169
|
+
if (source.length === 0 && manifest === null) {
|
|
170
|
+
process.stdout.write(
|
|
171
|
+
`${green("Nothing to do.")} No file mentions ${OLD_NAME}.
|
|
172
|
+
|
|
173
|
+
`
|
|
174
|
+
);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
process.stdout.write(
|
|
178
|
+
`The migration will rewrite ${bold(String(source.length + (manifest ? 1 : 0)))} file(s):
|
|
179
|
+
|
|
180
|
+
`
|
|
181
|
+
);
|
|
182
|
+
for (const change of source) {
|
|
183
|
+
process.stdout.write(` ${blue(path.relative(root, change.file))}
|
|
184
|
+
`);
|
|
185
|
+
}
|
|
186
|
+
if (manifest) {
|
|
187
|
+
process.stdout.write(` ${blue(path.relative(root, manifest.file))}
|
|
188
|
+
`);
|
|
189
|
+
}
|
|
190
|
+
process.stdout.write(`
|
|
191
|
+
${OLD_NAME} becomes ${NEW_NAME}.
|
|
192
|
+
`);
|
|
193
|
+
process.stdout.write(
|
|
194
|
+
`${dim("Entry points keep their names: /core, /react and /tanstack.")}
|
|
195
|
+
|
|
196
|
+
`
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
async function applyChange(change) {
|
|
200
|
+
await writeFile(change.file, change.after, "utf8");
|
|
201
|
+
}
|
|
202
|
+
async function runMigrate(options) {
|
|
203
|
+
const root = path.resolve(options.cwd);
|
|
204
|
+
const version = await readOwnVersion();
|
|
205
|
+
const source = await planSourceChanges(root);
|
|
206
|
+
const manifest = await planPackageJsonChange(root, version);
|
|
207
|
+
reportPlan(root, source, manifest);
|
|
208
|
+
if (source.length === 0 && manifest === null) {
|
|
209
|
+
return 0;
|
|
210
|
+
}
|
|
211
|
+
if (!options.yes) {
|
|
212
|
+
const proceed = await confirm(`Rewrite these files? ${dim("[y/N]")} `);
|
|
213
|
+
if (!proceed) {
|
|
214
|
+
process.stdout.write(`
|
|
215
|
+
${yellow("Cancelled.")} No file was changed.
|
|
216
|
+
`);
|
|
217
|
+
return 0;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
for (const change of source) {
|
|
221
|
+
await applyChange(change);
|
|
222
|
+
}
|
|
223
|
+
if (manifest) {
|
|
224
|
+
await applyChange(manifest);
|
|
225
|
+
}
|
|
226
|
+
const total = source.length + (manifest ? 1 : 0);
|
|
227
|
+
process.stdout.write(
|
|
228
|
+
`
|
|
229
|
+
${green("Done.")} Rewrote ${bold(String(total))} file(s).
|
|
230
|
+
`
|
|
231
|
+
);
|
|
232
|
+
process.stdout.write(
|
|
233
|
+
`Install the new package with ${cyan(`${bold(NEW_NAME)}`)} and run your package manager.
|
|
234
|
+
|
|
235
|
+
`
|
|
236
|
+
);
|
|
237
|
+
if (manifest?.keptRange) {
|
|
238
|
+
process.stdout.write(
|
|
239
|
+
`${yellow("Note.")} The command could not read its own version, so the dependency range in package.json was left as it was. Set it to ^${NEW_NAME}'s current version by hand.
|
|
240
|
+
|
|
241
|
+
`
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
return 0;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// src/cli/index.ts
|
|
248
|
+
var USAGE = `${bold("uitheme-web")}
|
|
249
|
+
|
|
250
|
+
${bold("Usage")}
|
|
251
|
+
uitheme-web <command> [options]
|
|
252
|
+
|
|
253
|
+
${bold("Commands")}
|
|
254
|
+
migrate Move a project from @ui-theme/web to uitheme-web
|
|
255
|
+
|
|
256
|
+
${bold("Options")}
|
|
257
|
+
-c, --cwd <dir> Project directory. Defaults to the current directory
|
|
258
|
+
-y, --yes Rewrite without asking for confirmation
|
|
259
|
+
-h, --help Show this help
|
|
260
|
+
|
|
261
|
+
${dim("Example")}
|
|
262
|
+
npx uitheme-web migrate
|
|
263
|
+
`;
|
|
264
|
+
function fail(message) {
|
|
265
|
+
process.stderr.write(`${red(message)}
|
|
266
|
+
|
|
267
|
+
${USAGE}`);
|
|
268
|
+
process.exit(1);
|
|
269
|
+
}
|
|
270
|
+
async function main(argv) {
|
|
271
|
+
let values;
|
|
272
|
+
let positionals;
|
|
273
|
+
try {
|
|
274
|
+
const parsed = parseArgs({
|
|
275
|
+
args: argv,
|
|
276
|
+
allowPositionals: true,
|
|
277
|
+
options: {
|
|
278
|
+
cwd: { type: "string", short: "c" },
|
|
279
|
+
yes: { type: "boolean", short: "y", default: false },
|
|
280
|
+
help: { type: "boolean", short: "h", default: false }
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
values = parsed.values;
|
|
284
|
+
positionals = parsed.positionals;
|
|
285
|
+
} catch (error) {
|
|
286
|
+
fail(error instanceof Error ? error.message : String(error));
|
|
287
|
+
}
|
|
288
|
+
const [command, ...rest] = positionals;
|
|
289
|
+
if (values.help || command === void 0 || command === "help") {
|
|
290
|
+
process.stdout.write(USAGE);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (rest.length > 0) {
|
|
294
|
+
fail(`Unexpected argument: ${rest.join(" ")}`);
|
|
295
|
+
}
|
|
296
|
+
if (command === "migrate") {
|
|
297
|
+
await runMigrate({
|
|
298
|
+
cwd: values.cwd ?? process.cwd(),
|
|
299
|
+
yes: values.yes ?? false
|
|
300
|
+
});
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
fail(`Unknown command: ${command}`);
|
|
304
|
+
}
|
|
305
|
+
main(process.argv.slice(2)).catch((error) => {
|
|
306
|
+
process.stderr.write(
|
|
307
|
+
`${red("The command failed.")} ${error instanceof Error ? error.message : String(error)}
|
|
308
|
+
`
|
|
309
|
+
);
|
|
310
|
+
process.exitCode = 1;
|
|
311
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uitheme-web",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Cross-framework UI theme switching library",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -67,6 +67,9 @@
|
|
|
67
67
|
"README.md",
|
|
68
68
|
"LICENSE"
|
|
69
69
|
],
|
|
70
|
+
"bin": {
|
|
71
|
+
"uitheme-web": "./dist/cli/index.js"
|
|
72
|
+
},
|
|
70
73
|
"peerDependencies": {
|
|
71
74
|
"@radix-ui/react-select": ">=2.0.0",
|
|
72
75
|
"react": ">=18.0.0",
|
|
@@ -86,13 +89,14 @@
|
|
|
86
89
|
"@radix-ui/react-select": "^2.1.0",
|
|
87
90
|
"@types/react": "^19.0.0",
|
|
88
91
|
"@types/react-dom": "^19.0.0",
|
|
92
|
+
"kleur": "^4.1.5",
|
|
89
93
|
"react": "^19.0.0",
|
|
90
94
|
"react-dom": "^19.0.0",
|
|
91
95
|
"svelte": "^5.0.0",
|
|
92
96
|
"vue": "^3.5.0"
|
|
93
97
|
},
|
|
94
98
|
"scripts": {
|
|
95
|
-
"build": "tsup",
|
|
99
|
+
"build": "rm -rf dist && tsup",
|
|
96
100
|
"dev": "tsup --watch",
|
|
97
101
|
"typecheck": "tsc --noEmit",
|
|
98
102
|
"test": "vitest run --passWithNoTests",
|