Skip to content

Commit c94a562

Browse files
committed
refactor: cleanup of some console statements, fixes for the test setup
1 parent 6c1f243 commit c94a562

File tree

21 files changed

+274
-72
lines changed

21 files changed

+274
-72
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ calyInstance.test.setup.json
3535

3636
# Turborepo
3737
.turbo
38+
39+
# Jest
40+
coverage/

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
---
2727

28-
## 🚀 Quick Start
28+
## 🚀 [Dev] Quick Start
2929

3030
```
3131
# 1. Clone the repo
@@ -34,7 +34,7 @@
3434
pnpm install
3535
3636
# 3. Build the CLI
37-
pnpm build:packages
37+
pnpm build
3838
3939
# 4. Run any command
4040
xano
@@ -89,7 +89,7 @@ jobs:
8989

9090
### Xano Registry **(WIP)**
9191

92-
I have been astonished by the shadcn/ui CLI and the core principles of code distribution implemented in that tool. While that is primarily for frontend developers, their attempt to generalise their registry pointed me into the direction where I have started rebuilding a registry system for Xano powered by `xanoscript`. The reason for this is to overcome the bugs of Xano Snippets, avoid dependency of external providers of Xano Actions and in general to allow any team to build their own registries. These registries should also server as guidance for LLMs to eventually start generating more and more reliable `xanoscript`.
92+
I have been astonished by the shadcn/ui CLI and the core principles of code distribution implemented in that tool. While that is primarily for frontend developers, their attempt to generalise their registry pointed me into the direction where I have started rebuilding a registry system for Xano powered by `xanoscript`. The reason for this is to overcome the bugs of Xano Snippets, avoid dependency of external providers of Xano Actions and in general to allow any team to build their own registries with ease. These registries should also serve as guidance for LLMs to eventually start generating more and more reliable `xanoscript`.
9393

9494
<details>
9595
<summary>How to use the registry feature?</summary>
@@ -110,7 +110,7 @@ I have been astonished by the shadcn/ui CLI and the core principles of code dist
110110
```
111111

112112
> **Notes:**
113-
> Currently there is no way of automatically build out the registry from a collection of `xanoscript` files, so this is why
113+
> Currently there is no way of automatically building the registry from a collection of `xanoscript` files, so this is why
114114
> it is important to always keep the registry/definitions/index.json and the individual definition files in sync.
115115
> Currently there is theoretic support for registry:function and registry:table components, registry:query but registry:snippet is planned.
116116
> With the registry:snippet I aim to have a shot at fixing Xano's Snippets and make it searchable and reusable by also LLMs.

jest.config.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
/** @type {import('jest').Config} */
1+
import { createDefaultPreset } from 'ts-jest';
2+
3+
const tsJestTransformCfg = createDefaultPreset().transform;
4+
5+
/** @type {import("jest").Config} **/
26
export default {
3-
preset: 'ts-jest/presets/default-esm',
47
testEnvironment: 'node',
5-
extensionsToTreatAsEsm: ['.ts'],
68
transform: {
7-
'^.+\\.ts$': ['ts-jest', { useESM: true }],
9+
...tsJestTransformCfg,
810
},
9-
globals: {
10-
'ts-jest': {
11-
useESM: true,
12-
},
13-
},
14-
testMatch: ['**/__tests__/**/*.test.ts', '**/?(*.)+(spec|test).ts'],
15-
passWithNoTests: true,
16-
moduleFileExtensions: ['ts', 'js', 'json'],
17-
roots: ['<rootDir>/packages/'],
18-
coverageDirectory: 'coverage',
19-
collectCoverageFrom: ['packages/*/src/**/*.{ts,js}'],
2011
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"eslint": "^9.35.0",
3737
"eslint-plugin-import": "^2.32.0",
3838
"jest": "^30.2.0",
39+
"jest-html-reporter": "^4.3.0",
3940
"knip": "^5.63.1",
4041
"rollup": "^4.50.0",
4142
"rollup-plugin-dts": "^6.2.3",
@@ -46,5 +47,5 @@
4647
"turbo": "^2.5.8",
4748
"typescript": "^5.9.2"
4849
},
49-
"packageManager": "pnpm@10.15.1"
50+
"packageManager": "pnpm@10.18.2"
5051
}

