@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,7 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { a as __toESM, i as __require, n as __commonJSMin, r as __esmMin, t as main } from "./cli-main-BVVeBGKc.mjs";
3
- import { t as handleError } from "./errors-DyRfueHt.mjs";
4
- import { n as name, r as version } from "./interactive-BJBHyhfI.mjs";
2
+ import { createRequire } from "node:module";
5
3
  import process$1, { env } from "node:process";
6
4
  import { spawn } from "node:child_process";
7
5
  import { fileURLToPath } from "node:url";
@@ -9,9 +7,41 @@ import path from "node:path";
9
7
  import { format, promisify } from "node:util";
10
8
  import os from "node:os";
11
9
  import os$1 from "os";
12
- import path$1 from "path";
10
+ import path$1, { join, resolve } from "path";
13
11
  import fs from "node:fs";
14
12
  import tty from "node:tty";
13
+ import { isMainThread, parentPort } from "worker_threads";
14
+ import { BambooError, compact } from "@bamboocss/shared";
15
+ import { findConfig } from "@bamboocss/config";
16
+ import { colors, logger } from "@bamboocss/logger";
17
+ import { BambooContext, analyze, buildInfo, codegen, cssgen, debug, generate, loadConfigAndCreateContext, setLogStream, setupConfig, setupGitIgnore, setupPostcss, spec, startProfiling } from "@bamboocss/node";
18
+ import { cac } from "cac";
19
+ import * as p from "@clack/prompts";
20
+ //#region \0rolldown/runtime.js
21
+ var __create = Object.create;
22
+ var __defProp = Object.defineProperty;
23
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
24
+ var __getOwnPropNames = Object.getOwnPropertyNames;
25
+ var __getProtoOf = Object.getPrototypeOf;
26
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
27
+ var __esmMin = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
28
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
29
+ var __copyProps = (to, from, except, desc) => {
30
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
31
+ key = keys[i];
32
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
33
+ get: ((k) => from[k]).bind(null, key),
34
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
35
+ });
36
+ }
37
+ return to;
38
+ };
39
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
40
+ value: mod,
41
+ enumerable: true
42
+ }) : target, mod));
43
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
44
+ //#endregion
15
45
  //#region ../../node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/polyfills.js
16
46
  var require_polyfills$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
17
47
  var constants$1 = __require("constants");
@@ -7483,6 +7513,605 @@ function updateNotifier(options) {
7483
7513
  return updateNotifier;
7484
7514
  }
7485
7515
  //#endregion
