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