This commit is contained in:
Dan Schulte 2018-03-22 10:21:42 -07:00
Родитель edece972c9
Коммит f67ba941d1
1 изменённых файлов: 78 добавлений и 76 удалений

Просмотреть файл

@ -17,7 +17,7 @@ var mappings = require('./codegen_mappings.json');
const defaultAutoRestVersion = '1.2.2';
var usingAutoRestVersion;
const specRoot = args['spec-root'] || "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/specification";
const specRoot = args['spec-root'] || 'https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/specification';
const project = args['project'];
const use = args['use'];
const generateMetadata = args['generate-metadata'];
@ -48,7 +48,7 @@ function getAutorestVersion(version) {
function deleteFolderRecursive(path) {
if (fs.existsSync(path)) {
fs.readdirSync(path).forEach(function (file, index) {
var curPath = path + "/" + file;
var curPath = path + '/' + file;
if (fs.lstatSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath);
} else { // delete file
@ -57,7 +57,7 @@ function deleteFolderRecursive(path) {
});
fs.rmdirSync(path);
}
};
}
function clearProjectBeforeGenerating(projectDir) {
let modelsDir = `${projectDir}/models`;
@ -81,7 +81,7 @@ function clearProjectBeforeGenerating(projectDir) {
function generateProject(projectObj, specRoot, autoRestVersion) {
let specPath = specRoot + '/' + projectObj.source;
let isInputJson = projectObj.source.endsWith("json");
let isInputJson = projectObj.source.endsWith('json');
let result;
const azureTemplate = 'Azure.NodeJs';
language = azureTemplate;
@ -190,7 +190,7 @@ function codegen(projectObj, index) {
}
function iterateProject(proj, specRoot, usingAutoRestVersion) {
for (key in proj) {
for (const key in proj) {
if (proj[key]['packageName']) {
if (!versionSuccessfullyFound) {
checkAutorestVersion(proj[key], index);
@ -206,12 +206,12 @@ function codegen(projectObj, index) {
}
gulp.task('default', function () {
console.log("Usage: gulp codegen [--spec-root <swagger specs root>] [--use <autorest.nodejs root> [--project <project name>]\n");
console.log("--spec-root");
console.log("\tRoot location of Swagger API specs, default value is \"https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/specification");
console.log("--use");
console.log("\tRoot location of autorest.nodejs repository. If this is not specified, then the latest install generator for NodeJS will be used.");
console.log("--project\n\tProject to regenerate, default is all. List of available project names:");
console.log('Usage: gulp codegen [--spec-root <swagger specs root>] [--use <autorest.nodejs root> [--project <project name>]\n');
console.log('--spec-root');
console.log('\tRoot location of Swagger API specs, default value is \"https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/specification\"');
console.log('--use');
console.log('\tRoot location of autorest.nodejs repository. If this is not specified, then the latest install generator for NodeJS will be used.');
console.log('--project\n\tProject to regenerate, default is all. List of available project names:');
Object.keys(mappings).forEach(function (i) {
console.log('\t' + i.magenta);
});
@ -272,8 +272,8 @@ gulp.task('update-deps-rollup', (cb) => {
packagePaths.forEach((packagePath) => {
const package = require(packagePath);
//console.log(package);
let packageName = package.name
packageDir = path.dirname(packagePath);
let packageName = package.name;
const packageDir = path.dirname(packagePath);
if (rollupDependencies[packageName]) {
rollupDependencies[packageName] = packageDir;
} else {
@ -290,7 +290,7 @@ gulp.task('update-deps-rollup', (cb) => {
//are installed inside the node_modules folder.
gulp.task('test-create-rollup', (cb) => {
const azure = require('./lib/azure');
const keys = Object.keys(azure).filter((key) => { return key.startsWith('create') && !key.startsWith('createASM') && key.endsWith('Client') && key !== 'createSchedulerClient' });
const keys = Object.keys(azure).filter((key) => { return key.startsWith('create') && !key.startsWith('createASM') && key.endsWith('Client') && key !== 'createSchedulerClient'; });
//console.dir(keys);
//console.log(keys.length);
const creds = { signRequest: {} };
@ -335,12 +335,12 @@ gulp.task('sync-mappings-with-repo', (cb) => {
mappings[rp] = {};
if (fs.existsSync(rm)) {
mappings[rp]['resource-manager'] = {
"packageName": `azure-arm-${rp.toLowerCase()}`,
"packageVersion": "1.0.0-preview",
"generateMetadata": true,
"dir": `${rp}Management/lib`,
"source": `${rp}/resource-manager/readme.md`
}
'packageName': `azure-arm-${rp.toLowerCase()}`,
'packageVersion': '1.0.0-preview',
'generateMetadata': true,
'dir': `${rp}Management/lib`,
'source': `${rp}/resource-manager/readme.md`
};
newlyAdded.push(`${rp}['resource-manager']`);
console.log(`Updating RP: ${rp}, "resource-manager".`);
console.dir(mappings[rp]['resource-manager'], { depth: null, colors: true });
@ -348,12 +348,12 @@ gulp.task('sync-mappings-with-repo', (cb) => {
if (resourceProviderDataPlanesToIgnore.indexOf(rp.toLowerCase()) === -1) {
if (fs.existsSync(dp)) {
mappings[rp]['data-plane'] = {
"packageName": `azure-${rp.toLowerCase()}`,
"packageVersion": "1.0.0-preview",
"generateMetadata": true,
"dir": `${rp}/lib`,
"source": `${rp}/data-plane/readme.md`
}
'packageName': `azure-${rp.toLowerCase()}`,
'packageVersion': '1.0.0-preview',
'generateMetadata': true,
'dir': `${rp}/lib`,
'source': `${rp}/data-plane/readme.md`
};
newlyAdded.push(`${rp}['data-plane']`);
console.log(`Updating RP: ${rp}, "data-plane".`);
console.dir(mappings[rp]['data-plane'], { depth: null, colors: true });
@ -362,12 +362,12 @@ gulp.task('sync-mappings-with-repo', (cb) => {
} else {
if (fs.existsSync(rm) && !mappings[rp]['resource-manager']) {
mappings[rp]['resource-manager'] = {
"packageName": `azure-arm-${rp.toLowerCase()}`,
"packageVersion": "1.0.0-preview",
"generateMetadata": true,
"dir": `${rp}Management/lib`,
"source": `${rp}/resource-manager/readme.md`
}
'packageName': `azure-arm-${rp.toLowerCase()}`,
'packageVersion': '1.0.0-preview',
'generateMetadata': true,
'dir': `${rp}Management/lib`,
'source': `${rp}/resource-manager/readme.md`
};
newlyAdded.push(`${rp}['resource-manager']`);
console.log(`Updating RP: ${rp}, "resource-manager".`);
console.dir(mappings[rp]['resource-manager'], { depth: null, colors: true });
@ -375,12 +375,12 @@ gulp.task('sync-mappings-with-repo', (cb) => {
if (resourceProviderDataPlanesToIgnore.indexOf(rp.toLowerCase()) === -1) {
if (fs.existsSync(dp) && !mappings[rp]['data-plane']) {
mappings[rp]['data-plane'] = {
"packageName": `azure-${rp.toLowerCase()}`,
"packageVersion": "1.0.0-preview",
"generateMetadata": true,
"dir": `${rp}/lib`,
"source": `${rp}/data-plane/readme.md`
}
'packageName': `azure-${rp.toLowerCase()}`,
'packageVersion': '1.0.0-preview',
'generateMetadata': true,
'dir': `${rp}/lib`,
'source': `${rp}/data-plane/readme.md`
};
newlyAdded.push(`${rp}['data-plane']`);
console.log(`Updating RP: ${rp}, "data-plane".`);
console.dir(mappings[rp]['data-plane'], { depth: null, colors: true });
@ -396,7 +396,7 @@ gulp.task('sync-mappings-with-repo', (cb) => {
`the newly added projects "${newlyAdded.join()}" in the mappings.\n\n> Please ensure that other properties ` +
`like: "ft", "clientName", etc. are correctly added as deemed necessary.\n\n> If the specs repo had multiple ` +
`specs in data-plane or resource-manager (for example: "datalake-analytics.data-plane" has "catalog" ` +
`and "job" in it), then please update the project mappings yourself.`)
`and "job" in it), then please update the project mappings yourself.`);
}
console.log(`\n\n>>>>> Total projects in the mappings before sync: ${originalProjectCount}`);
console.log(`\n>>>>> Total projects in the mappings after sync: ${Object.keys(mappings).length}`);
@ -429,47 +429,49 @@ gulp.task('sync-deps-rollup', (cb) => {
gulp.task('sync-package-service-mapping', (cb) => {
let packageMapping = require('./package_service_mapping');
for (let serviceName in mappings) {
let serviceObj = mappings[serviceName];
let resourceMgr = serviceObj['resource-manager'];
let Dataplane = serviceObj['data-plane'];
if (resourceMgr) {
if (resourceMgr.packageName) {
if (!packageMapping[resourceMgr.packageName]) {
packageMapping[resourceMgr.packageName] = {
category: 'Management',
'service_name': resourceMgr.dir.split('/')[0]
};
}
} else {
for (let service in resourceMgr) {
if (resourceMgr[service].packageName) {
if (!packageMapping[resourceMgr[service].packageName]) {
packageMapping[resourceMgr[service].packageName] = {
category: 'Management',
'service_name': resourceMgr[service].dir.split('/')[0]
};
for (const serviceName in mappings) {
if (serviceName) {
const serviceObj = mappings[serviceName];
const resourceMgr = serviceObj['resource-manager'];
const Dataplane = serviceObj['data-plane'];
if (resourceMgr) {
if (resourceMgr.packageName) {
if (!packageMapping[resourceMgr.packageName]) {
packageMapping[resourceMgr.packageName] = {
category: 'Management',
'service_name': resourceMgr.dir.split('/')[0]
};
}
} else {
for (let service in resourceMgr) {
if (resourceMgr[service].packageName) {
if (!packageMapping[resourceMgr[service].packageName]) {
packageMapping[resourceMgr[service].packageName] = {
'category': 'Management',
'service_name': resourceMgr[service].dir.split('/')[0]
};
}
}
}
}
}
}
if (Dataplane) {
if (Dataplane.packageName) {
if (!packageMapping[Dataplane.packageName]) {
packageMapping[Dataplane.packageName] = {
category: 'Client',
'service_name': Dataplane.dir.split('/')[0]
};
}
} else {
for (let service in Dataplane) {
if (Dataplane[service].packageName) {
if (!packageMapping[Dataplane[service].packageName]) {
packageMapping[Dataplane[service].packageName] = {
category: 'Client',
'service_name': Dataplane[service].dir.split('/')[0]
};
if (Dataplane) {
if (Dataplane.packageName) {
if (!packageMapping[Dataplane.packageName]) {
packageMapping[Dataplane.packageName] = {
category: 'Client',
'service_name': Dataplane.dir.split('/')[0]
};
}
} else {
for (let service in Dataplane) {
if (Dataplane[service].packageName) {
if (!packageMapping[Dataplane[service].packageName]) {
packageMapping[Dataplane[service].packageName] = {
category: 'Client',
'service_name': Dataplane[service].dir.split('/')[0]
};
}
}
}
}