7516
+ //#region ../../node_modules/.pnpm/kleur@4.1.5/node_modules/kleur/index.mjs
7517
+ let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY = true;
7518
+ if (typeof process !== "undefined") {
7519
+ ({FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM} = process.env || {});
7520
+ isTTY = process.stdout && process.stdout.isTTY;
7521
+ }
7522
+ const $ = {
7523
+ enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== "dumb" && (FORCE_COLOR != null && FORCE_COLOR !== "0" || isTTY),
7524
+ reset: init(0, 0),
7525
+ bold: init(1, 22),
7526
+ dim: init(2, 22),
7527
+ italic: init(3, 23),
7528
+ underline: init(4, 24),
7529
+ inverse: init(7, 27),
7530
+ hidden: init(8, 28),
7531
+ strikethrough: init(9, 29),
7532
+ black: init(30, 39),
7533
+ red: init(31, 39),
7534
+ green: init(32, 39),
7535
+ yellow: init(33, 39),
7536
+ blue: init(34, 39),
7537
+ magenta: init(35, 39),
7538
+ cyan: init(36, 39),
7539
+ white: init(37, 39),
7540
+ gray: init(90, 39),
7541
+ grey: init(90, 39),
7542
+ bgBlack: init(40, 49),
7543
+ bgRed: init(41, 49),
7544
+ bgGreen: init(42, 49),
7545
+ bgYellow: init(43, 49),
7546
+ bgBlue: init(44, 49),
7547
+ bgMagenta: init(45, 49),
7548
+ bgCyan: init(46, 49),
7549
+ bgWhite: init(47, 49)
7550
+ };
7551
+ function run(arr, str) {
7552
+ let i = 0, tmp, beg = "", end = "";
7553
+ for (; i < arr.length; i++) {
7554
+ tmp = arr[i];
7555
+ beg += tmp.open;
7556
+ end += tmp.close;
7557
+ if (!!~str.indexOf(tmp.close)) str = str.replace(tmp.rgx, tmp.close + tmp.open);
7558
+ }
7559
+ return beg + str + end;
7560
+ }
7561
+ function chain(has, keys) {
7562
+ let ctx = {
7563
+ has,
7564
+ keys
7565
+ };
7566
+ ctx.reset = $.reset.bind(ctx);
7567
+ ctx.bold = $.bold.bind(ctx);
7568
+ ctx.dim = $.dim.bind(ctx);
7569
+ ctx.italic = $.italic.bind(ctx);
7570
+ ctx.underline = $.underline.bind(ctx);
7571
+ ctx.inverse = $.inverse.bind(ctx);
7572
+ ctx.hidden = $.hidden.bind(ctx);
7573
+ ctx.strikethrough = $.strikethrough.bind(ctx);
7574
+ ctx.black = $.black.bind(ctx);
7575
+ ctx.red = $.red.bind(ctx);
7576
+ ctx.green = $.green.bind(ctx);
7577
+ ctx.yellow = $.yellow.bind(ctx);
7578
+ ctx.blue = $.blue.bind(ctx);
7579
+ ctx.magenta = $.magenta.bind(ctx);
7580
+ ctx.cyan = $.cyan.bind(ctx);
7581
+ ctx.white = $.white.bind(ctx);
7582
+ ctx.gray = $.gray.bind(ctx);
7583
+ ctx.grey = $.grey.bind(ctx);
7584
+ ctx.bgBlack = $.bgBlack.bind(ctx);
7585
+ ctx.bgRed = $.bgRed.bind(ctx);
7586
+ ctx.bgGreen = $.bgGreen.bind(ctx);
7587
+ ctx.bgYellow = $.bgYellow.bind(ctx);
7588
+ ctx.bgBlue = $.bgBlue.bind(ctx);
7589
+ ctx.bgMagenta = $.bgMagenta.bind(ctx);
7590
+ ctx.bgCyan = $.bgCyan.bind(ctx);
7591
+ ctx.bgWhite = $.bgWhite.bind(ctx);
7592
+ return ctx;
7593
+ }
7594
+ function init(open, close) {
7595
+ let blk = {
7596
+ open: `\x1b[${open}m`,
7597
+ close: `\x1b[${close}m`,
7598
+ rgx: new RegExp(`\\x1b\\[${close}m`, "g")
7599
+ };
7600
+ return function(txt) {
7601
+ if (this !== void 0 && this.has !== void 0) {
7602
+ ~this.has.indexOf(open) || (this.has.push(open), this.keys.push(blk));
7603
+ return txt === void 0 ? this : $.enabled ? run(this.keys, txt + "") : txt + "";
7604
+ }
7605
+ return txt === void 0 ? chain([open], [blk]) : $.enabled ? run([blk], txt + "") : txt + "";
7606
+ };
7607
+ }
7608
+ //#endregion
7609
+ //#region src/errors.ts
7610
+ function handleError(error) {
7611
+ if (error instanceof BambooError) {
7612
+ console.error($.red(`${error.code}: ${error.message}`));
7613
+ if (error.hint) console.error($.dim(error.hint));
7614
+ if (error.cause instanceof Error) console.error($.dim(`Caused by: ${error.cause.message}`));
7615
+ } else if (isLocError(error)) {
7616
+ console.error($.bold($.red(`Error parsing: ${error.loc.file}:${error.loc.line}:${error.loc.column}`)));
7617
+ if (error.frame) {
7618
+ console.error($.red(error.message));
7619
+ console.error($.dim(error.frame));
7620
+ } else console.error($.red(error.message));
7621
+ } else {
7622
+ const message = error instanceof Error ? error.message : String(error);
7623
+ console.error($.red(message));
7624
+ }
7625
+ process.exitCode = 1;
7626
+ if (!isMainThread && parentPort) parentPort.postMessage("error");
7627
+ }
7628
+ function isLocError(error) {
7629
+ return typeof error === "object" && error !== null && "loc" in error && typeof error.loc === "object" && "message" in error;
7630
+ }
7631
+ //#endregion
7632
+ //#region package.json
7633
+ var name = "@bamboocss/dev";
7634
+ var version = "1.12.0";
7635
+ //#endregion
7636
+ //#region src/interactive.ts
7637
+ const interactive = async () => {
7638
+ p.intro(`bamboo v${version}`);
7639
+ const initFlags = await p.group({
7640
+ usePostcss: () => p.select({
7641
+ message: "Would you like to use PostCSS ?",
7642
+ initialValue: "yes",
7643
+ options: [{
7644
+ value: "yes",
7645
+ label: "Yes"
7646
+ }, {
7647
+ value: "no",
7648
+ label: "No"
7649
+ }]
7650
+ }),
7651
+ useMjsExtension: () => p.select({
7652
+ message: "Use the mjs extension ?",
7653
+ initialValue: "yes",
7654
+ options: [{
7655
+ value: "yes",
7656
+ label: "Yes"
7657
+ }, {
7658
+ value: "no",
7659
+ label: "No"
7660
+ }]
7661
+ }),
7662
+ jsxOptions: () => p.group({
7663
+ styleProps: () => p.select({
7664
+ message: "Would you like to use JSX Style Props ?",
7665
+ initialValue: "yes",
7666
+ options: [{
7667
+ value: "yes",
7668
+ label: "Yes"
7669
+ }, {
7670
+ value: "no",
7671
+ label: "No"
7672
+ }]
7673
+ }),
7674
+ jsxFramework: () => p.select({
7675
+ message: "What JSX framework?",
7676
+ initialValue: "react",
7677
+ options: [
7678
+ {
7679
+ value: "react",
7680
+ label: "React"
7681
+ },
7682
+ {
7683
+ value: "vue",
7684
+ label: "Vue"
7685
+ },
7686
+ {
7687
+ value: "solid",
7688
+ label: "Solid"
7689
+ },
7690
+ {
7691
+ value: "qwik",
7692
+ label: "Qwik"
7693
+ }
7694
+ ]
7695
+ })
7696
+ }),
7697
+ whatSyntax: () => p.select({
7698
+ message: "What css syntax would you like to use?",
7699
+ initialValue: "object",
7700
+ options: [{
7701
+ value: "object-literal",
7702
+ label: "Object"
7703
+ }, {
7704
+ value: "template-literal",
7705
+ label: "Template literal"
7706
+ }]
7707
+ }),
7708
+ withStrictTokens: () => p.select({
7709
+ message: "Use strict tokens to enforce full type-safety?",
7710
+ initialValue: "no",
7711
+ options: [{
7712
+ value: "yes",
7713
+ label: "Yes"
7714
+ }, {
7715
+ value: "no",
7716
+ label: "No"
7717
+ }]
7718
+ }),
7719
+ shouldUpdateGitignore: () => p.select({
7720
+ message: "Update gitignore?",
7721
+ initialValue: "yes",
7722
+ options: [{
7723
+ value: "yes",
7724
+ label: "Yes"
7725
+ }, {
7726
+ value: "no",
7727
+ label: "No"
7728
+ }]
7729
+ })
7730
+ }, { onCancel: () => {
7731
+ p.cancel("Operation cancelled.");
7732
+ process.exit(0);
7733
+ } });
7734
+ p.outro("Let's get started! 🐼");
7735
+ return {
7736
+ postcss: initFlags.usePostcss === "yes",
7737
+ outExtension: initFlags.useMjsExtension === "yes" ? "mjs" : "js",
7738
+ jsxFramework: initFlags.jsxOptions.jsxFramework,
7739
+ syntax: initFlags.whatSyntax,
7740
+ strictTokens: initFlags.withStrictTokens === "yes",
7741
+ gitignore: initFlags.shouldUpdateGitignore === "yes"
7742
+ };
7743
+ };
7744
+ //#endregion
7745
+ //#region src/cli-main.ts
7746
+ async function main() {
7747
+ const cli = cac("bamboo");
7748
+ const cwd = process.cwd();
7749
+ 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 = {}) => {
7750
+ let options = {};
7751
+ if (initFlags.interactive) options = await interactive();
7752
+ const flags = {
7753
+ ...initFlags,
7754
+ ...options
7755
+ };
7756
+ const { force, postcss, silent, gitignore, outExtension, jsxFramework, config: configPath, syntax } = flags;
7757
+ const cwd = resolve(flags.cwd ?? "");
7758
+ if (silent) logger.level = "silent";
7759
+ const stream = setLogStream({
7760
+ cwd,
7761
+ logfile: flags.logfile
7762
+ });
7763
+ logger.info("cli", `Bamboo v${version}\n`);
7764
+ const done = logger.time.info("✨ Bamboo initialized");
7765
+ if (postcss) await setupPostcss(cwd);
7766
+ await setupConfig(cwd, compact({
7767
+ force,
7768
+ outExtension,
7769
+ jsxFramework,
7770
+ syntax,
7771
+ outdir: flags.outdir
7772
+ }));
7773
+ const ctx = await loadConfigAndCreateContext({
7774
+ cwd,
7775
+ configPath,
7776
+ config: compact({
7777
+ gitignore,
7778
+ outdir: flags.outdir
7779
+ })
7780
+ });
7781
+ if (gitignore) setupGitIgnore(ctx);
7782
+ if (flags.codegen) {
7783
+ const { msg, box } = await codegen(ctx);
7784
+ logger.log(msg + box);
7785
+ } else logger.log(ctx.initMessage());
7786
+ done();
7787
+ stream.end();
7788
+ });
7789
+ 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) => {
7790
+ const { silent, clean, config: configPath, watch, poll } = flags;
7791
+ const cwd = resolve(flags.cwd ?? "");
7792
+ const stream = setLogStream({
7793
+ cwd,
7794
+ logfile: flags.logfile
7795
+ });
7796
+ let stopProfiling = () => void 0;
7797
+ if (flags.cpuProf) stopProfiling = await startProfiling(cwd, "codegen", flags.watch);
7798
+ if (silent) logger.level = "silent";
7799
+ let ctx = await loadConfigAndCreateContext({
7800
+ cwd,
7801
+ config: { clean },
7802
+ configPath
7803
+ });
7804
+ const { msg } = await codegen(ctx);
7805
+ logger.log(msg);
7806
+ if (watch) ctx.watchConfig(async () => {
7807
+ const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
7808
+ ctx = new BambooContext(conf);
7809
+ });
7810
+ await ctx.hooks["config:change"]?.({
7811
+ config: ctx.config,
7812
+ changes: affecteds
7813
+ });
7814
+ await codegen(ctx, Array.from(affecteds.artifacts));
7815
+ logger.info("ctx:updated", "config rebuilt ✅");
7816
+ }, {
7817
+ cwd,
7818
+ poll
7819
+ });
7820
+ else stream.end();
7821
+ stopProfiling();
7822
+ });
7823
+ 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 = {}) => {
7824
+ const { silent, config: configPath, outfile, watch, poll, minimal, splitting, ...rest } = flags;
7825
+ const cwd = resolve(flags.cwd ?? "");
7826
+ const stream = setLogStream({
7827
+ cwd,
7828
+ logfile: flags.logfile
7829
+ });
7830
+ let stopProfiling = () => void 0;
7831
+ if (flags.cpuProf) stopProfiling = await startProfiling(cwd, "cssgen", flags.watch);
7832
+ const cssArtifact = [
7833
+ "preflight",
7834
+ "tokens",
7835
+ "static",
7836
+ "global",
7837
+ "keyframes"
7838
+ ].find((type) => type === maybeGlob);
7839
+ const glob = cssArtifact ? void 0 : maybeGlob;
7840
+ if (silent) logger.level = "silent";
7841
+ let ctx = await loadConfigAndCreateContext({
7842
+ cwd,
7843
+ config: {
7844
+ ...rest,
7845
+ ...glob ? { include: [glob] } : void 0
7846
+ },
7847
+ configPath
7848
+ });
7849
+ const options = {
7850
+ cwd,
7851
+ outfile,
7852
+ type: cssArtifact,
7853
+ minimal,
7854
+ splitting
7855
+ };
7856
+ await cssgen(ctx, options);
7857
+ if (watch) {
7858
+ ctx.watchConfig(async () => {
7859
+ const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
7860
+ ctx = new BambooContext(conf);
7861
+ });
7862
+ await ctx.hooks["config:change"]?.({
7863
+ config: ctx.config,
7864
+ changes: affecteds
7865
+ });
7866
+ await cssgen(ctx, options);
7867
+ logger.info("ctx:updated", "config rebuilt ✅");
7868
+ }, {
7869
+ cwd,
7870
+ poll
7871
+ });
7872
+ ctx.watchFiles(async (event, file) => {
7873
+ if (event === "unlink") ctx.project.removeSourceFile(ctx.runtime.path.abs(cwd, file));
7874
+ else if (event === "change") {
7875
+ ctx.project.reloadSourceFile(file);
7876
+ await cssgen(ctx, options);
7877
+ } else if (event === "add") {
7878
+ ctx.project.createSourceFile(file);
7879
+ await cssgen(ctx, options);
7880
+ }
7881
+ });
7882
+ } else {
7883
+ stream.end();
7884
+ stopProfiling();
7885
+ }
7886
+ });
7887
+ 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) => {
7888
+ const { config: configPath, silent, ...rest } = flags;
7889
+ const cwd = resolve(flags.cwd ?? "");
7890
+ const stream = setLogStream({
7891
+ cwd,
7892
+ logfile: flags.logfile
7893
+ });
7894
+ let stopProfiling = () => void 0;
7895
+ if (flags.cpuProf) stopProfiling = await startProfiling(cwd, "cli", flags.watch);
7896
+ if (silent) logger.level = "silent";
7897
+ await generate(compact({
7898
+ include: files,
7899
+ ...rest,
7900
+ cwd
7901
+ }), configPath);
7902
+ stopProfiling();
7903
+ if (!flags.watch) stream.end();
7904
+ });
7905
+ 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) => {
7906
+ const { silent, config: configPath, outdir } = flags;
7907
+ const cwd = resolve(flags.cwd ?? "");
7908
+ if (silent) logger.level = "silent";
7909
+ await spec(await loadConfigAndCreateContext({
7910
+ cwd,
7911
+ configPath,
7912
+ config: { cwd }
7913
+ }), { outdir });
7914
+ });
7915
+ 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) => {
7916
+ const { build, preview, port, host, outdir, config, base } = flags;
7917
+ const cwd = resolve(flags.cwd ?? "");
7918
+ const ctx = await loadConfigAndCreateContext({
7919
+ cwd,
7920
+ configPath: config
7921
+ });
7922
+ const buildOpts = {
7923
+ configPath: findConfig({
7924
+ cwd,
7925
+ file: config
7926
+ }),
7927
+ outDir: resolve(outdir || ctx.studio.outdir),
7928
+ port,
7929
+ host,
7930
+ base
7931
+ };
7932
+ let studio;
7933
+ try {
7934
+ studio = __require(__require.resolve("@bamboocss/studio", { paths: [cwd] }));
7935
+ } catch (error) {
7936
+ throw new BambooError("MISSING_STUDIO", "You need to install '@bamboocss/studio' to use this command", { cause: error });
7937
+ }
7938
+ if (preview) await studio.previewStudio(buildOpts);
7939
+ else if (build) await studio.buildStudio(buildOpts);
7940
+ else {
7941
+ await studio.serveStudio(buildOpts);
7942
+ const note = `use ${colors.reset(colors.bold("--build"))} to build`;
7943
+ const port = `use ${colors.reset(colors.bold("--port"))} for a different port`;
7944
+ logger.log(colors.dim(` ${colors.green("➜")} ${colors.bold("Build")}: ${note}`));
7945
+ logger.log(colors.dim(` ${colors.green("➜")} ${colors.bold("Port")}: ${port}`));
7946
+ }
7947
+ });
7948
+ 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 = {}) => {
7949
+ const { silent, config: configPath, scope } = flags;
7950
+ const tokenScope = scope == null || scope === "token";
7951
+ const recipeScope = scope == null || scope === "recipe";
7952
+ const cwd = resolve(flags.cwd);
7953
+ if (silent) logger.level = "silent";
7954
+ const ctx = await loadConfigAndCreateContext({
7955
+ cwd,
7956
+ config: maybeGlob ? { include: [maybeGlob] } : void 0,
7957
+ configPath
7958
+ });
7959
+ const result = analyze(ctx);
7960
+ if (flags?.outfile && typeof flags.outfile === "string") {
7961
+ await result.writeReport(flags.outfile);
7962
+ logger.info("cli", `JSON report saved to ${resolve(flags.outfile)}`);
7963
+ return;
7964
+ }
7965
+ if (tokenScope) if (!ctx.tokens.isEmpty) {
7966
+ const tokenAnalysis = result.getTokenReport();
7967
+ logger.info("analyze:tokens", `Token usage report 🎨 \n${tokenAnalysis.formatted}`);
7968
+ } else logger.info("analyze:tokens", "No tokens found");
7969
+ if (recipeScope) if (!ctx.recipes.isEmpty()) {
7970
+ const recipeAnalysis = result.getRecipeReport();
7971
+ logger.info("analyze:recipes", `Config recipes usage report 🎛️ \n${recipeAnalysis.formatted}`);
7972
+ } else logger.info("analyze:recipes", "No config recipes found");
7973
+ });
7974
+ 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 = {}) => {
7975
+ const { silent, dry = false, outdir: outdirFlag, config: configPath } = flags ?? {};
7976
+ const cwd = resolve(flags.cwd);
7977
+ const stream = setLogStream({
7978
+ cwd,
7979
+ logfile: flags.logfile
7980
+ });
7981
+ let stopProfiling = () => void 0;
7982
+ if (flags.cpuProf) stopProfiling = await startProfiling(cwd, "debug");
7983
+ if (silent) logger.level = "silent";
7984
+ const ctx = await loadConfigAndCreateContext({
7985
+ cwd,
7986
+ config: maybeGlob ? { include: [maybeGlob] } : void 0,
7987
+ configPath
7988
+ });
7989
+ await debug(ctx, {
7990
+ outdir: outdirFlag ?? join(...ctx.paths.root, "debug"),
7991
+ dry,
7992
+ onlyConfig: flags.onlyConfig
7993
+ });
7994
+ stopProfiling();
7995
+ stream.end();
7996
+ });
7997
+ 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 = {}) => {
7998
+ const { silent, outfile: outfileFlag, minify, config: configPath, watch, poll } = flags;
7999
+ const cwd = resolve(flags.cwd);
8000
+ if (silent) logger.level = "silent";
8001
+ let ctx = await loadConfigAndCreateContext({
8002
+ cwd,
8003
+ config: maybeGlob ? { include: [maybeGlob] } : void 0,
8004
+ configPath
8005
+ });
8006
+ const outfile = outfileFlag ?? join(...ctx.paths.root, "bamboo.buildinfo.json");
8007
+ if (minify) ctx.config.minify = true;
8008
+ await buildInfo(ctx, outfile);
8009
+ if (watch) {
8010
+ ctx.watchConfig(async () => {
8011
+ const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
8012
+ ctx = new BambooContext(conf);
8013
+ });
8014
+ await ctx.hooks["config:change"]?.({
8015
+ config: ctx.config,
8016
+ changes: affecteds
8017
+ });
8018
+ await buildInfo(ctx, outfile);
8019
+ logger.info("ctx:updated", "config rebuilt ✅");
8020
+ }, {
8021
+ cwd,
8022
+ poll
8023
+ });
8024
+ ctx.watchFiles(async (event, file) => {
8025
+ if (event === "unlink") ctx.project.removeSourceFile(ctx.runtime.path.abs(cwd, file));
8026
+ else if (event === "change") {
8027
+ ctx.project.reloadSourceFile(file);
8028
+ await buildInfo(ctx, outfile);
8029
+ } else if (event === "add") {
8030
+ ctx.project.createSourceFile(file);
8031
+ await buildInfo(ctx, outfile);
8032
+ }
8033
+ });
8034
+ }
8035
+ });
8036
+ 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) => {
8037
+ const { outdir, silent, base } = flags;
8038
+ if (silent) logger.level = "silent";
8039
+ const cwd = resolve(flags.cwd);
8040
+ const ctx = await loadConfigAndCreateContext({
8041
+ cwd,
8042
+ config: { cwd }
8043
+ });
8044
+ const pkgPath = resolve(cwd, outdir, "package.json");
8045
+ const exists = ctx.runtime.fs.existsSync(pkgPath);
8046
+ const exports = [];
8047
+ const createDir = (...dir) => {
8048
+ return [
8049
+ ".",
8050
+ base,
8051
+ ...dir
8052
+ ].filter(Boolean).join("/");
8053
+ };
8054
+ const createEntry = (dir) => ({
8055
+ types: ctx.file.extDts(createDir(dir, "index")),
8056
+ require: ctx.file.ext(createDir(dir, "index")),
8057
+ import: ctx.file.ext(createDir(dir, "index"))
8058
+ });
8059
+ exports.push(["./css", createEntry("css")], ["./tokens", createEntry("tokens")], ["./types", createEntry("types")]);
8060
+ if (!ctx.patterns.isEmpty()) exports.push(["./patterns", createEntry("patterns")]);
8061
+ if (!ctx.recipes.isEmpty()) exports.push(["./recipes", createEntry("recipes")]);
8062
+ if (!ctx.patterns.isEmpty()) exports.push(["./jsx", createEntry("jsx")]);
8063
+ if (ctx.config.themes) exports.push(["./themes", createEntry("themes")]);
8064
+ const stylesDir = createDir("styles.css");
8065
+ if (!exists) {
8066
+ const content = {
8067
+ name: outdir,
8068
+ description: "This package is auto-generated by Bamboo CSS",
8069
+ version: "0.1.0",
8070
+ type: "module",
8071
+ keywords: [
8072
+ "bamboocss",
8073
+ "styled-system",
8074
+ "codegen"
8075
+ ],
8076
+ license: "ISC",
8077
+ exports: {
8078
+ ...Object.fromEntries(exports),
8079
+ "./styles.css": stylesDir
8080
+ },
8081
+ scripts: { prepare: "bamboo codegen --clean" }
8082
+ };
8083
+ await ctx.runtime.fs.writeFile(pkgPath, JSON.stringify(content, null, 2));
8084
+ } else {
8085
+ const content = JSON.parse(ctx.runtime.fs.readFileSync(pkgPath));
8086
+ content.exports = {
8087
+ ...content.exports,
8088
+ ...Object.fromEntries(exports),
8089
+ "./styles.css": stylesDir
8090
+ };
8091
+ await ctx.runtime.fs.writeFile(pkgPath, JSON.stringify(content, null, 2));
8092
+ }
8093
+ logger.info("cli", `Emit package.json to ${pkgPath}`);
8094
+ });
8095
+ 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) => {
8096
+ const { startMcpServer } = await import("@bamboocss/mcp");
8097
+ await startMcpServer(mcpFlags);
8098
+ });
8099
+ 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) => {
8100
+ const { initMcpConfig } = await import("@bamboocss/mcp");
8101
+ const resolvedCwd = resolve(mcpInitFlags.cwd ?? cwd);
8102
+ let clients;
8103
+ if (mcpInitFlags.client) clients = (Array.isArray(mcpInitFlags.client) ? mcpInitFlags.client : [mcpInitFlags.client]).flatMap((c) => c.split(",")).map((c) => c.trim());
8104
+ await initMcpConfig({
8105
+ cwd: resolvedCwd,
8106
+ clients
8107
+ });
8108
+ });
8109
+ cli.help();
8110
+ cli.version(version);
8111
+ cli.parse(process.argv, { run: false });
8112
+ await cli.runMatchedCommand();
8113
+ }
8114
+ //#endregion
7486
8115
  //#region src/cli-default.ts
7487
8116
  updateNotifier({
7488
8117
  pkg: {