@bamboocss/dev 1.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.
@@ -0,0 +1,537 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/cli-main.ts
31
+ var cli_main_exports = {};
32
+ __export(cli_main_exports, {
33
+ main: () => main
34
+ });
35
+ module.exports = __toCommonJS(cli_main_exports);
36
+ var import_config = require("@bamboocss/config");
37
+ var import_logger = require("@bamboocss/logger");
38
+ var import_node = require("@bamboocss/node");
39
+ var import_shared = require("@bamboocss/shared");
40
+ var import_cac = require("cac");
41
+ var import_path = require("path");
42
+
43
+ // package.json
44
+ var version = "1.11.1";
45
+
46
+ // src/interactive.ts
47
+ var p = __toESM(require("@clack/prompts"));
48
+ var interactive = async () => {
49
+ p.intro(`bamboo v${version}`);
50
+ const initFlags = await p.group(
51
+ {
52
+ usePostcss: () => p.select({
53
+ message: "Would you like to use PostCSS ?",
54
+ initialValue: "yes",
55
+ options: [
56
+ { value: "yes", label: "Yes" },
57
+ { value: "no", label: "No" }
58
+ ]
59
+ }),
60
+ useMjsExtension: () => p.select({
61
+ message: "Use the mjs extension ?",
62
+ initialValue: "yes",
63
+ options: [
64
+ { value: "yes", label: "Yes" },
65
+ { value: "no", label: "No" }
66
+ ]
67
+ }),
68
+ jsxOptions: () => p.group({
69
+ styleProps: () => p.select({
70
+ message: "Would you like to use JSX Style Props ?",
71
+ initialValue: "yes",
72
+ options: [
73
+ { value: "yes", label: "Yes" },
74
+ { value: "no", label: "No" }
75
+ ]
76
+ }),
77
+ jsxFramework: () => p.select({
78
+ message: "What JSX framework?",
79
+ initialValue: "react",
80
+ options: [
81
+ { value: "react", label: "React" },
82
+ { value: "vue", label: "Vue" },
83
+ { value: "solid", label: "Solid" },
84
+ { value: "qwik", label: "Qwik" }
85
+ ]
86
+ })
87
+ }),
88
+ whatSyntax: () => p.select({
89
+ message: "What css syntax would you like to use?",
90
+ initialValue: "object",
91
+ options: [
92
+ { value: "object-literal", label: "Object" },
93
+ { value: "template-literal", label: "Template literal" }
94
+ ]
95
+ }),
96
+ withStrictTokens: () => p.select({
97
+ message: "Use strict tokens to enforce full type-safety?",
98
+ initialValue: "no",
99
+ options: [
100
+ { value: "yes", label: "Yes" },
101
+ { value: "no", label: "No" }
102
+ ]
103
+ }),
104
+ shouldUpdateGitignore: () => p.select({
105
+ message: "Update gitignore?",
106
+ initialValue: "yes",
107
+ options: [
108
+ { value: "yes", label: "Yes" },
109
+ { value: "no", label: "No" }
110
+ ]
111
+ })
112
+ },
113
+ {
114
+ // On Cancel callback that wraps the group
115
+ // So if the user cancels one of the prompts in the group this function will be called
116
+ onCancel: () => {
117
+ p.cancel("Operation cancelled.");
118
+ process.exit(0);
119
+ }
120
+ }
121
+ );
122
+ p.outro("Let's get started! \u{1F43C}");
123
+ return {
124
+ postcss: initFlags.usePostcss === "yes",
125
+ outExtension: initFlags.useMjsExtension === "yes" ? "mjs" : "js",
126
+ jsxFramework: initFlags.jsxOptions.jsxFramework,
127
+ syntax: initFlags.whatSyntax,
128
+ strictTokens: initFlags.withStrictTokens === "yes",
129
+ gitignore: initFlags.shouldUpdateGitignore === "yes"
130
+ };
131
+ };
132
+
133
+ // src/cli-main.ts
134
+ async function main() {
135
+ const cli = (0, import_cac.cac)("bamboo");
136
+ const cwd = process.cwd();
137
+ 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 = {}) => {
138
+ let options = {};
139
+ if (initFlags.interactive) {
140
+ options = await interactive();
141
+ }
142
+ const flags = { ...initFlags, ...options };
143
+ const { force, postcss, silent, gitignore, outExtension, jsxFramework, config: configPath, syntax } = flags;
144
+ const cwd2 = (0, import_path.resolve)(flags.cwd ?? "");
145
+ if (silent) {
146
+ import_logger.logger.level = "silent";
147
+ }
148
+ const stream = (0, import_node.setLogStream)({ cwd: cwd2, logfile: flags.logfile });
149
+ import_logger.logger.info("cli", `Bamboo v${version}
150
+ `);
151
+ const done = import_logger.logger.time.info("\u2728 Bamboo initialized");
152
+ if (postcss) {
153
+ await (0, import_node.setupPostcss)(cwd2);
154
+ }
155
+ await (0, import_node.setupConfig)(
156
+ cwd2,
157
+ (0, import_shared.compact)({
158
+ force,
159
+ outExtension,
160
+ jsxFramework,
161
+ syntax,
162
+ outdir: flags.outdir
163
+ })
164
+ );
165
+ const ctx = await (0, import_node.loadConfigAndCreateContext)({
166
+ cwd: cwd2,
167
+ configPath,
168
+ config: (0, import_shared.compact)({ gitignore, outdir: flags.outdir })
169
+ });
170
+ if (gitignore) {
171
+ (0, import_node.setupGitIgnore)(ctx);
172
+ }
173
+ if (flags.codegen) {
174
+ const { msg, box } = await (0, import_node.codegen)(ctx);
175
+ import_logger.logger.log(msg + box);
176
+ } else {
177
+ import_logger.logger.log(ctx.initMessage());
178
+ }
179
+ done();
180
+ stream.end();
181
+ });
182
+ 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) => {
183
+ const { silent, clean, config: configPath, watch, poll } = flags;
184
+ const cwd2 = (0, import_path.resolve)(flags.cwd ?? "");
185
+ const stream = (0, import_node.setLogStream)({ cwd: cwd2, logfile: flags.logfile });
186
+ let stopProfiling = () => void 0;
187
+ if (flags.cpuProf) {
188
+ stopProfiling = await (0, import_node.startProfiling)(cwd2, "codegen", flags.watch);
189
+ }
190
+ if (silent) {
191
+ import_logger.logger.level = "silent";
192
+ }
193
+ let ctx = await (0, import_node.loadConfigAndCreateContext)({
194
+ cwd: cwd2,
195
+ config: { clean },
196
+ configPath
197
+ });
198
+ const { msg } = await (0, import_node.codegen)(ctx);
199
+ import_logger.logger.log(msg);
200
+ if (watch) {
201
+ ctx.watchConfig(
202
+ async () => {
203
+ const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
204
+ ctx = new import_node.BambooContext(conf);
205
+ });
206
+ await ctx.hooks["config:change"]?.({ config: ctx.config, changes: affecteds });
207
+ await (0, import_node.codegen)(ctx, Array.from(affecteds.artifacts));
208
+ import_logger.logger.info("ctx:updated", "config rebuilt \u2705");
209
+ },
210
+ { cwd: cwd2, poll }
211
+ );
212
+ } else {
213
+ stream.end();
214
+ }
215
+ stopProfiling();
216
+ });
217
+ cli.command(
218
+ "cssgen [globOrType]",
219
+ "Generate the css from files, or generate the css from the specified type which can be: preflight, tokens, static, global, keyframes"
220
+ ).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 = {}) => {
221
+ const { silent, config: configPath, outfile, watch, poll, minimal, splitting, ...rest } = flags;
222
+ const cwd2 = (0, import_path.resolve)(flags.cwd ?? "");
223
+ const stream = (0, import_node.setLogStream)({ cwd: cwd2, logfile: flags.logfile });
224
+ let stopProfiling = () => void 0;
225
+ if (flags.cpuProf) {
226
+ stopProfiling = await (0, import_node.startProfiling)(cwd2, "cssgen", flags.watch);
227
+ }
228
+ const cssArtifact = ["preflight", "tokens", "static", "global", "keyframes"].find(
229
+ (type) => type === maybeGlob
230
+ );
231
+ const glob = cssArtifact ? void 0 : maybeGlob;
232
+ if (silent) {
233
+ import_logger.logger.level = "silent";
234
+ }
235
+ const overrideConfig = {
236
+ ...rest,
237
+ ...glob ? { include: [glob] } : void 0
238
+ };
239
+ let ctx = await (0, import_node.loadConfigAndCreateContext)({
240
+ cwd: cwd2,
241
+ config: overrideConfig,
242
+ configPath
243
+ });
244
+ const options = {
245
+ cwd: cwd2,
246
+ outfile,
247
+ type: cssArtifact,
248
+ minimal,
249
+ splitting
250
+ };
251
+ await (0, import_node.cssgen)(ctx, options);
252
+ if (watch) {
253
+ ctx.watchConfig(
254
+ async () => {
255
+ const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
256
+ ctx = new import_node.BambooContext(conf);
257
+ });
258
+ await ctx.hooks["config:change"]?.({ config: ctx.config, changes: affecteds });
259
+ await (0, import_node.cssgen)(ctx, options);
260
+ import_logger.logger.info("ctx:updated", "config rebuilt \u2705");
261
+ },
262
+ { cwd: cwd2, poll }
263
+ );
264
+ ctx.watchFiles(async (event, file) => {
265
+ if (event === "unlink") {
266
+ ctx.project.removeSourceFile(ctx.runtime.path.abs(cwd2, file));
267
+ } else if (event === "change") {
268
+ ctx.project.reloadSourceFile(file);
269
+ await (0, import_node.cssgen)(ctx, options);
270
+ } else if (event === "add") {
271
+ ctx.project.createSourceFile(file);
272
+ await (0, import_node.cssgen)(ctx, options);
273
+ }
274
+ });
275
+ } else {
276
+ stream.end();
277
+ stopProfiling();
278
+ }
279
+ });
280
+ 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) => {
281
+ const { config: configPath, silent, ...rest } = flags;
282
+ const cwd2 = (0, import_path.resolve)(flags.cwd ?? "");
283
+ const stream = (0, import_node.setLogStream)({ cwd: cwd2, logfile: flags.logfile });
284
+ let stopProfiling = () => void 0;
285
+ if (flags.cpuProf) {
286
+ stopProfiling = await (0, import_node.startProfiling)(cwd2, "cli", flags.watch);
287
+ }
288
+ if (silent) {
289
+ import_logger.logger.level = "silent";
290
+ }
291
+ const config = (0, import_shared.compact)({ include: files, ...rest, cwd: cwd2 });
292
+ await (0, import_node.generate)(config, configPath);
293
+ stopProfiling();
294
+ if (!flags.watch) {
295
+ stream.end();
296
+ }
297
+ });
298
+ 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) => {
299
+ const { silent, config: configPath, outdir } = flags;
300
+ const cwd2 = (0, import_path.resolve)(flags.cwd ?? "");
301
+ if (silent) {
302
+ import_logger.logger.level = "silent";
303
+ }
304
+ const ctx = await (0, import_node.loadConfigAndCreateContext)({
305
+ cwd: cwd2,
306
+ configPath,
307
+ config: { cwd: cwd2 }
308
+ });
309
+ await (0, import_node.spec)(ctx, { outdir });
310
+ });
311
+ 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) => {
312
+ const { build, preview, port, host, outdir, config, base } = flags;
313
+ const cwd2 = (0, import_path.resolve)(flags.cwd ?? "");
314
+ const ctx = await (0, import_node.loadConfigAndCreateContext)({
315
+ cwd: cwd2,
316
+ configPath: config
317
+ });
318
+ const buildOpts = {
319
+ configPath: (0, import_config.findConfig)({ cwd: cwd2, file: config }),
320
+ outDir: (0, import_path.resolve)(outdir || ctx.studio.outdir),
321
+ port,
322
+ host,
323
+ base
324
+ };
325
+ let studio;
326
+ try {
327
+ const studioPath = require.resolve("@bamboocss/studio", { paths: [cwd2] });
328
+ studio = require(studioPath);
329
+ } catch (error) {
330
+ throw new import_shared.BambooError("MISSING_STUDIO", "You need to install '@bamboocss/studio' to use this command", {
331
+ cause: error
332
+ });
333
+ }
334
+ if (preview) {
335
+ await studio.previewStudio(buildOpts);
336
+ } else if (build) {
337
+ await studio.buildStudio(buildOpts);
338
+ } else {
339
+ await studio.serveStudio(buildOpts);
340
+ const note = `use ${import_logger.colors.reset(import_logger.colors.bold("--build"))} to build`;
341
+ const port2 = `use ${import_logger.colors.reset(import_logger.colors.bold("--port"))} for a different port`;
342
+ import_logger.logger.log(import_logger.colors.dim(` ${import_logger.colors.green("\u279C")} ${import_logger.colors.bold("Build")}: ${note}`));
343
+ import_logger.logger.log(import_logger.colors.dim(` ${import_logger.colors.green("\u279C")} ${import_logger.colors.bold("Port")}: ${port2}`));
344
+ }
345
+ });
346
+ 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 = {}) => {
347
+ const { silent, config: configPath, scope } = flags;
348
+ const tokenScope = scope == null || scope === "token";
349
+ const recipeScope = scope == null || scope === "recipe";
350
+ const cwd2 = (0, import_path.resolve)(flags.cwd);
351
+ if (silent) {
352
+ import_logger.logger.level = "silent";
353
+ }
354
+ const ctx = await (0, import_node.loadConfigAndCreateContext)({
355
+ cwd: cwd2,
356
+ config: maybeGlob ? { include: [maybeGlob] } : void 0,
357
+ configPath
358
+ });
359
+ const result = (0, import_node.analyze)(ctx);
360
+ if (flags?.outfile && typeof flags.outfile === "string") {
361
+ await result.writeReport(flags.outfile);
362
+ import_logger.logger.info("cli", `JSON report saved to ${(0, import_path.resolve)(flags.outfile)}`);
363
+ return;
364
+ }
365
+ if (tokenScope) {
366
+ if (!ctx.tokens.isEmpty) {
367
+ const tokenAnalysis = result.getTokenReport();
368
+ import_logger.logger.info("analyze:tokens", `Token usage report \u{1F3A8}
369
+ ${tokenAnalysis.formatted}`);
370
+ } else {
371
+ import_logger.logger.info("analyze:tokens", "No tokens found");
372
+ }
373
+ }
374
+ if (recipeScope) {
375
+ if (!ctx.recipes.isEmpty()) {
376
+ const recipeAnalysis = result.getRecipeReport();
377
+ import_logger.logger.info("analyze:recipes", `Config recipes usage report \u{1F39B}\uFE0F
378
+ ${recipeAnalysis.formatted}`);
379
+ } else {
380
+ import_logger.logger.info("analyze:recipes", "No config recipes found");
381
+ }
382
+ }
383
+ });
384
+ 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 = {}) => {
385
+ const { silent, dry = false, outdir: outdirFlag, config: configPath } = flags ?? {};
386
+ const cwd2 = (0, import_path.resolve)(flags.cwd);
387
+ const stream = (0, import_node.setLogStream)({ cwd: cwd2, logfile: flags.logfile });
388
+ let stopProfiling = () => void 0;
389
+ if (flags.cpuProf) {
390
+ stopProfiling = await (0, import_node.startProfiling)(cwd2, "debug");
391
+ }
392
+ if (silent) {
393
+ import_logger.logger.level = "silent";
394
+ }
395
+ const ctx = await (0, import_node.loadConfigAndCreateContext)({
396
+ cwd: cwd2,
397
+ config: maybeGlob ? { include: [maybeGlob] } : void 0,
398
+ configPath
399
+ });
400
+ const outdir = outdirFlag ?? (0, import_path.join)(...ctx.paths.root, "debug");
401
+ await (0, import_node.debug)(ctx, { outdir, dry, onlyConfig: flags.onlyConfig });
402
+ stopProfiling();
403
+ stream.end();
404
+ });
405
+ cli.command("ship [glob]", "Ship extract result from files in glob").option("--silent", "Don't print any logs").option(
406
+ "--o, --outfile [file]",
407
+ "Output path for the build info file, default to './styled-system/bamboo.buildinfo.json'"
408
+ ).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 = {}) => {
409
+ const { silent, outfile: outfileFlag, minify, config: configPath, watch, poll } = flags;
410
+ const cwd2 = (0, import_path.resolve)(flags.cwd);
411
+ if (silent) {
412
+ import_logger.logger.level = "silent";
413
+ }
414
+ let ctx = await (0, import_node.loadConfigAndCreateContext)({
415
+ cwd: cwd2,
416
+ config: maybeGlob ? { include: [maybeGlob] } : void 0,
417
+ configPath
418
+ });
419
+ const outfile = outfileFlag ?? (0, import_path.join)(...ctx.paths.root, "bamboo.buildinfo.json");
420
+ if (minify) {
421
+ ctx.config.minify = true;
422
+ }
423
+ await (0, import_node.buildInfo)(ctx, outfile);
424
+ if (watch) {
425
+ ctx.watchConfig(
426
+ async () => {
427
+ const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
428
+ ctx = new import_node.BambooContext(conf);
429
+ });
430
+ await ctx.hooks["config:change"]?.({ config: ctx.config, changes: affecteds });
431
+ await (0, import_node.buildInfo)(ctx, outfile);
432
+ import_logger.logger.info("ctx:updated", "config rebuilt \u2705");
433
+ },
434
+ { cwd: cwd2, poll }
435
+ );
436
+ ctx.watchFiles(async (event, file) => {
437
+ if (event === "unlink") {
438
+ ctx.project.removeSourceFile(ctx.runtime.path.abs(cwd2, file));
439
+ } else if (event === "change") {
440
+ ctx.project.reloadSourceFile(file);
441
+ await (0, import_node.buildInfo)(ctx, outfile);
442
+ } else if (event === "add") {
443
+ ctx.project.createSourceFile(file);
444
+ await (0, import_node.buildInfo)(ctx, outfile);
445
+ }
446
+ });
447
+ }
448
+ });
449
+ 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) => {
450
+ const { outdir, silent, base } = flags;
451
+ if (silent) {
452
+ import_logger.logger.level = "silent";
453
+ }
454
+ const cwd2 = (0, import_path.resolve)(flags.cwd);
455
+ const ctx = await (0, import_node.loadConfigAndCreateContext)({
456
+ cwd: cwd2,
457
+ config: { cwd: cwd2 }
458
+ });
459
+ const pkgPath = (0, import_path.resolve)(cwd2, outdir, "package.json");
460
+ const exists = ctx.runtime.fs.existsSync(pkgPath);
461
+ const exports2 = [];
462
+ const createDir = (...dir) => {
463
+ return [".", base, ...dir].filter(Boolean).join("/");
464
+ };
465
+ const createEntry = (dir) => ({
466
+ types: ctx.file.extDts(createDir(dir, "index")),
467
+ require: ctx.file.ext(createDir(dir, "index")),
468
+ import: ctx.file.ext(createDir(dir, "index"))
469
+ });
470
+ exports2.push(
471
+ ["./css", createEntry("css")],
472
+ ["./tokens", createEntry("tokens")],
473
+ ["./types", createEntry("types")]
474
+ );
475
+ if (!ctx.patterns.isEmpty()) {
476
+ exports2.push(["./patterns", createEntry("patterns")]);
477
+ }
478
+ if (!ctx.recipes.isEmpty()) {
479
+ exports2.push(["./recipes", createEntry("recipes")]);
480
+ }
481
+ if (!ctx.patterns.isEmpty()) {
482
+ exports2.push(["./jsx", createEntry("jsx")]);
483
+ }
484
+ if (ctx.config.themes) {
485
+ exports2.push(["./themes", createEntry("themes")]);
486
+ }
487
+ const stylesDir = createDir("styles.css");
488
+ if (!exists) {
489
+ const content = {
490
+ name: outdir,
491
+ description: "This package is auto-generated by Bamboo CSS",
492
+ version: "0.1.0",
493
+ type: "module",
494
+ keywords: ["bamboocss", "styled-system", "codegen"],
495
+ license: "ISC",
496
+ exports: {
497
+ ...Object.fromEntries(exports2),
498
+ "./styles.css": stylesDir
499
+ },
500
+ scripts: {
501
+ prepare: "bamboo codegen --clean"
502
+ }
503
+ };
504
+ await ctx.runtime.fs.writeFile(pkgPath, JSON.stringify(content, null, 2));
505
+ } else {
506
+ const content = JSON.parse(ctx.runtime.fs.readFileSync(pkgPath));
507
+ content.exports = {
508
+ ...content.exports,
509
+ ...Object.fromEntries(exports2),
510
+ "./styles.css": stylesDir
511
+ };
512
+ await ctx.runtime.fs.writeFile(pkgPath, JSON.stringify(content, null, 2));
513
+ }
514
+ import_logger.logger.info("cli", `Emit package.json to ${pkgPath}`);
515
+ });
516
+ 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) => {
517
+ const { startMcpServer } = await import("@bamboocss/mcp");
518
+ await startMcpServer(mcpFlags);
519
+ });
520
+ 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) => {
521
+ const { initMcpConfig } = await import("@bamboocss/mcp");
522
+ const resolvedCwd = (0, import_path.resolve)(mcpInitFlags.cwd ?? cwd);
523
+ let clients;
524
+ if (mcpInitFlags.client) {
525
+ clients = (Array.isArray(mcpInitFlags.client) ? mcpInitFlags.client : [mcpInitFlags.client]).flatMap((c) => c.split(",")).map((c) => c.trim());
526
+ }
527
+ await initMcpConfig({ cwd: resolvedCwd, clients });
528
+ });
529
+ cli.help();
530
+ cli.version(version);
531
+ cli.parse(process.argv, { run: false });
532
+ await cli.runMatchedCommand();
533
+ }
534
+ // Annotate the CommonJS export names for ESM import in node:
535
+ 0 && (module.exports = {
536
+ main
537
+ });