Skip to content

Commit 2ccd5ec

Browse files
authored
feat: Add init command (#44)
* Add generate config property helper * Init prompts POC - Using `ink` as renderer - Adding graphql codegen to talk with github API Overall I really like `prompt` API (simple promise base API and fully typesafe). The only and major problem is the ink `app` management. When I have two `this.promt.input`, the output is not following… * Add rxjs * Refactor prompts to have only one App This is avoid the bug around ctrl+C and permit to have the answer displayed * Remove ink-text-input (not compatible with es module) * Add `addImport` helper * Add logo & badges * Add `getText` util * Mark private method * Make initCommand works with `--dry-run` * Add cli-highlight * Make dry-run works * Dirty test fix (esm problems) * Finallize happy path * Fix cross-fetch dependency * Apply @moltar suggestion * Inject baseUrl if available * Improve getting started
1 parent 1d8055e commit 2ccd5ec

39 files changed

+37588
-1376
lines changed

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"cli": "1.3.1",
33
"plugins/typescript": "2.0.0"
4-
}
4+
}

LICENCE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2021
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
# OpenAPI Codegen
1+
<div align="center" style="margin-bottom: 16px">
2+
<img src="openapi-codegen-logo.svg" width="400px" />
3+
</div>
24

3-
⚠️ This project is in an early stage, please check the issues to see what’s missing! ⚠️
4-
5-
-> Insert logo and badges here
5+
[![npm](https://img.shields.io/npm/v/@openapi-codegen/cli.svg?style=for-the-badge)](https://www.npmjs.com/package/@openapi-codegen/cli)
6+
[![License](https://img.shields.io/npm/l/@openapi-codegen/cli.svg?style=for-the-badge)](https://github.com/fabien0102/openapi-codegen/blob/main/LICENSE)
67

78
Tooling to give you full type-safety around OpenAPI specs.
89

910
**For frontend:**
1011

1112
This will give you full auto-completion and type-safety of your APIs
1213

13-
**For backend:**
14+
**For backend: (in coming)**
1415

1516
This will generate everything you need to deliver a perfect API, spec driven.
1617

1718
## Getting started
1819

1920
```bash
20-
$ npx @openapi-codegen/cli init
21+
$ npm i -D @openapi-codegen/{cli,typescript}
22+
$ npx openapi-codegen init
2123
```
2224

23-
Follow the steps, this will generate a configuration file for you (openapi-codegen.config.ts) and update your `package.json`
24-
25-
```bash
26-
$ yarn gen # or the defined alias
27-
```
25+
Follow the steps, this will generate a configuration file for you (openapi-codegen.config.ts).
2826

2927
You should have a bunch of types / components ready to be used.
3028

29+
Note: The generated `{namespace}Fetcher.ts` assume a global `fetch` and the `qs` package, this is just a suggestion, you can do what ever you want on this file as soon as the types are compliant.
30+
3131
## Philosophy
3232

3333
In software development, communication between components and documentation around it is often no fun.

cli/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GITHUB_TOKEN=secret

cli/CHANGELOG.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,30 @@
22

33
### [1.3.1](https://github.com/fabien0102/openapi-codegen/compare/cli-v1.3.0...cli-v1.3.1) (2022-02-22)
44

5-
65
### Bug Fixes
76

8-
* Fix `path` usage for node 14 ([#34](https://github.com/fabien0102/openapi-codegen/issues/34)) ([4422e61](https://github.com/fabien0102/openapi-codegen/commit/4422e61b317ffd4d3aa0b30340592063c4a222cc))
7+
- Fix `path` usage for node 14 ([#34](https://github.com/fabien0102/openapi-codegen/issues/34)) ([4422e61](https://github.com/fabien0102/openapi-codegen/commit/4422e61b317ffd4d3aa0b30340592063c4a222cc))
98

109
## [1.3.0](https://github.com/fabien0102/openapi-codegen/compare/cli-v1.2.0...cli-v1.3.0) (2022-01-27)
1110

12-
1311
### Features
1412

15-
* Add support for flags in `gen` command ([#27](https://github.com/fabien0102/openapi-codegen/issues/27)) ([ec263c2](https://github.com/fabien0102/openapi-codegen/commit/ec263c2f55e4cc4fcb1bc427bf2c9fd1152f640d))
13+
- Add support for flags in `gen` command ([#27](https://github.com/fabien0102/openapi-codegen/issues/27)) ([ec263c2](https://github.com/fabien0102/openapi-codegen/commit/ec263c2f55e4cc4fcb1bc427bf2c9fd1152f640d))
1614

1715
## [1.2.0](https://github.com/fabien0102/openapi-codegen/compare/cli-v1.1.0...cli-v1.2.0) (2022-01-20)
1816

19-
2017
### Features
2118

22-
* [generateFetchers] Add extra props support ([#25](https://github.com/fabien0102/openapi-codegen/issues/25)) ([35fc219](https://github.com/fabien0102/openapi-codegen/commit/35fc219d9c644becdf38b0b3e38e1512d095d2d0))
19+
- [generateFetchers] Add extra props support ([#25](https://github.com/fabien0102/openapi-codegen/issues/25)) ([35fc219](https://github.com/fabien0102/openapi-codegen/commit/35fc219d9c644becdf38b0b3e38e1512d095d2d0))
2320

2421
## [1.1.0](https://github.com/fabien0102/openapi-codegen/compare/cli-v1.0.0...cli-v1.1.0) (2022-01-19)
2522

26-
2723
### Features
2824

29-
* generate fetchers only ([#22](https://github.com/fabien0102/openapi-codegen/issues/22)) ([b1d5c4a](https://github.com/fabien0102/openapi-codegen/commit/b1d5c4a6cc104904f4bc72777974973cdda7832d))
25+
- generate fetchers only ([#22](https://github.com/fabien0102/openapi-codegen/issues/22)) ([b1d5c4a](https://github.com/fabien0102/openapi-codegen/commit/b1d5c4a6cc104904f4bc72777974973cdda7832d))
3026

3127
## 1.0.0 (2022-01-17)
3228

33-
3429
### Bug Fixes
3530

36-
* adjust documentation with the current state of the project ([2a55e01](https://github.com/fabien0102/openapi-codegen/commit/2a55e0119e1155c0280cd16e5cee95b39e9e7bca))
31+
- adjust documentation with the current state of the project ([2a55e01](https://github.com/fabien0102/openapi-codegen/commit/2a55e0119e1155c0280cd16e5cee95b39e9e7bca))

cli/codegen.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
overwrite: true
2+
schema:
3+
- "https://api.github.com/graphql":
4+
headers:
5+
Authorization: Bearer ${GITHUB_TOKEN}
6+
documents: "src/**/*.graphql"
7+
generates:
8+
src/prompts/queries/github.tsx:
9+
plugins:
10+
- "typescript"
11+
- "typescript-operations"
12+
- "typescript-react-apollo"

cli/examples/openapi-codegen.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineConfig } from "../lib/index.js";
2+
import { generateFetchers } from "@openapi-codegen/typescript";
23

34
export default defineConfig({
45
withFile: {

0 commit comments

Comments
 (0)