diff --git a/packages/typespec-powershell/configuration.yaml b/packages/typespec-powershell/configuration.yaml index 45e0ffaf67..997d785d06 100644 --- a/packages/typespec-powershell/configuration.yaml +++ b/packages/typespec-powershell/configuration.yaml @@ -242,4 +242,31 @@ nuspec: "./{module-name}.nuspec" # misc configurations skip-model-cmdlets: false -module-version: 0.1.0 \ No newline at end of file +module-version: 0.1.0 + +# License configurations +header-definitions: + warning: Changes may cause incorrect behavior and will be lost if the code is regenerated. + + default: "Code generated by Microsoft (R) AutoRest Code Generator (autorest: {core}, generator: {generator})" + + no-version: Code generated by Microsoft (R) AutoRest Code Generator. + + apache: | + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + mit: Licensed under the MIT License. See License.txt in the project root for license information. + + mit-small: Licensed under the MIT License. + + microsoft: Copyright (c) Microsoft Corporation. All rights reserved. + +pwsh-license-header: MICROSOFT_APACHE_NO_VERSION \ No newline at end of file diff --git a/powershell/plugins/llcsharp-v2.ts b/powershell/plugins/llcsharp-v2.ts index 8d7bad352a..f97f45453a 100644 --- a/powershell/plugins/llcsharp-v2.ts +++ b/powershell/plugins/llcsharp-v2.ts @@ -24,14 +24,14 @@ export async function llcsharpV2(service: Host | TspHost, state?: ModelState project.state.writeFile(join(project.apifolder, fname), applyOverrides(content, project.overrides), undefined, 'source-file-csharp')); // recursive copy resources - await copyResources(join(resources, 'runtime', 'csharp', 'client'), async (fname, content) => project.state.writeFile(join(project.runtimefolder, fname), content, undefined, 'source-file-csharp'), project.overrides); - await copyResources(join(resources, 'runtime', 'csharp', 'pipeline'), async (fname, content) => project.state.writeFile(join(project.runtimefolder, fname), content, undefined, 'source-file-csharp'), project.overrides, transformOutput); + await copyResources(join(resources, 'runtime', 'csharp', 'client'), async (fname, content) => project.state.writeFile(join(project.runtimefolder, fname), content, undefined, 'source-file-other'), project.overrides); + await copyResources(join(resources, 'runtime', 'csharp', 'pipeline'), async (fname, content) => project.state.writeFile(join(project.runtimefolder, fname), content, undefined, 'source-file-other'), project.overrides, transformOutput); // Note: // we are using the Carbon.Json library, but we don't *really* want to expose that as public members where we don't have to // and I don't want to make code changes in the source repository, so I can keep merging from upstream as simple as possible. // so, we're converting as much as possible to internal, and exposing only what must be exposed to make the code compile. - await copyResources(join(resources, 'runtime', 'csharp', 'json'), async (fname, content) => project.state.writeFile(join(project.runtimefolder, fname), content, undefined, 'source-file-csharp'), { + await copyResources(join(resources, 'runtime', 'csharp', 'json'), async (fname, content) => project.state.writeFile(join(project.runtimefolder, fname), content, undefined, 'source-file-other'), { ...project.overrides, 'public': 'internal', 'internal (.*) class JsonNumber': 'public $1 class JsonNumber', @@ -68,11 +68,11 @@ export async function llcsharpV2(service: Host | TspHost, state?: ModelState project.state.writeFile(join(project.runtimefolder, fname), content, undefined, 'source-file-csharp'), project.overrides); + await copyResources(join(resources, 'runtime', 'csharp', 'xml'), async (fname, content) => project.state.writeFile(join(project.runtimefolder, fname), content, undefined, 'source-file-other'), project.overrides); } if (project.azure) { - await copyResources(join(resources, 'runtime', 'csharp.azure'), async (fname, content) => project.state.writeFile(join(project.runtimefolder, fname), content, undefined, 'source-file-csharp'), project.overrides); + await copyResources(join(resources, 'runtime', 'csharp.azure'), async (fname, content) => project.state.writeFile(join(project.runtimefolder, fname), content, undefined, 'source-file-other'), project.overrides); } } catch (E) { diff --git a/powershell/plugins/powershell-v2.ts b/powershell/plugins/powershell-v2.ts index a68a95a722..c5af572187 100644 --- a/powershell/plugins/powershell-v2.ts +++ b/powershell/plugins/powershell-v2.ts @@ -54,7 +54,7 @@ async function copyRequiredFiles(project: Project) { join(project.runtimeFolder, fname), content, undefined, - sourceFileCSharp + 'source-file-other' ), project.overrides, transformOutput @@ -68,7 +68,7 @@ async function copyRequiredFiles(project: Project) { join(project.utilsFolder, fname), content, undefined, - sourceFileCSharp + 'source-file-other' ), project.overrides, transformOutput diff --git a/powershell/utils/tsp-host.ts b/powershell/utils/tsp-host.ts index 891ad774c9..5ff5c76c65 100644 --- a/powershell/utils/tsp-host.ts +++ b/powershell/utils/tsp-host.ts @@ -1,4 +1,5 @@ import { Message } from '@autorest/extension-base'; +import { comment } from '@azure-tools/codegen'; import { writeFileSync, existsSync, mkdirSync } from 'fs'; import { dirname } from 'path'; export interface TspWriteFileOptions { @@ -65,6 +66,10 @@ export class TspHostImpl implements TspHost { if (artifactType === 'binary-file') { writeFileSync(filename, Buffer.from(content, 'base64')); } else { + if (artifactType === 'source-file-csharp' && filename.endsWith('.cs')) { + const header = comment('Copyright (c) Microsoft Corporation. All rights reserved.\nLicensed under the MIT License. See License.txt in the project root for license information.\nChanges may cause incorrect behavior and will be lost if the code is regenerated.', '//'); + content = header + '\n' + content; + } writeFileSync(filename, content); } }