move files in install to js

This commit is contained in:
Simon Larsen 2023-11-03 15:57:05 +00:00
parent 60d0f188ad
commit 4f93dd0f04
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
4 changed files with 19 additions and 19 deletions

View File

@ -2,12 +2,12 @@
import fs from 'fs';
const init: Function = (): void => {
const tempate: string = fs.readFileSync('./config.example.env', 'utf8');
const env: string = fs.readFileSync('./config.env', 'utf8');
const init = () => {
const tempate = fs.readFileSync('./config.example.env', 'utf8');
const env = fs.readFileSync('./config.env', 'utf8');
const linesInTemplate: Array<string> = tempate.split('\n');
const linesInEnv: Array<string> = env.split('\n');
const linesInTemplate = tempate.split('\n');
const linesInEnv= env.split('\n');
for (const line of linesInTemplate) {
// this is a comment, ignore.
@ -23,7 +23,7 @@ const init: Function = (): void => {
// if the line is present in template but is not present in env file then add it to the env file. We assume, values in template file are default values.
if (line.split('=').length > 0) {
if (
linesInEnv.filter((envLine: string) => {
linesInEnv.filter((envLine) => {
return (
envLine.split('=').length > 0 &&
envLine.split('=')[0] === line.split('=')[0]

View File

@ -2,14 +2,14 @@
import fs from 'fs';
const init: Function = (): void => {
let env: string = '';
const init = () => {
let env = '';
try {
env = fs.readFileSync('./config.env', 'utf8');
} catch (err) {
// do nothing.
}
const envValToReplace: string | undefined = process.argv[2];
const envValToReplace = process.argv[2];
if (!envValToReplace) {
// eslint-disable-next-line
@ -17,7 +17,7 @@ const init: Function = (): void => {
return;
}
const envValToReplaceWith: string | undefined = process.argv[3];
const envValToReplaceWith= process.argv[3];
if (!envValToReplaceWith) {
// eslint-disable-next-line
@ -25,9 +25,9 @@ const init: Function = (): void => {
return;
}
const linesInEnv: Array<string> = env.split('\n');
const linesToRender: Array<string> = [];
let found: boolean = false;
const linesInEnv = env.split('\n');
const linesToRender = [];
let found = false;
for (let line of linesInEnv) {
// this is a comment, ignore.
@ -35,7 +35,7 @@ const init: Function = (): void => {
linesToRender.push(line);
} else {
found = true;
const items: Array<string> = line.split('=');
const items = line.split('=');
items[1] = envValToReplaceWith;
line = items.join('=');
linesToRender.push(line);

View File

@ -170,7 +170,7 @@ touch config.env
source ~/.bashrc
#Run a scirpt to merge config.env.tpl to config.env
ts-node-esm ./Scripts/Install/MergeEnvTemplate.ts
node ./Scripts/Install/MergeEnvTemplate.js
# Load env values from config.env

View File

@ -34,10 +34,10 @@
"prettier": "^2.6.0"
},
"scripts": {
"config-to-dev": "ts-node-esm ./Scripts/Install/ReplaceValueInConfig.ts ENVIRONMENT development",
"config-to-ci": "ts-node-esm ./Scripts/Install/ReplaceValueInConfig.ts ENVIRONMENT ci",
"config-to-test": "ts-node-esm ./Scripts/Install/ReplaceValueInConfig.ts ENVIRONMENT test && ts-node-esm ./Scripts/Install/ReplaceValueInConfig.ts APP_TAG test",
"config-to-production": "ts-node-esm ./Scripts/Install/ReplaceValueInConfig.ts ENVIRONMENT production",
"config-to-dev": "node ./Scripts/Install/ReplaceValueInConfig.js ENVIRONMENT development",
"config-to-ci": "node ./Scripts/Install/ReplaceValueInConfig.js ENVIRONMENT ci",
"config-to-test": "node ./Scripts/Install/ReplaceValueInConfig.js ENVIRONMENT test && node ./Scripts/Install/ReplaceValueInConfig.js APP_TAG test",
"config-to-production": "node ./Scripts/Install/ReplaceValueInConfig.js ENVIRONMENT production",
"prerun": "bash configure.sh",
"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js",
"uninstall": "bash uninstall.sh",