@dotenvx/dotenvx 2.38.2 → 3.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +186 -3315
- package/bin/dotenvx.cjs +34 -0
- package/config.cjs +1 -0
- package/config.d.ts +1 -0
- package/config.mjs +2 -0
- package/index.cjs +139 -0
- package/index.d.ts +66 -0
- package/index.mjs +3 -0
- package/lib/cli.cjs +43 -0
- package/lib/native-package.cjs +21 -0
- package/lib/platforms.cjs +18 -0
- package/{src/lib/helpers/redactOutput.js → lib/redactOutput.cjs} +2 -48
- package/lib/redaction.cjs +64 -0
- package/lib/validateOptions.cjs +57 -0
- package/native.cjs +23 -0
- package/package.json +57 -65
- package/CHANGELOG.md +0 -2733
- package/src/cli/actions/armor/down.js +0 -38
- package/src/cli/actions/armor/invite.js +0 -21
- package/src/cli/actions/armor/move.js +0 -43
- package/src/cli/actions/armor/open.js +0 -28
- package/src/cli/actions/armor/pull.js +0 -38
- package/src/cli/actions/armor/push.js +0 -38
- package/src/cli/actions/armor/status.js +0 -7
- package/src/cli/actions/armor/up.js +0 -38
- package/src/cli/actions/check.js +0 -78
- package/src/cli/actions/curl.js +0 -71
- package/src/cli/actions/decrypt.js +0 -119
- package/src/cli/actions/del.js +0 -54
- package/src/cli/actions/doctor.js +0 -22
- package/src/cli/actions/encrypt.js +0 -104
- package/src/cli/actions/ext/genexample.js +0 -36
- package/src/cli/actions/ext/gitignore.js +0 -106
- package/src/cli/actions/ext/prebuild.js +0 -7
- package/src/cli/actions/ext/precommit.js +0 -38
- package/src/cli/actions/ext/scan.js +0 -33
- package/src/cli/actions/feedback.js +0 -42
- package/src/cli/actions/get.js +0 -128
- package/src/cli/actions/init.js +0 -67
- package/src/cli/actions/keychain/down.js +0 -30
- package/src/cli/actions/keychain/pull.js +0 -30
- package/src/cli/actions/keychain/push.js +0 -30
- package/src/cli/actions/keychain/up.js +0 -30
- package/src/cli/actions/keypair.js +0 -84
- package/src/cli/actions/login.js +0 -64
- package/src/cli/actions/logout.js +0 -37
- package/src/cli/actions/ls.js +0 -76
- package/src/cli/actions/policy.js +0 -14
- package/src/cli/actions/primitivesCheck.js +0 -32
- package/src/cli/actions/primitivesProfile.js +0 -15
- package/src/cli/actions/primitivesRedact.js +0 -19
- package/src/cli/actions/protect.js +0 -75
- package/src/cli/actions/protectDocker.js +0 -30
- package/src/cli/actions/protectProcess.js +0 -126
- package/src/cli/actions/protectStdin.js +0 -80
- package/src/cli/actions/run.js +0 -203
- package/src/cli/actions/set.js +0 -103
- package/src/cli/actions/settings/device.js +0 -23
- package/src/cli/actions/settings/hostname.js +0 -20
- package/src/cli/actions/settings/off.js +0 -14
- package/src/cli/actions/settings/on.js +0 -14
- package/src/cli/actions/settings/path.js +0 -20
- package/src/cli/actions/settings/token.js +0 -23
- package/src/cli/actions/settings/username.js +0 -20
- package/src/cli/actions/update.js +0 -15
- package/src/cli/commandAction.js +0 -16
- package/src/cli/commands/armor.js +0 -129
- package/src/cli/commands/custody.js +0 -45
- package/src/cli/commands/ext.js +0 -88
- package/src/cli/commands/fileOptions.js +0 -22
- package/src/cli/commands/native.js +0 -54
- package/src/cli/commands/primitives.js +0 -73
- package/src/cli/commands/settings.js +0 -63
- package/src/cli/dotenvx.js +0 -443
- package/src/cli/help.js +0 -179
- package/src/db/device.js +0 -67
- package/src/db/session.js +0 -330
- package/src/lib/api/getAccount.js +0 -32
- package/src/lib/api/getConnectionResources.js +0 -21
- package/src/lib/api/getTeamConnections.js +0 -27
- package/src/lib/api/getTeamServices.js +0 -23
- package/src/lib/api/getTeams.js +0 -28
- package/src/lib/api/postArmorDown.js +0 -48
- package/src/lib/api/postArmorMove.js +0 -48
- package/src/lib/api/postArmorPull.js +0 -48
- package/src/lib/api/postArmorPush.js +0 -48
- package/src/lib/api/postArmorUp.js +0 -53
- package/src/lib/api/postConnectionKeypair.js +0 -23
- package/src/lib/api/postFeedback.js +0 -31
- package/src/lib/api/postLogout.js +0 -34
- package/src/lib/api/postOauthDeviceCode.js +0 -38
- package/src/lib/api/postOauthToken.js +0 -35
- package/src/lib/api/postTeamInvitation.js +0 -28
- package/src/lib/api/teamConnectionSetup.js +0 -31
- package/src/lib/config.d.ts +0 -1
- package/src/lib/config.js +0 -1
- package/src/lib/conventions/environment.js +0 -27
- package/src/lib/conventions/filepaths.js +0 -9
- package/src/lib/conventions/keynames.js +0 -38
- package/src/lib/custodians/index.js +0 -75
- package/src/lib/custodians/local/bitwarden.js +0 -165
- package/src/lib/custodians/local/file.js +0 -18
- package/src/lib/custodians/local/native/backend.js +0 -56
- package/src/lib/custodians/local/native/index.js +0 -28
- package/src/lib/custodians/local/native/store.js +0 -24
- package/src/lib/custodians/local/onepassword.js +0 -149
- package/src/lib/custodians/managed/armor/index.js +0 -14
- package/src/lib/custodians/managed/armor/store.js +0 -48
- package/src/lib/custodians/resolveLocalKey.js +0 -67
- package/src/lib/decryptors/armor/index.js +0 -23
- package/src/lib/decryptors/decryptor-worker.js +0 -6
- package/src/lib/decryptors/index.js +0 -69
- package/src/lib/envfile/discovery/discoverEnvFiles.js +0 -29
- package/src/lib/envfile/discovery/extractEnvKeys.js +0 -173
- package/src/lib/envfile/discovery/scanSource.js +0 -79
- package/src/lib/envfile/parsing/formatEnvfileSyntaxError.js +0 -24
- package/src/lib/envfile/parsing/readEnvfile.js +0 -43
- package/src/lib/envfile/parsing/resolveEnvfilePath.js +0 -5
- package/src/lib/envfile/rendering/normalizeEnvfile.js +0 -53
- package/src/lib/envfile/rendering/previewEnvfile.js +0 -43
- package/src/lib/envfile/rendering/renderEnvfile.js +0 -30
- package/src/lib/envfile/validation/diagnosticLocation.js +0 -29
- package/src/lib/envfile/validation/protectEnvfile.js +0 -40
- package/src/lib/envfile/validation/validateEnvfile.js +0 -14
- package/src/lib/events/backends/armor.js +0 -31
- package/src/lib/events/background.js +0 -59
- package/src/lib/events/catalog.js +0 -14
- package/src/lib/events/cli.js +0 -40
- package/src/lib/events/delivery.js +0 -89
- package/src/lib/events/index.js +0 -73
- package/src/lib/events/metadata.js +0 -25
- package/src/lib/events/sdk.js +0 -44
- package/src/lib/events/worker.js +0 -29
- package/src/lib/events/workerEnvironment.js +0 -14
- package/src/lib/helpers/armoredKeyDisplay.js +0 -10
- package/src/lib/helpers/arrayToTree.js +0 -27
- package/src/lib/helpers/buildApiError.js +0 -19
- package/src/lib/helpers/buildCommandEnvs.js +0 -40
- package/src/lib/helpers/buildConfigEnvs.js +0 -13
- package/src/lib/helpers/buildEnvs.js +0 -24
- package/src/lib/helpers/buildOauthError.js +0 -14
- package/src/lib/helpers/canonicalEnvFilename.js +0 -13
- package/src/lib/helpers/catchAndLog.js +0 -16
- package/src/lib/helpers/checklist.js +0 -50
- package/src/lib/helpers/chomp.js +0 -5
- package/src/lib/helpers/colorDepth.js +0 -23
- package/src/lib/helpers/conventions.js +0 -28
- package/src/lib/helpers/createElapsedStatus.js +0 -17
- package/src/lib/helpers/createProtectSpinner.js +0 -13
- package/src/lib/helpers/createSpinner.js +0 -40
- package/src/lib/helpers/cryptography/decryptKeyValue.js +0 -50
- package/src/lib/helpers/cryptography/index.js +0 -7
- package/src/lib/helpers/cryptography/isDotenvPublicKey.js +0 -7
- package/src/lib/helpers/cryptography/isPlainKey.js +0 -7
- package/src/lib/helpers/cryptography/mutateKeysSrc.js +0 -22
- package/src/lib/helpers/cryptography/mutateSrc.js +0 -24
- package/src/lib/helpers/custodySelect.js +0 -25
- package/src/lib/helpers/decryptDeviceValue.js +0 -7
- package/src/lib/helpers/detectEncoding.js +0 -22
- package/src/lib/helpers/detectEncodingSync.js +0 -22
- package/src/lib/helpers/dotenvOptionPaths.js +0 -25
- package/src/lib/helpers/dotenvPrivateKeyNames.js +0 -7
- package/src/lib/helpers/enclavedHint.js +0 -11
- package/src/lib/helpers/encryptDeviceValue.js +0 -7
- package/src/lib/helpers/envResolution/determine.js +0 -49
- package/src/lib/helpers/envResolution/index.js +0 -8
- package/src/lib/helpers/errors.js +0 -374
- package/src/lib/helpers/escape.js +0 -6
- package/src/lib/helpers/execute.js +0 -12
- package/src/lib/helpers/executeCommand.js +0 -208
- package/src/lib/helpers/executeDynamic.js +0 -86
- package/src/lib/helpers/executeExtension.js +0 -39
- package/src/lib/helpers/filterKeys.js +0 -15
- package/src/lib/helpers/findEnvFiles.js +0 -25
- package/src/lib/helpers/formatCode.js +0 -11
- package/src/lib/helpers/fsx.js +0 -110
- package/src/lib/helpers/guessPrivateKeyFilename.js +0 -15
- package/src/lib/helpers/hasPlaintextSecrets.js +0 -7
- package/src/lib/helpers/http.js +0 -14
- package/src/lib/helpers/installPrecommitHook.js +0 -82
- package/src/lib/helpers/installProtectFilter.js +0 -57
- package/src/lib/helpers/installProtectIgnore.js +0 -27
- package/src/lib/helpers/isPublicKey.js +0 -3
- package/src/lib/helpers/isTeamRequiredError.js +0 -10
- package/src/lib/helpers/jsonToEnv.js +0 -7
- package/src/lib/helpers/keypairMetadata.js +0 -90
- package/src/lib/helpers/kits/sample.js +0 -5
- package/src/lib/helpers/linuxSecretService.js +0 -52
- package/src/lib/helpers/listenForOpenKey.js +0 -46
- package/src/lib/helpers/logProtectedFiles.js +0 -9
- package/src/lib/helpers/logSetSummary.js +0 -21
- package/src/lib/helpers/macosKeychain.js +0 -52
- package/src/lib/helpers/mask.js +0 -22
- package/src/lib/helpers/maskEnvSrc.js +0 -15
- package/src/lib/helpers/maskProcessedEnvs.js +0 -29
- package/src/lib/helpers/matchesStoredKey.js +0 -5
- package/src/lib/helpers/nativeStoreError.js +0 -10
- package/src/lib/helpers/normalizeDotenvConfigConvention.js +0 -13
- package/src/lib/helpers/normalizeDotenvConfigIgnore.js +0 -18
- package/src/lib/helpers/normalizeDotenvConfigPath.js +0 -14
- package/src/lib/helpers/normalizeDotenvConfigQuiet.js +0 -13
- package/src/lib/helpers/normalizeToken.js +0 -5
- package/src/lib/helpers/openUrl.js +0 -7
- package/src/lib/helpers/packageJson.js +0 -3
- package/src/lib/helpers/parseWithDecryptor.js +0 -115
- package/src/lib/helpers/plaintextKeys.js +0 -9
- package/src/lib/helpers/precommitEnvPatterns.js +0 -1
- package/src/lib/helpers/prependPublicKey.js +0 -17
- package/src/lib/helpers/preserveShebang.js +0 -16
- package/src/lib/helpers/prompts.js +0 -169
- package/src/lib/helpers/protectSettings.js +0 -64
- package/src/lib/helpers/ptyCommand.js +0 -27
- package/src/lib/helpers/readEnvKey.js +0 -32
- package/src/lib/helpers/redact.js +0 -9
- package/src/lib/helpers/redactProcessOutput.js +0 -58
- package/src/lib/helpers/redactedValues.js +0 -29
- package/src/lib/helpers/removeDynamicHelpSection.js +0 -21
- package/src/lib/helpers/removeEnvKey.js +0 -51
- package/src/lib/helpers/removeLegacyProtectFilter.js +0 -43
- package/src/lib/helpers/removeOptionsHelpParts.js +0 -59
- package/src/lib/helpers/resolveBitwardenPassword.js +0 -165
- package/src/lib/helpers/resolveDirectoryFilepath.js +0 -16
- package/src/lib/helpers/resolveEnvKeysFile.js +0 -11
- package/src/lib/helpers/resolveHome.js +0 -12
- package/src/lib/helpers/resolveOnePassword.js +0 -82
- package/src/lib/helpers/sanitizeCommandForMetadata.js +0 -64
- package/src/lib/helpers/selectConnection.js +0 -51
- package/src/lib/helpers/selectConnectionResource.js +0 -41
- package/src/lib/helpers/selectEnvfileEnvs.js +0 -29
- package/src/lib/helpers/selectKeyStorage.js +0 -140
- package/src/lib/helpers/statusReporter.js +0 -8
- package/src/lib/helpers/storeKeyStorage.js +0 -39
- package/src/lib/helpers/teamChoicesFromMeta.js +0 -8
- package/src/lib/helpers/truncate.js +0 -10
- package/src/lib/helpers/uninstallPrecommitHook.js +0 -67
- package/src/lib/helpers/upsertEnvKey.js +0 -62
- package/src/lib/helpers/windowsCredentialManager.js +0 -166
- package/src/lib/main.d.ts +0 -509
- package/src/lib/main.js +0 -468
- package/src/lib/providers/index.js +0 -86
- package/src/lib/providers/native/index.js +0 -2
- package/src/lib/resolvers/envs.js +0 -416
- package/src/lib/resolvers/get.js +0 -87
- package/src/lib/resolvers/keypair.js +0 -135
- package/src/lib/resolvers/ls.js +0 -69
- package/src/lib/services/armorDown.js +0 -73
- package/src/lib/services/armorInvite.js +0 -36
- package/src/lib/services/armorMove.js +0 -55
- package/src/lib/services/armorOpen.js +0 -26
- package/src/lib/services/armorPull.js +0 -73
- package/src/lib/services/armorPush.js +0 -66
- package/src/lib/services/armorUp.js +0 -71
- package/src/lib/services/custodyTransfer.js +0 -50
- package/src/lib/services/doctor.js +0 -93
- package/src/lib/services/genexample.js +0 -112
- package/src/lib/services/init.js +0 -83
- package/src/lib/services/keychainDown.js +0 -60
- package/src/lib/services/keychainPull.js +0 -46
- package/src/lib/services/keychainPush.js +0 -51
- package/src/lib/services/keychainUp.js +0 -72
- package/src/lib/services/login.js +0 -51
- package/src/lib/services/logout.js +0 -26
- package/src/lib/services/prebuild.js +0 -91
- package/src/lib/services/precommit.js +0 -144
- package/src/lib/services/validate.js +0 -57
- package/src/lib/transforms/decrypt.js +0 -98
- package/src/lib/transforms/del.js +0 -58
- package/src/lib/transforms/encrypt.js +0 -164
- package/src/lib/transforms/set.js +0 -144
- package/src/shared/colors.js +0 -67
- package/src/shared/logger.js +0 -148
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
const prompts = require('../helpers/prompts')
|
|
2
|
-
const PostArmorDown = require('../api/postArmorDown')
|
|
3
|
-
const keynames = require('../conventions/keynames')
|
|
4
|
-
const upsertEnvKey = require('../helpers/upsertEnvKey')
|
|
5
|
-
const readEnvKey = require('../helpers/readEnvKey')
|
|
6
|
-
const teamChoicesFromMeta = require('../helpers/teamChoicesFromMeta')
|
|
7
|
-
const isTeamRequiredError = require('../helpers/isTeamRequiredError')
|
|
8
|
-
|
|
9
|
-
class ArmorDown {
|
|
10
|
-
constructor (hostname, token, devicePublicKey, envFile = '.env', team = undefined) {
|
|
11
|
-
this.hostname = hostname
|
|
12
|
-
this.token = token
|
|
13
|
-
this.devicePublicKey = devicePublicKey
|
|
14
|
-
this.envFile = envFile
|
|
15
|
-
this.team = team
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async run () {
|
|
19
|
-
const hostname = this.hostname
|
|
20
|
-
const token = this.token
|
|
21
|
-
const devicePublicKey = this.devicePublicKey
|
|
22
|
-
const envFile = this.envFile
|
|
23
|
-
const team = this.team
|
|
24
|
-
|
|
25
|
-
const {
|
|
26
|
-
publicKeyName,
|
|
27
|
-
privateKeyName
|
|
28
|
-
} = keynames(envFile)
|
|
29
|
-
|
|
30
|
-
const publicKey = readEnvKey(publicKeyName, envFile, { strict: true, ignore: ['MISSING_PRIVATE_KEY'] })
|
|
31
|
-
let json
|
|
32
|
-
|
|
33
|
-
if (team) {
|
|
34
|
-
json = await new PostArmorDown(hostname, token, devicePublicKey, publicKey, team).run()
|
|
35
|
-
} else {
|
|
36
|
-
try {
|
|
37
|
-
json = await new PostArmorDown(hostname, token, devicePublicKey, publicKey, undefined).run()
|
|
38
|
-
} catch (error) {
|
|
39
|
-
if (!isTeamRequiredError(error)) {
|
|
40
|
-
throw error
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const choices = teamChoicesFromMeta(error.meta)
|
|
44
|
-
|
|
45
|
-
let team = choices[0].value
|
|
46
|
-
if (choices.length > 1) {
|
|
47
|
-
team = await prompts.select({
|
|
48
|
-
message: 'Select team',
|
|
49
|
-
prefix: '⛨',
|
|
50
|
-
choices
|
|
51
|
-
}, {
|
|
52
|
-
input: process.stdin,
|
|
53
|
-
output: process.stderr
|
|
54
|
-
})
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
json = await new PostArmorDown(hostname, token, devicePublicKey, publicKey, team).run()
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
upsertEnvKey(privateKeyName, json.private_key)
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
...json,
|
|
65
|
-
changed: json.changed,
|
|
66
|
-
privateKeyName,
|
|
67
|
-
privateKeyValue: json.private_key,
|
|
68
|
-
publicKeyValue: publicKey
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
module.exports = ArmorDown
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const prompts = require('../helpers/prompts')
|
|
2
|
-
const GetTeams = require('../api/getTeams')
|
|
3
|
-
const PostTeamInvitation = require('../api/postTeamInvitation')
|
|
4
|
-
|
|
5
|
-
class ArmorInvite {
|
|
6
|
-
constructor (hostname, token, team, email) {
|
|
7
|
-
this.hostname = hostname
|
|
8
|
-
this.token = token
|
|
9
|
-
this.team = team
|
|
10
|
-
this.email = email
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async run () {
|
|
14
|
-
let team = this.team
|
|
15
|
-
let email = this.email
|
|
16
|
-
const context = { input: process.stdin, output: process.stderr }
|
|
17
|
-
if ((!team || !email) && !process.stdin.isTTY) {
|
|
18
|
-
throw new Error('provide --team and --email when running non-interactively')
|
|
19
|
-
}
|
|
20
|
-
if (!team) {
|
|
21
|
-
const { teams } = await new GetTeams(this.hostname, this.token).run()
|
|
22
|
-
const choices = teams
|
|
23
|
-
.filter(team => ['owner', 'admin'].includes(team.current_user_role))
|
|
24
|
-
.map(team => ({ name: team.slug, value: team.slug }))
|
|
25
|
-
if (!choices.length) throw new Error('no teams available to invite members to (requires owner or admin role)')
|
|
26
|
-
team = await prompts.select({ message: 'Select team', prefix: '⛨', choices }, context)
|
|
27
|
-
}
|
|
28
|
-
if (!email) email = await prompts.input({ message: 'Email address' }, context)
|
|
29
|
-
email = email.trim()
|
|
30
|
-
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) throw new Error('enter a valid email address')
|
|
31
|
-
const json = await new PostTeamInvitation(this.hostname, this.token, team, email).run()
|
|
32
|
-
return { ...json, team, email }
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
module.exports = ArmorInvite
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
const prompts = require('../helpers/prompts')
|
|
2
|
-
const PostArmorMove = require('../api/postArmorMove')
|
|
3
|
-
const GetAccount = require('../api/getAccount')
|
|
4
|
-
const keynames = require('../conventions/keynames')
|
|
5
|
-
const readEnvKey = require('../helpers/readEnvKey')
|
|
6
|
-
|
|
7
|
-
class ArmorMove {
|
|
8
|
-
constructor (hostname, token, devicePublicKey, envFile = '.env') {
|
|
9
|
-
this.hostname = hostname
|
|
10
|
-
this.token = token
|
|
11
|
-
this.devicePublicKey = devicePublicKey
|
|
12
|
-
this.envFile = envFile
|
|
13
|
-
|
|
14
|
-
this.team = null
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async run () {
|
|
18
|
-
const hostname = this.hostname
|
|
19
|
-
const token = this.token
|
|
20
|
-
const devicePublicKey = this.devicePublicKey
|
|
21
|
-
const envFile = this.envFile
|
|
22
|
-
let team = this.team
|
|
23
|
-
|
|
24
|
-
const {
|
|
25
|
-
publicKeyName,
|
|
26
|
-
privateKeyName
|
|
27
|
-
} = keynames(envFile)
|
|
28
|
-
const publicKey = readEnvKey(publicKeyName, envFile, { strict: true, ignore: ['MISSING_PRIVATE_KEY'] })
|
|
29
|
-
|
|
30
|
-
const accountJson = await new GetAccount(hostname, token).run()
|
|
31
|
-
const choices = accountJson.organizations.map(o => ({
|
|
32
|
-
name: o.provider_slug,
|
|
33
|
-
value: o.provider_slug
|
|
34
|
-
}))
|
|
35
|
-
team = await prompts.select({
|
|
36
|
-
message: 'Select team',
|
|
37
|
-
prefix: '⛨',
|
|
38
|
-
choices
|
|
39
|
-
}, {
|
|
40
|
-
input: process.stdin,
|
|
41
|
-
output: process.stderr
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
const json = await new PostArmorMove(hostname, token, devicePublicKey, publicKey, team).run()
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
...json,
|
|
48
|
-
privateKeyName,
|
|
49
|
-
privateKeyValue: json.private_key,
|
|
50
|
-
publicKeyValue: publicKey
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
module.exports = ArmorMove
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const keynames = require('../conventions/keynames')
|
|
2
|
-
const readEnvKey = require('../helpers/readEnvKey')
|
|
3
|
-
|
|
4
|
-
class ArmorOpen {
|
|
5
|
-
constructor (hostname, envFile = '.env') {
|
|
6
|
-
this.hostname = hostname
|
|
7
|
-
this.envFile = envFile
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
run () {
|
|
11
|
-
const hostname = this.hostname
|
|
12
|
-
const envFile = this.envFile
|
|
13
|
-
|
|
14
|
-
const { publicKeyName } = keynames(envFile)
|
|
15
|
-
const publicKey = readEnvKey(publicKeyName, envFile, { strict: true })
|
|
16
|
-
const url = `${hostname}/go/arm_${publicKey}`
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
url,
|
|
20
|
-
publicKeyName,
|
|
21
|
-
publicKeyValue: publicKey
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
module.exports = ArmorOpen
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
const prompts = require('../helpers/prompts')
|
|
2
|
-
const PostArmorPull = require('../api/postArmorPull')
|
|
3
|
-
const upsertEnvKey = require('../helpers/upsertEnvKey')
|
|
4
|
-
const keynames = require('../conventions/keynames')
|
|
5
|
-
const readEnvKey = require('../helpers/readEnvKey')
|
|
6
|
-
const teamChoicesFromMeta = require('../helpers/teamChoicesFromMeta')
|
|
7
|
-
const isTeamRequiredError = require('../helpers/isTeamRequiredError')
|
|
8
|
-
|
|
9
|
-
class ArmorPull {
|
|
10
|
-
constructor (hostname, token, devicePublicKey, envFile = '.env', team = undefined) {
|
|
11
|
-
this.hostname = hostname
|
|
12
|
-
this.token = token
|
|
13
|
-
this.devicePublicKey = devicePublicKey
|
|
14
|
-
this.envFile = envFile
|
|
15
|
-
this.team = team
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async run () {
|
|
19
|
-
const hostname = this.hostname
|
|
20
|
-
const token = this.token
|
|
21
|
-
const devicePublicKey = this.devicePublicKey
|
|
22
|
-
const envFile = this.envFile
|
|
23
|
-
const team = this.team
|
|
24
|
-
|
|
25
|
-
const {
|
|
26
|
-
publicKeyName,
|
|
27
|
-
privateKeyName
|
|
28
|
-
} = keynames(envFile)
|
|
29
|
-
|
|
30
|
-
const publicKey = readEnvKey(publicKeyName, envFile, { strict: true, ignore: ['MISSING_PRIVATE_KEY'] })
|
|
31
|
-
let json
|
|
32
|
-
|
|
33
|
-
if (team) {
|
|
34
|
-
json = await new PostArmorPull(hostname, token, devicePublicKey, publicKey, team).run()
|
|
35
|
-
} else {
|
|
36
|
-
try {
|
|
37
|
-
json = await new PostArmorPull(hostname, token, devicePublicKey, publicKey, undefined).run()
|
|
38
|
-
} catch (error) {
|
|
39
|
-
if (!isTeamRequiredError(error)) {
|
|
40
|
-
throw error
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const choices = teamChoicesFromMeta(error.meta)
|
|
44
|
-
|
|
45
|
-
let team = choices[0].value
|
|
46
|
-
if (choices.length > 1) {
|
|
47
|
-
team = await prompts.select({
|
|
48
|
-
message: 'Select team',
|
|
49
|
-
prefix: '⛨',
|
|
50
|
-
choices
|
|
51
|
-
}, {
|
|
52
|
-
input: process.stdin,
|
|
53
|
-
output: process.stderr
|
|
54
|
-
})
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
json = await new PostArmorPull(hostname, token, devicePublicKey, publicKey, team).run()
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const result = upsertEnvKey(privateKeyName, json.private_key)
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
...json,
|
|
65
|
-
changed: result.changed,
|
|
66
|
-
privateKeyName,
|
|
67
|
-
privateKeyValue: json.private_key,
|
|
68
|
-
publicKeyValue: publicKey
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
module.exports = ArmorPull
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
const prompts = require('../helpers/prompts')
|
|
2
|
-
const resolveLocalKey = require('../custodians/resolveLocalKey')
|
|
3
|
-
const PostArmorPush = require('../api/postArmorPush')
|
|
4
|
-
const teamChoicesFromMeta = require('../helpers/teamChoicesFromMeta')
|
|
5
|
-
const isTeamRequiredError = require('../helpers/isTeamRequiredError')
|
|
6
|
-
|
|
7
|
-
class ArmorPush {
|
|
8
|
-
constructor (hostname, token, devicePublicKey, envFile = '.env', team = undefined) {
|
|
9
|
-
this.hostname = hostname
|
|
10
|
-
this.token = token
|
|
11
|
-
this.devicePublicKey = devicePublicKey
|
|
12
|
-
this.envFile = envFile
|
|
13
|
-
this.team = team
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async run () {
|
|
17
|
-
const hostname = this.hostname
|
|
18
|
-
const token = this.token
|
|
19
|
-
const devicePublicKey = this.devicePublicKey
|
|
20
|
-
const envFile = this.envFile
|
|
21
|
-
const team = this.team
|
|
22
|
-
|
|
23
|
-
const source = await resolveLocalKey(envFile)
|
|
24
|
-
const { publicKey, privateKey, privateKeyName } = source
|
|
25
|
-
|
|
26
|
-
let json
|
|
27
|
-
|
|
28
|
-
if (team) {
|
|
29
|
-
json = await new PostArmorPush(hostname, token, devicePublicKey, privateKey, team).run()
|
|
30
|
-
} else {
|
|
31
|
-
try {
|
|
32
|
-
json = await new PostArmorPush(hostname, token, devicePublicKey, privateKey, undefined).run()
|
|
33
|
-
} catch (error) {
|
|
34
|
-
if (!isTeamRequiredError(error)) {
|
|
35
|
-
throw error
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const choices = teamChoicesFromMeta(error.meta)
|
|
39
|
-
|
|
40
|
-
let team = choices[0].value
|
|
41
|
-
if (choices.length > 1) {
|
|
42
|
-
team = await prompts.select({
|
|
43
|
-
message: 'Select team',
|
|
44
|
-
prefix: '⛨',
|
|
45
|
-
choices
|
|
46
|
-
}, {
|
|
47
|
-
input: process.stdin,
|
|
48
|
-
output: process.stderr
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
json = await new PostArmorPush(hostname, token, devicePublicKey, privateKey, team).run()
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
...json,
|
|
58
|
-
changed: json.changed,
|
|
59
|
-
privateKeyName,
|
|
60
|
-
privateKeyValue: json.private_key,
|
|
61
|
-
publicKeyValue: publicKey
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
module.exports = ArmorPush
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
const keypairMetadata = require('../helpers/keypairMetadata')
|
|
2
|
-
const prompts = require('../helpers/prompts')
|
|
3
|
-
const resolveLocalKey = require('../custodians/resolveLocalKey')
|
|
4
|
-
const PostArmorUp = require('../api/postArmorUp')
|
|
5
|
-
const teamChoicesFromMeta = require('../helpers/teamChoicesFromMeta')
|
|
6
|
-
const isTeamRequiredError = require('../helpers/isTeamRequiredError')
|
|
7
|
-
|
|
8
|
-
class ArmorUp {
|
|
9
|
-
constructor (hostname, token, devicePublicKey, envFile = '.env', team = undefined) {
|
|
10
|
-
this.hostname = hostname
|
|
11
|
-
this.token = token
|
|
12
|
-
this.devicePublicKey = devicePublicKey
|
|
13
|
-
this.envFile = envFile
|
|
14
|
-
this.team = team
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async run () {
|
|
18
|
-
const hostname = this.hostname
|
|
19
|
-
const token = this.token
|
|
20
|
-
const devicePublicKey = this.devicePublicKey
|
|
21
|
-
const envFile = this.envFile
|
|
22
|
-
const team = this.team
|
|
23
|
-
|
|
24
|
-
const source = await resolveLocalKey(envFile, { allowMissing: true })
|
|
25
|
-
const { publicKey, privateKey, privateKeyName } = source
|
|
26
|
-
|
|
27
|
-
const metadata = keypairMetadata.file(envFile)
|
|
28
|
-
|
|
29
|
-
let json
|
|
30
|
-
|
|
31
|
-
if (team) {
|
|
32
|
-
json = await new PostArmorUp(hostname, token, devicePublicKey, publicKey, privateKey, team, metadata).run()
|
|
33
|
-
} else {
|
|
34
|
-
try {
|
|
35
|
-
json = await new PostArmorUp(hostname, token, devicePublicKey, publicKey, privateKey, undefined, metadata).run()
|
|
36
|
-
} catch (error) {
|
|
37
|
-
if (!isTeamRequiredError(error)) {
|
|
38
|
-
throw error
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const choices = teamChoicesFromMeta(error.meta)
|
|
42
|
-
|
|
43
|
-
let team = choices[0].value
|
|
44
|
-
if (choices.length > 1) {
|
|
45
|
-
team = await prompts.select({
|
|
46
|
-
message: 'Select team',
|
|
47
|
-
prefix: '⛨',
|
|
48
|
-
choices
|
|
49
|
-
}, {
|
|
50
|
-
input: process.stdin,
|
|
51
|
-
output: process.stderr
|
|
52
|
-
})
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
json = await new PostArmorUp(hostname, token, devicePublicKey, publicKey, privateKey, team, metadata).run()
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
await source.remove()
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
...json,
|
|
63
|
-
changed: Boolean(json.changed || privateKey),
|
|
64
|
-
privateKeyName,
|
|
65
|
-
privateKeyValue: json.private_key,
|
|
66
|
-
publicKeyValue: publicKey
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
module.exports = ArmorUp
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
const matchesStoredKey = require('../helpers/matchesStoredKey')
|
|
2
|
-
const keynames = require('../conventions/keynames')
|
|
3
|
-
const readEnvKey = require('../helpers/readEnvKey')
|
|
4
|
-
const removeEnvKey = require('../helpers/removeEnvKey')
|
|
5
|
-
const upsertEnvKey = require('../helpers/upsertEnvKey')
|
|
6
|
-
|
|
7
|
-
function verify (publicKey, privateKey) {
|
|
8
|
-
try {
|
|
9
|
-
if (matchesStoredKey(publicKey, privateKey)) return
|
|
10
|
-
} catch {}
|
|
11
|
-
throw new Error('private key does not match the .env public key')
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async function custodyTransfer (provider, name, operation, envFile = '.env', envKeysFile = '.env.keys') {
|
|
15
|
-
if (!['up', 'down', 'push', 'pull'].includes(operation)) throw new Error('unknown custody operation')
|
|
16
|
-
const { publicKeyName, privateKeyName } = keynames(envFile)
|
|
17
|
-
const publicKey = readEnvKey(publicKeyName, envFile, { strict: true })
|
|
18
|
-
const result = changed => ({ changed, privateKeyName, publicKeyValue: publicKey })
|
|
19
|
-
const local = readEnvKey(privateKeyName, envKeysFile)
|
|
20
|
-
if (operation === 'up' || operation === 'push') {
|
|
21
|
-
if (local) verify(publicKey, local)
|
|
22
|
-
if (operation === 'push' && !local) throw new Error(`missing ${privateKeyName} in ${envKeysFile}`)
|
|
23
|
-
const existing = (await provider.get(publicKey))[publicKey]
|
|
24
|
-
if (existing) verify(publicKey, existing)
|
|
25
|
-
if (!local && !existing) throw new Error(`missing ${privateKeyName} in ${envKeysFile}`)
|
|
26
|
-
if (!existing) await provider.set(publicKey, local)
|
|
27
|
-
const saved = (await provider.get(publicKey))[publicKey]
|
|
28
|
-
if (!saved || saved !== (local || existing)) throw new Error(`could not verify private key in ${name}; ${envKeysFile} unchanged`)
|
|
29
|
-
if (operation === 'up') return result(removeEnvKey(privateKeyName, envKeysFile).changed || !existing)
|
|
30
|
-
return result(!existing)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const privateKey = (await provider.get(publicKey))[publicKey]
|
|
34
|
-
if (!privateKey) {
|
|
35
|
-
if (operation === 'down' && local) {
|
|
36
|
-
verify(publicKey, local)
|
|
37
|
-
return result(false)
|
|
38
|
-
}
|
|
39
|
-
throw new Error(`[NOT_FOUND] private key not found in ${name}`)
|
|
40
|
-
}
|
|
41
|
-
verify(publicKey, privateKey)
|
|
42
|
-
const written = upsertEnvKey(privateKeyName, privateKey, envKeysFile)
|
|
43
|
-
if (readEnvKey(privateKeyName, envKeysFile, { strict: true }) !== privateKey) {
|
|
44
|
-
throw new Error(`could not verify private key in ${envKeysFile}; ${name} unchanged`)
|
|
45
|
-
}
|
|
46
|
-
if (operation === 'down') await provider.delete(publicKey)
|
|
47
|
-
return result(written.changed || operation === 'down')
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
module.exports = custodyTransfer
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
const { Fdir } = require('@dotenvx/tooling')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
const { match } = require('@dotenvx/primitives')
|
|
4
|
-
const fsx = require('./../helpers/fsx')
|
|
5
|
-
|
|
6
|
-
const patterns = [
|
|
7
|
-
{ lang: 'Python', file: /\.py$/, match: /load_dotenv\s*\([^)]*\)/, msg: 'found python-dotenv load call' },
|
|
8
|
-
{ lang: 'Python', file: /\.py$/, match: /dotenv_values\s*\([^)]*\)/, msg: 'found python-dotenv values call' },
|
|
9
|
-
|
|
10
|
-
{ lang: 'Node', file: /\.(js|cjs|mjs|ts)$/, match: /require\(['"]dotenv['"]\)\.config\s*\([^)]*\)/, msg: 'found dotenv config require call' },
|
|
11
|
-
{ lang: 'Node', file: /\.(js|cjs|mjs|ts)$/, match: /import\s+['"]dotenv\/config['"]/, msg: 'found dotenv/config import' },
|
|
12
|
-
{ lang: 'Node', file: /\.(js|cjs|mjs|ts)$/, match: /dotenv\.config\s*\([^)]*\)/, msg: 'found dotenv config call' },
|
|
13
|
-
|
|
14
|
-
{ lang: 'Ruby', file: /\.rb$/, match: /Dotenv\.(load|overload)\s*\([^)]*\)/, msg: 'found ruby dotenv load call' },
|
|
15
|
-
{ lang: 'Go', file: /\.go$/, match: /godotenv\.(Load|Overload)\s*\([^)]*\)/, msg: 'found godotenv load call' },
|
|
16
|
-
{ lang: 'PHP', file: /\.php$/, match: /Dotenv\\Dotenv::create\w*\s*\([^)]*\)/, msg: 'found vlucas/phpdotenv loader' },
|
|
17
|
-
|
|
18
|
-
{ lang: 'Rust', file: /\.rs$/, match: /dotenvy?::dotenv\s*\([^)]*\)/, msg: 'found Rust dotenv load call' },
|
|
19
|
-
{ lang: 'Java', file: /\.java$/, match: /Dotenv\.(load|configure)\s*\([^)]*\)/, msg: 'found java-dotenv load call' },
|
|
20
|
-
{ lang: 'Kotlin', file: /\.kt$/, match: /Dotenv\.(load|configure)\s*\([^)]*\)/, msg: 'found java-dotenv load call' },
|
|
21
|
-
{ lang: '.NET', file: /\.(cs|fs|vb)$/, match: /(?:DotNetEnv\.)?Env\.Load\s*\([^)]*\)/, msg: 'found DotNetEnv load call' }
|
|
22
|
-
]
|
|
23
|
-
|
|
24
|
-
class Doctor {
|
|
25
|
-
constructor (directory = './') {
|
|
26
|
-
this.cwd = path.resolve(directory)
|
|
27
|
-
this.ignore = [
|
|
28
|
-
'**/node_modules/**',
|
|
29
|
-
'**/.git/**',
|
|
30
|
-
'**/vendor/**',
|
|
31
|
-
'**/dist/**',
|
|
32
|
-
'**/build/**',
|
|
33
|
-
'**/coverage/**',
|
|
34
|
-
'**/.next/**'
|
|
35
|
-
]
|
|
36
|
-
this.exclude = match(this.ignore)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
run () {
|
|
40
|
-
const findings = []
|
|
41
|
-
|
|
42
|
-
for (const filepath of this._filepaths()) {
|
|
43
|
-
findings.push(...this._scanFile(filepath))
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return findings
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
_filepaths () {
|
|
50
|
-
return new Fdir()
|
|
51
|
-
.withRelativePaths()
|
|
52
|
-
.exclude((dir, filepath) => this._ignored(filepath))
|
|
53
|
-
.filter((filepath) => this._patternsFor(filepath).length > 0)
|
|
54
|
-
.crawl(this.cwd)
|
|
55
|
-
.sync()
|
|
56
|
-
.sort()
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
_scanFile (relativeFilepath) {
|
|
60
|
-
const src = fsx.readFileXSync(path.join(this.cwd, relativeFilepath))
|
|
61
|
-
const lines = src.split(/\r?\n/)
|
|
62
|
-
const findings = []
|
|
63
|
-
|
|
64
|
-
lines.forEach((line, index) => {
|
|
65
|
-
for (const pattern of this._patternsFor(relativeFilepath)) {
|
|
66
|
-
if (pattern.match.test(line)) {
|
|
67
|
-
const match = line.match(pattern.match)
|
|
68
|
-
findings.push({
|
|
69
|
-
lang: pattern.lang,
|
|
70
|
-
filepath: relativeFilepath,
|
|
71
|
-
line: index + 1,
|
|
72
|
-
code: match[0].trim(),
|
|
73
|
-
msg: pattern.msg
|
|
74
|
-
})
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
return findings
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
_patternsFor (filepath) {
|
|
83
|
-
return patterns.filter(pattern => pattern.file.test(filepath))
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
_ignored (filepath) {
|
|
87
|
-
return this.exclude(filepath)
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
Doctor.patterns = patterns
|
|
92
|
-
|
|
93
|
-
module.exports = Doctor
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
const fsx = require('./../helpers/fsx')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
|
|
4
|
-
const Errors = require('../helpers/errors')
|
|
5
|
-
const findEnvFiles = require('../helpers/findEnvFiles')
|
|
6
|
-
const { scan, upsert } = require('@dotenvx/primitives')
|
|
7
|
-
|
|
8
|
-
function finalValues (src) {
|
|
9
|
-
const { parsed } = scan(src)
|
|
10
|
-
const result = {}
|
|
11
|
-
|
|
12
|
-
for (const key in parsed) {
|
|
13
|
-
const values = parsed[key]
|
|
14
|
-
result[key] = values[values.length - 1]
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return result
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
class Genexample {
|
|
21
|
-
constructor (directory = '.', envFile) {
|
|
22
|
-
this.directory = directory
|
|
23
|
-
this.envFile = envFile || findEnvFiles(directory)
|
|
24
|
-
|
|
25
|
-
this.exampleFilename = '.env.example'
|
|
26
|
-
this.exampleFilepath = path.resolve(this.directory, this.exampleFilename)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
run () {
|
|
30
|
-
if (this.envFile.length < 1) {
|
|
31
|
-
throw new Errors().missingEnvFiles()
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const keys = new Set()
|
|
35
|
-
const addedKeys = new Set()
|
|
36
|
-
const envFilepaths = this._envFilepaths()
|
|
37
|
-
/** @type {Record<string, string>} */
|
|
38
|
-
const injected = {}
|
|
39
|
-
/** @type {Record<string, string>} */
|
|
40
|
-
const existed = {}
|
|
41
|
-
|
|
42
|
-
let exampleSrc = `# ${this.exampleFilename} - generated with dotenvx\n`
|
|
43
|
-
|
|
44
|
-
for (const envFilepath of envFilepaths) {
|
|
45
|
-
const filepath = path.resolve(this.directory, envFilepath)
|
|
46
|
-
if (!fsx.existsSync(filepath)) {
|
|
47
|
-
const error = new Errors({ envFilepath, filepath }).missingEnvFile()
|
|
48
|
-
error.help = `? add it with [echo "HELLO=World" > ${envFilepath}] and then run [dotenvx genexample]`
|
|
49
|
-
throw error
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// get the original src
|
|
53
|
-
let src = fsx.readFileXSync(filepath)
|
|
54
|
-
const parsed = finalValues(src)
|
|
55
|
-
for (const key in parsed) {
|
|
56
|
-
// used later
|
|
57
|
-
keys.add(key)
|
|
58
|
-
|
|
59
|
-
// once newSrc is built write it out
|
|
60
|
-
src = upsert(src, key, '') // empty value
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
exampleSrc += `\n${src}`
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (!fsx.existsSync(this.exampleFilepath)) {
|
|
67
|
-
// it doesn't exist so just write this first generated one
|
|
68
|
-
// exampleSrc - already written to from the prior loop
|
|
69
|
-
for (const key of [...keys]) {
|
|
70
|
-
// every key is added since it's the first time generating .env.example
|
|
71
|
-
addedKeys.add(key)
|
|
72
|
-
|
|
73
|
-
injected[key] = ''
|
|
74
|
-
}
|
|
75
|
-
} else {
|
|
76
|
-
// it already exists (which means the user might have it modified a way in which they prefer, so replace exampleSrc with their existing .env.example)
|
|
77
|
-
exampleSrc = fsx.readFileXSync(this.exampleFilepath)
|
|
78
|
-
|
|
79
|
-
const parsed = finalValues(exampleSrc)
|
|
80
|
-
for (const key of [...keys]) {
|
|
81
|
-
if (key in parsed) {
|
|
82
|
-
existed[key] = parsed[key]
|
|
83
|
-
} else {
|
|
84
|
-
exampleSrc += `${key}=''\n`
|
|
85
|
-
|
|
86
|
-
addedKeys.add(key)
|
|
87
|
-
|
|
88
|
-
injected[key] = ''
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return {
|
|
94
|
-
envExampleFile: exampleSrc,
|
|
95
|
-
envFile: this.envFile,
|
|
96
|
-
exampleFilepath: this.exampleFilepath,
|
|
97
|
-
addedKeys: [...addedKeys],
|
|
98
|
-
injected,
|
|
99
|
-
existed
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
_envFilepaths () {
|
|
104
|
-
if (!Array.isArray(this.envFile)) {
|
|
105
|
-
return [this.envFile]
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return this.envFile
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
module.exports = Genexample
|