Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
96a145b
Generated from c0b2862c0002fa73fe7b3e70cb1bac9435719186
AutorestCI Oct 18, 2018
6d79e92
Update status badge.
sergey-shandar Nov 5, 2018
6519374
Merge branch 'master' into sergey/status-badge
sergey-shandar Nov 6, 2018
ce2c22e
Merge branch 'master' into sergey/status-badge
sergey-shandar Nov 7, 2018
0972f13
[AutoPR] sql/resource-manager (#420)
AutorestCI Nov 7, 2018
28bd262
[AutoPR] storagesync/resource-manager (#425)
AutorestCI Nov 7, 2018
6dbb7b1
Merge branch 'master' into sergey/status-badge
kpajdzik Nov 7, 2018
79e112d
Merge pull request #406 from Azure/sergey/status-badge
sergey-shandar Nov 7, 2018
eb89ff2
Update README.md authentication section
Nov 7, 2018
bf100d7
Merge pull request #433 from Azure/daschult/updateReadme
Nov 7, 2018
63202d7
Update outdated readme paragraphs
kpajdzik Nov 8, 2018
3cc4351
Regenerated "@azure/arm-cognitiveservices" SDK.
kpajdzik Nov 8, 2018
5078752
Generated from c0b2862c0002fa73fe7b3e70cb1bac9435719186
AutorestCI Nov 9, 2018
5d42150
[AutoPR network/resource-manager] [Network wathcer] add a new field t…
AutorestCI Nov 9, 2018
98da35c
Merge remote-tracking branch 'origin/master'
kpajdzik Nov 9, 2018
12ceccf
use tenantId instead of subscriptionId
amarzavery Nov 9, 2018
02e4f67
Merge remote-tracking branch 'origin/master'
kpajdzik Nov 9, 2018
f998ea6
Regenerated "@azure/arm-appservice" SDK.
kpajdzik Nov 9, 2018
783a10e
Merge branch 'restapi_auto_4291' of https://github.com/Azure/azure-sd…
kpajdzik Nov 9, 2018
2ff8ddb
Update README.md
amarzavery Nov 9, 2018
765675d
Reset to 96a145b
kpajdzik Nov 9, 2018
5726a0b
Merge remote-tracking branch 'origin/master' into restapi_auto_4291
kpajdzik Nov 9, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,9 @@ child.conf.json
# temporary test artifacts
test/tmp/*

# dotenv environment variables file
# dotenv environment variables file
.env

# Coverage report
coverage
.nyc_output

*.tgz
**/dist/**/*
**/dist/**/*
126 changes: 17 additions & 109 deletions .scripts/commandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,103 +4,8 @@
* license information.
*/

import minimist from "minimist";
import * as path from "path";
import * as yargs from "yargs";
import { Options } from "yargs";
import { arrayContains, findAzureRestApiSpecsRepositoryPathSync } from "./common";

export type YargsMapping = { [key: string]: Options };

export enum SdkType {
ResourceManager = "resource-manager",
DataPlane = "data-plane",
ControlPlane = "control-plane",
Unknown = "unknown"
}

export module Argv {
export const Options: { [key: string]: YargsMapping } = {
Common: {
"logging-level": {
alias: "l",
default: "info",
choices: ["all", "trace", "debug", "info", "warn", "error"],
global: true,
description: "Defines how detailed logging statements are"
}
},
Generate: {
"skip-spec": {
boolean: true,
description: "Whether to skip generating readme.typescript.md file"
},
"skip-sdk": {
boolean: true,
description: "Whether to skip SDK generation"
}
},
Package: {
"package": {
alias: ["p", "package-name"],
string: true,
description: "Name of the manipulated package e.g. @azure/arm-servicebus"
},
"type": {
alias: "sdk-type",
string: true,
coerce: parseSdkType,
choices: ["rm", "data", "control"],
description: "Type of SDK to manipulate."
}
},
Repository: {
"azure-sdk-for-js-root": {
alias: ["sdk", "azureSDKForJSRepoRoot"],
string: true,
default: path.resolve(__dirname, ".."),
description: "Path to the azure-sdk-for-js repository"
},
"azure-rest-api-specs-root": {
alias: ["specs", "azureRestAPISpecsRoot"],
string: true,
default: findAzureRestApiSpecsRepositoryPathSync(),
description: "Path to the azure-rest-api-specs repository"
}
}
}

export const Global = {
loggingLevel: yargs.options(Argv.Options.Common).argv["logging-level"],
}

export function combine(...configs: YargsMapping[]): YargsMapping {
let result = Options.Common;
for (const config of configs) {
result = { ...result, ...config };
}
return result;
}

export function construct(...configs: YargsMapping[]): yargs.Argv {
const mergedOption: YargsMapping = combine(...configs);
const args: yargs.Argv = yargs.options(mergedOption)
.strict()
.help("?")
.showHelpOnFail(true, "Invalid usage. Run with -? to see help.")
.wrap(Math.min(yargs.terminalWidth(), 150));

(args as any).toPrettyString = function (): string {
return JSON.stringify(this, undefined, " ");
}

return args;
}

export function print(): String {
return process.argv.slice(2).join(", ");
}
}
import * as minimist from "minimist";
import { arrayContains } from "./common";

export interface CommandLineOptions extends minimist.ParsedArgs {
"azure-sdk-for-js-repo-root": string;
Expand All @@ -117,7 +22,7 @@ export interface CommandLineOptions extends minimist.ParsedArgs {
getSdkType(): SdkType;
}

export const commandLineConfiguration: minimist.Opts = {
export const commandLineConfiguration = {
string: ["azure-sdk-for-js-repo-root", "azure-rest-api-specs-root", "logging-level", "package", "type"],
boolean: ["debugger", "use", "skip-sdk", "skip-spec", "verbose", "whatif"],
alias: {
Expand All @@ -133,34 +38,37 @@ export const commandLineConfiguration: minimist.Opts = {
}
};

export enum SdkType {
ResourceManager = "resource-manager",
DataPlane = "data-plane",
ControlPlane = "control-plane"
}

let _options: CommandLineOptions;
export function getCommandLineOptions(): CommandLineOptions {
export function getCommandLineOptions() {
if (!_options) {
_options = createCommandLineParameters();
}

return _options;
}

function createCommandLineParameters(): CommandLineOptions {
const args: CommandLineOptions = minimist(process.argv.slice(2), commandLineConfiguration) as CommandLineOptions;
args.getSdkType = () => parseSdkType(args.type);
function createCommandLineParameters() {
const args = minimist(process.argv.slice(2), commandLineConfiguration) as CommandLineOptions;
args.getSdkType = getSdkType;
return args;
}

export function parseSdkType(str: string): SdkType {
export function getSdkType() {
const resourceManagerStrings = ["arm", "rm", "resourcemanager"]
const dataPlaneStrings = ["dp", "data", "dataplane"]
const controlPlaneStrings = ["control"]

const type = str.toLowerCase().replace("-", "");
const type = this.type.toLowerCase().replace("-", "");
if (arrayContains(resourceManagerStrings, type)) {
return SdkType.ResourceManager;
} else if (arrayContains(dataPlaneStrings, type)) {
return SdkType.DataPlane;
} else if (arrayContains(controlPlaneStrings, type)) {
return SdkType.ControlPlane;
} else {
return SdkType.Unknown;
throw new Error("Unknown SDK type");
}
}
}
61 changes: 13 additions & 48 deletions .scripts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,46 @@
* license information.
*/

import { execSync } from "child_process";
import * as fssync from "fs";
import { promises as fs } from "fs";
import * as path from "path";
import { execSync } from "child_process";
import { getLogger } from "./logger";

const _logger = getLogger();

export function arrayContains<T>(array: T[], el: T): boolean {
return array.indexOf(el) != -1
}

export async function isDirectory(directoryPath: string): Promise<boolean> {
try {
const stats = await fs.lstat(directoryPath);
return stats.isDirectory();
} catch {
return false;
}
const stats = await fs.lstat(directoryPath);
return stats.isDirectory();
}

export async function pathExists(path: string): Promise<boolean> {
return new Promise<boolean>((resolve) => {
return new Promise<boolean>((resolve, reject) => {
fssync.exists(path, exists => {
resolve(exists);
});
})
});
}

export function startsWith(value: string, prefix: string): boolean {
return !!(value && prefix && value.indexOf(prefix) === 0);
return value && prefix && value.indexOf(prefix) === 0;
}

export function endsWith(value: string, suffix: string): boolean {
return !!(value && suffix && value.length >= suffix.length && value.lastIndexOf(suffix) === value.length - suffix.length);
return value && suffix && value.length >= suffix.length && value.lastIndexOf(suffix) === value.length - suffix.length;
}

export function contains(values: string[], searchString: string): boolean {
return arrayContains(values, searchString);
}

export function execute(command: string, packageFolderPath: string): void {
if (fssync.existsSync(packageFolderPath)) {
if (!fssync.existsSync(packageFolderPath)) {
_logger.logWithPath(packageFolderPath, "Folder not found.");
} else {
execSync(command, { cwd: packageFolderPath, stdio: "inherit" });
}
}
Expand All @@ -55,38 +55,3 @@ export function npmRunBuild(packageFolderPath: string): void {
export function npmInstall(packageFolderPath: string): void {
execute("npm install", packageFolderPath);
}

export async function getChildDirectories(parent: string): Promise<string[]> {
const allChildren = await fs.readdir(parent);
const childDirectories = [];

for (const child of allChildren) {
if (await isDirectory(path.resolve(parent, child))) {
childDirectories.push(child);
}
}

return childDirectories;
}

export function findAzureRestApiSpecsRepositoryPathSync(): string | undefined {
const repositoryName = "azure-rest-api-specs";
let currentDirectory = __dirname;
const pathData = path.parse(currentDirectory);
const rootDirectory = pathData.root;

do {
currentDirectory = path.resolve(currentDirectory, "..");

if (containsDirectorySync(repositoryName, currentDirectory)) {
return path.resolve(currentDirectory, repositoryName);
}

} while (currentDirectory != rootDirectory);

return undefined;
}

function containsDirectorySync(directoryName: string, parentPath: string): boolean {
return fssync.existsSync(path.resolve(parentPath, directoryName));
}
118 changes: 118 additions & 0 deletions .scripts/generateSdks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/

import { promises as fs } from "fs";
import * as path from "path";
import { SdkType } from "./commandLine";
import { pathExists, isDirectory, arrayContains } from "./common";
import { getLogger } from "./logger";
import { doesReadmeMdFileSpecifiesTypescriptSdk } from "./readme";

const repositoryName = "azure-rest-api-specs";
const specificationsSegment = "specification";

const _logger = getLogger();

if (!fs) {
throw new Error("This script has to be run on Node.js 10.0+");
}

export async function findAzureRestApiSpecsRepositoryPath(): Promise<string> {
let currentDirectory = __dirname;
const pathData = path.parse(currentDirectory);
const rootDirectory = pathData.root;

do {
currentDirectory = path.resolve(currentDirectory, "..");

if (await containsDirectory(repositoryName, currentDirectory)) {
return path.resolve(currentDirectory, repositoryName);
}

} while (currentDirectory != rootDirectory);

return Promise.reject(`${repositoryName} not found!`)
}

async function containsDirectory(directoryName: string, parentPath: string): Promise<boolean> {
return await pathExists(path.resolve(parentPath, directoryName));
}

export async function findSdkDirectory(azureRestApiSpecsRepository: string, packageName: string, sdkType: SdkType): Promise<string> {
const sdkPath = path.resolve(azureRestApiSpecsRepository, specificationsSegment, packageName, sdkType);

if (await !pathExists(sdkPath)) {
return Promise.reject(`${sdkPath} SDK specs don't exist`);
}

return sdkPath;
}

export async function findMissingSdks(azureRestApiSpecsRepository: string): Promise<{ sdkName: string; sdkType: SdkType }[]> {
_logger.logTrace(`Finding missing SDKS in ${azureRestApiSpecsRepository}`);

const specsDirectory = path.resolve(azureRestApiSpecsRepository, specificationsSegment);
_logger.logTrace(`Reading "${azureRestApiSpecsRepository}" directory`);

const serviceSpecs = await fs.readdir(specsDirectory);
_logger.logTrace(`Found ${serviceSpecs.length} specification folders`);

const missingSdks = [];

for (const serviceDirectory of serviceSpecs) {
const fullServicePath = path.resolve(specsDirectory, serviceDirectory);
_logger.logTrace(`Analyzing ${serviceDirectory} in ${fullServicePath}`);

if (!(await isDirectory(fullServicePath))) {
_logger.logWarn(`"${fullServicePath}" is not a directory. Skipping`);
continue;
}

const sdkTypeDirectories = await fs.readdir(fullServicePath);
_logger.logTrace(`Found ${sdkTypeDirectories.length} specification type folders: [${sdkTypeDirectories}]`);

for (const sdkTypeDirectory of sdkTypeDirectories) {
const fullSdkPath = path.resolve(fullServicePath, sdkTypeDirectory);
_logger.logTrace(`Analyzing ${sdkTypeDirectory} in ${fullSdkPath}`);

if (!(await isDirectory(fullSdkPath))) {
_logger.logWarn(`"${fullServicePath}" is not a directory. Skipping`);
continue;
}

const readmeFiles = (await fs.readdir(fullSdkPath)).filter(file => /^readme/.test(file));
const fullSpecName = `${serviceDirectory} [${sdkTypeDirectory}]`
const sdk = { sdkName: serviceDirectory, sdkType: sdkTypeDirectory };

if (readmeFiles.length <= 0) {
// No readme.md
continue;
} else if (arrayContains(readmeFiles, "readme.nodejs.md")) {
if (!arrayContains(readmeFiles, "readme.typescript.md")) {
missingSdks.push(sdk);
_logger.logWithDebugDetails(`${fullSpecName}`.negative, "readme.nodejs.md exists but no matching readme.typescript.md");
} else {
_logger.logDebug(fullSpecName.positive);
}
} else if (arrayContains(readmeFiles, "readme.md")) {
const readmeMdPath = path.resolve(fullSdkPath, "readme.md");
if (await doesReadmeMdFileSpecifiesTypescriptSdk(readmeMdPath)) {
missingSdks.push(sdk);
_logger.logWithDebugDetails(`${fullSpecName}`.negative, "typescript mentioned in readme.md but no readme.typescript.md exists");
} else {
_logger.logDebug(fullSpecName.positive);
}
}
}
}

return missingSdks;
}

export async function saveContentToFile(filePath: string, content: string): Promise<void> {
await fs.writeFile(filePath, content);
}

Loading