gatsby-attainlabs-cms 1.0.0 → 1.0.2

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.
Files changed (3) hide show
  1. package/README.md +97 -10
  2. package/gatsby-node.js +38 -11
  3. package/package.json +3 -2
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # gatsby-attain-labs-cms
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
- ## Install
9
+ ## Installation
10
10
 
11
11
  ```bash
12
- npm install gatsby-attain-labs-cms
12
+ npm install gatsby-attainlabs-cms
13
13
  ```
14
14
 
15
15
  ---
16
16
 
17
- ## Usage
17
+ ## Setup
18
18
 
19
- In your gatsby-config.js, configure the plugin with the brand you want to sync:
19
+ ### 1. Add environment variable
20
20
 
21
- ```javascript
22
- {
23
- resolve: "gatsby-attain-labs-cms",
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
- // Select one: 'LendDirect', 'Cash Money', or 'Heights Finance'
26
- brand: "LendDirect",
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
- const pat = process.env.GATSBY_PERSONAL_ACCESS_TOKEN;
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";
@@ -23,14 +47,18 @@ export const onPreInit = async (_, pluginOptions) => {
23
47
  // List of folders to download from
24
48
  const targets = [
25
49
  {
26
- repoPath: `/apps/cms/src/cms/components/editor/templates/visual-block-editor/components/brands/${brands[brand]}`,
50
+ repoPath: `/apps/cms/src/cms/components/editor/visual-block-editor/components/brands/${brands[brand]}`,
27
51
  localBasePath: path.resolve("./src/cms/components/brand"),
28
52
  },
29
53
  {
30
54
  repoPath:
31
- "/apps/cms/src/cms/components/editor/templates/visual-block-editor/components/global/blocks",
55
+ "/apps/cms/src/cms/components/editor/visual-block-editor/components/global/blocks",
32
56
  localBasePath: path.resolve("./src/cms/components/global"),
33
57
  },
58
+ {
59
+ repoPath: `/apps/cms/gatsby-plugin-theme-ui/${brands[brand]}`,
60
+ localBasePath: path.resolve("./src/gatsby-plugin-theme-ui"),
61
+ },
34
62
  ];
35
63
 
36
64
  const options = {
@@ -69,12 +97,13 @@ export const onPreInit = async (_, pluginOptions) => {
69
97
  // Keep only index.tsx files
70
98
  const items = (result.value || []).filter(
71
99
  (i) =>
72
- !i.isFolder &&
73
- i.gitObjectType === "blob" &&
74
- posix.basename(i.path) === "index.tsx"
100
+ (!i.isFolder &&
101
+ i.gitObjectType === "blob" &&
102
+ posix.basename(i.path) === "index.tsx") ||
103
+ posix.extname(i.path) === "ts"
75
104
  );
76
105
 
77
- console.log(`Found ${items.length} index.tsx files in ${repoPath}`);
106
+ console.log(`Found ${items.length} files in ${repoPath}`);
78
107
  items.forEach((item) =>
79
108
  downloadFile(item.path, repoPath, localBasePath)
80
109
  );
@@ -144,5 +173,3 @@ export const onPreInit = async (_, pluginOptions) => {
144
173
  doRequest(fileUrl);
145
174
  }
146
175
  };
147
-
148
- onPreInit({}, { brand: "LendDirect" }); // For testing purposes, remove when done
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gatsby-attainlabs-cms",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "main": "gatsby-node.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -13,6 +13,7 @@
13
13
  "gatsby": "^5.0.0 || ^4.0.0"
14
14
  },
15
15
  "dependencies": {
16
- "dotenv": "^17.2.1"
16
+ "dotenv": "^17.2.1",
17
+ "react-slick": "^0.31.0"
17
18
  }
18
19
  }