mirror of https://github.com/bitwarden/cli.git
Browse Source
* Add build-time feature flag capabilities * Toggle `bw serve` command with `serve` flag * Run linter and prettierpull/457/head
9 changed files with 117 additions and 18 deletions
@ -1,3 +1,5 @@
@@ -1,3 +1,5 @@
|
||||
node_modules |
||||
build |
||||
dist |
||||
|
||||
config/local.json |
||||
|
||||
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
function load(envName) { |
||||
return { |
||||
...loadConfig(envName), |
||||
...loadConfig("local"), |
||||
}; |
||||
} |
||||
|
||||
function log(configObj) { |
||||
const repeatNum = 50; |
||||
console.log(`${"=".repeat(repeatNum)}\nenvConfig`); |
||||
console.log(JSON.stringify(configObj, null, 2)); |
||||
console.log(`${"=".repeat(repeatNum)}`); |
||||
} |
||||
|
||||
function loadConfig(configName) { |
||||
try { |
||||
return require(`./${configName}.json`); |
||||
} catch (e) { |
||||
if (e instanceof Error && e.code === "MODULE_NOT_FOUND") { |
||||
return {}; |
||||
} else { |
||||
throw e; |
||||
} |
||||
} |
||||
} |
||||
|
||||
module.exports = { |
||||
load, |
||||
log, |
||||
}; |
||||
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
{ |
||||
"flags": { |
||||
"serve": true |
||||
} |
||||
} |
||||
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
{ |
||||
"flags": { |
||||
"serve": false |
||||
} |
||||
} |
||||
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
import { FlagName } from "../src/flags"; |
||||
import { CliUtils } from "../src/utils"; |
||||
describe("flagEnabled", () => { |
||||
it("is true if flag is null", () => { |
||||
process.env.FLAGS = JSON.stringify({ test: null }); |
||||
|
||||
expect(CliUtils.flagEnabled("test" as FlagName)).toBe(true); |
||||
}); |
||||
|
||||
it("is true if flag is undefined", () => { |
||||
process.env.FLAGS = JSON.stringify({}); |
||||
|
||||
expect(CliUtils.flagEnabled("test" as FlagName)).toBe(true); |
||||
}); |
||||
|
||||
it("is true if flag is true", () => { |
||||
process.env.FLAGS = JSON.stringify({ test: true }); |
||||
|
||||
expect(CliUtils.flagEnabled("test" as FlagName)).toBe(true); |
||||
}); |
||||
|
||||
it("is false if flag is false", () => { |
||||
process.env.FLAGS = JSON.stringify({ test: false }); |
||||
|
||||
expect(CliUtils.flagEnabled("test" as FlagName)).toBe(false); |
||||
}); |
||||
}); |
||||
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
export type Flags = { |
||||
serve?: boolean; |
||||
}; |
||||
|
||||
export type FlagName = keyof Flags; |
||||
Loading…
Reference in new issue