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
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);