2016-02-28 06:30:26 +03:00
|
|
|
var gulp = require('gulp');
|
|
|
|
var args = require('yargs').argv;
|
|
|
|
var colors = require('colors');
|
2016-03-01 10:11:50 +03:00
|
|
|
var fs = require('fs');
|
|
|
|
var util = require('util');
|
2016-03-02 06:15:07 +03:00
|
|
|
var path = require('path');
|
2016-02-28 06:30:26 +03:00
|
|
|
var exec = require('child_process').exec;
|
|
|
|
|
|
|
|
var mappings = {
|
2016-10-12 06:57:11 +03:00
|
|
|
'analysisservices': {
|
|
|
|
'dir': 'analysisServices/lib',
|
2016-10-27 15:25:20 +03:00
|
|
|
'source': 'arm-analysisservices/2016-05-16/swagger/analysisservices.json',
|
2016-10-12 06:57:11 +03:00
|
|
|
},
|
2016-02-28 06:30:26 +03:00
|
|
|
'authorization': {
|
|
|
|
'dir': 'authorizationManagement/lib',
|
|
|
|
'source': 'arm-authorization/2015-07-01/swagger/authorization.json',
|
|
|
|
'ft': 1
|
|
|
|
},
|
2016-04-15 03:26:42 +03:00
|
|
|
'batch.Management': {
|
|
|
|
'dir': 'batchManagement/lib',
|
|
|
|
'source': 'arm-batch/2015-12-01/swagger/BatchManagement.json',
|
|
|
|
'ft': 1
|
|
|
|
},
|
|
|
|
'batch.Service': {
|
|
|
|
'dir': 'batch/lib',
|
2016-07-06 20:06:33 +03:00
|
|
|
'source': 'batch/2016-07-01.3.1/swagger/BatchService.json',
|
2016-04-15 03:26:42 +03:00
|
|
|
'ft': 1
|
|
|
|
},
|
2016-03-08 02:02:43 +03:00
|
|
|
'cdn': {
|
|
|
|
'dir': 'cdnManagement/lib',
|
2016-10-28 04:51:27 +03:00
|
|
|
'source': 'arm-cdn/2016-10-02/swagger/cdn.json',
|
2016-03-08 02:02:43 +03:00
|
|
|
'ft': 2
|
2016-02-28 06:30:26 +03:00
|
|
|
},
|
|
|
|
'compute': {
|
|
|
|
'dir': 'computeManagement2/lib',
|
2016-03-15 02:26:47 +03:00
|
|
|
'source': 'arm-compute/compositeComputeClient.json',
|
|
|
|
'ft': 1,
|
|
|
|
'modeler': 'CompositeSwagger'
|
2016-02-28 06:30:26 +03:00
|
|
|
},
|
2016-03-08 02:02:43 +03:00
|
|
|
'datalake.analytics.account': {
|
|
|
|
'dir': 'dataLake.Analytics/lib/account',
|
|
|
|
'source': 'arm-datalake-analytics/account/2015-10-01-preview/swagger/account.json'
|
|
|
|
},
|
|
|
|
'datalake.analytics.job': {
|
|
|
|
'dir': 'dataLake.Analytics/lib/job',
|
2016-04-01 20:55:38 +03:00
|
|
|
'source': 'arm-datalake-analytics/job/2016-03-20-preview/swagger/job.json'
|
2016-03-08 02:02:43 +03:00
|
|
|
},
|
|
|
|
'datalake.analytics.catalog': {
|
|
|
|
'dir': 'dataLake.Analytics/lib/catalog',
|
|
|
|
'source': 'arm-datalake-analytics/catalog/2015-10-01-preview/swagger/catalog.json'
|
|
|
|
},
|
|
|
|
'datalake.store.account': {
|
|
|
|
'dir': 'dataLake.Store/lib/account',
|
|
|
|
'source': 'arm-datalake-store/account/2015-10-01-preview/swagger/account.json'
|
|
|
|
},
|
|
|
|
'datalake.store.filesystem': {
|
|
|
|
'dir': 'dataLake.Store/lib/filesystem',
|
|
|
|
'source': 'arm-datalake-store/filesystem/2015-10-01-preview/swagger/filesystem.json'
|
|
|
|
},
|
2016-09-03 01:39:03 +03:00
|
|
|
'devtestlabs': {
|
2016-05-20 02:40:26 +03:00
|
|
|
'dir': 'devTestLabs/lib',
|
2016-09-03 01:39:03 +03:00
|
|
|
'source': 'arm-devtestlabs/2016-05-15/swagger/DTL.json'
|
2016-05-20 02:40:26 +03:00
|
|
|
},
|
2016-07-29 03:52:05 +03:00
|
|
|
'dns': {
|
|
|
|
'dir': 'dnsManagement/lib',
|
|
|
|
'source': 'arm-dns/2016-04-01/swagger/dns.json'
|
|
|
|
},
|
2016-09-03 01:39:03 +03:00
|
|
|
'eventhub': {
|
|
|
|
'dir': 'eventHubManagement/lib',
|
|
|
|
'source': 'arm-eventhub/2015-08-01/swagger/EventHub.json'
|
|
|
|
},
|
2016-03-08 02:02:43 +03:00
|
|
|
'graph': {
|
|
|
|
'dir': 'graphManagement/lib',
|
2016-06-17 21:49:20 +03:00
|
|
|
'source': 'arm-graphrbac/compositeGraphRbacManagementClient.json',
|
|
|
|
'ft': 1,
|
|
|
|
'modeler': 'CompositeSwagger'
|
2016-03-08 02:02:43 +03:00
|
|
|
},
|
2016-02-28 06:30:26 +03:00
|
|
|
'intune': {
|
|
|
|
'dir': 'intune/lib',
|
|
|
|
'source': 'arm-intune/2015-01-14-preview/swagger/intune.json',
|
|
|
|
},
|
2016-09-20 20:25:16 +03:00
|
|
|
'insights': {
|
|
|
|
'dir': 'insights/lib',
|
|
|
|
'source': 'insights/compositeInsightsClient.json',
|
|
|
|
'ft': 1,
|
|
|
|
'modeler': 'CompositeSwagger'
|
|
|
|
},
|
|
|
|
'insights.management': {
|
|
|
|
'dir': 'insightsManagement/lib',
|
|
|
|
'source': 'arm-insights/compositeInsightsManagementClient.json',
|
|
|
|
'ft': 1,
|
|
|
|
'modeler': 'CompositeSwagger'
|
|
|
|
},
|
2016-06-16 22:09:15 +03:00
|
|
|
'iothub': {
|
|
|
|
'dir': 'iothub/lib',
|
|
|
|
'source': 'arm-iothub/2016-02-03/swagger/iothub.json',
|
|
|
|
'ft': 1
|
|
|
|
},
|
2016-09-02 07:47:30 +03:00
|
|
|
'keyvault': {
|
|
|
|
'dir': 'keyvault/lib',
|
|
|
|
'source': 'keyvault/2015-06-01/swagger/keyvault.json',
|
|
|
|
'ft': 1
|
|
|
|
},
|
|
|
|
'keyvaultmanagement': {
|
|
|
|
'dir': 'keyVaultManagement/lib',
|
|
|
|
'source': 'arm-keyvault/2015-06-01/swagger/keyvault.json',
|
|
|
|
'ft': 1
|
|
|
|
},
|
2016-02-28 06:30:26 +03:00
|
|
|
'network': {
|
|
|
|
'dir': 'networkManagement2/lib',
|
2016-09-21 22:20:24 +03:00
|
|
|
'source': 'arm-network/2016-09-01/swagger/network.json',
|
2016-02-28 06:30:26 +03:00
|
|
|
'ft': 1
|
|
|
|
},
|
2016-05-19 21:14:36 +03:00
|
|
|
'notificationHubs':{
|
|
|
|
'dir': 'notificationHubsManagement/lib',
|
2016-08-13 02:29:42 +03:00
|
|
|
'source': 'arm-notificationhubs/2016-03-01/swagger/notificationhubs.json'
|
2016-05-19 21:14:36 +03:00
|
|
|
},
|
2016-05-19 03:47:31 +03:00
|
|
|
'powerbiembedded': {
|
|
|
|
'dir': 'powerbiembedded/lib',
|
|
|
|
'source': 'arm-powerbiembedded/2016-01-29/swagger/powerbiembedded.json'
|
|
|
|
},
|
2016-02-28 06:30:26 +03:00
|
|
|
'rediscache': {
|
|
|
|
'dir': 'rediscachemanagement/lib',
|
2016-09-02 07:47:30 +03:00
|
|
|
'source': 'arm-redis/2016-04-01/swagger/redis.json',
|
2016-02-28 06:30:26 +03:00
|
|
|
'ft': 1
|
|
|
|
},
|
|
|
|
'resource': {
|
|
|
|
'dir': 'resourceManagement/lib/resource',
|
2016-09-16 21:25:50 +03:00
|
|
|
'source': 'arm-resources/resources/2016-09-01/swagger/resources.json'
|
2016-02-28 06:30:26 +03:00
|
|
|
},
|
|
|
|
'resource.subscription': {
|
|
|
|
'dir': 'resourceManagement/lib/subscription',
|
2016-09-02 07:47:30 +03:00
|
|
|
'source': 'arm-resources/subscriptions/2016-06-01/swagger/subscriptions.json'
|
2016-02-28 06:30:26 +03:00
|
|
|
},
|
2016-03-08 02:02:43 +03:00
|
|
|
'resource.lock': {
|
|
|
|
'dir': 'resourceManagement/lib/lock',
|
|
|
|
'source': 'arm-resources/locks/2015-01-01/swagger/locks.json'
|
2016-02-28 06:30:26 +03:00
|
|
|
},
|
2016-10-13 09:51:19 +03:00
|
|
|
'resource.link': {
|
|
|
|
'dir': 'resourceManagement/lib/link',
|
|
|
|
'source': 'arm-resources/links/2016-09-01/swagger/links.json'
|
|
|
|
},
|
2016-02-28 06:30:26 +03:00
|
|
|
'resource.feature': {
|
|
|
|
'dir': 'resourceManagement/lib/feature',
|
|
|
|
'source': 'arm-resources/features/2015-12-01/swagger/features.json'
|
|
|
|
},
|
2016-04-06 00:20:48 +03:00
|
|
|
'resource.policy': {
|
|
|
|
'dir': 'resourceManagement/lib/policy',
|
2016-04-12 00:56:40 +03:00
|
|
|
'source': 'arm-resources/policy/2016-04-01/swagger/policy.json'
|
2016-04-06 00:20:48 +03:00
|
|
|
},
|
2016-05-19 21:14:36 +03:00
|
|
|
'servermanagement': {
|
|
|
|
'dir': 'servermanagement/lib',
|
|
|
|
'source': 'arm-servermanagement/2015-07-01-preview/servermanagement.json'
|
|
|
|
},
|
2016-09-03 01:39:03 +03:00
|
|
|
'servicebus.management': {
|
|
|
|
'dir': 'serviceBusManagement2/lib',
|
|
|
|
'source': 'arm-servicebus/2015-08-01/swagger/servicebus.json'
|
|
|
|
},
|
2016-03-08 02:02:43 +03:00
|
|
|
'serviceFabric': {
|
|
|
|
'dir': 'serviceFabric/lib',
|
2016-04-15 03:26:42 +03:00
|
|
|
'source': 'servicefabric/2016-01-28/swagger/servicefabric.json',
|
2016-03-08 02:02:43 +03:00
|
|
|
'language': 'NodeJS'
|
|
|
|
},
|
2016-09-02 07:47:30 +03:00
|
|
|
'storage': {
|
|
|
|
'dir': 'storageManagement2/lib',
|
|
|
|
'source': 'arm-storage/2016-01-01/swagger/storage.json',
|
|
|
|
'ft': 2
|
|
|
|
},
|
2016-04-15 03:26:42 +03:00
|
|
|
'traffic':{
|
2016-09-02 08:22:41 +03:00
|
|
|
'dir': 'trafficManagerManagement2/lib',
|
|
|
|
'source': 'arm-trafficmanager/2015-11-01/swagger/trafficmanager.json',
|
2016-04-15 03:26:42 +03:00
|
|
|
'ft': 1
|
|
|
|
},
|
2016-02-28 06:30:26 +03:00
|
|
|
'website': {
|
|
|
|
'dir': 'websiteManagement2/lib',
|
|
|
|
'source': 'arm-web/2015-08-01/swagger/service.json',
|
|
|
|
'ft': 1
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-10-21 04:24:37 +03:00
|
|
|
var defaultAutoRestVersion = '0.17.0-Nightly20161019';
|
2016-03-01 10:11:50 +03:00
|
|
|
var usingAutoRestVersion;
|
2016-02-28 06:30:26 +03:00
|
|
|
var specRoot = args['spec-root'] || "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master";
|
|
|
|
var project = args['project'];
|
2016-03-02 06:15:07 +03:00
|
|
|
var nugetExe = path.join('tools', 'nuget.exe');
|
|
|
|
var autoRestExe = constructAutorestExePath(defaultAutoRestVersion);
|
2016-02-28 06:30:26 +03:00
|
|
|
var nugetSource = 'https://www.myget.org/F/autorest/api/v2';
|
2016-03-01 05:32:11 +03:00
|
|
|
var language = 'Azure.NodeJS';
|
2016-03-01 10:11:50 +03:00
|
|
|
var modeler = 'Swagger';
|
2016-03-01 05:32:11 +03:00
|
|
|
var isWindows = (process.platform.lastIndexOf('win') === 0);
|
2016-03-02 06:15:07 +03:00
|
|
|
function clrCmd(cmd){
|
2016-03-01 05:32:11 +03:00
|
|
|
return isWindows ? cmd : ('mono ' + cmd);
|
|
|
|
};
|
|
|
|
|
2016-03-02 06:15:07 +03:00
|
|
|
function constructAutorestExePath(version) {
|
2016-09-02 10:34:03 +03:00
|
|
|
return path.join('packages', 'Autorest.' + version, 'tools', 'AutoRest.exe');
|
2016-03-02 06:15:07 +03:00
|
|
|
}
|
2016-03-01 05:32:11 +03:00
|
|
|
function codegen(project, cb) {
|
2016-03-01 10:11:50 +03:00
|
|
|
var found = false;
|
|
|
|
if (mappings[project].autorestversion) {
|
|
|
|
usingAutoRestVersion = mappings[project].autoRestVersion;
|
|
|
|
} else {
|
|
|
|
usingAutoRestVersion = defaultAutoRestVersion;
|
|
|
|
}
|
2016-03-02 06:15:07 +03:00
|
|
|
autoRestExe = constructAutorestExePath(usingAutoRestVersion);
|
2016-03-01 10:11:50 +03:00
|
|
|
try {
|
|
|
|
fs.statSync(autoRestExe);
|
|
|
|
found = true;
|
|
|
|
} catch (err) {
|
|
|
|
if (!err.message.match(/^ENONET.*/ig)) {
|
|
|
|
cb(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found) {
|
|
|
|
generateProject(project, specRoot, usingAutoRestVersion);
|
|
|
|
} else {
|
2016-09-02 07:47:30 +03:00
|
|
|
var nugetCmd2 = clrCmd(nugetExe) + ' install Autorest -Source ' + nugetSource + ' -Version ' + usingAutoRestVersion + ' -o packages';
|
2016-03-02 06:15:07 +03:00
|
|
|
console.log('Downloading Autorest version: ' + nugetCmd2);
|
|
|
|
exec(nugetCmd2, function(err, stdout, stderr) {
|
2016-03-01 10:11:50 +03:00
|
|
|
console.log(stdout);
|
|
|
|
console.error(stderr);
|
|
|
|
generateProject(project, specRoot, usingAutoRestVersion);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateProject(project, specRoot, autoRestVersion) {
|
2016-04-07 21:20:24 +03:00
|
|
|
var currentModeler = modeler;
|
2016-03-01 10:11:50 +03:00
|
|
|
var specPath = specRoot + '/' + mappings[project].source;
|
2016-03-01 05:32:11 +03:00
|
|
|
//servicefabric wants to generate using generic NodeJS.
|
|
|
|
if (mappings[project].language && mappings[project].language.match(/^NodeJS$/ig) !== null) {
|
|
|
|
language = mappings[project].language;
|
|
|
|
}
|
2016-03-01 10:11:50 +03:00
|
|
|
//default Modeler is Swagger. However, some services may want to use CompositeSwaggerModeler
|
|
|
|
if (mappings[project].modeler && mappings[project].modeler.match(/^CompositeSwagger$/ig) !== null) {
|
2016-04-07 21:20:24 +03:00
|
|
|
currentModeler = mappings[project].modeler;
|
2016-03-01 10:11:50 +03:00
|
|
|
}
|
2016-02-28 06:30:26 +03:00
|
|
|
|
2016-03-01 05:32:11 +03:00
|
|
|
console.log(util.format('Generating "%s" from spec file "%s" with language "%s" and AutoRest version "%s".',
|
|
|
|
project, specRoot + '/' + mappings[project].source, language, autoRestVersion));
|
2016-03-02 06:15:07 +03:00
|
|
|
autoRestExe = constructAutorestExePath(autoRestVersion);
|
2016-04-15 03:26:42 +03:00
|
|
|
var cmd = util.format('%s -Modeler %s -CodeGenerator %s -Input %s -outputDirectory lib/services/%s -Header MICROSOFT_MIT_NO_VERSION',
|
2016-04-07 21:20:24 +03:00
|
|
|
autoRestExe, currentModeler, language, specPath, mappings[project].dir);
|
2016-02-28 06:30:26 +03:00
|
|
|
if (mappings[project].ft !== null && mappings[project].ft !== undefined) cmd += ' -FT ' + mappings[project].ft;
|
|
|
|
if (mappings[project].args !== undefined) {
|
|
|
|
cmd = cmd + ' ' + args;
|
|
|
|
}
|
2016-03-08 02:02:43 +03:00
|
|
|
console.log('Executing: ' + clrCmd(cmd));
|
2016-03-01 05:32:11 +03:00
|
|
|
exec(clrCmd(cmd), function(err, stdout, stderr) {
|
2016-02-28 06:30:26 +03:00
|
|
|
console.log(stdout);
|
|
|
|
console.error(stderr);
|
|
|
|
});
|
2016-03-01 05:32:11 +03:00
|
|
|
}
|
2016-02-28 06:30:26 +03:00
|
|
|
|
|
|
|
gulp.task('default', function() {
|
|
|
|
console.log("Usage: gulp codegen [--spec-root <swagger specs 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\"");
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('codegen', function(cb) {
|
2016-09-02 10:34:03 +03:00
|
|
|
var nugetCmd = clrCmd(nugetExe) + ' install Autorest -Source ' + nugetSource + ' -Version ' + defaultAutoRestVersion + ' -o packages';
|
2016-03-02 06:15:07 +03:00
|
|
|
console.log('Downloading default AutoRest version: ' + nugetCmd);
|
|
|
|
exec(nugetCmd, function(err, stdout, stderr) {
|
2016-02-28 06:30:26 +03:00
|
|
|
console.log(stdout);
|
|
|
|
console.error(stderr);
|
|
|
|
if (project === undefined) {
|
|
|
|
Object.keys(mappings).forEach(function(proj) {
|
|
|
|
codegen(proj, cb);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (mappings[project] === undefined) {
|
|
|
|
console.error('Invalid project name "' + project + '"!');
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
codegen(project, cb);
|
|
|
|
}
|
|
|
|
});
|
2016-03-08 01:16:25 +03:00
|
|
|
});
|