Skip to content

Commit b7b1c59

Browse files
authored
feat(script): use typescript for all scripts APIC-334 (#170)
1 parent a549125 commit b7b1c59

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1487
-1187
lines changed

.github/workflows/check.yml

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
uses: ./.github/actions/cache
6161

6262
- name: Building ${{ matrix.client }} specs
63-
run: yarn build:specs ${{ matrix.client }}
63+
run: yarn cli build specs ${{ matrix.client }}
6464

6565
- name: Check diff with pushed spec
6666
run: exit $(git status --porcelain specs/bundled/${{ matrix.client }}.yml | wc -l)
@@ -123,15 +123,15 @@ jobs:
123123

124124
- name: Generate ${{ matrix.client.name }} client
125125
if: steps.cache.outputs.cache-hit != 'true'
126-
run: yarn generate javascript ${{ matrix.client.name }}
126+
run: yarn cli generate javascript ${{ matrix.client.name }}
127127

128128
- name: Check diff with pushed client
129129
if: steps.cache.outputs.cache-hit != 'true'
130130
run: exit $(git status --porcelain ${{ matrix.client.folder }} | wc -l)
131131

132132
- name: Build ${{ matrix.client.name }} client
133133
if: steps.cache.outputs.cache-hit != 'true'
134-
run: yarn build:clients javascript ${{ matrix.client.name }}
134+
run: yarn cli build clients javascript ${{ matrix.client.name }}
135135

136136
client_java:
137137
runs-on: ubuntu-20.04
@@ -160,15 +160,15 @@ jobs:
160160

161161
- name: Generate ${{ matrix.client.name }} client
162162
if: steps.cache.outputs.cache-hit != 'true'
163-
run: yarn generate java ${{ matrix.client.name }}
163+
run: yarn cli generate java ${{ matrix.client.name }}
164164

165165
- name: Check diff with pushed client
166166
if: steps.cache.outputs.cache-hit != 'true'
167167
run: exit $(git status --porcelain ${{ matrix.client.folder }} | wc -l)
168168

169169
- name: Build ${{ matrix.client.name }} client
170170
if: steps.cache.outputs.cache-hit != 'true'
171-
run: yarn build:clients java ${{ matrix.client.name }}
171+
run: yarn cli build clients java ${{ matrix.client.name }}
172172

173173
client_php:
174174
runs-on: ubuntu-20.04
@@ -190,15 +190,15 @@ jobs:
190190

191191
- name: Generate ${{ matrix.client.name }} client
192192
if: steps.cache.outputs.cache-hit != 'true'
193-
run: yarn generate php ${{ matrix.client.name }}
193+
run: yarn cli generate php ${{ matrix.client.name }}
194194

195195
- name: Check diff with pushed client
196196
if: steps.cache.outputs.cache-hit != 'true'
197197
run: exit $(git status --porcelain ${{ matrix.client.folder }} | wc -l)
198198

199199
- name: Build ${{ matrix.client.name }} client
200200
if: steps.cache.outputs.cache-hit != 'true'
201-
run: yarn build:clients php ${{ matrix.client.name }}
201+
run: yarn cli build clients php ${{ matrix.client.name }}
202202

203203
cts:
204204
runs-on: ubuntu-20.04
@@ -217,20 +217,14 @@ jobs:
217217
with:
218218
job: cts
219219

220-
- name: Check script linting
221-
run: yarn cts:lint:scripts
222-
223-
- name: Test CTS script
224-
run: yarn cts:test:scripts
225-
226220
- name: Generate CTS
227-
run: yarn cts:generate
221+
run: yarn cli cts generate
228222

229223
- name: Check diff with pushed CTS
230224
run: exit $(git status --porcelain ./tests/output | wc -l)
231225

232226
- name: Run CTS
233-
run: yarn cts:test
227+
run: yarn cli cts run
234228

235229
scripts:
236230
runs-on: ubuntu-20.04
@@ -243,5 +237,8 @@ jobs:
243237
id: restore
244238
uses: ./.github/actions/cache
245239

240+
- name: Check script linting
241+
run: yarn scripts:lint
242+
246243
- name: Test scripts
247-
run: yarn workspace scripts test
244+
run: yarn scripts:test

README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,34 +53,34 @@ You can make changes locally and run commands through the docker container.
5353
#### Usage
5454

5555
```bash
56-
yarn docker build:specs <client | all>
56+
yarn docker build specs <client | all>
5757
```
5858

5959
#### Build all specs
6060

6161
```bash
62-
yarn docker build:specs
62+
yarn docker build specs
6363
```
6464

6565
#### Build specific spec
6666

6767
```bash
68-
yarn docker build:specs recommend
68+
yarn docker build specs recommend
6969
```
7070

7171
#### Fix the specs format
7272

7373
This is used by the build script and should not need to be called manually but if you want to format all specs file do:
7474

7575
```bash
76-
yarn docker specs:fix
76+
yarn specs:fix
7777
```
7878

7979
If you just want to check the format (not override the files), run:
8080

8181
```bash
82-
yarn docker specs:lint <client>
83-
yarn docker specs:lint search
82+
yarn specs:lint <client>
83+
yarn specs:lint search
8484
```
8585

8686
### Generate clients based on the [`specs`](./specs/)
@@ -102,15 +102,23 @@ yarn docker generate
102102
#### Usage
103103

104104
```bash
105-
yarn docker build:clients <language | all> <client | all>
105+
yarn docker build clients <language | all> <client | all>
106106
```
107107

108108
### Build specific client for specific language
109109

110110
```bash
111-
yarn docker build:clients java recommend
111+
yarn docker build clients java recommend
112112
```
113113

114+
### Verbose command
115+
116+
You can add `-v` to almost every command to have a more verbose output.
117+
118+
### Interactive command
119+
120+
If you want to choose the language and client from a list you can add the `--interactive` option, or `-i`.
121+
114122
## Testing clients
115123

116124
You can test our generated clients by running:

base.tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
"typeRoots": ["node_modules/@types"],
1818
"types": ["node"],
1919
"resolveJsonModule": true
20-
}
20+
},
21+
"exclude": ["node_modules"]
2122
}

