diff --git a/src/templates/TemplateProvider.ts b/src/templates/CentralTemplateProvider.ts similarity index 100% rename from src/templates/TemplateProvider.ts rename to src/templates/CentralTemplateProvider.ts diff --git a/src/templates/TemplateRetriever.ts b/src/templates/TemplateProviderBase.ts similarity index 100% rename from src/templates/TemplateRetriever.ts rename to src/templates/TemplateProviderBase.ts diff --git a/src/templates/DotnetTemplateRetriever.ts b/src/templates/dotnet/DotnetTemplateProvider.ts similarity index 74% rename from src/templates/DotnetTemplateRetriever.ts rename to src/templates/dotnet/DotnetTemplateProvider.ts index 384dac47..d33df568 100644 --- a/src/templates/DotnetTemplateRetriever.ts +++ b/src/templates/dotnet/DotnetTemplateProvider.ts @@ -8,7 +8,6 @@ import * as path from 'path'; import { IActionContext } from 'vscode-azureextensionui'; import { ProjectRuntime } from '../constants'; import { ext } from '../extensionVariables'; -import { localize } from '../localize'; import { downloadFile } from '../utils/fs'; import { cliFeedJsonResponse } from '../utils/getCliFeedJson'; import { executeDotnetTemplateCommand, getDotnetItemTemplatePath, getDotnetProjectTemplatePath, getDotnetTemplatesPath } from './executeDotnetTemplateCommand'; @@ -60,41 +59,3 @@ export class DotnetTemplateRetriever extends TemplateRetriever { return parseDotnetTemplates(this._rawTemplates, runtime); } } - -export function getDotnetVerifiedTemplateIds(runtime: string): string[] { - let verifiedTemplateIds: string[] = [ - 'EventHubTrigger', - 'HttpTrigger', - 'BlobTrigger', - 'QueueTrigger', - 'TimerTrigger', - 'ServiceBusTopicTrigger', - 'ServiceBusQueueTrigger', - 'CosmosDBTrigger' - ]; - - if (runtime === ProjectRuntime.v1) { - verifiedTemplateIds = verifiedTemplateIds.concat([ - 'EventGridTrigger', - 'GenericWebHook', - 'GitHubWebHook', - 'HttpTriggerWithParameters' - ]); - } else { - verifiedTemplateIds = verifiedTemplateIds.concat([ - 'DurableFunctionsOrchestration' - ]); - } - - return verifiedTemplateIds.map((id: string) => { - id = `Azure.Function.CSharp.${id}`; - switch (runtime) { - case ProjectRuntime.v1: - return `${id}.1.x`; - case ProjectRuntime.v2: - return `${id}.2.x`; - default: - throw new RangeError(localize('invalidRuntime', 'Invalid runtime "{0}".', runtime)); - } - }); -} diff --git a/src/templates/executeDotnetTemplateCommand.ts b/src/templates/dotnet/executeDotnetTemplateCommand.ts similarity index 100% rename from src/templates/executeDotnetTemplateCommand.ts rename to src/templates/dotnet/executeDotnetTemplateCommand.ts diff --git a/src/templates/dotnet/getDotnetVerifiedTemplateIds.ts b/src/templates/dotnet/getDotnetVerifiedTemplateIds.ts new file mode 100644 index 00000000..aa1fd442 --- /dev/null +++ b/src/templates/dotnet/getDotnetVerifiedTemplateIds.ts @@ -0,0 +1,45 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { ProjectRuntime } from '../../constants'; +import { localize } from '../../localize'; + +export function getDotnetVerifiedTemplateIds(runtime: string): string[] { + let verifiedTemplateIds: string[] = [ + 'EventHubTrigger', + 'HttpTrigger', + 'BlobTrigger', + 'QueueTrigger', + 'TimerTrigger', + 'ServiceBusTopicTrigger', + 'ServiceBusQueueTrigger', + 'CosmosDBTrigger' + ]; + + if (runtime === ProjectRuntime.v1) { + verifiedTemplateIds = verifiedTemplateIds.concat([ + 'EventGridTrigger', + 'GenericWebHook', + 'GitHubWebHook', + 'HttpTriggerWithParameters' + ]); + } else { + verifiedTemplateIds = verifiedTemplateIds.concat([ + 'DurableFunctionsOrchestration' + ]); + } + + return verifiedTemplateIds.map((id: string) => { + id = `Azure.Function.CSharp.${id}`; + switch (runtime) { + case ProjectRuntime.v1: + return `${id}.1.x`; + case ProjectRuntime.v2: + return `${id}.2.x`; + default: + throw new RangeError(localize('invalidRuntime', 'Invalid runtime "{0}".', runtime)); + } + }); +} diff --git a/src/templates/parseDotnetTemplates.ts b/src/templates/dotnet/parseDotnetTemplates.ts similarity index 100% rename from src/templates/parseDotnetTemplates.ts rename to src/templates/dotnet/parseDotnetTemplates.ts diff --git a/src/templates/parseJavaTemplates.ts b/src/templates/java/JavaTemplateProvider.ts similarity index 100% rename from src/templates/parseJavaTemplates.ts rename to src/templates/java/JavaTemplateProvider.ts diff --git a/src/templates/ScriptTemplateRetriever.ts b/src/templates/script/ScriptTemplateProvider.ts similarity index 57% rename from src/templates/ScriptTemplateRetriever.ts rename to src/templates/script/ScriptTemplateProvider.ts index 049baa1d..729bf2ba 100644 --- a/src/templates/ScriptTemplateRetriever.ts +++ b/src/templates/script/ScriptTemplateProvider.ts @@ -7,7 +7,6 @@ import * as extract from 'extract-zip'; import * as fse from 'fs-extra'; import * as os from 'os'; import * as path from 'path'; -import * as vscode from 'vscode'; import { IActionContext } from 'vscode-azureextensionui'; import { ProjectRuntime } from '../constants'; import { ext } from '../extensionVariables'; @@ -81,84 +80,3 @@ export class ScriptTemplateRetriever extends TemplateRetriever { return parseScriptTemplates(this._rawResources, this._rawTemplates, this._rawConfig); } } - -/** - * Unlike templates.json and bindings.json, Resources.json has a capital letter - */ -export async function getResourcesPath(templatesPath: string, vscodeLang: string = vscode.env.language): Promise { - const folder: string = path.join(templatesPath, 'resources'); - - try { - // Example: "en-US" - const parts: string[] = vscodeLang.split('-'); - // Example: "en" for "english" - const language: string = parts[0]; - // Example: "US" for "United States" (locale is optional) - let locale: string | undefined = parts[1]; - - const files: string[] = await fse.readdir(folder); - let matchingFile: string | undefined; - if (!locale) { - const regExp: RegExp = new RegExp(`resources\\.${language}\\.json`, 'i'); - matchingFile = files.find(f => regExp.test(f)); - } - - if (!matchingFile) { - // tslint:disable-next-line: strict-boolean-expressions - locale = locale || '[a-z]*'; - const regExp: RegExp = new RegExp(`resources\\.${language}(-${locale})?\\.json`, 'i'); - matchingFile = files.find(f => regExp.test(f)); - } - - if (matchingFile) { - return path.join(folder, matchingFile); - } - } catch { - // ignore and fall back to english - } - - return path.join(folder, 'Resources.json'); -} - -export function getScriptVerifiedTemplateIds(runtime: string): string[] { - let verifiedTemplateIds: string[] = [ - 'BlobTrigger-JavaScript', - 'HttpTrigger-JavaScript', - 'QueueTrigger-JavaScript', - 'TimerTrigger-JavaScript' - ]; - - if (runtime === ProjectRuntime.v1) { - verifiedTemplateIds = verifiedTemplateIds.concat([ - 'GenericWebHook-JavaScript', - 'GitHubWebHook-JavaScript', - 'HttpTriggerWithParameters-JavaScript', - 'ManualTrigger-JavaScript' - ]); - } else { - // For JavaScript, only include triggers that require extensions in v2. v1 doesn't have the same support for 'func extensions install' - verifiedTemplateIds = verifiedTemplateIds.concat([ - 'CosmosDBTrigger-JavaScript', - 'DurableFunctionsActivity-JavaScript', - 'DurableFunctionsHttpStart-JavaScript', - 'DurableFunctionsOrchestrator-JavaScript', - 'EventGridTrigger-JavaScript', - 'EventHubTrigger-JavaScript', - 'ServiceBusQueueTrigger-JavaScript', - 'ServiceBusTopicTrigger-JavaScript' - ]); - - const javaScriptTemplateIds: string[] = verifiedTemplateIds; - - // Python is only supported in v2 - same functions as JavaScript except Durable - verifiedTemplateIds = verifiedTemplateIds.concat(javaScriptTemplateIds.filter(t => !/durable/i.test(t)).map(t => t.replace('JavaScript', 'Python'))); - - // TypeScript is only supported in v2 - same functions as JavaScript - verifiedTemplateIds = verifiedTemplateIds.concat(javaScriptTemplateIds.map(t => t.replace('JavaScript', 'TypeScript'))); - - // PowerShell is only supported in v2 - same functions as JavaScript except Durable - verifiedTemplateIds = verifiedTemplateIds.concat(javaScriptTemplateIds.filter(t => !/durable/i.test(t)).map(t => t.replace('JavaScript', 'PowerShell'))); - } - - return verifiedTemplateIds; -} diff --git a/src/templates/script/getScriptResourcesPath.ts b/src/templates/script/getScriptResourcesPath.ts new file mode 100644 index 00000000..51432b40 --- /dev/null +++ b/src/templates/script/getScriptResourcesPath.ts @@ -0,0 +1,46 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as fse from 'fs-extra'; +import * as path from 'path'; +import * as vscode from 'vscode'; + +/** + * Unlike templates.json and bindings.json, Resources.json has a capital letter + */ +export async function getScriptResourcesPath(templatesPath: string, vscodeLang: string = vscode.env.language): Promise { + const folder: string = path.join(templatesPath, 'resources'); + + try { + // Example: "en-US" + const parts: string[] = vscodeLang.split('-'); + // Example: "en" for "english" + const language: string = parts[0]; + // Example: "US" for "United States" (locale is optional) + let locale: string | undefined = parts[1]; + + const files: string[] = await fse.readdir(folder); + let matchingFile: string | undefined; + if (!locale) { + const regExp: RegExp = new RegExp(`resources\\.${language}\\.json`, 'i'); + matchingFile = files.find(f => regExp.test(f)); + } + + if (!matchingFile) { + // tslint:disable-next-line: strict-boolean-expressions + locale = locale || '[a-z]*'; + const regExp: RegExp = new RegExp(`resources\\.${language}(-${locale})?\\.json`, 'i'); + matchingFile = files.find(f => regExp.test(f)); + } + + if (matchingFile) { + return path.join(folder, matchingFile); + } + } catch { + // ignore and fall back to english + } + + return path.join(folder, 'Resources.json'); +} diff --git a/src/templates/script/getScriptVerifiedTemplateIds.ts b/src/templates/script/getScriptVerifiedTemplateIds.ts new file mode 100644 index 00000000..edc37791 --- /dev/null +++ b/src/templates/script/getScriptVerifiedTemplateIds.ts @@ -0,0 +1,49 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { ProjectRuntime } from '../../constants'; + +export function getScriptVerifiedTemplateIds(runtime: string): string[] { + let verifiedTemplateIds: string[] = [ + 'BlobTrigger-JavaScript', + 'HttpTrigger-JavaScript', + 'QueueTrigger-JavaScript', + 'TimerTrigger-JavaScript' + ]; + + if (runtime === ProjectRuntime.v1) { + verifiedTemplateIds = verifiedTemplateIds.concat([ + 'GenericWebHook-JavaScript', + 'GitHubWebHook-JavaScript', + 'HttpTriggerWithParameters-JavaScript', + 'ManualTrigger-JavaScript' + ]); + } else { + // For JavaScript, only include triggers that require extensions in v2. v1 doesn't have the same support for 'func extensions install' + verifiedTemplateIds = verifiedTemplateIds.concat([ + 'CosmosDBTrigger-JavaScript', + 'DurableFunctionsActivity-JavaScript', + 'DurableFunctionsHttpStart-JavaScript', + 'DurableFunctionsOrchestrator-JavaScript', + 'EventGridTrigger-JavaScript', + 'EventHubTrigger-JavaScript', + 'ServiceBusQueueTrigger-JavaScript', + 'ServiceBusTopicTrigger-JavaScript' + ]); + + const javaScriptTemplateIds: string[] = verifiedTemplateIds; + + // Python is only supported in v2 - same functions as JavaScript except Durable + verifiedTemplateIds = verifiedTemplateIds.concat(javaScriptTemplateIds.filter(t => !/durable/i.test(t)).map(t => t.replace('JavaScript', 'Python'))); + + // TypeScript is only supported in v2 - same functions as JavaScript + verifiedTemplateIds = verifiedTemplateIds.concat(javaScriptTemplateIds.map(t => t.replace('JavaScript', 'TypeScript'))); + + // PowerShell is only supported in v2 - same functions as JavaScript except Durable + verifiedTemplateIds = verifiedTemplateIds.concat(javaScriptTemplateIds.filter(t => !/durable/i.test(t)).map(t => t.replace('JavaScript', 'PowerShell'))); + } + + return verifiedTemplateIds; +} diff --git a/src/templates/parseScriptTemplates.ts b/src/templates/script/parseScriptTemplates.ts similarity index 100% rename from src/templates/parseScriptTemplates.ts rename to src/templates/script/parseScriptTemplates.ts