feat: decouple l-s entrypoint
This commit is contained in:
parent
2a2c1fccc8
commit
f4d6b5e454
48 changed files with 411 additions and 232 deletions
24
tools/set-env-var.js
Normal file
24
tools/set-env-var.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
const fs = require('fs')
|
||||
const os = require('os')
|
||||
const path = require('path')
|
||||
|
||||
const setEnvVariable = (key, value) => {
|
||||
const ENV_VARIABLES = fs.readFileSync(path.resolve(__dirname, '../.env'), 'utf-8').split(os.EOL)
|
||||
const target = ENV_VARIABLES.indexOf(ENV_VARIABLES.find(line => line.match(new RegExp(`^${key}=`))))
|
||||
|
||||
if (target < 0) {
|
||||
// The variable doesn't exist, add it
|
||||
ENV_VARIABLES.push(`${key}=${value}`)
|
||||
} else {
|
||||
// .env already has that variable set, or at least has the definition of its key
|
||||
//
|
||||
// This is currently circumventing a possible bug on dotenv
|
||||
// where the variables on this script were showing up as undefined on the first run despite the key existing,
|
||||
// while on a second run they'd appear as empty string, as intended
|
||||
ENV_VARIABLES.splice(target, 1, `${key}=${value}`)
|
||||
}
|
||||
|
||||
fs.writeFileSync(path.resolve(__dirname, '../.env'), ENV_VARIABLES.join(os.EOL))
|
||||
}
|
||||
|
||||
module.exports = setEnvVariable
|
||||
Loading…
Add table
Add a link
Reference in a new issue