clients.config.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"java": {
3+
"folder": "clients/algoliasearch-client-java-2",
4+
"tests": {
5+
"extension": ".test.java",
6+
"outputFolder": "src/test/java/com/algolia"
7+
}
8+
},
9+
"javascript": {
10+
"folder": "clients/algoliasearch-client-javascript",
11+
"tests": {
12+
"extension": ".test.ts",
13+
"outputFolder": "src"
14+
}
15+
},
16+
"php": {
17+
"folder": "clients/algoliasearch-client-php"
18+
}
19+
}

docs/CTS.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ It is automaticaly generated for all languages, from a JSON entry point.
88
> CTS requires all clients to be built
99
1010
```bash
11-
yarn docker build:specs
12-
yarn docker build:clients
13-
yarn docker cts:generate
14-
yarn docker cts:test
11+
yarn docker build specs all
12+
yarn docker build clients all all
13+
yarn docker cts generate all all
14+
yarn docker cts run all
1515
```
1616

1717
If you only want to generate the tests for a language, you can run:
1818

1919
```bash
20-
yarn docker cts:generate javascript
20+
yarn docker cts generate javascript all
2121
```
2222

2323
Or for a specific client:
2424

2525
```bash
26-
yarn docker cts:generate all search
26+
yarn docker cts generate all search
2727
```
2828

2929
Or a specific language and client:
3030

3131
```bash
32-
yarn docker cts:generate javascript search
32+
yarn docker cts generate javascript search
3333
```
3434

3535
## How to add test

