gatsby-attainlabs-cms 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -10
- package/gatsby-node.js +27 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# gatsby-
|
|
1
|
+
# gatsby-attainlabs-cms
|
|
2
2
|
|
|
3
3
|
A Gatsby plugin that downloads and syncs `index.tsx` components from the **Attain Labs CMS** hosted in Azure Repos into your Gatsby project at build time.
|
|
4
4
|
|
|
@@ -6,24 +6,111 @@ This is especially useful for keeping brand-specific and global CMS blocks up to
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Installation
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
npm install gatsby-
|
|
12
|
+
npm install gatsby-attainlabs-cms
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## Setup
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
### 1. Add environment variable
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
At the root of your Gatsby site, create a `.env.development` and/or `.env.production` file if it doesn’t already exist:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
touch .env.development
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Inside the file, add your Azure DevOps Personal Access Token (PAT):
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
PERSONAL_ACCESS_TOKEN=xxxxxxxxxxxxxxxx
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
⚠️ **Do not** prefix this with `GATSBY_`.
|
|
34
|
+
That prefix exposes variables to the browser bundle, which is not safe for secrets.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
### 2. Load `.env` in Gatsby
|
|
39
|
+
|
|
40
|
+
At the top of your `gatsby-config.js`, load dotenv:
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
require("dotenv").config({
|
|
44
|
+
path: `.env.${process.env.NODE_ENV}`,
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
### 3. Configure the plugin in `gatsby-config.js`
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
module.exports = {
|
|
54
|
+
plugins: [
|
|
55
|
+
{
|
|
56
|
+
resolve: "gatsby-plugin-your-plugin",
|
|
24
57
|
options: {
|
|
25
|
-
|
|
26
|
-
|
|
58
|
+
brand: "Cash Money", // LendDirect | Cash Money | Heights Finance adding-puck-for-visual-code-editing
|
|
59
|
+
// personalAccessToken: "optional-fallback", // not recommended, but supported
|
|
27
60
|
},
|
|
28
61
|
},
|
|
62
|
+
],
|
|
63
|
+
};
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Behavior
|
|
69
|
+
|
|
70
|
+
- Downloads brand-specific `index.tsx` components into:
|
|
71
|
+
- `src/cms/components/brand/`
|
|
72
|
+
- `src/cms/components/global/`
|
|
73
|
+
|
|
74
|
+
- Requires an Azure DevOps Personal Access Token (PAT) to authenticate requests.
|
|
75
|
+
|
|
76
|
+
- If the PAT is missing, the plugin will **warn and skip execution** instead of failing the build.
|
|
77
|
+
|
|
78
|
+
- If the `brand` option is missing or invalid, the plugin will **throw an error** and stop the build.
|
|
79
|
+
Valid values are:
|
|
80
|
+
- `LendDirect`
|
|
81
|
+
- `Cash Money`
|
|
82
|
+
- `Heights Finance`
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Troubleshooting
|
|
87
|
+
|
|
88
|
+
### PAT missing warning
|
|
89
|
+
|
|
90
|
+
If you see:
|
|
91
|
+
|
|
29
92
|
```
|
|
93
|
+
⚠️ [gatsby-plugin-your-plugin] No PERSONAL_ACCESS_TOKEN found...
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
➡️ Double-check that `.env.development` or `.env.production` exists and is loaded in `gatsby-config.js`.
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
### Invalid brand option
|
|
101
|
+
|
|
102
|
+
If you see:
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
[gatsby-plugin-your-plugin] Invalid or missing "brand" option.
|
|
106
|
+
You must specify one of: LendDirect, Cash Money, Heights Finance
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
➡️ Make sure you pass a valid brand in `gatsby-config.js`.
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
### Token in client code
|
|
114
|
+
|
|
115
|
+
Don’t use `GATSBY_PERSONAL_ACCESS_TOKEN`. That will leak your secret into the browser bundle.
|
|
116
|
+
Always use `PERSONAL_ACCESS_TOKEN`.
|
package/gatsby-node.js
CHANGED
|
@@ -5,9 +5,20 @@ import "dotenv/config";
|
|
|
5
5
|
// Load PAT from env instead of hardcoding (fallback to old const for now but warn)
|
|
6
6
|
|
|
7
7
|
export const onPreInit = async (_, pluginOptions) => {
|
|
8
|
-
const { brand, azureBranch } = pluginOptions;
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const { brand, azureBranch, personalAccessToken: patOption } = pluginOptions;
|
|
9
|
+
|
|
10
|
+
// Try env first, then plugin option fallback
|
|
11
|
+
const pat = process.env.PERSONAL_ACCESS_TOKEN || patOption;
|
|
12
|
+
|
|
13
|
+
if (!pat) {
|
|
14
|
+
console.warn(
|
|
15
|
+
"⚠️ [gatsby-plugin-your-plugin] No PERSONAL_ACCESS_TOKEN found. " +
|
|
16
|
+
"Set it in your project's .env file (recommended) or pass via plugin options.\n" +
|
|
17
|
+
"Example .env:\n" +
|
|
18
|
+
"PERSONAL_ACCESS_TOKEN=xxxxxxx\n"
|
|
19
|
+
);
|
|
20
|
+
return; // stop execution early
|
|
21
|
+
}
|
|
11
22
|
|
|
12
23
|
const brands = {
|
|
13
24
|
LendDirect: "lenddirect",
|
|
@@ -15,6 +26,19 @@ export const onPreInit = async (_, pluginOptions) => {
|
|
|
15
26
|
"Heights Finance": "heightsfinance",
|
|
16
27
|
};
|
|
17
28
|
|
|
29
|
+
// 🚨 Validate brand option
|
|
30
|
+
if (!brand || !brands[brand]) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`[gatsby-plugin-your-plugin] Invalid or missing "brand" option.\n` +
|
|
33
|
+
`You must specify one of: ${Object.keys(brands).join(", ")}\n` +
|
|
34
|
+
`Example:\n` +
|
|
35
|
+
`{\n` +
|
|
36
|
+
` resolve: "gatsby-plugin-your-plugin",\n` +
|
|
37
|
+
` options: { brand: "Cash Money" }\n` +
|
|
38
|
+
`}`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
18
42
|
const org = "CuroFinTech";
|
|
19
43
|
const project = "Marketing";
|
|
20
44
|
const repo = "Attain Labs";
|
|
@@ -144,5 +168,3 @@ export const onPreInit = async (_, pluginOptions) => {
|
|
|
144
168
|
doRequest(fileUrl);
|
|
145
169
|
}
|
|
146
170
|
};
|
|
147
|
-
|
|
148
|
-
onPreInit({}, { brand: "LendDirect" }); // For testing purposes, remove when done
|