Add cofiguration of environment variables using .env.
This commit is contained in:
parent
6e4c632283
commit
ec2d5321ba
9
.env.example
Normal file
9
.env.example
Normal file
@ -0,0 +1,9 @@
|
||||
CHAIN_ID=
|
||||
LOGGING_URL=
|
||||
META_URL=
|
||||
KEYS_URL=
|
||||
CACHE_URL=
|
||||
WEB3_PROVIDER=
|
||||
USSD_URL=
|
||||
REGISTRY_ADDRESS=
|
||||
TRUSTED_ADDRESS=
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -44,3 +44,6 @@ testem.log
|
||||
# System Files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Configuration Files
|
||||
.env
|
||||
|
629
package-lock.json
generated
629
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
18
package.json
18
package.json
@ -3,11 +3,13 @@
|
||||
"version": "0.0.0",
|
||||
"scripts": {
|
||||
"ng": "ng",
|
||||
"config": "node set-env.js",
|
||||
"start": "ng serve",
|
||||
"start-dev": "ng serve -o",
|
||||
"build": "ng build",
|
||||
"test": "ng test",
|
||||
"config": "ts-node set-env.ts",
|
||||
"start:dev": "npm run config --environment=dev && ng serve",
|
||||
"start:prod": "npm run config --environment=prod && ng serve",
|
||||
"build:dev": "npm run config --environment=dev && ng build",
|
||||
"build:prod": "npm run config --environment=prod && ng build --prod",
|
||||
"test:dev": "npm run config --environment=dev && ng test",
|
||||
"test:prod": "npm run config --environment=prod && ng test",
|
||||
"lint": "ng lint",
|
||||
"e2e": "ng e2e",
|
||||
"postinstall": "node patch-webpack.js"
|
||||
@ -57,8 +59,9 @@
|
||||
"@types/jasmine": "~3.5.0",
|
||||
"@types/jasminewd2": "~2.0.3",
|
||||
"@types/jquery": "^3.5.4",
|
||||
"@types/node": "^12.19.14",
|
||||
"@types/node": "^12.20.6",
|
||||
"codelyzer": "^6.0.0",
|
||||
"dotenv": "^8.2.0",
|
||||
"jasmine-core": "~3.6.0",
|
||||
"jasmine-spec-reporter": "~5.0.0",
|
||||
"karma": "~5.0.0",
|
||||
@ -71,6 +74,7 @@
|
||||
"secp256k1": "^4.0.2",
|
||||
"ts-node": "~8.3.0",
|
||||
"tslint": "~6.1.0",
|
||||
"typescript": "~4.0.2"
|
||||
"typescript": "~4.0.2",
|
||||
"yargs": "^13.3.2"
|
||||
}
|
||||
}
|
||||
|
52
set-env.js
52
set-env.js
@ -1,52 +0,0 @@
|
||||
const fs = require('fs');
|
||||
|
||||
const devEnvironment = `
|
||||
import {NgxLoggerLevel} from 'ngx-logger';
|
||||
|
||||
export const environment = {
|
||||
production: false,
|
||||
bloxbergChainId: ${process.env.CHAIN_ID || 8996},
|
||||
level: NgxLoggerLevel.TRACE,
|
||||
serverLogLevel: NgxLoggerLevel.OFF,
|
||||
loggingUrl: ${process.env.LOGGING_URL || 'http://localhost:8000'},
|
||||
cicMetaUrl: ${process.env.META_URL || 'https://meta.dev.grassrootseconomics.net'},
|
||||
publicKeysUrl: ${process.env.KEYS_URL || 'http://localhost:8000/keys.asc'},
|
||||
cicCacheUrl: ${process.env.META_URL || 'https://cache.dev.grassrootseconomics.net'},
|
||||
web3Provider: ${process.env.WEB3_PROVIDER || 'ws://localhost:63546'},
|
||||
cicUssdUrl: ${process.env.USSD_URL || 'https://ussd.dev.grassrootseconomics.net'},
|
||||
registryAddress: ${process.env.REGISTRY_ADDRESS || '0x6Ca3cB14aA6F761712E1C18646AfBA4d5Ae249E8'},
|
||||
trustedDeclaratorAddress: ${process.env.TRUSTED_ADDRESS || '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C'}
|
||||
};
|
||||
`;
|
||||
|
||||
const prodEnvironment = `
|
||||
import {NgxLoggerLevel} from 'ngx-logger';
|
||||
|
||||
export const environment = {
|
||||
production: false,
|
||||
bloxbergChainId: ${process.env.CHAIN_ID || 8996},
|
||||
level: NgxLoggerLevel.TRACE,
|
||||
serverLogLevel: NgxLoggerLevel.OFF,
|
||||
loggingUrl: ${process.env.LOGGING_URL || 'http://localhost:8000'},
|
||||
cicMetaUrl: ${process.env.META_URL || 'https://meta.grassrootseconomics.net'},
|
||||
publicKeysUrl: ${process.env.KEYS_URL || 'http://localhost:8000/keys.asc'},
|
||||
cicCacheUrl: ${process.env.META_URL || 'https://cache.grassrootseconomics.net'},
|
||||
web3Provider: ${process.env.WEB3_PROVIDER || 'ws://localhost:63546'},
|
||||
cicUssdUrl: ${process.env.USSD_URL || 'https://ussd.grassrootseconomics.net'},
|
||||
registryAddress: ${process.env.REGISTRY_ADDRESS || '0x6Ca3cB14aA6F761712E1C18646AfBA4d5Ae249E8'},
|
||||
trustedDeclaratorAddress: ${process.env.TRUSTED_ADDRESS || '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C'}
|
||||
};
|
||||
`;
|
||||
|
||||
function setConfigs(configs, envFile) {
|
||||
fs.writeFile(`./src/environments/` + envFile, configs, function (err) {
|
||||
if (err) {
|
||||
throw console.error(err);
|
||||
} else {
|
||||
console.log(`Angular ${envFile} file generated`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setConfigs(devEnvironment, 'environment.ts');
|
||||
setConfigs(prodEnvironment, 'environment.prod.ts');
|
52
set-env.ts
Normal file
52
set-env.ts
Normal file
@ -0,0 +1,52 @@
|
||||
const { writeFile } = require('fs');
|
||||
const { argv } = require('yargs');
|
||||
const colors = require('colors');
|
||||
require('dotenv').config();
|
||||
|
||||
const environment = argv.environment;
|
||||
const isProduction = environment === 'prod';
|
||||
|
||||
const targetPath = isProduction ? `./src/environments/environment.prod.ts` : `./src/environments/environment.ts`;
|
||||
|
||||
const environmentVars = `import {NgxLoggerLevel} from 'ngx-logger';
|
||||
|
||||
export const environment = {
|
||||
production: ${isProduction},
|
||||
bloxbergChainId: ${process.env.CHAIN_ID || 8996},
|
||||
level: ${process.env.LOG_LEVEL || 'NgxLoggerLevel.OFF'},
|
||||
serverLogLevel: ${process.env.SERVER_LEVEL || 'NgxLoggerLevel.OFF'},
|
||||
loggingUrl: '${process.env.LOGGING_URL || 'http://localhost:8000'}',
|
||||
cicMetaUrl: '${process.env.META_URL || 'https://meta.dev.grassrootseconomics.net'}',
|
||||
publicKeysUrl: '${process.env.KEYS_URL || 'http://localhost:8000/keys.asc'}',
|
||||
cicCacheUrl: '${process.env.CACHE_URL || 'https://cache.dev.grassrootseconomics.net'}',
|
||||
web3Provider: '${process.env.WEB3_PROVIDER || 'ws://localhost:63546'}',
|
||||
cicUssdUrl: '${process.env.USSD_URL || 'https://ussd.dev.grassrootseconomics.net'}',
|
||||
registryAddress: '${process.env.REGISTRY_ADDRESS || '0x6Ca3cB14aA6F761712E1C18646AfBA4d5Ae249E8'}',
|
||||
trustedDeclaratorAddress: '${process.env.TRUSTED_ADDRESS || '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C'}'
|
||||
};
|
||||
`;
|
||||
|
||||
function setConfigs(configs): void {
|
||||
writeFile(targetPath, configs, err => {
|
||||
if (err) {
|
||||
throw console.error(err);
|
||||
} else {
|
||||
console.log(colors.cyan(`Wrote variables to '${targetPath}`));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!process.env.REGISTRY_ADDRESS) {
|
||||
console.error(colors.redBright('All the required environment variables were not provided!'));
|
||||
process.exit(-1);
|
||||
}
|
||||
|
||||
console.log(colors.yellow(process.env.REGISTRY_ADDRESS));
|
||||
if (isProduction) {
|
||||
console.log(colors.magenta('Running in production environment!'));
|
||||
setConfigs(environmentVars);
|
||||
} else {
|
||||
console.log(colors.green('Running in development environment!'));
|
||||
setConfigs(environmentVars);
|
||||
}
|
||||
|
@ -1,16 +1,3 @@
|
||||
import {NgxLoggerLevel} from 'ngx-logger';
|
||||
|
||||
export const environment = {
|
||||
production: true,
|
||||
bloxbergChainId: 8996,
|
||||
level: NgxLoggerLevel.OFF,
|
||||
serverLogLevel: NgxLoggerLevel.ERROR,
|
||||
loggingUrl: 'http://localhost:8000',
|
||||
cicMetaUrl: 'https://meta.grassrootseconomics.net',
|
||||
publicKeysUrl: 'http://localhost:8000/keys.asc',
|
||||
cicCacheUrl: 'https://cache.grassrootseconomics.net',
|
||||
web3Provider: 'ws://localhost:63546',
|
||||
cicUssdUrl: 'https://ussd.grassrootseconomics.net',
|
||||
registryAddress: '0x6Ca3cB14aA6F761712E1C18646AfBA4d5Ae249E8',
|
||||
trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C'
|
||||
production: true
|
||||
};
|
||||
|
@ -1,29 +1,3 @@
|
||||
// This file can be replaced during build by using the `fileReplacements` array.
|
||||
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
|
||||
// The list of file replacements can be found in `angular.json`.
|
||||
|
||||
import {NgxLoggerLevel} from 'ngx-logger';
|
||||
|
||||
export const environment = {
|
||||
production: false,
|
||||
bloxbergChainId: 8996,
|
||||
level: NgxLoggerLevel.TRACE,
|
||||
serverLogLevel: NgxLoggerLevel.OFF,
|
||||
loggingUrl: 'http://localhost:8000',
|
||||
cicMetaUrl: 'https://meta.dev.grassrootseconomics.net',
|
||||
publicKeysUrl: 'http://localhost:8000/keys.asc',
|
||||
cicCacheUrl: 'https://cache.dev.grassrootseconomics.net',
|
||||
web3Provider: 'ws://localhost:63546',
|
||||
cicUssdUrl: 'https://ussd.dev.grassrootseconomics.net',
|
||||
registryAddress: '0x6Ca3cB14aA6F761712E1C18646AfBA4d5Ae249E8',
|
||||
trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C'
|
||||
production: false
|
||||
};
|
||||
|
||||
/*
|
||||
* For easier debugging in development mode, you can import the following file
|
||||
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
|
||||
*
|
||||
* This import should be commented out in production mode because it will have a negative impact
|
||||
* on performance if an error is thrown.
|
||||
*/
|
||||
// import 'zone.js/dist/zone-error'; // Included with Angular CLI.
|
||||
|
Loading…
Reference in New Issue
Block a user