Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Move generating deprecation message inside of packages #83

Merged
merged 3 commits into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions src/vanilla/CodeGeneratorJs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public override async Task Generate(CodeModel cm)
await GenerateReadmeMd(codeModel, generatorSettings).ConfigureAwait(false);

await GenerateLicenseTxt(codeModel, generatorSettings).ConfigureAwait(false);

await GeneratePostinstallScript(codeModel, generatorSettings).ConfigureAwait(false);
}

protected async Task GenerateServiceClientJs<T>(Func<Template<T>> serviceClientTemplateCreator, GeneratorSettingsJs generatorSettings) where T : CodeModelJs
Expand Down Expand Up @@ -152,6 +154,14 @@ protected async Task GenerateLicenseTxt(CodeModelJs codeModel, GeneratorSettings
}
}

protected async Task GeneratePostinstallScript(CodeModelJs codeModel, GeneratorSettingsJs generatorSettings)
Copy link

Choose a reason for hiding this comment

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

Suggested change
protected async Task GeneratePostinstallScript(CodeModelJs codeModel, GeneratorSettingsJs generatorSettings)
protected async Task GeneratePostInstallScript(CodeModelJs codeModel, GeneratorSettingsJs generatorSettings)

Should install be captalized?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The name of the file is "postinstall.js" so that's why I capitalized it like that. What do you think?

Copy link

Choose a reason for hiding this comment

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

That's fine with me. Leave it the way you have it.

{
if (generatorSettings.GeneratePostinstallScript)
{
PostinstallScript postinstallScript = new PostinstallScript { Model = codeModel };
await Write(postinstallScript, ".scripts/postinstall.js").ConfigureAwait(false);
}
}
protected string GetModelSourceCodeFilePath(GeneratorSettingsJs generatorSettings, string modelFileName)
=> GetSourceCodeFilePath(generatorSettings, "models", modelFileName);

Expand Down
7 changes: 6 additions & 1 deletion src/vanilla/GeneratorSettingsJs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public class GeneratorSettingsJs : IGeneratorSettings
/// </summary>
public bool GenerateLicenseTxt { get; set; }

/// <summary>
/// Whether or not to generate the postinstall.js script.
/// </summary>
public bool GeneratePostinstallScript { get; set; } = true;

/// <summary>
/// The sub-folder path where source code will be generated.
/// </summary>
Expand Down Expand Up @@ -251,4 +256,4 @@ private static void Log(Category category, string message, params string[] messa
}
}
}
}
}
11 changes: 10 additions & 1 deletion src/vanilla/Model/CodeModelJs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,10 @@ private static string ConvertPackageNameToTypeScript(string packageName) {
{ "azure-arm-sb", "@azure/arm-servicebus" }
};

if (packageName == null) {
return "";
}

if (customNamePackages.ContainsKey(packageName)) {
return customNamePackages[packageName];
}
Expand All @@ -437,9 +441,14 @@ private static string ConvertPackageNameToTypeScript(string packageName) {
return $"@azure/{packageName}";
}

public string GetCorrespondingTypeScriptPackageName()
{
return ConvertPackageNameToTypeScript(PackageName);
}

