@bamboocss/dev 1.11.4 → 1.12.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.
@@ -1,404 +0,0 @@
1
- import { r as version, t as interactive } from "./interactive-BJBHyhfI.mjs";
2
- import { createRequire } from "node:module";
3
- import { join, resolve } from "path";
4
- import { BambooError, compact } from "@bamboocss/shared";
5
- import { findConfig } from "@bamboocss/config";
6
- import { colors, logger } from "@bamboocss/logger";
7
- import { BambooContext, analyze, buildInfo, codegen, cssgen, debug, generate, loadConfigAndCreateContext, setLogStream, setupConfig, setupGitIgnore, setupPostcss, spec, startProfiling } from "@bamboocss/node";
8
- import { cac } from "cac";
9
- //#region \0rolldown/runtime.js
10
- var __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __esmMin = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
17
- var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
18
- var __copyProps = (to, from, except, desc) => {
19
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
20
- key = keys[i];
21
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
22
- get: ((k) => from[k]).bind(null, key),
23
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
24
- });
25
- }
26
- return to;
27
- };
28
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
29
- value: mod,
30
- enumerable: true
31
- }) : target, mod));
32
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
33
- //#endregion
34
- //#region src/cli-main.ts
35
- async function main() {
36
- const cli = cac("bamboo");
37
- const cwd = process.cwd();
38
- cli.command("init", "Initialize the bamboo config file").option("-i, --interactive", "Run in interactive mode", { default: false }).option("-f, --force", "Force overwrite existing config file").option("-p, --postcss", "Emit postcss config file").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("--silent", "Suppress all messages except errors").option("--no-gitignore", "Don't update the .gitignore").option("--no-codegen", "Don't run the codegen logic").option("--out-extension <ext>", "The extension of the generated js files (default: 'mjs')").option("--outdir <dir>", "The output directory for the generated files").option("--jsx-framework <framework>", "The jsx framework to use").option("--syntax <syntax>", "The css syntax preference").option("--strict-tokens", "Using strictTokens: true").option("--logfile <file>", "Outputs logs to a file").action(async (initFlags = {}) => {
39
- let options = {};
40
- if (initFlags.interactive) options = await interactive();
41
- const flags = {
42
- ...initFlags,
43
- ...options
44
- };
45
- const { force, postcss, silent, gitignore, outExtension, jsxFramework, config: configPath, syntax } = flags;
46
- const cwd = resolve(flags.cwd ?? "");
47
- if (silent) logger.level = "silent";
48
- const stream = setLogStream({
49
- cwd,
50
- logfile: flags.logfile
51
- });
52
- logger.info("cli", `Bamboo v${version}\n`);
53
- const done = logger.time.info("✨ Bamboo initialized");
54
- if (postcss) await setupPostcss(cwd);
55
- await setupConfig(cwd, compact({
56
- force,
57
- outExtension,
58
- jsxFramework,
59
- syntax,
60
- outdir: flags.outdir
61
- }));
62
- const ctx = await loadConfigAndCreateContext({
63
- cwd,
64
- configPath,
65
- config: compact({
66
- gitignore,
67
- outdir: flags.outdir
68
- })
69
- });
70
- if (gitignore) setupGitIgnore(ctx);
71
- if (flags.codegen) {
72
- const { msg, box } = await codegen(ctx);
73
- logger.log(msg + box);
74
- } else logger.log(ctx.initMessage());
75
- done();
76
- stream.end();
77
- });
78
- cli.command("codegen", "Generate the bamboo system").option("--silent", "Don't print any logs").option("--clean", "Clean the output directory before generating").option("-c, --config <path>", "Path to bamboo config file").option("-w, --watch", "Watch files and rebuild").option("-p, --poll", "Use polling instead of filesystem events when watching").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("--cpu-prof", "Generates a `.cpuprofile` to help debug performance issues").option("--logfile <file>", "Outputs logs to a file").action(async (flags) => {
79
- const { silent, clean, config: configPath, watch, poll } = flags;
80
- const cwd = resolve(flags.cwd ?? "");
81
- const stream = setLogStream({
82
- cwd,
83
- logfile: flags.logfile
84
- });
85
- let stopProfiling = () => void 0;
86
- if (flags.cpuProf) stopProfiling = await startProfiling(cwd, "codegen", flags.watch);
87
- if (silent) logger.level = "silent";
88
- let ctx = await loadConfigAndCreateContext({
89
- cwd,
90
- config: { clean },
91
- configPath
92
- });
93
- const { msg } = await codegen(ctx);
94
- logger.log(msg);
95
- if (watch) ctx.watchConfig(async () => {
96
- const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
97
- ctx = new BambooContext(conf);
98
- });
99
- await ctx.hooks["config:change"]?.({
100
- config: ctx.config,
101
- changes: affecteds
102
- });
103
- await codegen(ctx, Array.from(affecteds.artifacts));
104
- logger.info("ctx:updated", "config rebuilt ✅");
105
- }, {
106
- cwd,
107
- poll
108
- });
109
- else stream.end();
110
- stopProfiling();
111
- });
112
- cli.command("cssgen [globOrType]", "Generate the css from files, or generate the css from the specified type which can be: preflight, tokens, static, global, keyframes").option("--silent", "Don't print any logs").option("-m, --minify", "Minify generated code").option("--clean", "Clean the output before generating").option("-c, --config <path>", "Path to bamboo config file").option("-w, --watch", "Watch files and rebuild").option("--minimal", "Do not include CSS generation for theme tokens, preflight, keyframes, static and global css").option("--lightningcss", "Use `lightningcss` instead of `postcss` for css optimization.").option("--polyfill", "Polyfill CSS @layers at-rules for older browsers.").option("-p, --poll", "Use polling instead of filesystem events when watching").option("-o, --outfile [file]", "Output file for extracted css, default to './styled-system/styles.css'").option("--splitting", "Emit CSS as separate files per layer (reset, global, tokens, utilities) and per recipe").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("--cpu-prof", "Generates a `.cpuprofile` to help debug performance issues").option("--logfile <file>", "Outputs logs to a file").action(async (maybeGlob, flags = {}) => {
113
- const { silent, config: configPath, outfile, watch, poll, minimal, splitting, ...rest } = flags;
114
- const cwd = resolve(flags.cwd ?? "");
115
- const stream = setLogStream({
116
- cwd,
117
- logfile: flags.logfile
118
- });
119
- let stopProfiling = () => void 0;
120
- if (flags.cpuProf) stopProfiling = await startProfiling(cwd, "cssgen", flags.watch);
121
- const cssArtifact = [
122
- "preflight",
123
- "tokens",
124
- "static",
125
- "global",
126
- "keyframes"
127
- ].find((type) => type === maybeGlob);
128
- const glob = cssArtifact ? void 0 : maybeGlob;
129
- if (silent) logger.level = "silent";
130
- let ctx = await loadConfigAndCreateContext({
131
- cwd,
132
- config: {
133
- ...rest,
134
- ...glob ? { include: [glob] } : void 0
135
- },
136
- configPath
137
- });
138
- const options = {
139
- cwd,
140
- outfile,
141
- type: cssArtifact,
142
- minimal,
143
- splitting
144
- };
145
- await cssgen(ctx, options);
146
- if (watch) {
147
- ctx.watchConfig(async () => {
148
- const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
149
- ctx = new BambooContext(conf);
150
- });
151
- await ctx.hooks["config:change"]?.({
152
- config: ctx.config,
153
- changes: affecteds
154
- });
155
- await cssgen(ctx, options);
156
- logger.info("ctx:updated", "config rebuilt ✅");
157
- }, {
158
- cwd,
159
- poll
160
- });
161
- ctx.watchFiles(async (event, file) => {
162
- if (event === "unlink") ctx.project.removeSourceFile(ctx.runtime.path.abs(cwd, file));
163
- else if (event === "change") {
164
- ctx.project.reloadSourceFile(file);
165
- await cssgen(ctx, options);
166
- } else if (event === "add") {
167
- ctx.project.createSourceFile(file);
168
- await cssgen(ctx, options);
169
- }
170
- });
171
- } else {
172
- stream.end();
173
- stopProfiling();
174
- }
175
- });
176
- cli.command("[files]", "Include file glob", { ignoreOptionDefaultValue: true }).option("-o, --outdir <dir>", "Output directory", { default: "styled-system" }).option("-m, --minify", "Minify generated code").option("-w, --watch", "Watch files and rebuild").option("-p, --poll", "Use polling instead of filesystem events when watching").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("--preflight", "Enable css reset").option("--silent", "Suppress all messages except errors").option("-e, --exclude <files>", "Exclude files", { default: [] }).option("--clean", "Clean output directory").option("--hash", "Hash the generated classnames to make them shorter").option("--lightningcss", "Use `lightningcss` instead of `postcss` for css optimization.").option("--polyfill", "Polyfill CSS @layers at-rules for older browsers.").option("--emitTokensOnly", "Whether to only emit the `tokens` directory").option("--cpu-prof", "Generates a `.cpuprofile` to help debug performance issues").option("--logfile <file>", "Outputs logs to a file").action(async (files, flags) => {
177
- const { config: configPath, silent, ...rest } = flags;
178
- const cwd = resolve(flags.cwd ?? "");
179
- const stream = setLogStream({
180
- cwd,
181
- logfile: flags.logfile
182
- });
183
- let stopProfiling = () => void 0;
184
- if (flags.cpuProf) stopProfiling = await startProfiling(cwd, "cli", flags.watch);
185
- if (silent) logger.level = "silent";
186
- await generate(compact({
187
- include: files,
188
- ...rest,
189
- cwd
190
- }), configPath);
191
- stopProfiling();
192
- if (!flags.watch) stream.end();
193
- });
194
- cli.command("spec", "Generate spec files for your theme (useful for documentation)").option("--silent", "Don't print any logs").option("--outdir <dir>", "Output directory for spec files").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).action(async (flags) => {
195
- const { silent, config: configPath, outdir } = flags;
196
- const cwd = resolve(flags.cwd ?? "");
197
- if (silent) logger.level = "silent";
198
- await spec(await loadConfigAndCreateContext({
199
- cwd,
200
- configPath,
201
- config: { cwd }
202
- }), { outdir });
203
- });
204
- cli.command("studio", "Realtime documentation for your design tokens").option("--build", "Build").option("--preview", "Preview").option("--port <port>", "Port").option("--host", "Host").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("--outdir <dir>", "Output directory for static files").option("--base <path>", "Base path of project").action(async (flags) => {
205
- const { build, preview, port, host, outdir, config, base } = flags;
206
- const cwd = resolve(flags.cwd ?? "");
207
- const ctx = await loadConfigAndCreateContext({
208
- cwd,
209
- configPath: config
210
- });
211
- const buildOpts = {
212
- configPath: findConfig({
213
- cwd,
214
- file: config
215
- }),
216
- outDir: resolve(outdir || ctx.studio.outdir),
217
- port,
218
- host,
219
- base
220
- };
221
- let studio;
222
- try {
223
- studio = __require(__require.resolve("@bamboocss/studio", { paths: [cwd] }));
224
- } catch (error) {
225
- throw new BambooError("MISSING_STUDIO", "You need to install '@bamboocss/studio' to use this command", { cause: error });
226
- }
227
- if (preview) await studio.previewStudio(buildOpts);
228
- else if (build) await studio.buildStudio(buildOpts);
229
- else {
230
- await studio.serveStudio(buildOpts);
231
- const note = `use ${colors.reset(colors.bold("--build"))} to build`;
232
- const port = `use ${colors.reset(colors.bold("--port"))} for a different port`;
233
- logger.log(colors.dim(` ${colors.green("➜")} ${colors.bold("Build")}: ${note}`));
234
- logger.log(colors.dim(` ${colors.green("➜")} ${colors.bold("Port")}: ${port}`));
235
- }
236
- });
237
- cli.command("analyze [glob]", "Analyze design token usage in glob").option("--outfile [filepath]", "Output analyze report in JSON").option("--silent", "Don't print any logs").option("--scope <type>", "Select analysis scope (token or recipe)").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).action(async (maybeGlob, flags = {}) => {
238
- const { silent, config: configPath, scope } = flags;
239
- const tokenScope = scope == null || scope === "token";
240
- const recipeScope = scope == null || scope === "recipe";
241
- const cwd = resolve(flags.cwd);
242
- if (silent) logger.level = "silent";
243
- const ctx = await loadConfigAndCreateContext({
244
- cwd,
245
- config: maybeGlob ? { include: [maybeGlob] } : void 0,
246
- configPath
247
- });
248
- const result = analyze(ctx);
249
- if (flags?.outfile && typeof flags.outfile === "string") {
250
- await result.writeReport(flags.outfile);
251
- logger.info("cli", `JSON report saved to ${resolve(flags.outfile)}`);
252
- return;
253
- }
254
- if (tokenScope) if (!ctx.tokens.isEmpty) {
255
- const tokenAnalysis = result.getTokenReport();
256
- logger.info("analyze:tokens", `Token usage report 🎨 \n${tokenAnalysis.formatted}`);
257
- } else logger.info("analyze:tokens", "No tokens found");
258
- if (recipeScope) if (!ctx.recipes.isEmpty()) {
259
- const recipeAnalysis = result.getRecipeReport();
260
- logger.info("analyze:recipes", `Config recipes usage report 🎛️ \n${recipeAnalysis.formatted}`);
261
- } else logger.info("analyze:recipes", "No config recipes found");
262
- });
263
- cli.command("debug [glob]", "Debug design token extraction & css generated from files in glob").option("--silent", "Don't print any logs").option("--dry", "Output debug files in stdout without writing to disk").option("--outdir [dir]", "Output directory for debug files, default to './styled-system/debug'").option("--only-config", "Should only output the config file, default to 'false'").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("--cpu-prof", "Generates a `.cpuprofile` to help debug performance issues").option("--logfile <file>", "Outputs logs to a file").action(async (maybeGlob, flags = {}) => {
264
- const { silent, dry = false, outdir: outdirFlag, config: configPath } = flags ?? {};
265
- const cwd = resolve(flags.cwd);
266
- const stream = setLogStream({
267
- cwd,
268
- logfile: flags.logfile
269
- });
270
- let stopProfiling = () => void 0;
271
- if (flags.cpuProf) stopProfiling = await startProfiling(cwd, "debug");
272
- if (silent) logger.level = "silent";
273
- const ctx = await loadConfigAndCreateContext({
274
- cwd,
275
- config: maybeGlob ? { include: [maybeGlob] } : void 0,
276
- configPath
277
- });
278
- await debug(ctx, {
279
- outdir: outdirFlag ?? join(...ctx.paths.root, "debug"),
280
- dry,
281
- onlyConfig: flags.onlyConfig
282
- });
283
- stopProfiling();
284
- stream.end();
285
- });
286
- cli.command("ship [glob]", "Ship extract result from files in glob").option("--silent", "Don't print any logs").option("--o, --outfile [file]", "Output path for the build info file, default to './styled-system/bamboo.buildinfo.json'").option("-m, --minify", "Minify generated JSON file").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("-w, --watch", "Watch files and rebuild").option("-p, --poll", "Use polling instead of filesystem events when watching").action(async (maybeGlob, flags = {}) => {
287
- const { silent, outfile: outfileFlag, minify, config: configPath, watch, poll } = flags;
288
- const cwd = resolve(flags.cwd);
289
- if (silent) logger.level = "silent";
290
- let ctx = await loadConfigAndCreateContext({
291
- cwd,
292
- config: maybeGlob ? { include: [maybeGlob] } : void 0,
293
- configPath
294
- });
295
- const outfile = outfileFlag ?? join(...ctx.paths.root, "bamboo.buildinfo.json");
296
- if (minify) ctx.config.minify = true;
297
- await buildInfo(ctx, outfile);
298
- if (watch) {
299
- ctx.watchConfig(async () => {
300
- const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
301
- ctx = new BambooContext(conf);
302
- });
303
- await ctx.hooks["config:change"]?.({
304
- config: ctx.config,
305
- changes: affecteds
306
- });
307
- await buildInfo(ctx, outfile);
308
- logger.info("ctx:updated", "config rebuilt ✅");
309
- }, {
310
- cwd,
311
- poll
312
- });
313
- ctx.watchFiles(async (event, file) => {
314
- if (event === "unlink") ctx.project.removeSourceFile(ctx.runtime.path.abs(cwd, file));
315
- else if (event === "change") {
316
- ctx.project.reloadSourceFile(file);
317
- await buildInfo(ctx, outfile);
318
- } else if (event === "add") {
319
- ctx.project.createSourceFile(file);
320
- await buildInfo(ctx, outfile);
321
- }
322
- });
323
- }
324
- });
325
- cli.command("emit-pkg", "Emit package.json with entrypoints").option("--outdir <dir>", "Output directory", { default: "." }).option("--base <source>", "The base directory of the package.json entrypoints").option("--silent", "Don't print any logs").option("--cwd <cwd>", "Current working directory", { default: cwd }).action(async (flags) => {
326
- const { outdir, silent, base } = flags;
327
- if (silent) logger.level = "silent";
328
- const cwd = resolve(flags.cwd);
329
- const ctx = await loadConfigAndCreateContext({
330
- cwd,
331
- config: { cwd }
332
- });
333
- const pkgPath = resolve(cwd, outdir, "package.json");
334
- const exists = ctx.runtime.fs.existsSync(pkgPath);
335
- const exports = [];
336
- const createDir = (...dir) => {
337
- return [
338
- ".",
339
- base,
340
- ...dir
341
- ].filter(Boolean).join("/");
342
- };
343
- const createEntry = (dir) => ({
344
- types: ctx.file.extDts(createDir(dir, "index")),
345
- require: ctx.file.ext(createDir(dir, "index")),
346
- import: ctx.file.ext(createDir(dir, "index"))
347
- });
348
- exports.push(["./css", createEntry("css")], ["./tokens", createEntry("tokens")], ["./types", createEntry("types")]);
349
- if (!ctx.patterns.isEmpty()) exports.push(["./patterns", createEntry("patterns")]);
350
- if (!ctx.recipes.isEmpty()) exports.push(["./recipes", createEntry("recipes")]);
351
- if (!ctx.patterns.isEmpty()) exports.push(["./jsx", createEntry("jsx")]);
352
- if (ctx.config.themes) exports.push(["./themes", createEntry("themes")]);
353
- const stylesDir = createDir("styles.css");
354
- if (!exists) {
355
- const content = {
356
- name: outdir,
357
- description: "This package is auto-generated by Bamboo CSS",
358
- version: "0.1.0",
359
- type: "module",
360
- keywords: [
361
- "bamboocss",
362
- "styled-system",
363
- "codegen"
364
- ],
365
- license: "ISC",
366
- exports: {
367
- ...Object.fromEntries(exports),
368
- "./styles.css": stylesDir
369
- },
370
- scripts: { prepare: "bamboo codegen --clean" }
371
- };
372
- await ctx.runtime.fs.writeFile(pkgPath, JSON.stringify(content, null, 2));
373
- } else {
374
- const content = JSON.parse(ctx.runtime.fs.readFileSync(pkgPath));
375
- content.exports = {
376
- ...content.exports,
377
- ...Object.fromEntries(exports),
378
- "./styles.css": stylesDir
379
- };
380
- await ctx.runtime.fs.writeFile(pkgPath, JSON.stringify(content, null, 2));
381
- }
382
- logger.info("cli", `Emit package.json to ${pkgPath}`);
383
- });
384
- cli.command("mcp", "Start MCP server for AI assistants").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).action(async (mcpFlags) => {
385
- const { startMcpServer } = await import("@bamboocss/mcp");
386
- await startMcpServer(mcpFlags);
387
- });
388
- cli.command("init-mcp", "Initialize MCP configuration for AI clients").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("--client <clients>", "AI clients to configure (claude, cursor, vscode, windsurf, codex)").action(async (mcpInitFlags) => {
389
- const { initMcpConfig } = await import("@bamboocss/mcp");
390
- const resolvedCwd = resolve(mcpInitFlags.cwd ?? cwd);
391
- let clients;
392
- if (mcpInitFlags.client) clients = (Array.isArray(mcpInitFlags.client) ? mcpInitFlags.client : [mcpInitFlags.client]).flatMap((c) => c.split(",")).map((c) => c.trim());
393
- await initMcpConfig({
394
- cwd: resolvedCwd,
395
- clients
396
- });
397
- });
398
- cli.help();
399
- cli.version(version);
400
- cli.parse(process.argv, { run: false });
401
- await cli.runMatchedCommand();
402
- }
403
- //#endregion
404
- export { __toESM as a, __require as i, __commonJSMin as n, __esmMin as r, main as t };
@@ -1,125 +0,0 @@
1
- require("./chunk-C2EiDwsr.cjs");
2
- let worker_threads = require("worker_threads");
3
- let _bamboocss_shared = require("@bamboocss/shared");
4
- //#region ../../node_modules/.pnpm/kleur@4.1.5/node_modules/kleur/index.mjs
5
- let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY = true;
6
- if (typeof process !== "undefined") {
7
- ({FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM} = process.env || {});
8
- isTTY = process.stdout && process.stdout.isTTY;
9
- }
10
- const $ = {
11
- enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== "dumb" && (FORCE_COLOR != null && FORCE_COLOR !== "0" || isTTY),
12
- reset: init(0, 0),
13
- bold: init(1, 22),
14
- dim: init(2, 22),
15
- italic: init(3, 23),
16
- underline: init(4, 24),
17
- inverse: init(7, 27),
18
- hidden: init(8, 28),
19
- strikethrough: init(9, 29),
20
- black: init(30, 39),
21
- red: init(31, 39),
22
- green: init(32, 39),
23
- yellow: init(33, 39),
24
- blue: init(34, 39),
25
- magenta: init(35, 39),
26
- cyan: init(36, 39),
27
- white: init(37, 39),
28
- gray: init(90, 39),
29
- grey: init(90, 39),
30
- bgBlack: init(40, 49),
31
- bgRed: init(41, 49),
32
- bgGreen: init(42, 49),
33
- bgYellow: init(43, 49),
34
- bgBlue: init(44, 49),
35
- bgMagenta: init(45, 49),
36
- bgCyan: init(46, 49),
37
- bgWhite: init(47, 49)
38
- };
39
- function run(arr, str) {
40
- let i = 0, tmp, beg = "", end = "";
41
- for (; i < arr.length; i++) {
42
- tmp = arr[i];
43
- beg += tmp.open;
44
- end += tmp.close;
45
- if (!!~str.indexOf(tmp.close)) str = str.replace(tmp.rgx, tmp.close + tmp.open);
46
- }
47
- return beg + str + end;
48
- }
49
- function chain(has, keys) {
50
- let ctx = {
51
- has,
52
- keys
53
- };
54
- ctx.reset = $.reset.bind(ctx);
55
- ctx.bold = $.bold.bind(ctx);
56
- ctx.dim = $.dim.bind(ctx);
57
- ctx.italic = $.italic.bind(ctx);
58
- ctx.underline = $.underline.bind(ctx);
59
- ctx.inverse = $.inverse.bind(ctx);
60
- ctx.hidden = $.hidden.bind(ctx);
61
- ctx.strikethrough = $.strikethrough.bind(ctx);
62
- ctx.black = $.black.bind(ctx);
63
- ctx.red = $.red.bind(ctx);
64
- ctx.green = $.green.bind(ctx);
65
- ctx.yellow = $.yellow.bind(ctx);
66
- ctx.blue = $.blue.bind(ctx);
67
- ctx.magenta = $.magenta.bind(ctx);
68
- ctx.cyan = $.cyan.bind(ctx);
69
- ctx.white = $.white.bind(ctx);
70
- ctx.gray = $.gray.bind(ctx);
71
- ctx.grey = $.grey.bind(ctx);
72
- ctx.bgBlack = $.bgBlack.bind(ctx);
73
- ctx.bgRed = $.bgRed.bind(ctx);
74
- ctx.bgGreen = $.bgGreen.bind(ctx);
75
- ctx.bgYellow = $.bgYellow.bind(ctx);
76
- ctx.bgBlue = $.bgBlue.bind(ctx);
77
- ctx.bgMagenta = $.bgMagenta.bind(ctx);
78
- ctx.bgCyan = $.bgCyan.bind(ctx);
79
- ctx.bgWhite = $.bgWhite.bind(ctx);
80
- return ctx;
81
- }
82
- function init(open, close) {
83
- let blk = {
84
- open: `\x1b[${open}m`,
85
- close: `\x1b[${close}m`,
86
- rgx: new RegExp(`\\x1b\\[${close}m`, "g")
87
- };
88
- return function(txt) {
89
- if (this !== void 0 && this.has !== void 0) {
90
- ~this.has.indexOf(open) || (this.has.push(open), this.keys.push(blk));
91
- return txt === void 0 ? this : $.enabled ? run(this.keys, txt + "") : txt + "";
92
- }
93
- return txt === void 0 ? chain([open], [blk]) : $.enabled ? run([blk], txt + "") : txt + "";
94
- };
95
- }
96
- //#endregion
97
- //#region src/errors.ts
98
- function handleError(error) {
99
- if (error instanceof _bamboocss_shared.BambooError) {
100
- console.error($.red(`${error.code}: ${error.message}`));
101
- if (error.hint) console.error($.dim(error.hint));
102
- if (error.cause instanceof Error) console.error($.dim(`Caused by: ${error.cause.message}`));
103
- } else if (isLocError(error)) {
104
- console.error($.bold($.red(`Error parsing: ${error.loc.file}:${error.loc.line}:${error.loc.column}`)));
105
- if (error.frame) {
106
- console.error($.red(error.message));
107
- console.error($.dim(error.frame));
108
- } else console.error($.red(error.message));
109
- } else {
110
- const message = error instanceof Error ? error.message : String(error);
111
- console.error($.red(message));
112
- }
113
- process.exitCode = 1;
114
- if (!worker_threads.isMainThread && worker_threads.parentPort) worker_threads.parentPort.postMessage("error");
115
- }
116
- function isLocError(error) {
117
- return typeof error === "object" && error !== null && "loc" in error && typeof error.loc === "object" && "message" in error;
118
- }
119
- //#endregion
120
- Object.defineProperty(exports, "handleError", {
121
- enumerable: true,
122
- get: function() {
123
- return handleError;
124
- }
125
- });
@@ -1,119 +0,0 @@
1
- import { isMainThread, parentPort } from "worker_threads";
2
- import { BambooError } from "@bamboocss/shared";
3
- //#region ../../node_modules/.pnpm/kleur@4.1.5/node_modules/kleur/index.mjs
4
- let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY = true;
5
- if (typeof process !== "undefined") {
6
- ({FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM} = process.env || {});
7
- isTTY = process.stdout && process.stdout.isTTY;
8
- }
9
- const $ = {
10
- enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== "dumb" && (FORCE_COLOR != null && FORCE_COLOR !== "0" || isTTY),
11
- reset: init(0, 0),
12
- bold: init(1, 22),
13
- dim: init(2, 22),
14
- italic: init(3, 23),
15
- underline: init(4, 24),
16
- inverse: init(7, 27),
17
- hidden: init(8, 28),
18
- strikethrough: init(9, 29),
19
- black: init(30, 39),
20
- red: init(31, 39),
21
- green: init(32, 39),
22
- yellow: init(33, 39),
23
- blue: init(34, 39),
24
- magenta: init(35, 39),
25
- cyan: init(36, 39),
26
- white: init(37, 39),
27
- gray: init(90, 39),
28
- grey: init(90, 39),
29
- bgBlack: init(40, 49),
30
- bgRed: init(41, 49),
31
- bgGreen: init(42, 49),
32
- bgYellow: init(43, 49),
33
- bgBlue: init(44, 49),
34
- bgMagenta: init(45, 49),
35
- bgCyan: init(46, 49),
36
- bgWhite: init(47, 49)
37
- };
38
- function run(arr, str) {
39
- let i = 0, tmp, beg = "", end = "";
40
- for (; i < arr.length; i++) {
41
- tmp = arr[i];
42
- beg += tmp.open;
43
- end += tmp.close;
44
- if (!!~str.indexOf(tmp.close)) str = str.replace(tmp.rgx, tmp.close + tmp.open);
45
- }
46
- return beg + str + end;
47
- }
48
- function chain(has, keys) {
49
- let ctx = {
50
- has,
51
- keys
52
- };
53
- ctx.reset = $.reset.bind(ctx);
54
- ctx.bold = $.bold.bind(ctx);
55
- ctx.dim = $.dim.bind(ctx);
56
- ctx.italic = $.italic.bind(ctx);
57
- ctx.underline = $.underline.bind(ctx);
58
- ctx.inverse = $.inverse.bind(ctx);
59
- ctx.hidden = $.hidden.bind(ctx);
60
- ctx.strikethrough = $.strikethrough.bind(ctx);
61
- ctx.black = $.black.bind(ctx);
62
- ctx.red = $.red.bind(ctx);
63
- ctx.green = $.green.bind(ctx);
64
- ctx.yellow = $.yellow.bind(ctx);
65
- ctx.blue = $.blue.bind(ctx);
66
- ctx.magenta = $.magenta.bind(ctx);
67
- ctx.cyan = $.cyan.bind(ctx);
68
- ctx.white = $.white.bind(ctx);
69
- ctx.gray = $.gray.bind(ctx);
70
- ctx.grey = $.grey.bind(ctx);
71
- ctx.bgBlack = $.bgBlack.bind(ctx);
72
- ctx.bgRed = $.bgRed.bind(ctx);
73
- ctx.bgGreen = $.bgGreen.bind(ctx);
74
- ctx.bgYellow = $.bgYellow.bind(ctx);
75
- ctx.bgBlue = $.bgBlue.bind(ctx);
76
- ctx.bgMagenta = $.bgMagenta.bind(ctx);
77
- ctx.bgCyan = $.bgCyan.bind(ctx);
78
- ctx.bgWhite = $.bgWhite.bind(ctx);
79
- return ctx;
80
- }
81
- function init(open, close) {
82
- let blk = {
83
- open: `\x1b[${open}m`,
84
- close: `\x1b[${close}m`,
85
- rgx: new RegExp(`\\x1b\\[${close}m`, "g")
86
- };
87
- return function(txt) {
88
- if (this !== void 0 && this.has !== void 0) {
89
- ~this.has.indexOf(open) || (this.has.push(open), this.keys.push(blk));
90
- return txt === void 0 ? this : $.enabled ? run(this.keys, txt + "") : txt + "";
91
- }
92
- return txt === void 0 ? chain([open], [blk]) : $.enabled ? run([blk], txt + "") : txt + "";
93
- };
94
- }
95
- //#endregion
96
- //#region src/errors.ts
97
- function handleError(error) {
98
- if (error instanceof BambooError) {
99
- console.error($.red(`${error.code}: ${error.message}`));
100
- if (error.hint) console.error($.dim(error.hint));
101
- if (error.cause instanceof Error) console.error($.dim(`Caused by: ${error.cause.message}`));
102
- } else if (isLocError(error)) {
103
- console.error($.bold($.red(`Error parsing: ${error.loc.file}:${error.loc.line}:${error.loc.column}`)));
104
- if (error.frame) {
105
- console.error($.red(error.message));
106
- console.error($.dim(error.frame));
107
- } else console.error($.red(error.message));
108
- } else {
109
- const message = error instanceof Error ? error.message : String(error);
110
- console.error($.red(message));
111
- }
112
- process.exitCode = 1;
113
- if (!isMainThread && parentPort) parentPort.postMessage("error");
114
- }
115
- function isLocError(error) {
116
- return typeof error === "object" && error !== null && "loc" in error && typeof error.loc === "object" && "message" in error;
117
- }
118
- //#endregion
119
- export { handleError as t };