openapitools.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@
241241
"sourceFolder": "algoliasearch-core",
242242
"java8": true,
243243
"dateLibrary": "java8",
244-
"packageName": "algoliasearch-client-java-2"
244+
"packageName": "algoliasearch-client-java-2",
245+
"packageVersion": "0.0.1"
245246
}
246247
},
247248
"php-search": {
@@ -259,7 +260,8 @@
259260
"configClassname": "SearchConfig",
260261
"useCache": true,
261262
"variableNamingConvention": "camelCase",
262-
"packageName": "algoliasearch-client-php"
263+
"packageName": "algoliasearch-client-php",
264+
"packageVersion": "0.0.1"
263265
}
264266
},
265267
"php-recommend": {
@@ -277,7 +279,8 @@
277279
"configClassname": "RecommendConfig",
278280
"useCache": true,
279281
"variableNamingConvention": "camelCase",
280-
"packageName": "algoliasearch-client-php"
282+
"packageName": "algoliasearch-client-php",
283+
"packageVersion": "0.0.1"
281284
}
282285
},
283286
"php-personalization": {
@@ -297,6 +300,7 @@
297300
"allowedRegions": "us-eu",
298301
"variableNamingConvention": "camelCase",
299302
"packageName": "algoliasearch-client-php",
303+
"packageVersion": "0.0.1",
300304
"isEuHost": true,
301305
"host": "personalization",
302306
"topLevelDomain": "com"
@@ -319,6 +323,7 @@
319323
"allowedRegions": "us-de",
320324
"variableNamingConvention": "camelCase",
321325
"packageName": "algoliasearch-client-php",
326+
"packageVersion": "0.0.1",
322327
"fallbackToAliasHost": true,
323328
"isDeHost": true,
324329
"host": "analytics",
@@ -342,6 +347,7 @@
342347
"allowedRegions": "us-de",
343348
"variableNamingConvention": "camelCase",
344349
"packageName": "algoliasearch-client-php",
350+
"packageVersion": "0.0.1",
345351
"fallbackToAliasHost": true,
346352
"isDeHost": true,
347353
"host": "insights",
@@ -365,6 +371,7 @@
365371
"allowedRegions": "us-de",
366372
"variableNamingConvention": "camelCase",
367373
"packageName": "algoliasearch-client-php",
374+
"packageVersion": "0.0.1",
368375
"fallbackToAliasHost": true,
369376
"isDeHost": true,
370377
"host": "analytics",
@@ -388,11 +395,12 @@
388395
"allowedRegions": "us-eu",
389396
"variableNamingConvention": "camelCase",
390397
"packageName": "algoliasearch-client-php",
398+
"packageVersion": "0.0.1",
391399
"isEuHost": true,
392400
"host": "query-suggestions",
393401
"topLevelDomain": "com"
394402
}
395403
}
396404
}
397405
}
398-
}
406+
}

package.json

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,24 @@
55
"clients/algoliasearch-client-javascript/",
66
"playground/javascript/node/",
77
"playground/javascript/browser/",
8-
"tests/",
9-
"scripts/"
8+
"scripts/",
9+
"tests/output/javascript"
1010
],
1111
"scripts": {
12-
"build:clients": "./scripts/multiplexer.sh ${2:-nonverbose} ./scripts/builds/clients.sh ${0:-all} ${1:-all}",
13-
"build:specs": "./scripts/builds/specs.sh ${0:-all} ${1:-yml}",
14-
"build": "yarn build:specs && yarn build:clients",
12+
"cli": "yarn workspace scripts ts-node --transpile-only ./index.ts",
1513
"clean": "rm -rf **/dist **/build **/node_modules **/.gradle",
16-
"cts:generate": "yarn workspace tests build && ./scripts/multiplexer.sh ${2:-nonverbose} yarn workspace tests generate ${0:-all} ${1:-all}",
17-
"cts:test": "./scripts/multiplexer.sh ${1:-nonverbose} ./scripts/runCTS.sh ${0:-all} all",
18-
"cts:test:scripts": "yarn workspace tests test:scripts",
19-
"cts:lint:scripts": "eslint --ext=ts tests/src/",
2014
"docker:build": "./scripts/docker/build.sh",
2115
"docker:clean": "docker stop dev; docker rm -f dev; docker image rm -f api-clients-automation",
2216
"docker:mount": "./scripts/docker/mount.sh",
2317
"docker:setup": "yarn docker:clean && yarn docker:build && yarn docker:mount",
24-
"docker": "docker exec -it dev yarn $*",
25-
"lint": "eslint --ext=ts .",
26-
"post:generate": "./scripts/post-gen/global.sh",
27-
"generate": "./scripts/multiplexer.sh ${2:-nonverbose} ./scripts/generate.sh ${0:-all} ${1:-all} && yarn post:generate ${0:-all}",
18+
"docker": "docker exec -it dev yarn cli $*",
19+
"github-actions:lint": "eslint --ext=yml .github/",
2820
"playground:browser": "yarn workspace javascript-browser-playground start",
29-
"playground": "yarn && ./scripts/multiplexer.sh ${2:-nonverbose} ./scripts/playground.sh ${0:-javascript} ${1:-search}",
21+
"release": "yarn workspace scripts createReleaseIssue",
22+
"scripts:lint": "eslint --ext=ts scripts/",
23+
"scripts:test": "yarn workspace scripts test",
3024
"specs:fix": "eslint --ext=yml specs/ --fix",
31-
"specs:lint": "eslint --ext=yml specs/$0",
32-
"github-actions:lint": "eslint --ext=yml .github/",
33-
"release": "yarn workspace scripts createReleaseIssue"
25+
"specs:lint": "eslint --ext=yml specs/$0"
3426
},
3527
"devDependencies": {
3628
"@openapitools/openapi-generator-cli": "2.4.26",

0 commit comments

Comments
 (0)