Skip to content

Commit

Permalink
Simplify seed creation/validation commands (#1202)
Browse files Browse the repository at this point in the history
Removed unnecessary commands, reworked validation logic to always return
errors as array of strings instead of throwing.
  • Loading branch information
goodov authored Oct 16, 2024
1 parent 024f17f commit 4a7fbb2
Show file tree
Hide file tree
Showing 22 changed files with 684 additions and 696 deletions.
4 changes: 2 additions & 2 deletions src/scripts/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ function getLintDiffCommands(options: Options): Record<string, any> {
'*': 'prettier --ignore-unknown' + (options.fix ? ' --write' : ' --check'),
'*.{ts,js,tsx,jsx}':
'eslint --config src/.eslintrc.js' + (options.fix ? ' --fix' : ''),
'studies/**/*.json':
'npm run seed_tools -- check_study' + (options.fix ? ' --fix' : ''),
'studies/*': () =>
'npm run seed_tools -- lint studies' + (options.fix ? ' --fix' : ''),
};
}

Expand Down
75 changes: 7 additions & 68 deletions src/seed_tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,88 +4,27 @@

## Tools

### `check_study`

Validates study files for both logic and format errors. Called automatically
during `lint` for `studies/**/*.json` files.

##### Syntax

```bash
npm run seed_tools -- check_study <study_files...> [--fix]
```

##### Arguments

- `<study_files...>`: One or more study files that you want to check.

##### Options

- `--fix`: Fix format errors in-place.

### `create_seed`

Generates a `seed.bin` file from study files.

##### Syntax

```bash
npm run seed_tools -- create_seed <studies_dir> <output_file> [--mock_serial_number <value>] [--serial_number_path <path>]
```

##### Arguments

- `<studies_dir>`: The directory containing the study files.
- `<output_file>`: The output file for the generated seed.

##### Options

- `--mock_serial_number <value>`: Mock a serial number. If not provided, a
random number is used.
- `--serial_number_path <path>`: The file path to write the serial number to.

### `compare_seeds`

Compares two seed binary files and displays a human-readable diff. Used for safe
migration from the python seed generator to the typescript seed generator.

##### Syntax
### `create`

```bash
npm run seed_tools -- compare_seeds <seed1_file> <seed2_file>
```
Generates a `seed.bin` file from study files.

##### Arguments
### `lint`

- `<seed1_file>`: The first seed binary file to compare.
- `<seed2_file>`: The second seed binary file to compare.
Lints study files.

### `split_seed_json`

Splits a legacy `seed.json` file into individual study files.

##### Syntax

```bash
npm run seed_tools -- split_seed_json <seed_json_path> <output_dir>
```

##### Arguments

- `<seed_json_path>`: The path to the `seed.json` file to be split.
- `<output_dir>`: The directory where the individual study files will be
outputted.
## Tools help

### `validate_seed`

Validates a seed protobuf.

##### Syntax
Run to get available arguments and options:

```bash
npm run seed_tools -- validate_seed <seed_file>
npm run seed_tools -- <tool> --help
```

##### Arguments

- `<seed_file>`: The path to the binary-serialized `seed` protobuf.
132 changes: 0 additions & 132 deletions src/seed_tools/commands/check_study.test.ts

This file was deleted.

89 changes: 0 additions & 89 deletions src/seed_tools/commands/check_study.ts

This file was deleted.

12 changes: 7 additions & 5 deletions src/seed_tools/commands/compare_seeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { promises as fs } from 'fs';
import { VariationsSeed } from '../../proto/generated/variations_seed';
import diffStrings from '../utils/diff_strings';

export default new Command('compare_seeds')
.description('Compare two seed.bin')
.argument('<seed1_file>', 'seed1 file')
.argument('<seed2_file>', 'seed2 file')
.action(main);
export default function createCommand() {
return new Command('compare_seeds')
.description('Compare two seed.bin')
.argument('<seed1_file>', 'seed1 file')
.argument('<seed2_file>', 'seed2 file')
.action(main);
}

async function main(seed1FilePath: string, seed2FilePath: string) {
const seed1Binary: Buffer = await fs.readFile(seed1FilePath);
Expand Down
Loading

0 comments on commit 4a7fbb2

Please sign in to comment.