harmonyc 0.4.3 → 0.5.0
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/README.md +26 -9
- package/cli.js +17 -6
- package/compiler.js +3 -2
- package/package.json +1 -1
- package/run.js +24 -0
- package/watch.js +2 -1
package/README.md
CHANGED
|
@@ -6,18 +6,35 @@ A test design & BDD tool that helps you separate the _what_ to test from the _ho
|
|
|
6
6
|
|
|
7
7
|
## Usage
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
2. You can compile your `*.md` files in the `src` folder by running
|
|
9
|
+
- ### watch and run mode
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
npx harmonyc src/**/*.md
|
|
14
|
-
```
|
|
11
|
+
- You can compile and run your `*.md` files in the `src` folder, and watch it, by running
|
|
15
12
|
|
|
16
|
-
|
|
13
|
+
```bash script
|
|
14
|
+
npx harmonyc --run --watch src/**/*.md
|
|
15
|
+
```
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
- ### compiling and running
|
|
18
|
+
|
|
19
|
+
- You can compile and run your `*.md` files in the `src` folder by running
|
|
20
|
+
|
|
21
|
+
```bash script
|
|
22
|
+
npx harmonyc --run src/**/*.md
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
- ### compiling and running separately
|
|
26
|
+
|
|
27
|
+
1. You can compile your `*.md` files in the `src` folder by running
|
|
28
|
+
|
|
29
|
+
```bash script
|
|
30
|
+
npx harmonyc src/**/*.md
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
2. Then you can run the generated tests with Vitest by running
|
|
34
|
+
|
|
35
|
+
```bash script
|
|
36
|
+
npx vitest
|
|
37
|
+
```
|
|
21
38
|
|
|
22
39
|
## Syntax
|
|
23
40
|
|
package/cli.js
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
import { compileFiles } from './compiler.js';
|
|
3
3
|
import { parseArgs } from 'node:util';
|
|
4
4
|
import { watchFiles } from './watch.js';
|
|
5
|
+
import { run, runWatch } from './run.js';
|
|
5
6
|
const args = parseArgs({
|
|
6
7
|
options: {
|
|
7
8
|
help: { type: 'boolean' },
|
|
8
9
|
watch: { type: 'boolean' },
|
|
10
|
+
run: { type: 'boolean' },
|
|
9
11
|
},
|
|
10
12
|
allowPositionals: true,
|
|
11
13
|
});
|
|
@@ -13,9 +15,18 @@ if (args.positionals.length === 0 || args.values.help) {
|
|
|
13
15
|
console.error('Usage: harmonyc <input files glob pattern>');
|
|
14
16
|
process.exit(1);
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
;
|
|
19
|
+
(async () => {
|
|
20
|
+
if (args.values.watch) {
|
|
21
|
+
const outFns = await watchFiles(args.positionals);
|
|
22
|
+
if (args.values.run) {
|
|
23
|
+
runWatch(outFns);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const { outFns } = await compileFiles(args.positionals);
|
|
28
|
+
if (args.values.run) {
|
|
29
|
+
run(outFns);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
})();
|
package/compiler.js
CHANGED
|
@@ -6,13 +6,14 @@ export async function compileFiles(pattern) {
|
|
|
6
6
|
const fns = await glob(pattern);
|
|
7
7
|
if (!fns.length)
|
|
8
8
|
throw new Error(`No files found for pattern: ${String(pattern)}`);
|
|
9
|
-
await Promise.all(fns.map((fn) => compileFile(fn)));
|
|
9
|
+
const outFns = await Promise.all(fns.map((fn) => compileFile(fn)));
|
|
10
10
|
console.log(`Compiled ${fns.length} file${fns.length === 1 ? '' : 's'}.`);
|
|
11
|
-
return fns;
|
|
11
|
+
return { fns, outFns };
|
|
12
12
|
}
|
|
13
13
|
export async function compileFile(fn) {
|
|
14
14
|
const src = readFileSync(fn, 'utf8').toString();
|
|
15
15
|
const name = basename(fn).replace(/\.[a-z]+$/i, '');
|
|
16
16
|
const outFn = `${fn.replace(/\.[a-z]+$/i, '')}.mjs`;
|
|
17
17
|
writeFileSync(outFn, compileFeature(fn, src));
|
|
18
|
+
return outFn;
|
|
18
19
|
}
|
package/package.json
CHANGED
package/run.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { exec } from 'child_process';
|
|
2
|
+
function runCommand(patterns) {
|
|
3
|
+
return `npx vitest run ${args(patterns)}`;
|
|
4
|
+
}
|
|
5
|
+
function runWatchCommand(patterns) {
|
|
6
|
+
return `npx vitest ${args(patterns)}`;
|
|
7
|
+
}
|
|
8
|
+
function args(patterns) {
|
|
9
|
+
return patterns.map((s) => JSON.stringify(s)).join(' ');
|
|
10
|
+
}
|
|
11
|
+
export function run(patterns) {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
const cmd = runCommand(patterns);
|
|
14
|
+
const p = exec(cmd, { cwd: process.cwd() });
|
|
15
|
+
(_a = p.stdout) === null || _a === void 0 ? void 0 : _a.pipe(process.stdout);
|
|
16
|
+
(_b = p.stderr) === null || _b === void 0 ? void 0 : _b.pipe(process.stderr);
|
|
17
|
+
}
|
|
18
|
+
export function runWatch(patterns) {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
const cmd = runWatchCommand(patterns);
|
|
21
|
+
const p = exec(cmd, { cwd: process.cwd() });
|
|
22
|
+
(_a = p.stdout) === null || _a === void 0 ? void 0 : _a.pipe(process.stdout);
|
|
23
|
+
(_b = p.stderr) === null || _b === void 0 ? void 0 : _b.pipe(process.stderr);
|
|
24
|
+
}
|
package/watch.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { watch } from 'node:fs';
|
|
2
2
|
import { compileFile, compileFiles } from './compiler.js';
|
|
3
3
|
export async function watchFiles(patterns) {
|
|
4
|
-
const fns = await compileFiles(patterns);
|
|
4
|
+
const { fns, outFns } = await compileFiles(patterns);
|
|
5
5
|
for (const file of fns) {
|
|
6
6
|
watch(file, () => {
|
|
7
7
|
compileFile(file);
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
|
+
return outFns;
|
|
10
11
|
}
|