Skip to content

Commit ae001a5

Browse files
authored
refactor: remove lint command, turn backup to stream (#76)
2 parents e7245bd + e373ead commit ae001a5

32 files changed

+183
-478
lines changed

.changeset/warm-dodos-decide.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@calycode/types": patch
3+
"@calycode/utils": patch
4+
"@calycode/core": patch
5+
"@calycode/cli": patch
6+
---
7+
8+
refactor: minor cleanup, removal of the linting command..
9+
fix: make backup to be stream, to allow bigger workspaces
10+
refactor: cleanup of fs / path imports in the cli

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ I have been astonished by the shadcn/ui CLI and the core principles of code dist
137137
- [x] **Scaffolding a registry** of reusable Xano components
138138
- [x] Exporting all available `xanoscript` from your instance via metadata API _*(important note: not all pieces of logic can be exported via metadata API, this especially is fragile on older and bigger instances)_.
139139
- [x] Adding components to Xano from a registry (only functions, tables, queries for now)
140-
- [ ] Automated test runner with assertion configuration
141-
- [ ] Linting with custom rulesets
140+
- [x] Automated test runner with assertion configuration
142141

143142
---
144143

eslint.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default [
3838
// TS/TSX files config
3939
{
4040
files: ['**/*.ts'],
41-
ignores: ['node_modules/**', 'dist/**', 'output/**'],
41+
ignores: ['node_modules/**', 'dist/**', 'output/**', 'scripts/**'],
4242
languageOptions: {
4343
parser: '@typescript-eslint/parser',
4444
parserOptions: {

packages/cli/esbuild.config.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,17 @@ import { cp, writeFile } from 'fs/promises';
22
import { resolve, dirname } from 'node:path';
33
import { fileURLToPath } from 'node:url';
44
import { build } from 'esbuild';
5-
import { intro, outro, log } from '@clack/prompts';
65

76
const __dirname = dirname(fileURLToPath(import.meta.url));
87
const rootDir = resolve(__dirname);
98
const distDir = resolve(__dirname, 'dist');
109

1110
(async () => {
1211
try {
13-
intro('Bundling Caly with esbuild');
14-
1512
// Copy github actions
1613
await cp(resolve(rootDir, 'src/actions'), resolve(distDir, 'actions'), {
1714
recursive: true,
1815
});
19-
log.step('Copied and minified assets to dist.');
2016

2117
// Bundle the application with esbuild
2218
const result = await build({
@@ -35,16 +31,15 @@ const distDir = resolve(__dirname, 'dist');
3531
sourcemap: false,
3632
metafile: true,
3733
});
38-
log.step('esbuild bundling complete.');
3934

4035
// Write the metafile for analysis
4136
await writeFile(resolve(distDir, 'meta.json'), JSON.stringify(result.metafile, null, 2));
4237

43-
outro(
38+
console.log(
4439
'Build complete. You can analyze the bundle with https://esbuild.github.io/analyze/ by uploading dist/meta.json'
4540
);
4641
} catch (error) {
47-
log.error(`Build failed: ${JSON.stringify(error, null, 2)}`);
42+
console.error(`Build failed: ${JSON.stringify(error, null, 2)}`);
4843
process.exit(1);
4944
}
5045
})();

packages/cli/src/commands/analyze.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { mkdir } from 'fs/promises';
2-
import { writeFileSync, existsSync, mkdirSync } from 'fs';
3-
import { dirname, join } from 'path';
1+
import { mkdir, writeFile, access } from 'node:fs/promises';
2+
import { dirname, join } from 'node:path';
43
import { log, outro, intro, spinner } from '@clack/prompts';
54
import { metaApiGet, replacePlaceholders, sanitizeFileName } from '@calycode/utils';
65
import {
@@ -12,7 +11,6 @@ import {
1211
import { resolveConfigs } from '../utils/commands/context-resolution';
1312
import { findProjectRoot } from '../utils/commands/project-root-finder';
1413

15-
// [ ] CORE, but needs fs access.
1614
async function fetchFunctionsInXanoScript(instance, workspace, branch, printOutput = false, core) {
1715
intro('Starting to analyze functions.');
1816
let branchFunctions = {};
@@ -81,12 +79,14 @@ async function fetchFunctionsInXanoScript(instance, workspace, branch, printOutp
8179

8280
// Ensure the parent directory exists
8381
const parentDir = dirname(filePath);
84-
if (!existsSync(parentDir)) {
85-
mkdirSync(parentDir, { recursive: true });
82+
try {
83+
await access(parentDir);
84+
} catch {
85+
await mkdir(parentDir, { recursive: true });
8686
}
8787

8888
// Write the file
89-
writeFileSync(filePath, branchFunctions[item].script);
89+
await writeFile(filePath, branchFunctions[item].script);
9090
}
9191
s.stop(`Xano Script files are ready -> ${outputDir}`);
9292
} catch (err) {

packages/cli/src/commands/backups.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import path, { join } from 'path';
2-
import { readdirSync } from 'fs';
1+
import { basename, join } from 'node:path';
2+
import { readdir } from 'node:fs/promises';
33
import { openAsBlob } from 'node:fs';
44
import { select, confirm, outro } from '@clack/prompts';
55
import { replacePlaceholders } from '@calycode/utils';
@@ -48,7 +48,7 @@ async function restorationWizard({ instance, workspace, sourceBackup, forceConfi
4848

4949
let availableBackups;
5050
try {
51-
availableBackups = readdirSync(backupsDir);
51+
availableBackups = await readdir(backupsDir);
5252
} catch {
5353
outro(`No backups directory found for branch "${branchConfig.label}".`);
5454
process.exit(1);
@@ -82,7 +82,7 @@ async function restorationWizard({ instance, workspace, sourceBackup, forceConfi
8282
}
8383

8484
const formData = new FormData();
85-
formData.append('file', await openAsBlob(backupFilePath), path.basename(backupFilePath));
85+
formData.append('file', await openAsBlob(backupFilePath), basename(backupFilePath));
8686
formData.append('password', '');
8787

8888
// Pass on the formdata to the core implementation

packages/cli/src/commands/generate-code.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { log, outro, intro, spinner } from '@clack/prompts';
2-
import { metaApiGet, normalizeApiGroupName, replacePlaceholders, dirname } from '@calycode/utils';
2+
import { metaApiGet, normalizeApiGroupName, replacePlaceholders } from '@calycode/utils';
33
import {
44
addApiGroupOptions,
55
addFullContextOptions,

packages/cli/src/commands/generate-repo.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { existsSync, readdirSync, lstatSync, rmdirSync, unlinkSync } from 'fs';
1+
import { mkdir, access, readdir, lstat, rm, unlink } from 'node:fs/promises';
22
import { log, intro, outro } from '@clack/prompts';
33
import { load } from 'js-yaml';
4-
import { mkdir } from 'fs/promises';
54
import { joinPath, dirname, replacePlaceholders, fetchAndExtractYaml } from '@calycode/utils';
65
import {
76
addFullContextOptions,
@@ -14,21 +13,30 @@ import { resolveConfigs } from '../utils/commands/context-resolution';
1413
import { findProjectRoot } from '../utils/commands/project-root-finder';
1514

1615
/**
17-
* Clears the contents of a directory.
16+
* Recursively removes all files and subdirectories in a directory.
1817
* @param {string} directory - The directory to clear.
1918
*/
20-
function clearDirectory(directory) {
21-
if (existsSync(directory)) {
22-
readdirSync(directory).forEach((file) => {
19+
async function clearDirectory(directory: string): Promise<void> {
20+
try {
21+
await access(directory);
22+
} catch {
23+
// Directory does not exist; nothing to clear
24+
return;
25+
}
26+
27+
const files = await readdir(directory);
28+
await Promise.all(
29+
files.map(async (file) => {
2330
const curPath = joinPath(directory, file);
24-
if (lstatSync(curPath).isDirectory()) {
25-
clearDirectory(curPath);
26-
rmdirSync(curPath);
31+
const stat = await lstat(curPath);
32+
if (stat.isDirectory()) {
33+
await clearDirectory(curPath);
34+
await rm(curPath, { recursive: true, force: true }); // removes the (now-empty) dir
2735
} else {
28-
unlinkSync(curPath);
36+
await unlink(curPath);
2937
}
30-
});
31-
}
38+
})
39+
);
3240
}
3341

3442
async function generateRepo({

packages/cli/src/commands/generate-xanoscript-repo.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { existsSync, readdirSync, lstatSync, rmdirSync, unlinkSync, mkdirSync } from 'fs';
1+
import { access, readdir, lstat, rm, unlink, mkdir } from 'node:fs/promises';
22
import { joinPath, dirname } from '@calycode/utils';
33
import { attachCliEventHandlers } from '../utils/event-listener';
44
import { replacePlaceholders } from '@calycode/utils';
@@ -8,21 +8,30 @@ import { resolveConfigs } from '../utils/commands/context-resolution';
88
import { findProjectRoot } from '../utils/commands/project-root-finder';
99

1010
/**
11-
* Clears the contents of a directory.
11+
* Recursively removes all files and subdirectories in a directory.
1212
* @param {string} directory - The directory to clear.
1313
*/
14-
function clearDirectory(directory) {
15-
if (existsSync(directory)) {
16-
readdirSync(directory).forEach((file) => {
14+
async function clearDirectory(directory: string): Promise<void> {
15+
try {
16+
await access(directory);
17+
} catch {
18+
// Directory does not exist; nothing to clear
19+
return;
20+
}
21+
22+
const files = await readdir(directory);
23+
await Promise.all(
24+
files.map(async (file) => {
1725
const curPath = joinPath(directory, file);
18-
if (lstatSync(curPath).isDirectory()) {
19-
clearDirectory(curPath);
20-
rmdirSync(curPath);
26+
const stat = await lstat(curPath);
27+
if (stat.isDirectory()) {
28+
await clearDirectory(curPath);
29+
await rm(curPath, { recursive: true, force: true });
2130
} else {
22-
unlinkSync(curPath);
31+
await unlink(curPath);
2332
}
24-
});
25-
}
33+
})
34+
);
2635
}
2736

2837
async function generateXanoscriptRepo({ instance, workspace, branch, core, printOutput = false }) {
@@ -46,7 +55,7 @@ async function generateXanoscriptRepo({ instance, workspace, branch, core, print
4655
});
4756

4857
clearDirectory(outputDir);
49-
mkdirSync(outputDir, { recursive: true });
58+
await mkdir(outputDir, { recursive: true });
5059

5160
const plannedWrites: { path: string; content: string }[] = await core.buildXanoscriptRepo({
5261
instance: context.instance,

packages/cli/src/commands/run-lint.ts

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

0 commit comments

Comments
 (0)