Skip to content

Commit ce84f37

Browse files
committed
Minor changes, update CONTRIBUTING.md
1 parent f9a4286 commit ce84f37

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

.github/workflows/tests.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,8 @@ jobs:
7575
cache: 'yarn'
7676
- name: Install dependencies
7777
run: yarn --dev
78-
- name: Generate code sample files
79-
run: yarn generate-code-sample-files
8078
- name: Run code style check
8179
run: yarn style
82-
# https://github.com/prettier/prettier/issues/15438
83-
- name: Check formatting of code samples
84-
run: yarn prettier --ignore-path=.prettierignore -c generated-code-samples
8580
- name: Run yaml style check
8681
uses: ibiqlik/action-yamllint@v3
8782
with:
@@ -98,8 +93,6 @@ jobs:
9893
cache: 'yarn'
9994
- name: Install dependencies
10095
run: yarn --dev
101-
- name: Generate code sample files
102-
run: yarn generate-code-sample-files
10396
- name: Build project
10497
run: yarn build
10598
- name: Run types check

CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ yarn style:fix
7070
yarn build
7171
```
7272

73+
### Code samples
74+
75+
In this repository code samples are linted and type checked. To achieve this we generate
76+
TypeScript files from `.code-samples.meilisearch.yaml`, and vice-versa.
77+
78+
```bash
79+
# Generate files
80+
yarn generate-code-sample-files
81+
# Generate YAML file
82+
yarn generate-code-samples-yaml
83+
# For maintainers to generate new code samples
84+
yarn generate-code-sample-files new_sample_one new_sample_two
85+
```
86+
7387
## Git Guidelines
7488

7589
### Git Branches

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"build": "vite build && tsc -p tsconfig.build.json && vite --mode production-umd build",
4545
"postbuild": "node scripts/build.js",
4646
"test": "vitest run --coverage",
47-
"types": "tsc -p tsconfig.json --noEmit",
47+
"types": "yarn generate-code-sample-files && tsc -p tsconfig.json --noEmit",
4848
"types:watch": "yarn types --watch",
4949
"test:env:browser": "yarn build && node scripts/copy-umd-file.js --to ./tests/env/express/public && yarn --cwd tests/env/express && yarn --cwd tests/env/express test",
5050
"test:watch": "vitest watch",
@@ -61,8 +61,8 @@
6161
"fmt:fix": "prettier -w ./**/*.{js,ts}",
6262
"lint": "eslint",
6363
"lint:fix": "eslint --fix",
64-
"style": "yarn fmt && yarn lint",
65-
"style:fix": "yarn fmt:fix && yarn lint:fix",
64+
"style": "yarn generate-code-sample-files && prettier --ignore-path=.prettierignore -c generated-code-samples && yarn fmt && yarn lint",
65+
"style:fix": "yarn generate-code-sample-files && prettier --ignore-path=.prettierignore -c generated-code-samples && yarn fmt:fix && yarn lint:fix",
6666
"prepare": "husky"
6767
},
6868
"files": [

scripts/code-samples/from-yaml.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const headerClientDeclaration =
1111
'const _client = new MeiliSearch({ host: "http://127.0.0.1:7700" });\n';
1212
const headerComment =
1313
"// Code below this line will be written to code samples YAML file\n" +
14+
'// For more information consult CONTRIBUTING.md "Tests and Linter" section\n' +
1415
delimiter +
1516
"\n";
1617

@@ -32,6 +33,8 @@ for (const jsonFileToGenerate of jsonFilesToGenerate) {
3233
);
3334
}
3435

36+
let generatedFileTally = 0;
37+
3538
for (const { sampleName, code } of iterateCodeSamples()) {
3639
let header = "";
3740

@@ -51,6 +54,8 @@ for (const { sampleName, code } of iterateCodeSamples()) {
5154
new URL(sampleName + ".ts", generatedCodeSamplesDir),
5255
header + code + "\n",
5356
);
57+
58+
generatedFileTally += 1;
5459
}
5560

5661
// generate additional files from arguments passed
@@ -59,4 +64,8 @@ for (const sampleName of argv.slice(3)) {
5964
new URL(sampleName + ".ts", generatedCodeSamplesDir),
6065
headerImport + headerClientDeclaration + headerComment,
6166
);
67+
68+
generatedFileTally += 1;
6269
}
70+
71+
console.log(`generated ${generatedFileTally} code sample file(s)`);

scripts/code-samples/to-yaml.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,13 @@ const serializedCodeSamples = manipulatedCodeSamples
8686
.join("\n");
8787

8888
const header =
89-
"# This code-samples file is used by the Meilisearch documentation\n" +
89+
"# This code-samples file is used by the Meilisearch documentation.\n" +
9090
"# Every example written here will be automatically fetched by\n" +
91-
"# the documentation on build\n" +
91+
"# the documentation on build.\n" +
9292
"# You can read more at https://github.com/meilisearch/documentation\n" +
93+
'# This file is generated, read more in CONTRIBUTING.md "Tests and Linter" section.' +
9394
"---\n";
9495

9596
writeFileSync(codeSamplesPath, header + serializedCodeSamples + "\n");
97+
98+
console.log(`generated ${manipulatedCodeSamples.length} code sample(s)`);

0 commit comments

Comments
 (0)