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