@birdycom/omniacss-cli 0.11.0 → 0.11.1
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/LICENSE +21 -21
- package/bin/omniacss.mjs +234 -234
- package/package.json +45 -45
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Serge Cools (Birdycom)
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Serge Cools (Birdycom)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/bin/omniacss.mjs
CHANGED
|
@@ -1,235 +1,235 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// File: packages/cli/bin/omniacss.mjs
|
|
3
|
-
// OmniaCSS CLI — init a project, build on-demand CSS, migrate from Tailwind CSS.
|
|
4
|
-
// Map: args -> config -> commands (init | build | purge | migrate | tokens | add/list moved notice) -> output
|
|
5
|
-
// Author: Serge Cools | Framework: OmniaCSS
|
|
6
|
-
// Components and blocks moved to OmniaUI (October 2026): "npx omniaui add <name>" copies them now.
|
|
7
|
-
// "omniacss build" still includes the OmniaUI CSS when @birdycom/omniaui(-blocks) is installed.
|
|
8
|
-
|
|
9
|
-
import fs from "node:fs/promises";
|
|
10
|
-
import { watch } from "node:fs";
|
|
11
|
-
import path from "node:path";
|
|
12
|
-
import { createRequire } from "node:module";
|
|
13
|
-
import { parseArgs } from "node:util";
|
|
14
|
-
import { pathToFileURL } from "node:url";
|
|
15
|
-
|
|
16
|
-
const cwd = process.cwd();
|
|
17
|
-
const CONFIG = "omnia.config.json";
|
|
18
|
-
const requireFromProject = createRequire(path.join(cwd, "package.json"));
|
|
19
|
-
const requireFromCli = createRequire(import.meta.url);
|
|
20
|
-
|
|
21
|
-
/** Resolve a file of a package: the project's own install first, then the CLI's dependency. */
|
|
22
|
-
function resolvePkg(spec) {
|
|
23
|
-
for (const req of [requireFromProject, requireFromCli]) {
|
|
24
|
-
try { return req.resolve(spec); } catch { /* try next */ }
|
|
25
|
-
}
|
|
26
|
-
throw new Error(`Cannot find ${spec}. Install it with: npm install ${spec.split("/").slice(0, 2).join("/")}`);
|
|
27
|
-
}
|
|
28
|
-
const pkgDir = (name) => path.dirname(resolvePkg(`${name}/package.json`));
|
|
29
|
-
|
|
30
|
-
/** Folder of an optional package, or null when it is not installed. */
|
|
31
|
-
function optionalPkgDir(name) {
|
|
32
|
-
try { return pkgDir(name); } catch { return null; }
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Shown for the old "add" / "list" commands (they live in the omniaui CLI now).
|
|
36
|
-
const MOVED = "Components and blocks moved to OmniaUI: npx omniaui add <name> (npm i -D @birdycom/omniaui)";
|
|
37
|
-
|
|
38
|
-
const HELP = `
|
|
39
|
-
OmniaCSS CLI
|
|
40
|
-
|
|
41
|
-
omniacss init create omnia.config.json and an entry CSS file
|
|
42
|
-
omniacss build [--watch] [--minify] write only the CSS your project uses
|
|
43
|
-
omniacss migrate <scan|setup|codemod> switch a project from Tailwind CSS and keep its class names (needs @birdycom/omniacss-migrate)
|
|
44
|
-
omniacss migrate bootstrap <scan|codemod> convert a Bootstrap 3/4/5 site to OmniaCSS + OmniaUI
|
|
45
|
-
omniacss tokens [--format json|dtcg|python|css] [--out <file>|-] [--source <semantic.json>]
|
|
46
|
-
export the theme tokens for desktop apps (resolved per light/dark, sRGB hex)
|
|
47
|
-
|
|
48
|
-
Options for build (override omnia.config.json):
|
|
49
|
-
-c, --content <glob> content files to scan (repeatable)
|
|
50
|
-
-o, --output <file> output CSS file
|
|
51
|
-
--no-components do not include the OmniaUI component CSS (@birdycom/omniaui, when installed)
|
|
52
|
-
--no-layer do not wrap the output in @layer omnia
|
|
53
|
-
|
|
54
|
-
Components and blocks: ${MOVED}
|
|
55
|
-
`;
|
|
56
|
-
|
|
57
|
-
async function readJson(file) {
|
|
58
|
-
return JSON.parse(await fs.readFile(file, "utf8"));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async function loadConfig(flags) {
|
|
62
|
-
let config = {};
|
|
63
|
-
try { config = await readJson(path.join(cwd, CONFIG)); } catch { /* defaults below */ }
|
|
64
|
-
return {
|
|
65
|
-
content: flags.content?.length ? flags.content : config.content || ["**/*.html"],
|
|
66
|
-
output: flags.output || config.output || "omnia.css",
|
|
67
|
-
// "auto" (default): include the OmniaUI CSS when installed, skip silently when not.
|
|
68
|
-
components: flags["no-components"] ? false : config.components ?? "auto",
|
|
69
|
-
blocks: config.blocks ?? false,
|
|
70
|
-
// OmniaUI Pro (licensed): included when installed, like the components.
|
|
71
|
-
pro: config.pro ?? "auto",
|
|
72
|
-
layer: flags["no-layer"] ? false : config.layer ?? "omnia",
|
|
73
|
-
keep: config.keep || [],
|
|
74
|
-
minify: flags.minify ?? config.minify ?? false,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** Detect the project type so `init` can propose sensible content globs. */
|
|
79
|
-
async function detectContent() {
|
|
80
|
-
const exists = async (p) => !!(await fs.stat(path.join(cwd, p)).catch(() => null));
|
|
81
|
-
if (await exists("artisan")) return ["resources/views/**/*.blade.php", "resources/js/**/*.{js,ts,jsx,tsx,vue}"];
|
|
82
|
-
if (await exists("astro.config.mjs")) return ["src/**/*.{astro,html,md,mdx,jsx,tsx,vue,svelte}"];
|
|
83
|
-
if (await exists("nuxt.config.ts")) return ["{app,components,pages,layouts}/**/*.vue"];
|
|
84
|
-
if (await exists("src")) return ["index.html", "src/**/*.{html,js,ts,jsx,tsx,vue,svelte}"];
|
|
85
|
-
return ["**/*.html"];
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async function cmdInit() {
|
|
89
|
-
const configPath = path.join(cwd, CONFIG);
|
|
90
|
-
if (await fs.stat(configPath).catch(() => null)) {
|
|
91
|
-
console.log(`${CONFIG} already exists — nothing to do.`);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
const content = [...(await detectContent()), "omnia/**/*.html"];
|
|
95
|
-
const config = { $schema: "https://omniacss.eu/schema/omnia.config.json", content, output: "public/css/omnia.css", layer: "omnia", keep: [], minify: false };
|
|
96
|
-
await fs.writeFile(configPath, JSON.stringify(config, null, 2) + "\n");
|
|
97
|
-
console.log(`Created ${CONFIG} (content: ${content.join(", ")})
|
|
98
|
-
|
|
99
|
-
Next steps
|
|
100
|
-
1. npx omniacss build --watch (development)
|
|
101
|
-
2. npx omniacss build --minify (production)
|
|
102
|
-
3. <link rel="stylesheet" href="/css/omnia.css">
|
|
103
|
-
|
|
104
|
-
Using Vite / PostCSS instead? Add the plugin and put "@omnia;" in your CSS:
|
|
105
|
-
import omniacss from "@birdycom/omniacss/postcss";
|
|
106
|
-
export default { plugins: [omniacss({ content: ${JSON.stringify(content)} })] };`);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Extra CSS from OmniaUI (optional): components and blocks, only when the packages are installed.
|
|
111
|
-
* The utilities they use are kept by the engine like any other CSS in the input.
|
|
112
|
-
*/
|
|
113
|
-
async function omniauiCss(config) {
|
|
114
|
-
let css = "";
|
|
115
|
-
const parts = [["components", "@birdycom/omniaui", "dist/components.css"], ["blocks", "@birdycom/omniaui-blocks", "dist/blocks.css"], ["pro", "@birdycom/omniaui-pro", "dist/pro.css"]];
|
|
116
|
-
for (const [key, name, file] of parts) {
|
|
117
|
-
if (!config[key]) continue;
|
|
118
|
-
const dir = optionalPkgDir(name);
|
|
119
|
-
if (dir) css += "\n" + (await fs.readFile(path.join(dir, file), "utf8"));
|
|
120
|
-
else if (config[key] !== "auto") console.log(`omniacss: "${key}" is on but ${name} is not installed — skipped (npm i -D ${name}).`);
|
|
121
|
-
}
|
|
122
|
-
return css;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async function cmdBuild(flags) {
|
|
126
|
-
const config = await loadConfig(flags);
|
|
127
|
-
const engine = await import(pathToFileURL(resolvePkg("@birdycom/omniacss/engine")).href);
|
|
128
|
-
|
|
129
|
-
const run = async () => {
|
|
130
|
-
const started = Date.now();
|
|
131
|
-
const { candidates, files } = await engine.collectCandidates(config.content, cwd);
|
|
132
|
-
let full = await engine.loadFullCss({ dist: path.join(pkgDir("@birdycom/omniacss"), "dist") });
|
|
133
|
-
full += await omniauiCss(config);
|
|
134
|
-
let css = engine.generate(full, candidates, { layer: config.layer, keep: config.keep });
|
|
135
|
-
if (config.minify) {
|
|
136
|
-
const { transform } = await import("lightningcss");
|
|
137
|
-
css = transform({ filename: config.output, code: Buffer.from(css), minify: true }).code.toString();
|
|
138
|
-
}
|
|
139
|
-
const out = path.resolve(cwd, config.output);
|
|
140
|
-
await fs.mkdir(path.dirname(out), { recursive: true });
|
|
141
|
-
await fs.writeFile(out, css);
|
|
142
|
-
console.log(`omniacss: ${files.length} files scanned → ${path.relative(cwd, out)} (${(css.length / 1024).toFixed(1)} KB) in ${Date.now() - started}ms`);
|
|
143
|
-
return files;
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
const files = await run();
|
|
147
|
-
if (!flags.watch) return;
|
|
148
|
-
|
|
149
|
-
const dirs = new Set(files.map((f) => path.dirname(f)));
|
|
150
|
-
let timer;
|
|
151
|
-
console.log(`omniacss: watching ${dirs.size} folder(s) — Ctrl+C to stop`);
|
|
152
|
-
for (const dir of dirs) {
|
|
153
|
-
watch(dir, () => {
|
|
154
|
-
clearTimeout(timer);
|
|
155
|
-
timer = setTimeout(() => run().catch((e) => console.error(e.message)), 120);
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/** `omniacss migrate ...` delegates to @birdycom/omniacss-migrate (optional package). */
|
|
161
|
-
async function cmdMigrate(args) {
|
|
162
|
-
let file;
|
|
163
|
-
try { file = resolvePkg("@birdycom/omniacss-migrate/cli"); } catch { throw new Error("The migrate command needs @birdycom/omniacss-migrate. Install it with: npm install -D @birdycom/omniacss-migrate"); }
|
|
164
|
-
const { run } = await import(pathToFileURL(file).href);
|
|
165
|
-
return run(args);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* `omniacss tokens` — the semantic theme tokens resolved for non-web apps (desktop toolkits have no CSS engine):
|
|
170
|
-
* per mode (light/dark), no var() left, sRGB hex gamut mapped the CSS Color 4 way, OmniaCSS version stamped.
|
|
171
|
-
*/
|
|
172
|
-
async function cmdTokens(args) {
|
|
173
|
-
const { values } = parseArgs({
|
|
174
|
-
args,
|
|
175
|
-
options: {
|
|
176
|
-
format: { type: "string", short: "f", default: "json" },
|
|
177
|
-
out: { type: "string", short: "o" },
|
|
178
|
-
source: { type: "string", short: "s" },
|
|
179
|
-
},
|
|
180
|
-
});
|
|
181
|
-
const tokens = await import(pathToFileURL(resolvePkg("@birdycom/omniacss/tokens/export")).href);
|
|
182
|
-
const core = pkgDir("@birdycom/omniacss");
|
|
183
|
-
const { version } = await readJson(path.join(core, "package.json"));
|
|
184
|
-
const semantic = await tokens.loadSemantic(values.source ? path.resolve(cwd, values.source) : undefined);
|
|
185
|
-
const format = values.format;
|
|
186
|
-
let text;
|
|
187
|
-
if (format === "css") text = tokens.toCss(semantic, version);
|
|
188
|
-
else if (tokens.FORMATS[format]) text = tokens.FORMATS[format](tokens.buildExport(semantic, await tokens.loadPalette(path.join(core, "dist")), version));
|
|
189
|
-
else throw new Error(`unknown format "${format}" (use json, dtcg, python or css)`);
|
|
190
|
-
if (values.out === "-") { process.stdout.write(text); return; }
|
|
191
|
-
const out = path.resolve(cwd, values.out || (format === "css" ? "oc-theme.css" : tokens.EXTENSIONS[format]));
|
|
192
|
-
await fs.mkdir(path.dirname(out), { recursive: true });
|
|
193
|
-
await fs.writeFile(out, text);
|
|
194
|
-
console.log(`omniacss: ${format} tokens (OmniaCSS ${version}) → ${path.relative(cwd, out)}`);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
async function main() {
|
|
198
|
-
if (process.argv[2] === "migrate") return cmdMigrate(process.argv.slice(3));
|
|
199
|
-
if (process.argv[2] === "tokens") return cmdTokens(process.argv.slice(3));
|
|
200
|
-
// add/list moved to OmniaUI: answer before parsing so their old flags (-f, --kind …) do not fail.
|
|
201
|
-
if (["add", "list"].includes(process.argv[2])) {
|
|
202
|
-
console.log(MOVED);
|
|
203
|
-
process.exitCode = 1;
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
const { values, positionals } = parseArgs({
|
|
207
|
-
allowPositionals: true,
|
|
208
|
-
options: {
|
|
209
|
-
content: { type: "string", short: "c", multiple: true },
|
|
210
|
-
output: { type: "string", short: "o" },
|
|
211
|
-
watch: { type: "boolean", short: "w" },
|
|
212
|
-
minify: { type: "boolean", short: "m" },
|
|
213
|
-
"no-components": { type: "boolean" },
|
|
214
|
-
"no-layer": { type: "boolean" },
|
|
215
|
-
help: { type: "boolean", short: "h" },
|
|
216
|
-
version: { type: "boolean", short: "v" },
|
|
217
|
-
},
|
|
218
|
-
});
|
|
219
|
-
const [command] = positionals;
|
|
220
|
-
if (values.version) {
|
|
221
|
-
console.log((await readJson(new URL("../package.json", import.meta.url))).version);
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
switch (command) {
|
|
225
|
-
case "init": return cmdInit();
|
|
226
|
-
case "build": return cmdBuild(values);
|
|
227
|
-
case "purge": return cmdBuild({ ...values, "no-components": true }); // backwards compatible alias
|
|
228
|
-
default: console.log(HELP);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
main().catch((err) => {
|
|
233
|
-
console.error(`omniacss: ${err.message}`);
|
|
234
|
-
process.exit(1);
|
|
235
|
-
});
|
|
2
|
+
// File: packages/cli/bin/omniacss.mjs
|
|
3
|
+
// OmniaCSS CLI — init a project, build on-demand CSS, migrate from Tailwind CSS.
|
|
4
|
+
// Map: args -> config -> commands (init | build | purge | migrate | tokens | add/list moved notice) -> output
|
|
5
|
+
// Author: Serge Cools | Framework: OmniaCSS
|
|
6
|
+
// Components and blocks moved to OmniaUI (October 2026): "npx omniaui add <name>" copies them now.
|
|
7
|
+
// "omniacss build" still includes the OmniaUI CSS when @birdycom/omniaui(-blocks) is installed.
|
|
8
|
+
|
|
9
|
+
import fs from "node:fs/promises";
|
|
10
|
+
import { watch } from "node:fs";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import { createRequire } from "node:module";
|
|
13
|
+
import { parseArgs } from "node:util";
|
|
14
|
+
import { pathToFileURL } from "node:url";
|
|
15
|
+
|
|
16
|
+
const cwd = process.cwd();
|
|
17
|
+
const CONFIG = "omnia.config.json";
|
|
18
|
+
const requireFromProject = createRequire(path.join(cwd, "package.json"));
|
|
19
|
+
const requireFromCli = createRequire(import.meta.url);
|
|
20
|
+
|
|
21
|
+
/** Resolve a file of a package: the project's own install first, then the CLI's dependency. */
|
|
22
|
+
function resolvePkg(spec) {
|
|
23
|
+
for (const req of [requireFromProject, requireFromCli]) {
|
|
24
|
+
try { return req.resolve(spec); } catch { /* try next */ }
|
|
25
|
+
}
|
|
26
|
+
throw new Error(`Cannot find ${spec}. Install it with: npm install ${spec.split("/").slice(0, 2).join("/")}`);
|
|
27
|
+
}
|
|
28
|
+
const pkgDir = (name) => path.dirname(resolvePkg(`${name}/package.json`));
|
|
29
|
+
|
|
30
|
+
/** Folder of an optional package, or null when it is not installed. */
|
|
31
|
+
function optionalPkgDir(name) {
|
|
32
|
+
try { return pkgDir(name); } catch { return null; }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Shown for the old "add" / "list" commands (they live in the omniaui CLI now).
|
|
36
|
+
const MOVED = "Components and blocks moved to OmniaUI: npx omniaui add <name> (npm i -D @birdycom/omniaui)";
|
|
37
|
+
|
|
38
|
+
const HELP = `
|
|
39
|
+
OmniaCSS CLI
|
|
40
|
+
|
|
41
|
+
omniacss init create omnia.config.json and an entry CSS file
|
|
42
|
+
omniacss build [--watch] [--minify] write only the CSS your project uses
|
|
43
|
+
omniacss migrate <scan|setup|codemod> switch a project from Tailwind CSS and keep its class names (needs @birdycom/omniacss-migrate)
|
|
44
|
+
omniacss migrate bootstrap <scan|codemod> convert a Bootstrap 3/4/5 site to OmniaCSS + OmniaUI
|
|
45
|
+
omniacss tokens [--format json|dtcg|python|css] [--out <file>|-] [--source <semantic.json>]
|
|
46
|
+
export the theme tokens for desktop apps (resolved per light/dark, sRGB hex)
|
|
47
|
+
|
|
48
|
+
Options for build (override omnia.config.json):
|
|
49
|
+
-c, --content <glob> content files to scan (repeatable)
|
|
50
|
+
-o, --output <file> output CSS file
|
|
51
|
+
--no-components do not include the OmniaUI component CSS (@birdycom/omniaui, when installed)
|
|
52
|
+
--no-layer do not wrap the output in @layer omnia
|
|
53
|
+
|
|
54
|
+
Components and blocks: ${MOVED}
|
|
55
|
+
`;
|
|
56
|
+
|
|
57
|
+
async function readJson(file) {
|
|
58
|
+
return JSON.parse(await fs.readFile(file, "utf8"));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function loadConfig(flags) {
|
|
62
|
+
let config = {};
|
|
63
|
+
try { config = await readJson(path.join(cwd, CONFIG)); } catch { /* defaults below */ }
|
|
64
|
+
return {
|
|
65
|
+
content: flags.content?.length ? flags.content : config.content || ["**/*.html"],
|
|
66
|
+
output: flags.output || config.output || "omnia.css",
|
|
67
|
+
// "auto" (default): include the OmniaUI CSS when installed, skip silently when not.
|
|
68
|
+
components: flags["no-components"] ? false : config.components ?? "auto",
|
|
69
|
+
blocks: config.blocks ?? false,
|
|
70
|
+
// OmniaUI Pro (licensed): included when installed, like the components.
|
|
71
|
+
pro: config.pro ?? "auto",
|
|
72
|
+
layer: flags["no-layer"] ? false : config.layer ?? "omnia",
|
|
73
|
+
keep: config.keep || [],
|
|
74
|
+
minify: flags.minify ?? config.minify ?? false,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Detect the project type so `init` can propose sensible content globs. */
|
|
79
|
+
async function detectContent() {
|
|
80
|
+
const exists = async (p) => !!(await fs.stat(path.join(cwd, p)).catch(() => null));
|
|
81
|
+
if (await exists("artisan")) return ["resources/views/**/*.blade.php", "resources/js/**/*.{js,ts,jsx,tsx,vue}"];
|
|
82
|
+
if (await exists("astro.config.mjs")) return ["src/**/*.{astro,html,md,mdx,jsx,tsx,vue,svelte}"];
|
|
83
|
+
if (await exists("nuxt.config.ts")) return ["{app,components,pages,layouts}/**/*.vue"];
|
|
84
|
+
if (await exists("src")) return ["index.html", "src/**/*.{html,js,ts,jsx,tsx,vue,svelte}"];
|
|
85
|
+
return ["**/*.html"];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function cmdInit() {
|
|
89
|
+
const configPath = path.join(cwd, CONFIG);
|
|
90
|
+
if (await fs.stat(configPath).catch(() => null)) {
|
|
91
|
+
console.log(`${CONFIG} already exists — nothing to do.`);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const content = [...(await detectContent()), "omnia/**/*.html"];
|
|
95
|
+
const config = { $schema: "https://omniacss.eu/schema/omnia.config.json", content, output: "public/css/omnia.css", layer: "omnia", keep: [], minify: false };
|
|
96
|
+
await fs.writeFile(configPath, JSON.stringify(config, null, 2) + "\n");
|
|
97
|
+
console.log(`Created ${CONFIG} (content: ${content.join(", ")})
|
|
98
|
+
|
|
99
|
+
Next steps
|
|
100
|
+
1. npx omniacss build --watch (development)
|
|
101
|
+
2. npx omniacss build --minify (production)
|
|
102
|
+
3. <link rel="stylesheet" href="/css/omnia.css">
|
|
103
|
+
|
|
104
|
+
Using Vite / PostCSS instead? Add the plugin and put "@omnia;" in your CSS:
|
|
105
|
+
import omniacss from "@birdycom/omniacss/postcss";
|
|
106
|
+
export default { plugins: [omniacss({ content: ${JSON.stringify(content)} })] };`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Extra CSS from OmniaUI (optional): components and blocks, only when the packages are installed.
|
|
111
|
+
* The utilities they use are kept by the engine like any other CSS in the input.
|
|
112
|
+
*/
|
|
113
|
+
async function omniauiCss(config) {
|
|
114
|
+
let css = "";
|
|
115
|
+
const parts = [["components", "@birdycom/omniaui", "dist/components.css"], ["blocks", "@birdycom/omniaui-blocks", "dist/blocks.css"], ["pro", "@birdycom/omniaui-pro", "dist/pro.css"]];
|
|
116
|
+
for (const [key, name, file] of parts) {
|
|
117
|
+
if (!config[key]) continue;
|
|
118
|
+
const dir = optionalPkgDir(name);
|
|
119
|
+
if (dir) css += "\n" + (await fs.readFile(path.join(dir, file), "utf8"));
|
|
120
|
+
else if (config[key] !== "auto") console.log(`omniacss: "${key}" is on but ${name} is not installed — skipped (npm i -D ${name}).`);
|
|
121
|
+
}
|
|
122
|
+
return css;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function cmdBuild(flags) {
|
|
126
|
+
const config = await loadConfig(flags);
|
|
127
|
+
const engine = await import(pathToFileURL(resolvePkg("@birdycom/omniacss/engine")).href);
|
|
128
|
+
|
|
129
|
+
const run = async () => {
|
|
130
|
+
const started = Date.now();
|
|
131
|
+
const { candidates, files } = await engine.collectCandidates(config.content, cwd);
|
|
132
|
+
let full = await engine.loadFullCss({ dist: path.join(pkgDir("@birdycom/omniacss"), "dist") });
|
|
133
|
+
full += await omniauiCss(config);
|
|
134
|
+
let css = engine.generate(full, candidates, { layer: config.layer, keep: config.keep });
|
|
135
|
+
if (config.minify) {
|
|
136
|
+
const { transform } = await import("lightningcss");
|
|
137
|
+
css = transform({ filename: config.output, code: Buffer.from(css), minify: true }).code.toString();
|
|
138
|
+
}
|
|
139
|
+
const out = path.resolve(cwd, config.output);
|
|
140
|
+
await fs.mkdir(path.dirname(out), { recursive: true });
|
|
141
|
+
await fs.writeFile(out, css);
|
|
142
|
+
console.log(`omniacss: ${files.length} files scanned → ${path.relative(cwd, out)} (${(css.length / 1024).toFixed(1)} KB) in ${Date.now() - started}ms`);
|
|
143
|
+
return files;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const files = await run();
|
|
147
|
+
if (!flags.watch) return;
|
|
148
|
+
|
|
149
|
+
const dirs = new Set(files.map((f) => path.dirname(f)));
|
|
150
|
+
let timer;
|
|
151
|
+
console.log(`omniacss: watching ${dirs.size} folder(s) — Ctrl+C to stop`);
|
|
152
|
+
for (const dir of dirs) {
|
|
153
|
+
watch(dir, () => {
|
|
154
|
+
clearTimeout(timer);
|
|
155
|
+
timer = setTimeout(() => run().catch((e) => console.error(e.message)), 120);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** `omniacss migrate ...` delegates to @birdycom/omniacss-migrate (optional package). */
|
|
161
|
+
async function cmdMigrate(args) {
|
|
162
|
+
let file;
|
|
163
|
+
try { file = resolvePkg("@birdycom/omniacss-migrate/cli"); } catch { throw new Error("The migrate command needs @birdycom/omniacss-migrate. Install it with: npm install -D @birdycom/omniacss-migrate"); }
|
|
164
|
+
const { run } = await import(pathToFileURL(file).href);
|
|
165
|
+
return run(args);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* `omniacss tokens` — the semantic theme tokens resolved for non-web apps (desktop toolkits have no CSS engine):
|
|
170
|
+
* per mode (light/dark), no var() left, sRGB hex gamut mapped the CSS Color 4 way, OmniaCSS version stamped.
|
|
171
|
+
*/
|
|
172
|
+
async function cmdTokens(args) {
|
|
173
|
+
const { values } = parseArgs({
|
|
174
|
+
args,
|
|
175
|
+
options: {
|
|
176
|
+
format: { type: "string", short: "f", default: "json" },
|
|
177
|
+
out: { type: "string", short: "o" },
|
|
178
|
+
source: { type: "string", short: "s" },
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
const tokens = await import(pathToFileURL(resolvePkg("@birdycom/omniacss/tokens/export")).href);
|
|
182
|
+
const core = pkgDir("@birdycom/omniacss");
|
|
183
|
+
const { version } = await readJson(path.join(core, "package.json"));
|
|
184
|
+
const semantic = await tokens.loadSemantic(values.source ? path.resolve(cwd, values.source) : undefined);
|
|
185
|
+
const format = values.format;
|
|
186
|
+
let text;
|
|
187
|
+
if (format === "css") text = tokens.toCss(semantic, version);
|
|
188
|
+
else if (tokens.FORMATS[format]) text = tokens.FORMATS[format](tokens.buildExport(semantic, await tokens.loadPalette(path.join(core, "dist")), version));
|
|
189
|
+
else throw new Error(`unknown format "${format}" (use json, dtcg, python or css)`);
|
|
190
|
+
if (values.out === "-") { process.stdout.write(text); return; }
|
|
191
|
+
const out = path.resolve(cwd, values.out || (format === "css" ? "oc-theme.css" : tokens.EXTENSIONS[format]));
|
|
192
|
+
await fs.mkdir(path.dirname(out), { recursive: true });
|
|
193
|
+
await fs.writeFile(out, text);
|
|
194
|
+
console.log(`omniacss: ${format} tokens (OmniaCSS ${version}) → ${path.relative(cwd, out)}`);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async function main() {
|
|
198
|
+
if (process.argv[2] === "migrate") return cmdMigrate(process.argv.slice(3));
|
|
199
|
+
if (process.argv[2] === "tokens") return cmdTokens(process.argv.slice(3));
|
|
200
|
+
// add/list moved to OmniaUI: answer before parsing so their old flags (-f, --kind …) do not fail.
|
|
201
|
+
if (["add", "list"].includes(process.argv[2])) {
|
|
202
|
+
console.log(MOVED);
|
|
203
|
+
process.exitCode = 1;
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const { values, positionals } = parseArgs({
|
|
207
|
+
allowPositionals: true,
|
|
208
|
+
options: {
|
|
209
|
+
content: { type: "string", short: "c", multiple: true },
|
|
210
|
+
output: { type: "string", short: "o" },
|
|
211
|
+
watch: { type: "boolean", short: "w" },
|
|
212
|
+
minify: { type: "boolean", short: "m" },
|
|
213
|
+
"no-components": { type: "boolean" },
|
|
214
|
+
"no-layer": { type: "boolean" },
|
|
215
|
+
help: { type: "boolean", short: "h" },
|
|
216
|
+
version: { type: "boolean", short: "v" },
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
const [command] = positionals;
|
|
220
|
+
if (values.version) {
|
|
221
|
+
console.log((await readJson(new URL("../package.json", import.meta.url))).version);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
switch (command) {
|
|
225
|
+
case "init": return cmdInit();
|
|
226
|
+
case "build": return cmdBuild(values);
|
|
227
|
+
case "purge": return cmdBuild({ ...values, "no-components": true }); // backwards compatible alias
|
|
228
|
+
default: console.log(HELP);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
main().catch((err) => {
|
|
233
|
+
console.error(`omniacss: ${err.message}`);
|
|
234
|
+
process.exit(1);
|
|
235
|
+
});
|
package/package.json
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@birdycom/omniacss-cli",
|
|
3
|
-
"version": "0.11.
|
|
4
|
-
"description": "OmniaCSS command line: init a project, build on-demand CSS, migrate from Tailwind CSS. Components and blocks: see the omniaui CLI in @birdycom/omniaui.",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"author": "Serge Cools (Birdycom)",
|
|
8
|
-
"homepage": "https://omniacss.eu",
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/Birdycom/
|
|
12
|
-
"directory": "packages/cli"
|
|
13
|
-
},
|
|
14
|
-
"bugs": {
|
|
15
|
-
"url": "https://github.com/Birdycom/
|
|
16
|
-
},
|
|
17
|
-
"keywords": [
|
|
18
|
-
"css",
|
|
19
|
-
"cli",
|
|
20
|
-
"utility-first",
|
|
21
|
-
"omniacss"
|
|
22
|
-
],
|
|
23
|
-
"engines": {
|
|
24
|
-
"node": ">=22"
|
|
25
|
-
},
|
|
26
|
-
"bin": {
|
|
27
|
-
"omniacss": "./bin/omniacss.mjs"
|
|
28
|
-
},
|
|
29
|
-
"files": [
|
|
30
|
-
"bin",
|
|
31
|
-
"README.md",
|
|
32
|
-
"LICENSE"
|
|
33
|
-
],
|
|
34
|
-
"dependencies": {
|
|
35
|
-
"@birdycom/omniacss": "^0.11.
|
|
36
|
-
"lightningcss": "^1.33.0"
|
|
37
|
-
},
|
|
38
|
-
"sideEffects": false,
|
|
39
|
-
"publishConfig": {
|
|
40
|
-
"access": "public"
|
|
41
|
-
},
|
|
42
|
-
"scripts": {
|
|
43
|
-
"test": "node --test test/*.test.mjs"
|
|
44
|
-
}
|
|
45
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@birdycom/omniacss-cli",
|
|
3
|
+
"version": "0.11.1",
|
|
4
|
+
"description": "OmniaCSS command line: init a project, build on-demand CSS, migrate from Tailwind CSS. Components and blocks: see the omniaui CLI in @birdycom/omniaui.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Serge Cools (Birdycom)",
|
|
8
|
+
"homepage": "https://omniacss.eu",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/Birdycom/OmniaCSS.git",
|
|
12
|
+
"directory": "packages/cli"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/Birdycom/OmniaCSS/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"css",
|
|
19
|
+
"cli",
|
|
20
|
+
"utility-first",
|
|
21
|
+
"omniacss"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=22"
|
|
25
|
+
},
|
|
26
|
+
"bin": {
|
|
27
|
+
"omniacss": "./bin/omniacss.mjs"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"bin",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE"
|
|
33
|
+
],
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@birdycom/omniacss": "^0.11.1",
|
|
36
|
+
"lightningcss": "^1.33.0"
|
|
37
|
+
},
|
|
38
|
+
"sideEffects": false,
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"test": "node --test test/*.test.mjs"
|
|
44
|
+
}
|
|
45
|
+
}
|