-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
* Basic implementation of NPM * Feature flag and changes to model structure * Refactor some code, general cleaning * Minor fixes for bundle versions and tasks.json * Minor fixes * PR feedback * leanr to spell plz * Util function for file extension * Revert small change * PR feedback * Fix the build
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { AzExtFsExtra, nonNullProp } from '@microsoft/vscode-azext-utils'; | ||
import * as path from 'path'; | ||
import { functionSubpathSetting } from '../../../constants'; | ||
import { IScriptFunctionTemplate } from '../../../templates/script/parseScriptTemplates'; | ||
import { getWorkspaceSetting } from '../../../vsCodeConfig/settings'; | ||
import { FunctionCreateStepBase } from '../FunctionCreateStepBase'; | ||
import { IScriptFunctionWizardContext } from './IScriptFunctionWizardContext'; | ||
import { getFileExtensionFromLanguage } from './ScriptFunctionCreateStep'; | ||
|
||
export class NodeV4FunctionCreateStep extends FunctionCreateStepBase<IScriptFunctionWizardContext> { | ||
public async executeCore(context: IScriptFunctionWizardContext): Promise<string> { | ||
const functionSubpath: string = getWorkspaceSetting(functionSubpathSetting, context.projectPath) as string; | ||
const functionPath = path.join(context.projectPath, functionSubpath); | ||
await AzExtFsExtra.ensureDir(functionPath); | ||
|
||
const functionName = nonNullProp(context, 'functionName'); | ||
const fileExt = getFileExtensionFromLanguage(context.language); | ||
const fileName = `${functionName}${fileExt}`; | ||
|
||
const template: IScriptFunctionTemplate = nonNullProp(context, 'functionTemplate'); | ||
await Promise.all(Object.keys(template.templateFiles).map(async f => { | ||
let contents = template.templateFiles[f]; | ||
contents = contents.replace(/%functionName%/g, functionName); | ||
|
||
for (const setting of template.userPromptedSettings) { | ||
// the setting name keys are lowercased | ||
contents = contents.replace(new RegExp(`%${setting.name}%`, 'g'), context[setting.name.toLowerCase()]); | ||
} | ||
|
||
await AzExtFsExtra.writeFile(path.join(functionPath, fileName), contents); | ||
})); | ||
|
||
return path.join(functionPath, fileName); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { AzExtFsExtra } from '@microsoft/vscode-azext-utils'; | ||
import * as path from 'path'; | ||
import { functionSubpathSetting } from '../../../constants'; | ||
import { localize } from "../../../localize"; | ||
import { IScriptFunctionTemplate } from '../../../templates/script/parseScriptTemplates'; | ||
import { nonNullProp } from '../../../utils/nonNull'; | ||
import { getWorkspaceSetting } from '../../../vsCodeConfig/settings'; | ||
import { FunctionNameStepBase } from '../FunctionNameStepBase'; | ||
import { IScriptFunctionWizardContext } from './IScriptFunctionWizardContext'; | ||
import { getFileExtensionFromLanguage } from './ScriptFunctionCreateStep'; | ||
|
||
export class NodeV4FunctionNameStep extends FunctionNameStepBase<IScriptFunctionWizardContext> { | ||
protected async getUniqueFunctionName(context: IScriptFunctionWizardContext): Promise<string | undefined> { | ||
const template: IScriptFunctionTemplate = nonNullProp(context, 'functionTemplate'); | ||
const functionSubpath: string = getWorkspaceSetting(functionSubpathSetting, context.projectPath) as string; | ||
return await this.getUniqueFsPath( | ||
path.join(context.projectPath, functionSubpath), | ||
template.defaultFunctionName, | ||
getFileExtensionFromLanguage(context.language)); | ||
} | ||
|
||
protected async validateFunctionNameCore(context: IScriptFunctionWizardContext, name: string): Promise<string | undefined> { | ||
const functionSubpath: string = getWorkspaceSetting(functionSubpathSetting, context.projectPath) as string; | ||
name = `${name}${getFileExtensionFromLanguage(context.language)}`; | ||
|
||
if (await AzExtFsExtra.pathExists(path.join(context.projectPath, functionSubpath, name))) { | ||
return localize('existingFileError', 'A file with the name "{0}" already exists.', name); | ||
} else { | ||
return undefined; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { AzureWizardPromptStep, IAzureQuickPickItem, IAzureQuickPickOptions, nonNullValue, openUrl } from '@microsoft/vscode-azext-utils'; | ||
import { learnMoreQp, nodeProgrammingModelSetting } from '../../constants'; | ||
import { localize } from '../../localize'; | ||
import { getWorkspaceSetting } from '../../vsCodeConfig/settings'; | ||
import { IProjectWizardContext } from './IProjectWizardContext'; | ||
|
||
type ProgrammingModel = { modelVersion: number | undefined, label: string }; | ||
export class ProgrammingModelStep extends AzureWizardPromptStep<IProjectWizardContext> { | ||
public hideStepCount: boolean = true; | ||
private _models: ProgrammingModel[] = []; | ||
private _learnMoreLink: string | undefined; | ||
|
||
public constructor(options: { models: ProgrammingModel | ProgrammingModel[], learnMoreLink?: string }) { | ||
super(); | ||
this._models = Array.isArray(options.models) ? options.models : [options.models]; | ||
this._learnMoreLink = options.learnMoreLink; | ||
} | ||
|
||
public async prompt(context: IProjectWizardContext): Promise<void> { | ||
const modelsPick: IAzureQuickPickItem<number | undefined>[] = this._models.map(model => { | ||
return { | ||
label: model.label, | ||
data: model.modelVersion | ||
} | ||
}); | ||
|
||
if (this._learnMoreLink) { | ||
modelsPick.push(learnMoreQp); | ||
} | ||
|
||
const options: IAzureQuickPickOptions = { | ||
placeHolder: localize('selectLanguage', 'Select a {0} programming model', context.language), | ||
suppressPersistence: true, | ||
learnMoreLink: this._learnMoreLink | ||
}; | ||
|
||
let result: IAzureQuickPickItem<number | undefined>; | ||
do { | ||
result = (await context.ui.showQuickPick(modelsPick, options)); | ||
if (result === learnMoreQp) { | ||
await openUrl(nonNullValue(this._learnMoreLink)); | ||
} | ||
} | ||
while (result === learnMoreQp); | ||
|
||
context.languageModel = result.data; | ||
} | ||
|
||
public shouldPrompt(context: IProjectWizardContext): boolean { | ||
// auto-select the default model if there is only one | ||
if (this._models.length === 1) { | ||
context.languageModel = this._models[0].modelVersion; | ||
} | ||
|
||
// this only impacts node for now so only check the feature flag for node | ||
return context.languageModel === undefined && | ||
(!!getWorkspaceSetting(nodeProgrammingModelSetting) && | ||
(context.language === 'JavaScript' || context.language === 'TypeScript')); | ||
} | ||
} |