Skip to content

Commit 7b61ec0

Browse files
committed
feat: moved to cli cac
1 parent fb797ce commit 7b61ec0

51 files changed

Lines changed: 486 additions & 697 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/site/pages/reference/debug.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,45 @@
22
title: Debug
33
---
44

5-
65
## Log
76

87
To get verbose log and [enable output of debug](https://github.com/debug-js/debug), you need to call the [cli](cli.md)
98
with the `DEBUG=interact:*` environment
109

1110
Example
11+
1212
```bash
1313
DEBUG=interact:* interact
1414
DEBUG=interact:image* interact
1515
# or for the vite build
1616
DEBUG=vite:*
1717
```
1818

19+
## IDE Debugger
20+
21+
If your IDE cannot start cleanly a debug session or does not stop at breakpoint, here a clean method
22+
23+
* Start interact from the cli with the `--inspect` or `--inspect-brk` node options
24+
25+
```bash
26+
NODE_OPTIONS=--inspect interact start
27+
```
28+
29+
* The debug process listener will print the listening address
30+
31+
Example:
32+
33+
```bash
34+
Debugger listening on ws://127.0.0.1:9229/60d0f660-3811-4b87-ab68-7e1ee95e373f
35+
For help, see: https://nodejs.org/en/docs/inspector
36+
```
37+
38+
* Attach to it with your IDE to create a debug session. In Idea JetBrains, you can
39+
then [attach the debugger](https://www.jetbrains.com/help/idea/running-and-debugging-node-js.html#ws_node_debug_remote_chrome)
40+
41+
* No breakpoints should hit as the source map is likely missing, use the `debugger` word in your script and reload your
42+
page.
43+
44+
```javascript
45+
debugger
46+
```

package.json

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"license": "FSL-1.1-ALv2",
55
"type": "module",
66
"description": "A React publication framework to create documentation where users can log in and interact with it",
7-
"bin": "src/interact/cli/dev.js",
7+
"bin": "src/interact/cli/cli.ts",
88
"repository": "https://github.com/combostrap/interact",
99
"scripts": {
1010
"build": "tsc -p src/interact/tsconfig.json --listEmittedFiles",
@@ -14,10 +14,10 @@
1414
"check:resources": "tsc -p src/resources/tsconfig.json",
1515
"watch": "tsc --watch",
1616
"deploy": "yarn check && git tag -f early-access && git push -f origin early-access",
17-
"start": "src/interact/cli/dev.js start --confPath=apps/site",
18-
"site": "cd ../../gerardnico/com-gerardnico && node_modules/@combostrap/interact/src/interact/cli/dev.js start",
19-
"ssg": "src/interact/cli/dev.js build --confPath=apps/site",
20-
"preview": "src/interact/cli/dev.js preview --confPath=apps/site",
17+
"start": "interact start --confPath=apps/site",
18+
"site": "cd ../../gerardnico/com-gerardnico && interact start",
19+
"ssg": "interact build --confPath=apps/site",
20+
"preview": "interact preview --confPath=apps/site",
2121
"registry": "shadcn build --output apps/site/public/r"
2222
},
2323
"files": [
@@ -45,7 +45,6 @@
4545
"dependencies": {
4646
"@base-ui/react": "1.3.0",
4747
"@mdx-js/rollup": "3.1.1",
48-
"@oclif/core": "4.8.2",
4948
"@realfavicongenerator/generate-favicon": "0.6.3",
5049
"@realfavicongenerator/image-adapter-node": "0.6.3",
5150
"@stefanprobst/rehype-extract-toc": "3.0.0",
@@ -57,6 +56,7 @@
5756
"@vitejs/plugin-react": "6.0.2",
5857
"@vitejs/plugin-rsc": "0.5.26",
5958
"bootstrap-icons": "1.13.1",
59+
"cac": "^7.0.0",
6060
"class-variance-authority": "0.7.1",
6161
"clsx": "2.1.1",
6262
"debug": "4.4.3",
@@ -108,14 +108,6 @@
108108
"vitest": "4.1.0"
109109
},
110110
"packageManager": "yarn@4.12.0",
111-
"oclif": {
112-
"description": "Interact Cli",
113-
"version": "0.1.0",
114-
"bin": "interact",
115-
"dirname": "interact",
116-
"commands": "dist/interact/cli/commands",
117-
"topicSeparator": " "
118-
},
119111
"resolutions": {
120112
"sharp": "0.34.5",
121113
"@types/react": "19.2.14",

src/interact/cli/baseCommand.ts

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/interact/cli/cli.ts

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/usr/bin/env -S node -r tsx/cjs
2+
import {cac} from 'cac'
3+
import {build} from './commands/build.ts'
4+
import {start} from './commands/start.ts'
5+
import {previewCommand} from './commands/preview.ts'
6+
import {config} from './commands/config.ts'
7+
import {favicon} from './commands/favicon.ts'
8+
import {schema} from './commands/schema.ts'
9+
import type {LogLevel} from './shared/vite.config.ts'
10+
11+
const cli = cac('interact')
12+
13+
// Global option shared by every command.
14+
// The default is derived (cli, env or current dir) so no default is set here.
15+
cli.option('--confPath <path>', 'Project root directory or configuration file path')
16+
17+
cli
18+
.command('build', 'Build project for production')
19+
.option('--outDir <dir>', 'The output directory', {default: 'dist'})
20+
.option('--logLevel <level>', 'Specify level for logging (info|warn|error|silent)', {default: 'info'})
21+
.action(async (options) => {
22+
await build({
23+
confPath: options.confPath,
24+
outDir: options.outDir,
25+
logLevel: options.logLevel as LogLevel,
26+
})
27+
})
28+
29+
cli
30+
.command('start', 'Start development server')
31+
.option('--port <port>', 'Dev server port', {default: 5173})
32+
.option('--outDir <dir>', 'The output directory', {default: 'dist'})
33+
.option('--logLevel <level>', 'Specify level for logging (info|warn|error|silent)', {default: 'info'})
34+
.action(async (options) => {
35+
await start({
36+
confPath: options.confPath,
37+
port: Number(options.port),
38+
outDir: options.outDir,
39+
logLevel: options.logLevel as LogLevel,
40+
})
41+
})
42+
43+
cli
44+
.command('preview', 'Preview the static build')
45+
.option('--logLevel <level>', 'Specify level for logging (info|warn|error|silent)', {default: 'info'})
46+
.action(async (options) => {
47+
await previewCommand({
48+
confPath: options.confPath,
49+
logLevel: options.logLevel as LogLevel,
50+
})
51+
})
52+
53+
cli
54+
.command('config', 'Print the interact configuration (YAML by default)')
55+
.option('-f, --filter <key>', 'Filter configuration by key path (e.g., "theme.colors")')
56+
.option('-j, --json', 'Output in JSON format')
57+
.option('-y, --yaml', 'Output in YAML format (default)')
58+
.option('--no-pretty', 'Disable colorized output')
59+
.option('--plain', 'Disable colorized output (alias for --no-pretty)')
60+
.example(' $ interact config')
61+
.example(' $ interact config --json')
62+
.example(' $ interact config --filter theme.colors')
63+
.example(' $ interact config --json --no-pretty')
64+
.action(async (options) => {
65+
await config({
66+
confPath: options.confPath,
67+
filter: options.filter,
68+
json: options.tson,
69+
yaml: options.yaml,
70+
// cac maps --no-pretty to options.pretty === false
71+
noPretty: !options.pretty,
72+
plain: options.plain,
73+
})
74+
})
75+
76+
cli
77+
.command('favicon [filePath]', 'Generate the favicons and app manifest from a master icon file')
78+
.option('--dryRun', "Don't create the files")
79+
.option('-o, --outputDirectory <dir>', 'The output directory (default to the public directory)')
80+
.example(' $ interact favicon path/to/master-icon.svg')
81+
.action(async (filePath, options) => {
82+
await favicon({
83+
confPath: options.confPath,
84+
filePath,
85+
dryRun: options.dryRun,
86+
outputDirectory: options.outputDirectory,
87+
})
88+
})
89+
90+
cli
91+
.command('schema', 'Generate JSON schema')
92+
.example(' $ interact schema')
93+
.action(async (options) => {
94+
await schema({
95+
confPath: options.confPath,
96+
})
97+
})
98+
99+
cli.help()
100+
cli.version('0.1.0')
101+
102+
export async function run(argv: string[] = process.argv): Promise<void> {
103+
try {
104+
cli.parse(argv, {run: false})
105+
// Show help when no command was provided
106+
if (!cli.matchedCommand) {
107+
cli.outputHelp()
108+
return
109+
}
110+
await cli.runMatchedCommand()
111+
} catch (e) {
112+
const error = e as Error
113+
console.error(error.message)
114+
process.exit(1)
115+
}
116+
}
117+
118+
// Run when executed directly (e.g. via tsx / node).
119+
run()

src/interact/cli/commands/build.ts

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
import {createBuilder, createLogger} from 'vite'
22
import pc from "picocolors";
3-
import {BaseCommand} from "../baseCommand.js";
4-
import {resolveViteConfig} from "../shared/vite.config.js";
3+
import {resolveViteConfig} from "../shared/vite.config.ts";
4+
import type {LogLevel} from "../shared/vite.config.ts";
55

6-
export default class Build extends BaseCommand<typeof Build> {
7-
static description = 'Build project for production'
6+
export interface BuildActionOptions {
7+
confPath?: string;
8+
outDir?: string;
9+
logLevel?: LogLevel;
10+
}
811

9-
10-
async run(): Promise<void> {
11-
const {flags} = await this.parse(Build)
12-
13-
try {
14-
const builder = await createBuilder(await resolveViteConfig({
15-
confPath: flags.confPath,
16-
outDir: flags.outDir,
17-
logLevel: flags.logLevel,
18-
command: 'build'
19-
}))
20-
console.log(Object.keys(builder.environments))
21-
this.log('Interact Build Command: Starting Building')
22-
// build App will call the environment in order and is equivalent to:
23-
// await builder.build(builder.environments.rsc)
24-
// await builder.build(builder.environments.ssr)
25-
// await builder.build(builder.environments.client)
26-
// and calling the buildApp Hook (static generation uses this hook)
27-
await builder.buildApp();
28-
this.log('Interact Build Command: Build completed successfully!')
29-
} catch (e) {
30-
let error = e as Error;
31-
createLogger('error').error(pc.red(`error when building:\n${error.stack}`), {error: error});
32-
process.exit(1);
33-
}
12+
export async function build({confPath, outDir, logLevel}: BuildActionOptions): Promise<void> {
13+
try {
14+
const builder = await createBuilder(await resolveViteConfig({
15+
confPath,
16+
outDir,
17+
logLevel,
18+
command: 'build'
19+
}))
20+
console.log(Object.keys(builder.environments))
21+
console.log('Interact Build Command: Starting Building')
22+
// build App will call the environment in order and is equivalent to:
23+
// await builder.build(builder.environments.rsc)
24+
// await builder.build(builder.environments.ssr)
25+
// await builder.build(builder.environments.client)
26+
// and calling the buildApp Hook (static generation uses this hook)
27+
await builder.buildApp();
28+
console.log('Interact Build Command: Build completed successfully!')
29+
} catch (e) {
30+
let error = e as Error;
31+
createLogger('error').error(pc.red(`error when building:\n${error.stack}`), {error: error});
32+
process.exit(1);
3433
}
35-
}
34+
}

0 commit comments

Comments
 (0)