Skip to content

Commit d1ba8eb

Browse files
authored
Pull Prism config from prism config files in order to be Windows-compatible (#2)
* Pull Prism config from prism config files in order to be Windows-compatible * Make note about installing Prism
1 parent 78f3dd5 commit d1ba8eb

File tree

5 files changed

+49
-6
lines changed

5 files changed

+49
-6
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ You have two options for deploying white-labeled documentation:
2020
## Generating private connector documentation
2121

2222
If you have private connectors that you offer to your customers and you want documentation for them to live alongside the public connectors, you can generate documentation for them.
23+
2324
After installing node dependencies locally, ensure that you are logged in to the Prismatic CLI with `prism login`.
25+
If you do not have the Prismatic CLI installed, you can install it with:
26+
27+
```bash
28+
npm install -g @prismatic-io/prism
29+
```
30+
2431
Then, identify the key of the private connector you want to generate documentation for by running:
2532

2633
```bash
@@ -33,4 +40,6 @@ Using the `key` of the connector you want to generate documentation for, run:
3340
npm run generate-private-connector-docs YOUR-COMPONENT-KEY
3441
```
3542

43+
**Note**: Make sure you can successfully run `prism me` before running the above command, as it relies on your Prismatic CLI being configured correctly.
44+
3645
This will generate a markdown file in the `docs/connectors/` directory, and pull down the connector's icon into `docs/connectors/assets/`.

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
"format-js": "biome format --write",
1919
"format-markdown": "prettier --log-level warn --write \"docs/**/*.md\"",
2020
"generate-branded-markdown": "docusaurus generate-branded-markdown",
21-
"generate-public-connector-docs": "PRISMATIC_API_KEY=$(prism me:token) docusaurus generate-connector-docs --public-connectors",
21+
"generate-public-connector-docs": "docusaurus generate-connector-docs --public-connectors",
2222
"postgenerate-public-connector-docs": "npm run format-markdown",
23-
"generate-public-connector-docs-from-manifest": "PRISMATIC_API_KEY=$(prism me:token) docusaurus generate-connector-docs --public-connectors --from-manifest",
23+
"generate-public-connector-docs-from-manifest": "docusaurus generate-connector-docs --public-connectors --from-manifest",
2424
"postgenerate-public-connector-docs-from-manifest": "npm run format-markdown",
25-
"generate-private-connector-docs": "PRISMATIC_API_KEY=$(prism me:token) docusaurus generate-connector-docs --private-connector",
25+
"generate-private-connector-docs": "docusaurus generate-connector-docs --private-connector",
2626
"postgenerate-private-connector-docs": "npm run format-markdown",
2727
"resize-screenshots": "docusaurus resize-screenshots",
2828
"typecheck": "tsc"
@@ -50,6 +50,7 @@
5050
"graphql": "^16.11.0",
5151
"handlebars": "^4.7.8",
5252
"jimp": "^1.6.0",
53+
"js-yaml": "^4.1.0",
5354
"markdownlint-cli": "^0.45.0",
5455
"netlify-cli": "^22.1.6",
5556
"prettier": "^3.6.1",

src/plugins/connectors/auth.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { load } from "js-yaml";
2+
import fs from "node:fs";
3+
import { homedir } from "node:os";
4+
import path from "node:path";
5+
6+
export interface Configuration {
7+
accessToken: string;
8+
expiresIn: number;
9+
refreshToken: string;
10+
scope: string;
11+
tokenType: string;
12+
}
13+
14+
const configDirectory = path.join(homedir(), ".config", "prism");
15+
const configFilePath = path.join(configDirectory, "config.yml");
16+
17+
export const configFileExists = () => fs.existsSync(configFilePath);
18+
19+
export const readConfig = (): Configuration => {
20+
if (!configFileExists()) return null;
21+
const contents = fs.readFileSync(configFilePath, { encoding: "utf-8" });
22+
const config = load(contents.toString()) as Configuration;
23+
return config;
24+
};

src/plugins/connectors/graphqlClient.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* in order to pull metadata about existing connectors
44
*/
55
import { Graffle } from "graffle";
6+
import { readConfig } from "./auth";
67

78
export const getPrismaticConnection = () => {
89
const { PRISMATIC_API_KEY, PRISMATIC_URL } = process.env;
@@ -11,12 +12,19 @@ export const getPrismaticConnection = () => {
1112
? `${PRISMATIC_URL}/api`
1213
: "https://app.prismatic.io/api";
1314

14-
if (!PRISMATIC_API_KEY) {
15-
throw new Error("You must set a PRISMATIC_API_KEY environment variable.");
15+
// If the environment variable is set, use it to create the client
16+
if (PRISMATIC_API_KEY) {
17+
return {
18+
PRISMATIC_API_KEY,
19+
PRISMATIC_URL: PRISMATIC_URL || "https://app.prismatic.io",
20+
API_ENDPOINT,
21+
};
1622
}
1723

24+
// Otherwise, read the access token from the prism config file
25+
const { accessToken } = readConfig();
1826
return {
19-
PRISMATIC_API_KEY,
27+
PRISMATIC_API_KEY: accessToken,
2028
PRISMATIC_URL: PRISMATIC_URL || "https://app.prismatic.io",
2129
API_ENDPOINT,
2230
};

0 commit comments

Comments
 (0)