Skip to content
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][4/n] Setup Env Variables: Add helper text to existing env path #1284

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 37 additions & 21 deletions vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,18 +757,33 @@ 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"
);
var helperText: string = "\ntest, will change next PR";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: don't use var, use let

// fs.readFile(envTemplatePath.fsPath, function read(err, data) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Remove commented out code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I change it in the next PR, just wasn't able to get it to work and wanted quick feedback

// if (err) {
// throw err;
// }
// helperText = "\n" + data.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, helperText, function (err) {
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,
Expand All @@ -780,19 +795,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."
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add if/else to catch if this needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}

Expand Down