Skip to content

Commit 7a95ffe

Browse files
authored
Refactor envs validator: split schema and migrate to vite (#3140)
* migrate to vite * split validation schema
1 parent 34685ac commit 7a95ffe

31 files changed

+1392
-1843
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ COPY --from=builder /app/public ./public
165165
COPY --from=builder /app/package.json ./package.json
166166

167167
# Copy tools
168-
COPY --from=builder /app/deploy/tools/envs-validator/index.js ./envs-validator.js
168+
COPY --from=builder /app/deploy/tools/envs-validator/dist/index.js ./envs-validator/index.js
169169
COPY --from=builder /app/deploy/tools/feature-reporter/index.js ./feature-reporter.js
170170
COPY --from=builder /app/deploy/tools/multichain-config-generator/dist ./deploy/tools/multichain-config-generator/dist
171171
COPY --from=builder /app/deploy/tools/llms-txt-generator/dist ./deploy/tools/llms-txt-generator/dist

deploy/scripts/validate_envs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if [ -f .env ]; then
77
fi
88

99
# Check run-time ENVs values integrity
10-
node "$(dirname "$0")/envs-validator.js" "$input"
10+
node "$(dirname "$0")/envs-validator/index.js" "$input"
1111
if [ $? != 0 ]; then
1212
exit 1
1313
fi

deploy/tools/envs-validator/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/node_modules
22
/public
3+
/dist
34
.env
45
.env.registry
56
.env.secrets

deploy/tools/envs-validator/index.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
/* eslint-disable no-console */
2-
import fs from 'fs';
3-
import path from 'path';
2+
import fs from 'node:fs';
3+
import { dirname, resolve as resolvePath } from 'node:path';
44
import type { ValidationError } from 'yup';
55

6-
import { buildExternalAssetFilePath } from '../../../configs/app/utils';
6+
import { buildExternalAssetFilePath } from 'configs/app/utils';
77
import schema from './schema';
88
import schemaMultichain from './schema_multichain';
9+
import { fileURLToPath } from 'node:url';
10+
11+
const currentFilePath = fileURLToPath(import.meta.url);
12+
const distDir = dirname(currentFilePath);
913

1014
const silent = process.argv.includes('--silent');
1115

@@ -80,7 +84,7 @@ async function getExternalJsonContent(envName: string): Promise<string | void> {
8084
return new Promise((resolve, reject) => {
8185
const fileName = `./public${ buildExternalAssetFilePath(envName, 'https://foo.bar/baz.json') }`;
8286

83-
fs.readFile(path.resolve(__dirname, fileName), 'utf8', (err, data) => {
87+
fs.readFile(resolvePath(distDir, '..', fileName), 'utf8', (err, data) => {
8488
if (err) {
8589
console.log(`🚨 Unable to read file: ${ fileName }`);
8690
reject(err);
@@ -96,8 +100,8 @@ async function checkPlaceholdersCongruity(envsMap: Record<string, string>) {
96100
try {
97101
!silent && console.log(`🌀 Checking environment variables and their placeholders congruity...`);
98102

99-
const runTimeEnvs = await getEnvsPlaceholders(path.resolve(__dirname, '.env.registry'));
100-
const buildTimeEnvs = await getEnvsPlaceholders(path.resolve(__dirname, '.env'));
103+
const runTimeEnvs = await getEnvsPlaceholders(resolvePath(distDir, '..', '.env.registry'));
104+
const buildTimeEnvs = await getEnvsPlaceholders(resolvePath(distDir, '..', '.env'));
101105
const envs = Object.keys(envsMap).filter((env) => !buildTimeEnvs.includes(env));
102106

103107
const inconsistencies: Array<string> = [];
@@ -121,7 +125,7 @@ async function checkPlaceholdersCongruity(envsMap: Record<string, string>) {
121125

122126
!silent && console.log('👍 All good!\n');
123127
} catch (error) {
124-
console.log('🚨 Congruity check failed.\n');
128+
console.log('🚨 Congruity check failed.\n', error);
125129
throw error;
126130
}
127131
}
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
{
22
"name": "envs-validator",
3+
"type": "module",
34
"version": "1.0.0",
4-
"main": "index.js",
5+
"main": "dist/index.js",
56
"license": "MIT",
67
"scripts": {
7-
"build": "yarn webpack-cli -c ./webpack.config.js",
8-
"validate": "node ./index.js",
8+
"build": "vite build --logLevel error",
9+
"validate": "node ./dist/index.js",
910
"test": "./test.sh"
1011
},
11-
"dependencies": {
12-
"ts-loader": "^9.4.4",
13-
"webpack": "^5.88.2",
14-
"webpack-cli": "^5.1.4",
15-
"yup": "^1.2.0"
16-
},
1712
"devDependencies": {
13+
"yup": "^1.2.0",
1814
"dotenv-cli": "^7.2.1",
19-
"tsconfig-paths-webpack-plugin": "^4.1.0"
15+
"typescript": "5.4.2",
16+
"vite": "6.4.1"
2017
}
2118
}

0 commit comments

Comments
 (0)