@unocss/cli 0.14.0 → 0.15.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/bin/unocss.cjs +2 -0
- package/dist/chunks/index.cjs +137 -0
- package/dist/chunks/index.mjs +125 -0
- package/dist/cli.cjs +34 -0
- package/dist/cli.mjs +32 -0
- package/dist/index.cjs +19 -0
- package/dist/index.mjs +9 -0
- package/package.json +9 -9
- package/bin/unocss.js +0 -2
- package/dist/chunk-F3ZMRNDQ.js +0 -157
- package/dist/cli.js +0 -28
- package/dist/index.js +0 -10
package/bin/unocss.cjs
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const promises = require('fs/promises');
|
|
4
|
+
const pathe = require('pathe');
|
|
5
|
+
const fg = require('fast-glob');
|
|
6
|
+
const consola = require('consola');
|
|
7
|
+
const colorette = require('colorette');
|
|
8
|
+
const core = require('@unocss/core');
|
|
9
|
+
const config = require('@unocss/config');
|
|
10
|
+
const presetUno = require('@unocss/preset-uno');
|
|
11
|
+
|
|
12
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
13
|
+
|
|
14
|
+
const fg__default = /*#__PURE__*/_interopDefaultLegacy(fg);
|
|
15
|
+
const consola__default = /*#__PURE__*/_interopDefaultLegacy(consola);
|
|
16
|
+
const presetUno__default = /*#__PURE__*/_interopDefaultLegacy(presetUno);
|
|
17
|
+
|
|
18
|
+
const version = "0.15.0";
|
|
19
|
+
|
|
20
|
+
class PrettyError extends Error {
|
|
21
|
+
constructor(message) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.name = this.constructor.name;
|
|
24
|
+
if (typeof Error.captureStackTrace === "function")
|
|
25
|
+
Error.captureStackTrace(this, this.constructor);
|
|
26
|
+
else
|
|
27
|
+
this.stack = new Error(message).stack;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function handleError(error) {
|
|
31
|
+
if (error instanceof PrettyError)
|
|
32
|
+
consola__default.error(error.message);
|
|
33
|
+
process.exitCode = 1;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function debouncePromise(fn, delay, onError) {
|
|
37
|
+
let timeout;
|
|
38
|
+
let promiseInFly;
|
|
39
|
+
let callbackPending;
|
|
40
|
+
return function debounced(...args) {
|
|
41
|
+
if (promiseInFly) {
|
|
42
|
+
callbackPending = () => {
|
|
43
|
+
debounced(...args);
|
|
44
|
+
callbackPending = void 0;
|
|
45
|
+
};
|
|
46
|
+
} else {
|
|
47
|
+
if (timeout)
|
|
48
|
+
clearTimeout(timeout);
|
|
49
|
+
timeout = setTimeout(() => {
|
|
50
|
+
timeout = void 0;
|
|
51
|
+
promiseInFly = fn(...args).catch(onError).finally(() => {
|
|
52
|
+
promiseInFly = void 0;
|
|
53
|
+
if (callbackPending)
|
|
54
|
+
callbackPending();
|
|
55
|
+
});
|
|
56
|
+
}, delay);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const defaultConfig = {
|
|
62
|
+
envMode: "build",
|
|
63
|
+
presets: [
|
|
64
|
+
presetUno__default()
|
|
65
|
+
]
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const name = "unocss";
|
|
69
|
+
let uno;
|
|
70
|
+
const fileCache = /* @__PURE__ */ new Map();
|
|
71
|
+
async function generate(options) {
|
|
72
|
+
const outFile = options.outFile ?? pathe.resolve(process.cwd(), "uno.css");
|
|
73
|
+
const { css, matched } = await uno.generate([...fileCache].join("\n"));
|
|
74
|
+
await promises.writeFile(outFile, css, "utf-8");
|
|
75
|
+
if (!options.watch) {
|
|
76
|
+
consola__default.success(`${[...matched].length} utilities generated to ${colorette.cyan(pathe.relative(process.cwd(), outFile))}
|
|
77
|
+
`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async function resolveOptions(options) {
|
|
81
|
+
if (!options.patterns?.length) {
|
|
82
|
+
throw new PrettyError(`No glob patterns, try ${colorette.cyan(`${name} <path/to/**/*>`)}`);
|
|
83
|
+
}
|
|
84
|
+
return options;
|
|
85
|
+
}
|
|
86
|
+
async function build(_options) {
|
|
87
|
+
const options = await resolveOptions(_options);
|
|
88
|
+
const loadConfig = config.createConfigLoader();
|
|
89
|
+
const { config: config$1, sources: configSources } = await loadConfig();
|
|
90
|
+
uno = core.createGenerator(config$1, defaultConfig);
|
|
91
|
+
const files = await fg__default(options.patterns);
|
|
92
|
+
await Promise.all(files.map(async (file) => {
|
|
93
|
+
fileCache.set(file, await promises.readFile(file, "utf8"));
|
|
94
|
+
}));
|
|
95
|
+
consola__default.log(colorette.green(`${name} v${version}`));
|
|
96
|
+
consola__default.start(`UnoCSS ${options.watch ? "in watch mode..." : "for production..."}`);
|
|
97
|
+
const debouncedBuild = debouncePromise(async () => {
|
|
98
|
+
generate(options);
|
|
99
|
+
}, 100, handleError);
|
|
100
|
+
const startWatcher = async () => {
|
|
101
|
+
if (!options.watch)
|
|
102
|
+
return;
|
|
103
|
+
const { watch } = await import('chokidar');
|
|
104
|
+
const { patterns } = options;
|
|
105
|
+
const ignored = ["**/{.git,node_modules}/**"];
|
|
106
|
+
consola__default.info(`Watching for changes in ${colorette.cyan(Array.isArray(patterns) ? patterns.join(colorette.white(", ")) : patterns)}`);
|
|
107
|
+
const watcher = watch(patterns, {
|
|
108
|
+
ignoreInitial: true,
|
|
109
|
+
ignorePermissionErrors: true,
|
|
110
|
+
ignored
|
|
111
|
+
});
|
|
112
|
+
if (configSources.length) {
|
|
113
|
+
watcher.add(configSources);
|
|
114
|
+
watcher.on("all", async (type, file) => {
|
|
115
|
+
if (configSources.includes(file)) {
|
|
116
|
+
uno.setConfig((await loadConfig()).config);
|
|
117
|
+
consola__default.info(`${colorette.cyan(pathe.basename(file))} changed, setting new config`);
|
|
118
|
+
} else {
|
|
119
|
+
consola__default.log(`${colorette.green(`${type}`)} ${colorette.white(colorette.dim(file))}`);
|
|
120
|
+
if (type.startsWith("unlink"))
|
|
121
|
+
fileCache.delete(file);
|
|
122
|
+
else
|
|
123
|
+
fileCache.set(file, await promises.readFile(file, "utf8"));
|
|
124
|
+
}
|
|
125
|
+
debouncedBuild();
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
await generate(options);
|
|
130
|
+
startWatcher();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
exports.build = build;
|
|
134
|
+
exports.generate = generate;
|
|
135
|
+
exports.handleError = handleError;
|
|
136
|
+
exports.resolveOptions = resolveOptions;
|
|
137
|
+
exports.version = version;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { writeFile, readFile } from 'fs/promises';
|
|
2
|
+
import { resolve, relative, basename } from 'pathe';
|
|
3
|
+
import fg from 'fast-glob';
|
|
4
|
+
import consola from 'consola';
|
|
5
|
+
import { cyan, green, white, dim } from 'colorette';
|
|
6
|
+
import { createGenerator } from '@unocss/core';
|
|
7
|
+
import { createConfigLoader } from '@unocss/config';
|
|
8
|
+
import presetUno from '@unocss/preset-uno';
|
|
9
|
+
|
|
10
|
+
const version = "0.15.0";
|
|
11
|
+
|
|
12
|
+
class PrettyError extends Error {
|
|
13
|
+
constructor(message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = this.constructor.name;
|
|
16
|
+
if (typeof Error.captureStackTrace === "function")
|
|
17
|
+
Error.captureStackTrace(this, this.constructor);
|
|
18
|
+
else
|
|
19
|
+
this.stack = new Error(message).stack;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function handleError(error) {
|
|
23
|
+
if (error instanceof PrettyError)
|
|
24
|
+
consola.error(error.message);
|
|
25
|
+
process.exitCode = 1;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function debouncePromise(fn, delay, onError) {
|
|
29
|
+
let timeout;
|
|
30
|
+
let promiseInFly;
|
|
31
|
+
let callbackPending;
|
|
32
|
+
return function debounced(...args) {
|
|
33
|
+
if (promiseInFly) {
|
|
34
|
+
callbackPending = () => {
|
|
35
|
+
debounced(...args);
|
|
36
|
+
callbackPending = void 0;
|
|
37
|
+
};
|
|
38
|
+
} else {
|
|
39
|
+
if (timeout)
|
|
40
|
+
clearTimeout(timeout);
|
|
41
|
+
timeout = setTimeout(() => {
|
|
42
|
+
timeout = void 0;
|
|
43
|
+
promiseInFly = fn(...args).catch(onError).finally(() => {
|
|
44
|
+
promiseInFly = void 0;
|
|
45
|
+
if (callbackPending)
|
|
46
|
+
callbackPending();
|
|
47
|
+
});
|
|
48
|
+
}, delay);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const defaultConfig = {
|
|
54
|
+
envMode: "build",
|
|
55
|
+
presets: [
|
|
56
|
+
presetUno()
|
|
57
|
+
]
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const name = "unocss";
|
|
61
|
+
let uno;
|
|
62
|
+
const fileCache = /* @__PURE__ */ new Map();
|
|
63
|
+
async function generate(options) {
|
|
64
|
+
const outFile = options.outFile ?? resolve(process.cwd(), "uno.css");
|
|
65
|
+
const { css, matched } = await uno.generate([...fileCache].join("\n"));
|
|
66
|
+
await writeFile(outFile, css, "utf-8");
|
|
67
|
+
if (!options.watch) {
|
|
68
|
+
consola.success(`${[...matched].length} utilities generated to ${cyan(relative(process.cwd(), outFile))}
|
|
69
|
+
`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async function resolveOptions(options) {
|
|
73
|
+
if (!options.patterns?.length) {
|
|
74
|
+
throw new PrettyError(`No glob patterns, try ${cyan(`${name} <path/to/**/*>`)}`);
|
|
75
|
+
}
|
|
76
|
+
return options;
|
|
77
|
+
}
|
|
78
|
+
async function build(_options) {
|
|
79
|
+
const options = await resolveOptions(_options);
|
|
80
|
+
const loadConfig = createConfigLoader();
|
|
81
|
+
const { config, sources: configSources } = await loadConfig();
|
|
82
|
+
uno = createGenerator(config, defaultConfig);
|
|
83
|
+
const files = await fg(options.patterns);
|
|
84
|
+
await Promise.all(files.map(async (file) => {
|
|
85
|
+
fileCache.set(file, await readFile(file, "utf8"));
|
|
86
|
+
}));
|
|
87
|
+
consola.log(green(`${name} v${version}`));
|
|
88
|
+
consola.start(`UnoCSS ${options.watch ? "in watch mode..." : "for production..."}`);
|
|
89
|
+
const debouncedBuild = debouncePromise(async () => {
|
|
90
|
+
generate(options);
|
|
91
|
+
}, 100, handleError);
|
|
92
|
+
const startWatcher = async () => {
|
|
93
|
+
if (!options.watch)
|
|
94
|
+
return;
|
|
95
|
+
const { watch } = await import('chokidar');
|
|
96
|
+
const { patterns } = options;
|
|
97
|
+
const ignored = ["**/{.git,node_modules}/**"];
|
|
98
|
+
consola.info(`Watching for changes in ${cyan(Array.isArray(patterns) ? patterns.join(white(", ")) : patterns)}`);
|
|
99
|
+
const watcher = watch(patterns, {
|
|
100
|
+
ignoreInitial: true,
|
|
101
|
+
ignorePermissionErrors: true,
|
|
102
|
+
ignored
|
|
103
|
+
});
|
|
104
|
+
if (configSources.length) {
|
|
105
|
+
watcher.add(configSources);
|
|
106
|
+
watcher.on("all", async (type, file) => {
|
|
107
|
+
if (configSources.includes(file)) {
|
|
108
|
+
uno.setConfig((await loadConfig()).config);
|
|
109
|
+
consola.info(`${cyan(basename(file))} changed, setting new config`);
|
|
110
|
+
} else {
|
|
111
|
+
consola.log(`${green(`${type}`)} ${white(dim(file))}`);
|
|
112
|
+
if (type.startsWith("unlink"))
|
|
113
|
+
fileCache.delete(file);
|
|
114
|
+
else
|
|
115
|
+
fileCache.set(file, await readFile(file, "utf8"));
|
|
116
|
+
}
|
|
117
|
+
debouncedBuild();
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
await generate(options);
|
|
122
|
+
startWatcher();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export { build as b, generate as g, handleError as h, resolveOptions as r, version as v };
|
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const cac = require('cac');
|
|
4
|
+
const index = require('./chunks/index.cjs');
|
|
5
|
+
require('fs/promises');
|
|
6
|
+
require('pathe');
|
|
7
|
+
require('fast-glob');
|
|
8
|
+
require('consola');
|
|
9
|
+
require('colorette');
|
|
10
|
+
require('@unocss/core');
|
|
11
|
+
require('@unocss/config');
|
|
12
|
+
require('@unocss/preset-uno');
|
|
13
|
+
|
|
14
|
+
const name = "unocss";
|
|
15
|
+
async function main(options = {}) {
|
|
16
|
+
const cli = cac.cac(name);
|
|
17
|
+
cli.command("[...patterns]", "Glob patterns", {
|
|
18
|
+
ignoreOptionDefaultValue: true
|
|
19
|
+
}).option("-o, --out-file <file>", "Output file", {
|
|
20
|
+
default: process.cwd()
|
|
21
|
+
}).option("-w, --watch", "Watch for file changes").action(async (patterns, flags) => {
|
|
22
|
+
Object.assign(options, {
|
|
23
|
+
...flags
|
|
24
|
+
});
|
|
25
|
+
if (patterns)
|
|
26
|
+
options.patterns = patterns;
|
|
27
|
+
await index.build(options);
|
|
28
|
+
});
|
|
29
|
+
cli.help();
|
|
30
|
+
cli.version(index.version);
|
|
31
|
+
cli.parse(process.argv, { run: false });
|
|
32
|
+
await cli.runMatchedCommand();
|
|
33
|
+
}
|
|
34
|
+
main().catch(index.handleError);
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { cac } from 'cac';
|
|
2
|
+
import { h as handleError, b as build, v as version } from './chunks/index.mjs';
|
|
3
|
+
import 'fs/promises';
|
|
4
|
+
import 'pathe';
|
|
5
|
+
import 'fast-glob';
|
|
6
|
+
import 'consola';
|
|
7
|
+
import 'colorette';
|
|
8
|
+
import '@unocss/core';
|
|
9
|
+
import '@unocss/config';
|
|
10
|
+
import '@unocss/preset-uno';
|
|
11
|
+
|
|
12
|
+
const name = "unocss";
|
|
13
|
+
async function main(options = {}) {
|
|
14
|
+
const cli = cac(name);
|
|
15
|
+
cli.command("[...patterns]", "Glob patterns", {
|
|
16
|
+
ignoreOptionDefaultValue: true
|
|
17
|
+
}).option("-o, --out-file <file>", "Output file", {
|
|
18
|
+
default: process.cwd()
|
|
19
|
+
}).option("-w, --watch", "Watch for file changes").action(async (patterns, flags) => {
|
|
20
|
+
Object.assign(options, {
|
|
21
|
+
...flags
|
|
22
|
+
});
|
|
23
|
+
if (patterns)
|
|
24
|
+
options.patterns = patterns;
|
|
25
|
+
await build(options);
|
|
26
|
+
});
|
|
27
|
+
cli.help();
|
|
28
|
+
cli.version(version);
|
|
29
|
+
cli.parse(process.argv, { run: false });
|
|
30
|
+
await cli.runMatchedCommand();
|
|
31
|
+
}
|
|
32
|
+
main().catch(handleError);
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('fs/promises');
|
|
6
|
+
require('pathe');
|
|
7
|
+
require('fast-glob');
|
|
8
|
+
require('consola');
|
|
9
|
+
require('colorette');
|
|
10
|
+
require('@unocss/core');
|
|
11
|
+
require('@unocss/config');
|
|
12
|
+
const index = require('./chunks/index.cjs');
|
|
13
|
+
require('@unocss/preset-uno');
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
exports.build = index.build;
|
|
18
|
+
exports.generate = index.generate;
|
|
19
|
+
exports.resolveOptions = index.resolveOptions;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import 'fs/promises';
|
|
2
|
+
import 'pathe';
|
|
3
|
+
import 'fast-glob';
|
|
4
|
+
import 'consola';
|
|
5
|
+
import 'colorette';
|
|
6
|
+
import '@unocss/core';
|
|
7
|
+
import '@unocss/config';
|
|
8
|
+
export { b as build, g as generate, r as resolveOptions } from './chunks/index.mjs';
|
|
9
|
+
import '@unocss/preset-uno';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "CLI for UnoCSS",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"homepage": "https://github.com/antfu/unocss/tree/main/packages/cli#readme",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"email": "pkg@johannschopplich.com",
|
|
20
20
|
"url": "https://johannschopplich.com"
|
|
21
21
|
},
|
|
22
|
-
"exports": "./dist/index.
|
|
23
|
-
"main": "./dist/index.
|
|
22
|
+
"exports": "./dist/index.cjs",
|
|
23
|
+
"main": "./dist/index.cjs",
|
|
24
24
|
"bin": {
|
|
25
|
-
"unocss": "./bin/unocss.
|
|
25
|
+
"unocss": "./bin/unocss.cjs"
|
|
26
26
|
},
|
|
27
27
|
"types": "./dist/index.d.ts",
|
|
28
28
|
"files": [
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"node": ">=14"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@unocss/config": "0.
|
|
37
|
-
"@unocss/core": "0.
|
|
38
|
-
"@unocss/preset-uno": "0.
|
|
36
|
+
"@unocss/config": "0.15.0",
|
|
37
|
+
"@unocss/core": "0.15.0",
|
|
38
|
+
"@unocss/preset-uno": "0.15.0",
|
|
39
39
|
"cac": "^6.7.12",
|
|
40
40
|
"chokidar": "^3.5.2",
|
|
41
41
|
"colorette": "^2.0.16",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"pathe": "^0.2.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
|
-
"build": "
|
|
48
|
-
"
|
|
47
|
+
"build": "unbuild",
|
|
48
|
+
"stub": "unbuild --stub"
|
|
49
49
|
}
|
|
50
50
|
}
|
package/bin/unocss.js
DELETED
package/dist/chunk-F3ZMRNDQ.js
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// src/index.ts
|
|
19
|
-
var _promises = require('fs/promises');
|
|
20
|
-
var _pathe = require('pathe');
|
|
21
|
-
var _fastglob = require('fast-glob'); var _fastglob2 = _interopRequireDefault(_fastglob);
|
|
22
|
-
var _consola = require('consola'); var _consola2 = _interopRequireDefault(_consola);
|
|
23
|
-
var _colorette = require('colorette');
|
|
24
|
-
var _core = require('@unocss/core');
|
|
25
|
-
var _config = require('@unocss/config');
|
|
26
|
-
|
|
27
|
-
// package.json
|
|
28
|
-
var version = "0.14.0";
|
|
29
|
-
|
|
30
|
-
// src/errors.ts
|
|
31
|
-
|
|
32
|
-
var PrettyError = class extends Error {
|
|
33
|
-
constructor(message) {
|
|
34
|
-
super(message);
|
|
35
|
-
this.name = this.constructor.name;
|
|
36
|
-
if (typeof Error.captureStackTrace === "function")
|
|
37
|
-
Error.captureStackTrace(this, this.constructor);
|
|
38
|
-
else
|
|
39
|
-
this.stack = new Error(message).stack;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
function handleError(error) {
|
|
43
|
-
if (error instanceof PrettyError)
|
|
44
|
-
_consola2.default.error(error.message);
|
|
45
|
-
process.exitCode = 1;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// src/utils.ts
|
|
49
|
-
function debouncePromise(fn, delay, onError) {
|
|
50
|
-
let timeout;
|
|
51
|
-
let promiseInFly;
|
|
52
|
-
let callbackPending;
|
|
53
|
-
return function debounced(...args) {
|
|
54
|
-
if (promiseInFly) {
|
|
55
|
-
callbackPending = () => {
|
|
56
|
-
debounced(...args);
|
|
57
|
-
callbackPending = void 0;
|
|
58
|
-
};
|
|
59
|
-
} else {
|
|
60
|
-
if (timeout)
|
|
61
|
-
clearTimeout(timeout);
|
|
62
|
-
timeout = setTimeout(() => {
|
|
63
|
-
timeout = void 0;
|
|
64
|
-
promiseInFly = fn(...args).catch(onError).finally(() => {
|
|
65
|
-
promiseInFly = void 0;
|
|
66
|
-
if (callbackPending)
|
|
67
|
-
callbackPending();
|
|
68
|
-
});
|
|
69
|
-
}, delay);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// src/config.ts
|
|
75
|
-
var _presetuno = require('@unocss/preset-uno'); var _presetuno2 = _interopRequireDefault(_presetuno);
|
|
76
|
-
var defaultConfig = {
|
|
77
|
-
envMode: "build",
|
|
78
|
-
presets: [
|
|
79
|
-
_presetuno2.default.call(void 0, )
|
|
80
|
-
]
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
// src/index.ts
|
|
84
|
-
var name = "unocss";
|
|
85
|
-
var uno;
|
|
86
|
-
var fileCache = new Map();
|
|
87
|
-
async function generate(options) {
|
|
88
|
-
const outFile = _nullishCoalesce(options.outFile, () => ( _pathe.resolve.call(void 0, process.cwd(), "uno.css")));
|
|
89
|
-
const { css, matched } = await uno.generate([...fileCache].join("\n"));
|
|
90
|
-
await _promises.writeFile.call(void 0, outFile, css, "utf-8");
|
|
91
|
-
if (!options.watch) {
|
|
92
|
-
_consola2.default.success(`${[...matched].length} utilities generated to ${_colorette.cyan.call(void 0, _pathe.relative.call(void 0, process.cwd(), outFile))}
|
|
93
|
-
`);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
async function resolveOptions(options) {
|
|
97
|
-
var _a;
|
|
98
|
-
if (!((_a = options.patterns) == null ? void 0 : _a.length)) {
|
|
99
|
-
throw new PrettyError(`No glob patterns, try ${_colorette.cyan.call(void 0, `${name} <path/to/**/*>`)}`);
|
|
100
|
-
}
|
|
101
|
-
return options;
|
|
102
|
-
}
|
|
103
|
-
async function build(_options) {
|
|
104
|
-
const options = await resolveOptions(_options);
|
|
105
|
-
const loadConfig = _config.createConfigLoader.call(void 0, );
|
|
106
|
-
const { config, sources: configSources } = await loadConfig();
|
|
107
|
-
uno = _core.createGenerator.call(void 0, config, defaultConfig);
|
|
108
|
-
const files = await _fastglob2.default.call(void 0, options.patterns);
|
|
109
|
-
await Promise.all(files.map(async (file) => {
|
|
110
|
-
fileCache.set(file, await _promises.readFile.call(void 0, file, "utf8"));
|
|
111
|
-
}));
|
|
112
|
-
_consola2.default.log(_colorette.green.call(void 0, `${name} v${version}`));
|
|
113
|
-
_consola2.default.start(`UnoCSS ${options.watch ? "in watch mode..." : "for production..."}`);
|
|
114
|
-
const debouncedBuild = debouncePromise(async () => {
|
|
115
|
-
generate(options);
|
|
116
|
-
}, 100, handleError);
|
|
117
|
-
const startWatcher = async () => {
|
|
118
|
-
if (!options.watch)
|
|
119
|
-
return;
|
|
120
|
-
const { watch } = await Promise.resolve().then(() => require("chokidar"));
|
|
121
|
-
const { patterns } = options;
|
|
122
|
-
const ignored = ["**/{.git,node_modules}/**"];
|
|
123
|
-
_consola2.default.info(`Watching for changes in ${_colorette.cyan.call(void 0, Array.isArray(patterns) ? patterns.join(_colorette.white.call(void 0, ", ")) : patterns)}`);
|
|
124
|
-
const watcher = watch(patterns, {
|
|
125
|
-
ignoreInitial: true,
|
|
126
|
-
ignorePermissionErrors: true,
|
|
127
|
-
ignored
|
|
128
|
-
});
|
|
129
|
-
if (configSources.length) {
|
|
130
|
-
watcher.add(configSources);
|
|
131
|
-
watcher.on("all", async (type, file) => {
|
|
132
|
-
if (configSources.includes(file)) {
|
|
133
|
-
uno.setConfig((await loadConfig()).config);
|
|
134
|
-
_consola2.default.info(`${_colorette.cyan.call(void 0, _pathe.basename.call(void 0, file))} changed, setting new config`);
|
|
135
|
-
} else {
|
|
136
|
-
_consola2.default.log(`${_colorette.green.call(void 0, `${type}`)} ${_colorette.white.call(void 0, _colorette.dim.call(void 0, file))}`);
|
|
137
|
-
if (type.startsWith("unlink"))
|
|
138
|
-
fileCache.delete(file);
|
|
139
|
-
else
|
|
140
|
-
fileCache.set(file, await _promises.readFile.call(void 0, file, "utf8"));
|
|
141
|
-
}
|
|
142
|
-
debouncedBuild();
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
await generate(options);
|
|
147
|
-
startWatcher();
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
exports.__spreadValues = __spreadValues; exports.version = version; exports.handleError = handleError; exports.generate = generate; exports.resolveOptions = resolveOptions; exports.build = build;
|
package/dist/cli.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var _chunkF3ZMRNDQjs = require('./chunk-F3ZMRNDQ.js');
|
|
7
|
-
|
|
8
|
-
// src/cli.ts
|
|
9
|
-
var _cac = require('cac');
|
|
10
|
-
var name = "unocss";
|
|
11
|
-
async function main(options = {}) {
|
|
12
|
-
const cli = _cac.cac.call(void 0, name);
|
|
13
|
-
cli.command("[...patterns]", "Glob patterns", {
|
|
14
|
-
ignoreOptionDefaultValue: true
|
|
15
|
-
}).option("-o, --out-file <file>", "Output file", {
|
|
16
|
-
default: process.cwd()
|
|
17
|
-
}).option("-w, --watch", "Watch for file changes").action(async (patterns, flags) => {
|
|
18
|
-
Object.assign(options, _chunkF3ZMRNDQjs.__spreadValues.call(void 0, {}, flags));
|
|
19
|
-
if (patterns)
|
|
20
|
-
options.patterns = patterns;
|
|
21
|
-
await _chunkF3ZMRNDQjs.build.call(void 0, options);
|
|
22
|
-
});
|
|
23
|
-
cli.help();
|
|
24
|
-
cli.version(_chunkF3ZMRNDQjs.version);
|
|
25
|
-
cli.parse(process.argv, { run: false });
|
|
26
|
-
await cli.runMatchedCommand();
|
|
27
|
-
}
|
|
28
|
-
main().catch(_chunkF3ZMRNDQjs.handleError);
|
package/dist/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var _chunkF3ZMRNDQjs = require('./chunk-F3ZMRNDQ.js');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
exports.build = _chunkF3ZMRNDQjs.build; exports.generate = _chunkF3ZMRNDQjs.generate; exports.resolveOptions = _chunkF3ZMRNDQjs.resolveOptions;
|