public void GenerateTypeScriptSDKMessage(MarkdownBuilder builder)
{
string typeScriptPackageName = ConvertPackageNameToTypeScript(PackageName);
string typeScriptPackageName = GetCorrespondingTypeScriptPackageName();
builder.Line($"**This SDK will be deprecated next year and will be replaced by a new TypeScript-based isomorphic SDK (found at https://www.npmjs.com/package/{typeScriptPackageName}) which works on Node.js and browsers.**");
builder.Line($"**See https://aka.ms/azure-sdk-for-js-migration to learn more.**");
}
Expand Down
2 changes: 1 addition & 1 deletion src/vanilla/Templates/PackageJson.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"url": "@(Model.BugsUrl)"
},
"scripts": {
"postinstall": "npm explore ms-rest -- npm run print-deprecation-message"
"postinstall": "node .scripts/postinstall.js"
}
}
37 changes: 37 additions & 0 deletions src/vanilla/Templates/PostinstallScript.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@using System
@inherits AutoRest.Core.Template<AutoRest.NodeJS.Model.CodeModelJs>
@Header("// ")
@EmptyLine
const resetColor = "\x1b[0m";
const brightColor = "\x1b[1m";
const highlightColor = "\x1b[31m";
@EmptyLine
try {
const invisibleCharactersLength = resetColor.length + brightColor.length + highlightColor.length;
@EmptyLine
const firstLine = `Active development of this SDK has been moved to ${highlightColor}@(Model.GetCorrespondingTypeScriptPackageName())${resetColor}${brightColor} package.`;
const secondLine = "This package is in maintenance mode and will be deprecated in July 2018.";
const thirdLine = "Visit https://aka.ms/azure-sdk-for-js-migration for more information.";
@EmptyLine
const framePadding = 4;
const adjustedFirstLineLength = firstLine.length - invisibleCharactersLength;
const width = Math.max(adjustedFirstLineLength, secondLine.length, thirdLine.length) + framePadding;
const getPaddingLength = (strLength) => width - strLength - framePadding;
@EmptyLine
const firstLinePaddingLength = getPaddingLength(adjustedFirstLineLength);
const secondLinePaddingLength = getPaddingLength(secondLine.length);
const thirdLinePaddingLength = getPaddingLength(thirdLine.length);
const line = "#".repeat(width);
@EmptyLine
const formatTextLine = (text, padding) => `#${" ".repeat(Math.floor(padding / 2))} ${text} ${" ".repeat(Math.ceil(padding / 2))}#`;
@EmptyLine
console.log(brightColor);
console.log("\n" + line);
console.log(formatTextLine(firstLine, firstLinePaddingLength));
console.log(formatTextLine(secondLine, secondLinePaddingLength));
console.log(formatTextLine(thirdLine, thirdLinePaddingLength));
console.log(line + "\n");
console.log(resetColor);
} catch (err) {
// ignore
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.
//
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.

const resetColor = "\x1b[0m";
const brightColor = "\x1b[1m";
const highlightColor = "\x1b[31m";

try {
const invisibleCharactersLength = resetColor.length + brightColor.length + highlightColor.length;

const firstLine = `Active development of this SDK has been moved to ${highlightColor}@azure/arm-parameterflattening${resetColor}${brightColor} package.`;
const secondLine = "This package is in maintenance mode and will be deprecated in July 2018.";
const thirdLine = "Visit https://aka.ms/azure-sdk-for-js-migration for more information.";

const framePadding = 4;
const adjustedFirstLineLength = firstLine.length - invisibleCharactersLength;
const width = Math.max(adjustedFirstLineLength, secondLine.length, thirdLine.length) + framePadding;
const getPaddingLength = (strLength) => width - strLength - framePadding;

const firstLinePaddingLength = getPaddingLength(adjustedFirstLineLength);
const secondLinePaddingLength = getPaddingLength(secondLine.length);
const thirdLinePaddingLength = getPaddingLength(thirdLine.length);
const line = "#".repeat(width);

const formatTextLine = (text, padding) => `#${" ".repeat(Math.floor(padding / 2))} ${text} ${" ".repeat(Math.ceil(padding / 2))}#`;

console.log(brightColor);
console.log("\n" + line);
console.log(formatTextLine(firstLine, firstLinePaddingLength));
console.log(formatTextLine(secondLine, secondLinePaddingLength));
console.log(formatTextLine(thirdLine, thirdLinePaddingLength));
console.log(line + "\n");
console.log(resetColor);
} catch (err) {
// ignore
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"url": "https://github.com/azure/azure-sdk-for-node/issues"
},
"scripts": {
"postinstall": "npm explore ms-rest -- npm run print-deprecation-message"
"postinstall": "node .scripts/postinstall.js"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.
//
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.

const resetColor = "\x1b[0m";
const brightColor = "\x1b[1m";
const highlightColor = "\x1b[31m";

try {
const invisibleCharactersLength = resetColor.length + brightColor.length + highlightColor.length;

const firstLine = `Active development of this SDK has been moved to ${highlightColor}@azure/arm-parameterflattening${resetColor}${brightColor} package.`;
const secondLine = "This package is in maintenance mode and will be deprecated in July 2018.";
const thirdLine = "Visit https://aka.ms/azure-sdk-for-js-migration for more information.";

const framePadding = 4;
const adjustedFirstLineLength = firstLine.length - invisibleCharactersLength;
const width = Math.max(adjustedFirstLineLength, secondLine.length, thirdLine.length) + framePadding;
const getPaddingLength = (strLength) => width - strLength - framePadding;

const firstLinePaddingLength = getPaddingLength(adjustedFirstLineLength);
const secondLinePaddingLength = getPaddingLength(secondLine.length);
const thirdLinePaddingLength = getPaddingLength(thirdLine.length);
const line = "#".repeat(width);

const formatTextLine = (text, padding) => `#${" ".repeat(Math.floor(padding / 2))} ${text} ${" ".repeat(Math.ceil(padding / 2))}#`;

console.log(brightColor);
console.log("\n" + line);
console.log(formatTextLine(firstLine, firstLinePaddingLength));
console.log(formatTextLine(secondLine, secondLinePaddingLength));
console.log(formatTextLine(thirdLine, thirdLinePaddingLength));
console.log(line + "\n");
console.log(resetColor);
} catch (err) {
// ignore
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"url": "https://github.com/azure/azure-sdk-for-node/issues"
},
"scripts": {
"postinstall": "npm explore ms-rest -- npm run print-deprecation-message"
"postinstall": "node .scripts/postinstall.js"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.
//
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.

const resetColor = "\x1b[0m";
const brightColor = "\x1b[1m";
const highlightColor = "\x1b[31m";

try {
const invisibleCharactersLength = resetColor.length + brightColor.length + highlightColor.length;

const firstLine = `Active development of this SDK has been moved to ${highlightColor}@azure/arm-parameterflattening${resetColor}${brightColor} package.`;
const secondLine = "This package is in maintenance mode and will be deprecated in July 2018.";
const thirdLine = "Visit https://aka.ms/azure-sdk-for-js-migration for more information.";

const framePadding = 4;
const adjustedFirstLineLength = firstLine.length - invisibleCharactersLength;
const width = Math.max(adjustedFirstLineLength, secondLine.length, thirdLine.length) + framePadding;
const getPaddingLength = (strLength) => width - strLength - framePadding;

const firstLinePaddingLength = getPaddingLength(adjustedFirstLineLength);
const secondLinePaddingLength = getPaddingLength(secondLine.length);
const thirdLinePaddingLength = getPaddingLength(thirdLine.length);
const line = "#".repeat(width);

const formatTextLine = (text, padding) => `#${" ".repeat(Math.floor(padding / 2))} ${text} ${" ".repeat(Math.ceil(padding / 2))}#`;

console.log(brightColor);
console.log("\n" + line);
console.log(formatTextLine(firstLine, firstLinePaddingLength));
console.log(formatTextLine(secondLine, secondLinePaddingLength));
console.log(formatTextLine(thirdLine, thirdLinePaddingLength));
console.log(line + "\n");
console.log(resetColor);
} catch (err) {
// ignore
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"url": "https://github.com/azure/azure-sdk-for-node/issues"
},
"scripts": {
"postinstall": "npm explore ms-rest -- npm run print-deprecation-message"
"postinstall": "node .scripts/postinstall.js"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.
//
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.

const resetColor = "\x1b[0m";
const brightColor = "\x1b[1m";
const highlightColor = "\x1b[31m";

try {
const invisibleCharactersLength = resetColor.length + brightColor.length + highlightColor.length;

const firstLine = `Active development of this SDK has been moved to ${highlightColor}@azure/arm-parameterflattening${resetColor}${brightColor} package.`;
const secondLine = "This package is in maintenance mode and will be deprecated in July 2018.";
const thirdLine = "Visit https://aka.ms/azure-sdk-for-js-migration for more information.";

const framePadding = 4;
const adjustedFirstLineLength = firstLine.length - invisibleCharactersLength;
const width = Math.max(adjustedFirstLineLength, secondLine.length, thirdLine.length) + framePadding;
const getPaddingLength = (strLength) => width - strLength - framePadding;

const firstLinePaddingLength = getPaddingLength(adjustedFirstLineLength);
const secondLinePaddingLength = getPaddingLength(secondLine.length);
const thirdLinePaddingLength = getPaddingLength(thirdLine.length);
const line = "#".repeat(width);

const formatTextLine = (text, padding) => `#${" ".repeat(Math.floor(padding / 2))} ${text} ${" ".repeat(Math.ceil(padding / 2))}#`;

console.log(brightColor);
console.log("\n" + line);
console.log(formatTextLine(firstLine, firstLinePaddingLength));
console.log(formatTextLine(secondLine, secondLinePaddingLength));
console.log(formatTextLine(thirdLine, thirdLinePaddingLength));
console.log(line + "\n");
console.log(resetColor);
} catch (err) {
// ignore
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"url": "https://github.com/azure/azure-sdk-for-node/issues"
},
"scripts": {
"postinstall": "npm explore ms-rest -- npm run print-deprecation-message"
"postinstall": "node .scripts/postinstall.js"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"url": "https://github.com/azure/azure-sdk-for-node/issues"
},
"scripts": {
"postinstall": "npm explore ms-rest -- npm run print-deprecation-message"
"postinstall": "node .scripts/postinstall.js"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.
//
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.

const resetColor = "\x1b[0m";
const brightColor = "\x1b[1m";
const highlightColor = "\x1b[31m";

try {
const invisibleCharactersLength = resetColor.length + brightColor.length + highlightColor.length;

const firstLine = `Active development of this SDK has been moved to ${highlightColor}@azure/arm-parameterflattening${resetColor}${brightColor} package.`;
const secondLine = "This package is in maintenance mode and will be deprecated in July 2018.";
const thirdLine = "Visit https://aka.ms/azure-sdk-for-js-migration for more information.";

const framePadding = 4;
const adjustedFirstLineLength = firstLine.length - invisibleCharactersLength;
const width = Math.max(adjustedFirstLineLength, secondLine.length, thirdLine.length) + framePadding;
const getPaddingLength = (strLength) => width - strLength - framePadding;

const firstLinePaddingLength = getPaddingLength(adjustedFirstLineLength);
const secondLinePaddingLength = getPaddingLength(secondLine.length);
const thirdLinePaddingLength = getPaddingLength(thirdLine.length);
const line = "#".repeat(width);

const formatTextLine = (text, padding) => `#${" ".repeat(Math.floor(padding / 2))} ${text} ${" ".repeat(Math.ceil(padding / 2))}#`;

console.log(brightColor);
console.log("\n" + line);
console.log(formatTextLine(firstLine, firstLinePaddingLength));
console.log(formatTextLine(secondLine, secondLinePaddingLength));
console.log(formatTextLine(thirdLine, thirdLinePaddingLength));
console.log(line + "\n");
console.log(resetColor);
} catch (err) {
// ignore
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"url": "https://github.com/azure/azure-sdk-for-node/issues"
},
"scripts": {
"postinstall": "npm explore ms-rest -- npm run print-deprecation-message"
"postinstall": "node .scripts/postinstall.js"
}
}
Loading