@unocss/cli 0.39.0 → 0.39.3
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/dist/chunks/index.mjs +27 -25
- package/dist/cli.mjs +9 -8
- package/dist/index.d.ts +4 -2
- package/dist/index.mjs +1 -1
- package/package.json +4 -4
package/dist/chunks/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { promises, existsSync } from 'fs';
|
|
2
2
|
import { resolve, dirname, relative, basename } from 'pathe';
|
|
3
3
|
import fg from 'fast-glob';
|
|
4
4
|
import consola from 'consola';
|
|
@@ -8,7 +8,7 @@ import { createGenerator, toArray } from '@unocss/core';
|
|
|
8
8
|
import { loadConfig } from '@unocss/config';
|
|
9
9
|
import presetUno from '@unocss/preset-uno';
|
|
10
10
|
|
|
11
|
-
const version = "0.39.
|
|
11
|
+
const version = "0.39.3";
|
|
12
12
|
|
|
13
13
|
class PrettyError extends Error {
|
|
14
14
|
constructor(message) {
|
|
@@ -34,21 +34,6 @@ const defaultConfig = {
|
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
const name = "unocss";
|
|
37
|
-
let uno;
|
|
38
|
-
const fileCache = /* @__PURE__ */ new Map();
|
|
39
|
-
const getAbsolutePath = (file) => resolve(process.cwd(), file);
|
|
40
|
-
async function generate(options) {
|
|
41
|
-
const outFile = options.outFile ?? getAbsolutePath("uno.css");
|
|
42
|
-
const { css, matched } = await uno.generate([...fileCache].join("\n"));
|
|
43
|
-
const dir = dirname(outFile);
|
|
44
|
-
if (!existsSync(dir))
|
|
45
|
-
await promises.mkdir(dir, { recursive: true });
|
|
46
|
-
await promises.writeFile(outFile, css, "utf-8");
|
|
47
|
-
if (!options.watch) {
|
|
48
|
-
consola.success(`${[...matched].length} utilities generated to ${cyan(relative(process.cwd(), outFile))}
|
|
49
|
-
`);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
37
|
async function resolveOptions(options) {
|
|
53
38
|
if (!options.patterns?.length) {
|
|
54
39
|
throw new PrettyError(`No glob patterns, try ${cyan(`${name} <path/to/**/*>`)}`);
|
|
@@ -56,13 +41,14 @@ async function resolveOptions(options) {
|
|
|
56
41
|
return options;
|
|
57
42
|
}
|
|
58
43
|
async function build(_options) {
|
|
44
|
+
const fileCache = /* @__PURE__ */ new Map();
|
|
45
|
+
const cwd = _options.cwd || process.cwd();
|
|
59
46
|
const options = await resolveOptions(_options);
|
|
60
|
-
const { config, sources: configSources } = await loadConfig(
|
|
61
|
-
uno = createGenerator(config, defaultConfig);
|
|
62
|
-
const files = await fg(options.patterns);
|
|
47
|
+
const { config, sources: configSources } = await loadConfig(cwd, options.config);
|
|
48
|
+
const uno = createGenerator(config, defaultConfig);
|
|
49
|
+
const files = await fg(options.patterns, { cwd, absolute: true });
|
|
63
50
|
await Promise.all(files.map(async (file) => {
|
|
64
|
-
|
|
65
|
-
fileCache.set(absolutePath, await promises.readFile(absolutePath, "utf8"));
|
|
51
|
+
fileCache.set(file, await promises.readFile(file, "utf8"));
|
|
66
52
|
}));
|
|
67
53
|
consola.log(green(`${name} v${version}`));
|
|
68
54
|
consola.start(`UnoCSS ${options.watch ? "in watch mode..." : "for production..."}`);
|
|
@@ -78,7 +64,8 @@ async function build(_options) {
|
|
|
78
64
|
const watcher = watch(patterns, {
|
|
79
65
|
ignoreInitial: true,
|
|
80
66
|
ignorePermissionErrors: true,
|
|
81
|
-
ignored
|
|
67
|
+
ignored,
|
|
68
|
+
cwd
|
|
82
69
|
});
|
|
83
70
|
if (configSources.length)
|
|
84
71
|
watcher.add(configSources);
|
|
@@ -88,7 +75,7 @@ async function build(_options) {
|
|
|
88
75
|
consola.info(`${cyan(basename(file))} changed, setting new config`);
|
|
89
76
|
} else {
|
|
90
77
|
consola.log(`${green(type)} ${dim(file)}`);
|
|
91
|
-
const absolutePath =
|
|
78
|
+
const absolutePath = resolve(cwd, file);
|
|
92
79
|
if (type.startsWith("unlink"))
|
|
93
80
|
fileCache.delete(absolutePath);
|
|
94
81
|
else
|
|
@@ -100,6 +87,21 @@ async function build(_options) {
|
|
|
100
87
|
};
|
|
101
88
|
await generate(options);
|
|
102
89
|
startWatcher();
|
|
90
|
+
async function generate(options2) {
|
|
91
|
+
const outFile = resolve(options2.cwd || process.cwd(), options2.outFile ?? "uno.css");
|
|
92
|
+
const { css, matched } = await uno.generate([...fileCache].join("\n"), {
|
|
93
|
+
preflights: options2.preflights,
|
|
94
|
+
minify: options2.minify
|
|
95
|
+
});
|
|
96
|
+
const dir = dirname(outFile);
|
|
97
|
+
if (!existsSync(dir))
|
|
98
|
+
await promises.mkdir(dir, { recursive: true });
|
|
99
|
+
await promises.writeFile(outFile, css, "utf-8");
|
|
100
|
+
if (!options2.watch) {
|
|
101
|
+
consola.success(`${[...matched].length} utilities generated to ${cyan(relative(process.cwd(), outFile))}
|
|
102
|
+
`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
103
105
|
}
|
|
104
106
|
|
|
105
|
-
export { build as b,
|
|
107
|
+
export { build as b, handleError as h, resolveOptions as r, version as v };
|
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cac } from 'cac';
|
|
2
|
-
import {
|
|
2
|
+
import { b as build, v as version, h as handleError } from './chunks/index.mjs';
|
|
3
3
|
import 'fs';
|
|
4
4
|
import 'pathe';
|
|
5
5
|
import 'fast-glob';
|
|
@@ -10,15 +10,15 @@ import '@unocss/core';
|
|
|
10
10
|
import '@unocss/config';
|
|
11
11
|
import '@unocss/preset-uno';
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const cli = cac(name);
|
|
13
|
+
async function startCli(cwd = process.cwd(), argv = process.argv, options = {}) {
|
|
14
|
+
const cli = cac("unocss");
|
|
16
15
|
cli.command("[...patterns]", "Glob patterns", {
|
|
17
16
|
ignoreOptionDefaultValue: true
|
|
18
17
|
}).option("-o, --out-file <file>", "Output file", {
|
|
19
|
-
default:
|
|
20
|
-
}).option("-c, --config [file]", "Config file").option("-w, --watch", "Watch for file changes").action(async (patterns, flags) => {
|
|
18
|
+
default: cwd
|
|
19
|
+
}).option("-c, --config [file]", "Config file").option("-w, --watch", "Watch for file changes").option("--preflights", "Enable preflights", { default: true }).option("-m, --minify", "Minify generated CSS", { default: false }).action(async (patterns, flags) => {
|
|
21
20
|
Object.assign(options, {
|
|
21
|
+
cwd,
|
|
22
22
|
...flags
|
|
23
23
|
});
|
|
24
24
|
if (patterns)
|
|
@@ -27,7 +27,8 @@ async function main(options = {}) {
|
|
|
27
27
|
});
|
|
28
28
|
cli.help();
|
|
29
29
|
cli.version(version);
|
|
30
|
-
cli.parse(
|
|
30
|
+
cli.parse(argv, { run: false });
|
|
31
31
|
await cli.runMatchedCommand();
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
|
|
34
|
+
startCli().catch(handleError);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
/** Mark some properties as required, leaving others unchanged */
|
|
2
2
|
declare type MarkRequired<T, RK extends keyof T> = Exclude<T, RK> & Required<Pick<T, RK>>;
|
|
3
3
|
interface CliOptions {
|
|
4
|
+
cwd?: string;
|
|
4
5
|
patterns?: Array<string>;
|
|
5
6
|
outFile?: string;
|
|
6
7
|
watch?: boolean;
|
|
7
8
|
config?: string;
|
|
9
|
+
preflights?: boolean;
|
|
10
|
+
minify?: boolean;
|
|
8
11
|
}
|
|
9
12
|
declare type ResolvedCliOptions = MarkRequired<CliOptions, 'patterns'>;
|
|
10
13
|
|
|
11
|
-
declare function generate(options: ResolvedCliOptions): Promise<void>;
|
|
12
14
|
declare function resolveOptions(options: CliOptions): Promise<ResolvedCliOptions>;
|
|
13
15
|
declare function build(_options: CliOptions): Promise<void>;
|
|
14
16
|
|
|
15
|
-
export { build,
|
|
17
|
+
export { build, resolveOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -6,5 +6,5 @@ import 'colorette';
|
|
|
6
6
|
import 'perfect-debounce';
|
|
7
7
|
import '@unocss/core';
|
|
8
8
|
import '@unocss/config';
|
|
9
|
-
export { b as build,
|
|
9
|
+
export { b as build, r as resolveOptions } from './chunks/index.mjs';
|
|
10
10
|
import '@unocss/preset-uno';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/cli",
|
|
3
|
-
"version": "0.39.
|
|
3
|
+
"version": "0.39.3",
|
|
4
4
|
"description": "CLI for UnoCSS",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Johann Schopplich",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"node": ">=14"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@unocss/config": "0.39.
|
|
43
|
-
"@unocss/core": "0.39.
|
|
44
|
-
"@unocss/preset-uno": "0.39.
|
|
42
|
+
"@unocss/config": "0.39.3",
|
|
43
|
+
"@unocss/core": "0.39.3",
|
|
44
|
+
"@unocss/preset-uno": "0.39.3",
|
|
45
45
|
"cac": "^6.7.12",
|
|
46
46
|
"chokidar": "^3.5.3",
|
|
47
47
|
"colorette": "^2.0.16",
|