-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[vscode][5/n] Setup Env Variables: Read the text from the env template and append to existing file #1285
[vscode][5/n] Setup Env Variables: Read the text from the env template and append to existing file #1285
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,8 +58,8 @@ export function activate(context: vscode.ExtensionContext) { | |
context.subscriptions.push( | ||
vscode.commands.registerCommand( | ||
COMMANDS.SETUP_ENVIRONMENT_VARIABLES, | ||
() => { | ||
setupEnvironmentVariables(context); | ||
async () => { | ||
await setupEnvironmentVariables(context); | ||
} | ||
) | ||
); | ||
|
@@ -757,18 +757,29 @@ async function setupEnvironmentVariables(context: vscode.ExtensionContext) { | |
return; | ||
} | ||
|
||
const envTemplatePath = vscode.Uri.joinPath( | ||
context.extensionUri, | ||
"static", | ||
"env_template.env" | ||
); | ||
|
||
if (fs.existsSync(envPath)) { | ||
vscode.window.showInformationMessage( | ||
"Env file already exists, will implement next PR" | ||
); | ||
const helperText = ( | ||
await vscode.workspace.fs.readFile(envTemplatePath) | ||
).toString(); | ||
|
||
// TODO: Check if we already appended the template text to existing .env | ||
// file before. If we did, don't do it again | ||
fs.appendFile(envPath, "\n\n" + helperText, function (err) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine for now, but if a file already exists perhaps we should ask the user to specify a different file or ask them if they want to overwrite or append. Can be a future improvement. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to push back saying this is P1 and focus more on content for tonight. If I have time before midnight I'll do it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: define |
||
if (err) { | ||
throw err; | ||
} | ||
console.log( | ||
`Added .env template text from ${envTemplatePath.fsPath} to ${envPath}` | ||
); | ||
}); | ||
} else { | ||
// Create the .env file from the sample | ||
const envTemplatePath = vscode.Uri.joinPath( | ||
context.extensionUri, | ||
"static", | ||
"env_template.env" | ||
); | ||
|
||
try { | ||
await vscode.workspace.fs.copy( | ||
envTemplatePath, | ||
|
@@ -780,19 +791,20 @@ async function setupEnvironmentVariables(context: vscode.ExtensionContext) { | |
`Error creating new file ${envTemplatePath}: ${err}` | ||
); | ||
} | ||
} | ||
|
||
const doc = await vscode.workspace.openTextDocument(envPath); | ||
if (doc) { | ||
vscode.window.showTextDocument(doc, { | ||
preview: false, | ||
// Tried using vscode.ViewColumn.Active but that overrides existing | ||
// walkthrough window | ||
viewColumn: vscode.ViewColumn.Beside, | ||
}); | ||
vscode.window.showInformationMessage( | ||
"Please define your environment variables." | ||
); | ||
} | ||
// Open the env file that was either was created or already existed | ||
const doc = await vscode.workspace.openTextDocument(envPath); | ||
if (doc) { | ||
vscode.window.showTextDocument(doc, { | ||
preview: false, | ||
// Tried using vscode.ViewColumn.Active but that overrides existing | ||
// walkthrough window | ||
viewColumn: vscode.ViewColumn.Beside, | ||
}); | ||
vscode.window.showInformationMessage( | ||
"Please define your environment variables." | ||
); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! using const instead of let