@buzola/codegen 0.0.21 → 0.0.22
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/__tests__/cli.test.d.ts +2 -0
- package/dist/__tests__/cli.test.d.ts.map +1 -0
- package/dist/__tests__/cli.test.js +33 -0
- package/dist/__tests__/cli.test.js.map +1 -0
- package/dist/cli.js +8 -1
- package/dist/cli.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/cli.test.ts +40 -0
- package/src/cli.ts +9 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/cli.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from 'bun:test';
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import * as os from 'node:os';
|
|
4
|
+
import * as path from 'node:path';
|
|
5
|
+
// `tsc -b` also compiles this test into dist/, where the CLI beside it is cli.js.
|
|
6
|
+
const CLI = path.join(import.meta.dir, '..', `cli${path.extname(import.meta.path)}`);
|
|
7
|
+
function runCli(root, args) {
|
|
8
|
+
return Bun.spawnSync(['bun', CLI, '--root', root, ...args], { stdout: 'pipe', stderr: 'pipe' });
|
|
9
|
+
}
|
|
10
|
+
describe('buzola CLI', () => {
|
|
11
|
+
let root;
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
root = fs.mkdtempSync(path.join(os.tmpdir(), 'buzola-cli-test-'));
|
|
14
|
+
fs.mkdirSync(path.join(root, 'src', 'routes'), { recursive: true });
|
|
15
|
+
});
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
18
|
+
});
|
|
19
|
+
it('writes the same hot update code as the Vite plugin with --hot vite', () => {
|
|
20
|
+
expect(runCli(root, ['--hot', 'vite']).exitCode).toBe(0);
|
|
21
|
+
expect(fs.readFileSync(path.join(root, 'src', 'buzola.gen.ts'), 'utf-8')).toContain('import.meta.hot.accept(');
|
|
22
|
+
});
|
|
23
|
+
it('writes no hot update code by default', () => {
|
|
24
|
+
expect(runCli(root, []).exitCode).toBe(0);
|
|
25
|
+
expect(fs.readFileSync(path.join(root, 'src', 'buzola.gen.ts'), 'utf-8')).not.toContain('import.meta.hot');
|
|
26
|
+
});
|
|
27
|
+
it('refuses a bundler it does not know', () => {
|
|
28
|
+
const result = runCli(root, ['--hot', 'webpack']);
|
|
29
|
+
expect(result.exitCode).toBe(1);
|
|
30
|
+
expect(result.stderr.toString()).toContain('--hot accepts only "vite"');
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=cli.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.test.js","sourceRoot":"","sources":["../../src/__tests__/cli.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,UAAU,CAAA;AACtE,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,kFAAkF;AAClF,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AAEpF,SAAS,MAAM,CAAC,IAAY,EAAE,IAAc;IAC3C,OAAO,GAAG,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;AAChG,CAAC;AAED,QAAQ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AAA;IAC3G,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;QAC7C,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAA;QACjD,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAC/B,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,SAAS,CAAC,2BAA2B,CAAC,CAAA;IACxE,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
|
package/dist/cli.js
CHANGED
|
@@ -9,6 +9,7 @@ const { values } = parseArgs({
|
|
|
9
9
|
output: { type: 'string', short: 'o' },
|
|
10
10
|
'persistent-param': { type: 'string', multiple: true },
|
|
11
11
|
root: { type: 'string' },
|
|
12
|
+
hot: { type: 'string' },
|
|
12
13
|
help: { type: 'boolean', short: 'h', default: false },
|
|
13
14
|
},
|
|
14
15
|
strict: true,
|
|
@@ -21,16 +22,22 @@ Options:
|
|
|
21
22
|
-o, --output <path> Output file path (default: src/buzola.gen.ts)
|
|
22
23
|
--persistent-param <name> Persistent parameter name (repeatable)
|
|
23
24
|
--root <path> Project root directory (default: cwd)
|
|
25
|
+
--hot vite Emit Vite hot update code, as the Vite plugin does
|
|
24
26
|
-h, --help Show this help message`);
|
|
25
27
|
process.exit(0);
|
|
26
28
|
}
|
|
29
|
+
const hot = values.hot;
|
|
30
|
+
if (hot !== undefined && hot !== 'vite') {
|
|
31
|
+
console.error(`--hot accepts only "vite", got "${hot}"`);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
27
34
|
const options = await resolveOptions({
|
|
28
35
|
root: values.root,
|
|
29
36
|
routesDir: values['routes-dir'],
|
|
30
37
|
output: values.output,
|
|
31
38
|
persistentParams: values['persistent-param'],
|
|
32
39
|
});
|
|
33
|
-
const changed = await generate(options);
|
|
40
|
+
const changed = await generate({ ...options, hot });
|
|
34
41
|
if (changed) {
|
|
35
42
|
console.log(`Generated ${path.relative(options.root, options.outputPath)}`);
|
|
36
43
|
}
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC5B,OAAO,EAAE;QACR,YAAY,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE;QAC5C,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE;QACtC,kBAAkB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;QACtD,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACxB,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE;KACrD;IACD,MAAM,EAAE,IAAI;CACZ,CAAC,CAAA;AAEF,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;IACjB,OAAO,CAAC,GAAG,CAAC
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,MAAM,EA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AEnD,IAAI,OAAO,EAAE,CAAC;IACb,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;AAC5E,CAAC;KAAM,CAAC;IACP,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;AAC1B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buzola/codegen",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.22",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"directory": "packages/codegen"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@buzola/router": "^0.0.
|
|
27
|
+
"@buzola/router": "^0.0.22"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^25.3.3",
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from 'bun:test'
|
|
2
|
+
import * as fs from 'node:fs'
|
|
3
|
+
import * as os from 'node:os'
|
|
4
|
+
import * as path from 'node:path'
|
|
5
|
+
|
|
6
|
+
// `tsc -b` also compiles this test into dist/, where the CLI beside it is cli.js.
|
|
7
|
+
const CLI = path.join(import.meta.dir, '..', `cli${path.extname(import.meta.path)}`)
|
|
8
|
+
|
|
9
|
+
function runCli(root: string, args: string[]) {
|
|
10
|
+
return Bun.spawnSync(['bun', CLI, '--root', root, ...args], { stdout: 'pipe', stderr: 'pipe' })
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
describe('buzola CLI', () => {
|
|
14
|
+
let root: string
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
root = fs.mkdtempSync(path.join(os.tmpdir(), 'buzola-cli-test-'))
|
|
18
|
+
fs.mkdirSync(path.join(root, 'src', 'routes'), { recursive: true })
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
fs.rmSync(root, { recursive: true, force: true })
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('writes the same hot update code as the Vite plugin with --hot vite', () => {
|
|
26
|
+
expect(runCli(root, ['--hot', 'vite']).exitCode).toBe(0)
|
|
27
|
+
expect(fs.readFileSync(path.join(root, 'src', 'buzola.gen.ts'), 'utf-8')).toContain('import.meta.hot.accept(')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('writes no hot update code by default', () => {
|
|
31
|
+
expect(runCli(root, []).exitCode).toBe(0)
|
|
32
|
+
expect(fs.readFileSync(path.join(root, 'src', 'buzola.gen.ts'), 'utf-8')).not.toContain('import.meta.hot')
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('refuses a bundler it does not know', () => {
|
|
36
|
+
const result = runCli(root, ['--hot', 'webpack'])
|
|
37
|
+
expect(result.exitCode).toBe(1)
|
|
38
|
+
expect(result.stderr.toString()).toContain('--hot accepts only "vite"')
|
|
39
|
+
})
|
|
40
|
+
})
|
package/src/cli.ts
CHANGED
|
@@ -10,6 +10,7 @@ const { values } = parseArgs({
|
|
|
10
10
|
output: { type: 'string', short: 'o' },
|
|
11
11
|
'persistent-param': { type: 'string', multiple: true },
|
|
12
12
|
root: { type: 'string' },
|
|
13
|
+
hot: { type: 'string' },
|
|
13
14
|
help: { type: 'boolean', short: 'h', default: false },
|
|
14
15
|
},
|
|
15
16
|
strict: true,
|
|
@@ -23,10 +24,17 @@ Options:
|
|
|
23
24
|
-o, --output <path> Output file path (default: src/buzola.gen.ts)
|
|
24
25
|
--persistent-param <name> Persistent parameter name (repeatable)
|
|
25
26
|
--root <path> Project root directory (default: cwd)
|
|
27
|
+
--hot vite Emit Vite hot update code, as the Vite plugin does
|
|
26
28
|
-h, --help Show this help message`)
|
|
27
29
|
process.exit(0)
|
|
28
30
|
}
|
|
29
31
|
|
|
32
|
+
const hot = values.hot
|
|
33
|
+
if (hot !== undefined && hot !== 'vite') {
|
|
34
|
+
console.error(`--hot accepts only "vite", got "${hot}"`)
|
|
35
|
+
process.exit(1)
|
|
36
|
+
}
|
|
37
|
+
|
|
30
38
|
const options = await resolveOptions({
|
|
31
39
|
root: values.root,
|
|
32
40
|
routesDir: values['routes-dir'],
|
|
@@ -34,7 +42,7 @@ const options = await resolveOptions({
|
|
|
34
42
|
persistentParams: values['persistent-param'],
|
|
35
43
|
})
|
|
36
44
|
|
|
37
|
-
const changed = await generate(options)
|
|
45
|
+
const changed = await generate({ ...options, hot })
|
|
38
46
|
|
|
39
47
|
if (changed) {
|
|
40
48
|
console.log(`Generated ${path.relative(options.root, options.outputPath)}`)
|