-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from auth0-training/feat/keyword-replacement-m…
…appings Default Keyword Replacement Mapping Feature
- Loading branch information
Showing
8 changed files
with
110 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,50 @@ | ||
import * as vscode from 'vscode'; | ||
import { readUriContents } from '../../utils'; | ||
import { Resolver } from './resolver'; | ||
|
||
const openTextDocument = vscode.workspace.openTextDocument; | ||
const fs = vscode.workspace.fs; | ||
|
||
export class LabEnvWriter { | ||
constructor(private worspace: vscode.Uri) {} | ||
constructor(private workspace: vscode.Uri) {} | ||
|
||
getExisting = async (uri: vscode.Uri) => { | ||
try { | ||
// will error if file does not exist | ||
const stat = await fs.stat(uri); | ||
|
||
// read and parse file into name/value pairs | ||
return await readUriContents(uri) | ||
.then((file) => file.split('\n')) | ||
.then((lines) => | ||
lines.map((line) => { | ||
const pair = line.split('='); | ||
return { name: pair[0], value: pair[1] }; | ||
}) | ||
); | ||
} catch { | ||
// return an empty array if file does not exist | ||
return []; | ||
} | ||
}; | ||
|
||
writeAll = async (resolvers: Resolver[]) => { | ||
resolvers.forEach(async (resolver) => { | ||
for (const resolver of resolvers) { | ||
const uri = vscode.Uri.joinPath( | ||
this.worspace, | ||
this.workspace, | ||
resolver.getDirectory(), | ||
'.env' | ||
); | ||
const env = resolver | ||
.resolveEnv(resolvers) | ||
.map((i) => `${i.name}=${i.value}`) | ||
.join('\n'); | ||
|
||
const existingEnv = await this.getExisting(uri); | ||
const newEnv = resolver.resolveEnv(resolvers); | ||
const unique = [ | ||
...new Map(existingEnv.concat(newEnv).map((m) => [m.name, m])).values(), | ||
]; | ||
|
||
const env = unique.map((i) => `${i.name}=${i.value}`).join('\n'); | ||
|
||
await fs.writeFile(uri, Buffer.from(env, 'utf8')); | ||
}); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters