Skip to content

Commit 80c81ac

Browse files
committed
add starter-envvars
1 parent 339dbca commit 80c81ac

18 files changed

+461
-0
lines changed

packages/starter-envvars/.depcheckrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ignores: [
2+
"@types/*",
3+
"@owlprotocol/tsconfig",
4+
"@owlprotocol/prettier-config",
5+
"vite"
6+
]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
root: true,
3+
extends: ['@owlprotocol/eslint-config'],
4+
};

packages/starter-envvars/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
src/envvars.ts
2+
src/envvars.mts
3+
src/envvars.cts
4+
src/envvars.browser.ts
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
...require("@owlprotocol/prettier-config"),
3+
};

packages/starter-envvars/CHANGELOG.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# @owlprotocol/envvars
2+
3+
## 3.1.2
4+
5+
### Patch Changes
6+
7+
- 951cfb5: Test our changeset/action
8+
9+
## 3.1.1
10+
11+
### Patch Changes
12+
13+
- 81c8454: Updated release with all dependencies used by ui-components (soon to release)
14+
15+
## 3.1.0
16+
17+
### Minor Changes
18+
19+
- d72ac67: Updated release
20+
21+
## 2.0.6
22+
23+
### Patch Changes
24+
25+
- b6a190d7: fix find-config dependency as a prod one
26+
27+
## 2.0.5
28+
29+
### Patch Changes
30+
31+
- d7405311: envvars missing patch bump
32+
33+
## 2.0.2
34+
35+
### Patch Changes
36+
37+
- 26e0d473: Initial Release

packages/starter-envvars/LICENSE

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

packages/starter-envvars/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Envars Starter
2+
3+
Code generation for envvars management
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { cjsLibConfig, buildLib } from "@owlprotocol/esbuild-config";
2+
3+
//Ignore browser files
4+
cjsLibConfig.entryPoints = ["src/index.ts", "src/dotenvConfig.ts", "src/envvars.ts", "src/isProductionOrStaging.ts"];
5+
6+
await buildLib();

packages/starter-envvars/package.json

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"name": "@owlprotocol/starter-envvars",
3+
"version": "3.0.0",
4+
"keywords": [],
5+
"private": true,
6+
"type": "module",
7+
"homepage": "https://github.com/owlprotocol/starter-templates",
8+
"repository": {
9+
"type": "git",
10+
"url": "https://github.com/owlprotocol/starter-templates.git"
11+
},
12+
"copyright": "Copyright 2024 Owl Protocol",
13+
"license": "MIT",
14+
"author": {
15+
"name": "Leo Vigna",
16+
"email": "[email protected]",
17+
"url": "https://github.com/leovigna"
18+
},
19+
"files": [
20+
"dist/*",
21+
"lib/*",
22+
"src/*",
23+
"LICENSE",
24+
"README.md"
25+
],
26+
"main": "./lib/cjs/index.cjs",
27+
"module": "./lib/esm/index.mjs",
28+
"types": "./lib/types/index.d.mts",
29+
"exports": {
30+
".": {
31+
"types": "./lib/types/index.d.ts",
32+
"browser": "./lib/esm/index.browser.js",
33+
"import": "./lib/esm/index.js",
34+
"require": "./lib/cjs/index.js"
35+
},
36+
"./browser": {
37+
"types": "./lib/types/index.browser.d.ts",
38+
"browser": "./lib/esm/index.browser.js"
39+
}
40+
},
41+
"scripts": {
42+
"build": "pnpm run codegen && npm-run-all -p tsc esbuild",
43+
"build:watch": "npm-run-all -p tsc:watch esbuild:watch",
44+
"clean": "rimraf lib dist",
45+
"codegen": "tsx src/genEnvVars.ts",
46+
"depcheck": "depcheck",
47+
"esbuild": "node esbuild.config.mjs",
48+
"esbuild:watch": "ESBUILD_WATCH=true node esbuild.config.mjs",
49+
"lint": "eslint",
50+
"lint:fix": "eslint --fix",
51+
"tsc": "tsc",
52+
"tsc:watch": "tsc -w"
53+
},
54+
"dependencies": {
55+
"dotenv": "^16.4.5",
56+
"find-config": "^1.0.0"
57+
},
58+
"devDependencies": {
59+
"@owlprotocol/esbuild-config": "^3.0.0",
60+
"@owlprotocol/eslint-config": "^3.0.0",
61+
"@owlprotocol/prettier-config": "^3.0.0",
62+
"@owlprotocol/tsconfig": "^3.0.0",
63+
"@types/eslint": "^8.44.2",
64+
"@types/find-config": "^1.0.2",
65+
"@types/node": "^20.11.10",
66+
"eslint": "^8.55.0",
67+
"npm-run-all": "^4.1.5",
68+
"rimraf": "^3.0.2",
69+
"tsx": "^4.11.0",
70+
"typescript": "5.4.5",
71+
"vite": "^5.1.6",
72+
"depcheck": "^1.4.7"
73+
},
74+
"bugs": {
75+
"url": "https://github.com/owlprotocol/starter-templates/issues",
76+
"email": "[email protected]"
77+
},
78+
"funding": "https://owlprotocol.xyz",
79+
"engines": {
80+
"node": "^18.0.0"
81+
}
82+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import dotenv from "dotenv";
2+
import findConfig from "find-config";
3+
4+
export const NODE_ENV = process.env.NODE_ENV ?? "development";
5+
export const DOTENV_KEY = process.env.DOTENV_KEY;
6+
7+
export const isClient = () => typeof window !== "undefined";
8+
9+
export function dotenvConfig(nodeEnv = NODE_ENV, dotenvKey = DOTENV_KEY) {
10+
//Only works in Node Environment
11+
if (!isClient()) {
12+
if (dotenvKey) {
13+
console.debug("Loading .env.vault ");
14+
//Load remote envvars
15+
dotenv.config({ path: findConfig(".env.vault") ?? undefined, DOTENV_KEY: dotenvKey });
16+
} else if (nodeEnv === "development") {
17+
console.debug("Loading .env");
18+
dotenv.config({ path: findConfig(".env") ?? undefined });
19+
} else if (nodeEnv === "test") {
20+
console.debug("Loading .env");
21+
dotenv.config({ path: findConfig(".env") ?? undefined });
22+
} else if (nodeEnv === "ci") {
23+
console.debug("Loading .env.ci");
24+
dotenv.config({ path: findConfig(".env.ci") ?? undefined });
25+
} else if (nodeEnv === "staging") {
26+
dotenv.config({ path: findConfig(".env.staging") ?? undefined });
27+
console.debug("Loading .env.staging");
28+
} else if (nodeEnv === "production") {
29+
console.debug("Loading .env.production");
30+
dotenv.config({ path: findConfig(".env.production") ?? undefined });
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)