diff --git a/README.md b/README.md index a150eb8..3e35b3b 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,6 @@ restful-react is **very well tested, production ready** and powers all of our pr - - [Overview](#overview) - [Getting Started](#getting-started) - [Features](#features) @@ -664,12 +663,11 @@ To generate components from remote specifications, you'll need to follow the fol 1. Open a terminal and run `restful-react import --github username:repo:branch:path/to/openapi.yaml --output MY_FETCHERS.tsx`, substituting things where necessary. 1. You will be prompted for a token. 1. Paste your token. -1. You will be asked if you'd like to save it for later. This is _entirely_ up to you and completely safe: it is saved in your `node_modules` folder and _not_ committed to version control or sent to us or anything: the source code of this whole thing is public so you're safe. - - **Caveat:** _Since_ your token is stored in `node_modules`, your token will be removed on each `npm install` of `restful-react`. - +1. You will be asked if you'd like to save it for later. This is _entirely_ up to you and completely safe: it is saved in your home directory. 1. You're done! 🎉 +Note: For CI environment, you can also provide the github token with the environment variable called `GITHUB_TOKEN` + #### Transforming an Original Spec In some cases, you might need to augment an existing OpenAPI specification on the fly, for code-generation purposes. Our CLI makes this quite straightforward: diff --git a/src/bin/restful-react-import.ts b/src/bin/restful-react-import.ts index 3fa28d4..fe976d8 100644 --- a/src/bin/restful-react-import.ts +++ b/src/bin/restful-react-import.ts @@ -136,11 +136,11 @@ const importSpecs = async (options: AdvancedOptions) => { } else if (options.github) { const { github } = options; - let accessToken: string; + let accessToken = process.env.GITHUB_TOKEN; const githubTokenPath = join(homedir(), ".restful-react"); - if (existsSync(githubTokenPath)) { + if (!accessToken && existsSync(githubTokenPath)) { accessToken = readFileSync(githubTokenPath, "utf-8"); - } else { + } else if (!accessToken) { const answers = await inquirer.prompt<{ githubToken: string; saveToken: boolean }>([ { type: "input",