packages/cli/jest.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import config from '../../jest.config.js';
2+
export default config;

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"clean": "trash dist tsconfig.tsbuildinfo",
6060
"build:js": "tsx esbuild.config.ts",
6161
"build:chmod": "shx chmod +x dist/index.cjs",
62-
"build": "pnpm build:js && pnpm build:chmod && pnpm link -g",
62+
"build": "pnpm clean && pnpm build:js && pnpm build:chmod && pnpm link -g",
6363
"xano": "node dist/index.cjs"
6464
},
6565
"dependencies": {

packages/cli/src/features/code-gen/open-api-generator.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,35 @@ export async function runOpenApiGenerator({
1010
additionalArgs = [],
1111
logger = false,
1212
}) {
13-
// Always use npx and the official package
14-
const cliBin = process.platform === 'win32' ? 'npx.cmd' : 'npx';
15-
const inputPath = resolve(input).replace(/\\/g, '/');
16-
const outputPath = resolve(output);
13+
// [ ] Add list of orval supported generators
14+
// [ ] Add orval process runner on the analogy of the openapitools/openapi-generator-cli
1715

18-
const cliArgs = [
19-
'@openapitools/openapi-generator-cli',
20-
'generate',
21-
'-i',
22-
inputPath,
23-
'-g',
24-
generator,
25-
'-o',
26-
outputPath,
27-
...additionalArgs,
28-
].filter(Boolean);
16+
// Always use npx and the official package
17+
const cliBin = process.platform === 'win32' ? 'npx.cmd' : 'npx';
18+
const inputPath = resolve(input).replace(/\\/g, '/');
19+
const outputPath = resolve(output);
2920

30-
let logStream = null;
31-
let logPath = null;
21+
const cliArgs = [
22+
'@openapitools/openapi-generator-cli',
23+
'generate',
24+
'-i',
25+
inputPath,
26+
'-g',
27+
generator,
28+
'-o',
29+
outputPath,
30+
...additionalArgs,
31+
].filter(Boolean);
3232

33-
if (logger) {
34-
const logsDir = join(process.cwd(), 'output', '_logs');
35-
await mkdir(logsDir, { recursive: true });
36-
logPath = join(logsDir, `openapi-generator-${Date.now()}.log`);
37-
logStream = createWriteStream(logPath);
38-
}
33+
let logStream = null;
34+
let logPath = null;
35+
36+
if (logger) {
37+
const logsDir = join(process.cwd(), 'output', '_logs');
38+
await mkdir(logsDir, { recursive: true });
39+
logPath = join(logsDir, `openapi-generator-${Date.now()}.log`);
40+
logStream = createWriteStream(logPath);
41+
}
3942

4043
return new Promise((resolvePromise, reject) => {
4144
const proc = spawn(cliBin, cliArgs, { shell: true, stdio: ['ignore', 'pipe', 'pipe'] });
@@ -73,4 +76,3 @@ export async function runOpenApiGenerator({
7376
});
7477
});
7578
}
76-

packages/cli/src/program.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,19 @@ const core = new Caly(nodeConfigStorage);
2626
// Store start time on the command object
2727
program.hook('preAction', (thisCommand, actionCommand) => {
2828
commandStartTimes.set(thisCommand, Date.now());
29-
InitializedPostHog.capture({
29+
InitializedPostHog.captureImmediate({
3030
distinctId: 'anonymous',
3131
event: 'command_started',
3232
properties: {
3333
$process_person_profile: false,
3434
"command": actionCommand.name(),
3535
}
3636
});
37-
InitializedPostHog.shutdown();
3837
});
3938

4039
program.hook('postAction', (thisCommand, actionCommand) => {
4140
const start = commandStartTimes.get(thisCommand);
4241
if (!start) {
43-
// Could happen if preAction failed, or if there's a bug
44-
console.warn('⏱️ Command timer missing start time.');
4542
return;
4643
}
4744
const duration = ((Date.now() - start) / 1000).toFixed(2);
@@ -52,7 +49,7 @@ program.hook('postAction', (thisCommand, actionCommand) => {
5249
: actionCommand.name();
5350

5451
console.log(`\n⏱️ Command "${commandPath}" completed in ${duration}s`);
55-
InitializedPostHog.capture({
52+
InitializedPostHog.captureImmediate({
5653
distinctId: 'anonymous',
5754
event: 'command_finished',
5855
properties: {

packages/cli/src/utils/feature-focused/registry/scaffold.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ async function scaffoldRegistry(
7070
await writeFile(functionFilePath, sampleFunctionContent, 'utf8');
7171
await writeFile(functionDefPath, JSON.stringify(sampleRegistryItem, null, 2), 'utf8');
7272
await writeFile(indexPath, JSON.stringify(sampleIndex, null, 2), 'utf8');
73-
74-
console.log(`✅ Registry scaffolded at "${registryRoot}" with a sample component!`);
7573
}
7674

7775
export { scaffoldRegistry };

packages/core/jest.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import config from '../../jest.config.js';
2+
export default config;

0 commit comments

Comments
 (0)