Skip to content

Commit

Permalink
Use opt-out list instead of opt-in.
Browse files Browse the repository at this point in the history
  • Loading branch information
philliphoff committed Aug 19, 2022
1 parent 5718cf9 commit 70e4d64
Showing 1 changed file with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

import { AzExtFsExtra } from '@microsoft/vscode-azext-utils';
import * as path from 'path';
import * as vscode from 'vscode';
import { Progress, Uri, window, workspace } from 'vscode';
import { hostFileName, localSettingsFileName, ProjectLanguage, pythonFunctionAppFileName, requirementsFileName } from '../../../constants';
import { hostFileName, localSettingsFileName, ProjectLanguage, pythonFunctionAppFileName } from '../../../constants';
import { IHostJsonV2 } from '../../../funcConfig/host';
import { IScriptFunctionTemplate } from '../../../templates/script/parseScriptTemplates';
import { PysteinTemplateProvider } from '../../../templates/script/PysteinTemplateProvider';
Expand All @@ -19,6 +20,16 @@ import { showMarkdownPreviewFile } from '../../../utils/textUtils';

const gettingStartedFileName = 'getting_started.md';

async function fileExists(uri: vscode.Uri): Promise<boolean> {
try {
const result = await vscode.workspace.fs.stat(uri);

return result.type === vscode.FileType.File;
} catch {
return false;
}
}

export class PysteinProjectCreateStep extends ScriptProjectCreateStep {
protected gitignore: string = pythonGitignore;

Expand All @@ -37,13 +48,18 @@ export class PysteinProjectCreateStep extends ScriptProjectCreateStep {

await super.executeCore(context, progress);

const files = [
pythonFunctionAppFileName,
gettingStartedFileName,
requirementsFileName
const explicitlyHandledFiles = [
localSettingsFileName,
hostFileName
];

for (const file of files) {
// NOTE: We want to add all files in the templates *except* those we've explicitly handled (above and below).
const filesToAdd =
Object
.keys(projectTemplate.templateFiles)
.filter(file => !explicitlyHandledFiles.includes(file));

for (const file of filesToAdd) {
const fileContent = projectTemplate.templateFiles[file];

if (!fileContent) {
Expand All @@ -57,13 +73,17 @@ export class PysteinProjectCreateStep extends ScriptProjectCreateStep {
}
}

const functionAppPath: string = path.join(context.projectPath, pythonFunctionAppFileName);
const functionAppPath = Uri.file(path.join(context.projectPath, pythonFunctionAppFileName));

await window.showTextDocument(await workspace.openTextDocument(Uri.file(functionAppPath)));
if (await fileExists(functionAppPath)) {
await window.showTextDocument(await workspace.openTextDocument(functionAppPath));
}

const gettingStartedPath = path.join(context.projectPath, gettingStartedFileName);
const gettingStartedPath = Uri.file(path.join(context.projectPath, gettingStartedFileName));

await showMarkdownPreviewFile(Uri.file(gettingStartedPath), /* openToSide: */ true);
if (await fileExists(gettingStartedPath)) {
await showMarkdownPreviewFile(gettingStartedPath, /* openToSide: */ true);
}
}

protected async getHostContent(context: IProjectWizardContext): Promise<IHostJsonV2> {
Expand Down

0 comments on commit 70e4d64

Please sign in to comment.