File tree Expand file tree Collapse file tree 5 files changed +31
-12
lines changed Expand file tree Collapse file tree 5 files changed +31
-12
lines changed Original file line number Diff line number Diff line change 75
75
cache : ' yarn'
76
76
- name : Install dependencies
77
77
run : yarn --dev
78
- - name : Generate code sample files
79
- run : yarn generate-code-sample-files
80
78
- name : Run code style check
81
79
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
85
80
- name : Run yaml style check
86
81
uses : ibiqlik/action-yamllint@v3
87
82
with :
98
93
cache : ' yarn'
99
94
- name : Install dependencies
100
95
run : yarn --dev
101
- - name : Generate code sample files
102
- run : yarn generate-code-sample-files
103
96
- name : Build project
104
97
run : yarn build
105
98
- name : Run types check
Original file line number Diff line number Diff line change @@ -70,6 +70,20 @@ yarn style:fix
70
70
yarn build
71
71
```
72
72
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
+
73
87
## Git Guidelines
74
88
75
89
### Git Branches
Original file line number Diff line number Diff line change 44
44
"build" : " vite build && tsc -p tsconfig.build.json && vite --mode production-umd build" ,
45
45
"postbuild" : " node scripts/build.js" ,
46
46
"test" : " vitest run --coverage" ,
47
- "types" : " tsc -p tsconfig.json --noEmit" ,
47
+ "types" : " yarn generate-code-sample-files && tsc -p tsconfig.json --noEmit" ,
48
48
"types:watch" : " yarn types --watch" ,
49
49
"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" ,
50
50
"test:watch" : " vitest watch" ,
61
61
"fmt:fix" : " prettier -w ./**/*.{js,ts}" ,
62
62
"lint" : " eslint" ,
63
63
"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" ,
66
66
"prepare" : " husky"
67
67
},
68
68
"files" : [
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ const headerClientDeclaration =
11
11
'const _client = new MeiliSearch({ host: "http://127.0.0.1:7700" });\n' ;
12
12
const headerComment =
13
13
"// 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' +
14
15
delimiter +
15
16
"\n" ;
16
17
@@ -32,6 +33,8 @@ for (const jsonFileToGenerate of jsonFilesToGenerate) {
32
33
) ;
33
34
}
34
35
36
+ let generatedFileTally = 0 ;
37
+
35
38
for ( const { sampleName, code } of iterateCodeSamples ( ) ) {
36
39
let header = "" ;
37
40
@@ -51,6 +54,8 @@ for (const { sampleName, code } of iterateCodeSamples()) {
51
54
new URL ( sampleName + ".ts" , generatedCodeSamplesDir ) ,
52
55
header + code + "\n" ,
53
56
) ;
57
+
58
+ generatedFileTally += 1 ;
54
59
}
55
60
56
61
// generate additional files from arguments passed
@@ -59,4 +64,8 @@ for (const sampleName of argv.slice(3)) {
59
64
new URL ( sampleName + ".ts" , generatedCodeSamplesDir ) ,
60
65
headerImport + headerClientDeclaration + headerComment ,
61
66
) ;
67
+
68
+ generatedFileTally += 1 ;
62
69
}
70
+
71
+ console . log ( `generated ${ generatedFileTally } code sample file(s)` ) ;
Original file line number Diff line number Diff line change @@ -86,10 +86,13 @@ const serializedCodeSamples = manipulatedCodeSamples
86
86
. join ( "\n" ) ;
87
87
88
88
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" +
90
90
"# Every example written here will be automatically fetched by\n" +
91
- "# the documentation on build\n" +
91
+ "# the documentation on build. \n" +
92
92
"# 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.' +
93
94
"---\n" ;
94
95
95
96
writeFileSync ( codeSamplesPath , header + serializedCodeSamples + "\n" ) ;
97
+
98
+ console . log ( `generated ${ manipulatedCodeSamples . length } code sample(s)` ) ;
You can’t perform that action at this time.
0 commit comments