Skip to content

Commit 1e16c3a

Browse files
authored
Add npm package metadata (#84)
1 parent 21015e9 commit 1e16c3a

File tree

5 files changed

+166
-0
lines changed

5 files changed

+166
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
bin/
2+
obj/
3+
Properties/
4+
*.csproj
5+
*.csproj.user
6+
*.cs
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const readMeSrc = path.resolve(__dirname, '..', '..', '..', '..', 'docs', 'openapi-cli.md');
5+
const readMeDest = path.resolve(__dirname, '..', 'README.md');
6+
7+
fs.copyFile(readMeSrc, readMeDest, (err) => {
8+
if (err) throw err;
9+
console.log('Copied openapi-cli.md from the docs directory.');
10+
});
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#! /usr/bin/env node
2+
3+
const unzipper = require('unzipper');
4+
const url = require('url');
5+
const HttpsProxyAgent = require('https-proxy-agent');
6+
const https = require('https');
7+
const version = require('../package.json').version;
8+
const chalk = require('chalk');
9+
const path = require('path');
10+
const fs = require('fs');
11+
const rimraf = require('rimraf');
12+
const glob = require('glob');
13+
const execSync = require('child_process').execSync;
14+
const ProgressBar = require('progress');
15+
const os = require('os');
16+
const args = process.argv;
17+
18+
function getPath() {
19+
const bin = path.resolve(path.join(path.dirname(__filename), '..', 'bin'));
20+
if (fs.existsSync(bin)) {
21+
rimraf.sync(bin);
22+
}
23+
return bin
24+
}
25+
26+
let platform = '';
27+
28+
if (os.platform() === 'win32') {
29+
platform = 'win-x64';
30+
} else if (os.platform() === 'darwin') {
31+
platform = 'osx-x64';
32+
} else if (os.platform() === 'linux') {
33+
platform = 'linux-x64';
34+
} else {
35+
throw Error('platform ' + os.platform() + ' isn\'t supported');
36+
}
37+
38+
const endpoint = 'https://functionscdn.azureedge.net/public/' + version + '/Azure.Functions.Cli.' + platform + '.' + version + '.zip';
39+
console.log('attempting to GET %j', endpoint);
40+
const options = url.parse(endpoint);
41+
// npm config preceed system environment
42+
// https://github.com/npm/npm/blob/19397ad523434656af3d3765e80e22d7e6305f48/lib/config/reg-client.js#L7-L8
43+
// https://github.com/request/request/blob/b12a6245d9acdb1e13c6486d427801e123fdafae/lib/getProxyFromURI.js#L66-L71
44+
const proxy = process.env.npm_config_https_proxy ||
45+
process.env.npm_config_proxy ||
46+
process.env.HTTPS_PROXY ||
47+
process.env.https_proxy ||
48+
process.env.HTTP_PROXY ||
49+
process.env.http_proxy;
50+
51+
if (proxy) {
52+
console.log('using proxy server %j', proxy);
53+
options.agent = new HttpsProxyAgent(proxy);
54+
}
55+
56+
https.get(options, response => {
57+
58+
const bar = new ProgressBar('[:bar] Downloading Azure Functions Core Tools', {
59+
total: Number(response.headers['content-length']),
60+
width: 18
61+
});
62+
63+
if (response.statusCode === 200) {
64+
const installPath = getPath();
65+
response.on('data', data => bar.tick(data.length));
66+
const unzipStream = unzipper.Extract({ path: installPath })
67+
.on('close', () => {
68+
if (os.platform() === 'linux' || os.platform() === 'darwin') {
69+
fs.chmodSync(`${installPath}/azfuncopenapi`, 0o755);
70+
}
71+
});
72+
response.pipe(unzipStream);
73+
} else {
74+
console.error(chalk.red('Error downloading zip file from ' + endpoint));
75+
console.error(chalk.red('Expected: 200, Actual: ' + response.statusCode));
76+
process.exit(1);
77+
}
78+
})
79+
.on('error', err => {
80+
console.error(chalk.red(err));
81+
process.exit(1);
82+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#! /usr/bin/env node
2+
3+
const path = require('path');
4+
const fs = require('fs');
5+
const spawn = require('child_process').spawn;
6+
const fork = require('child_process').fork;
7+
const commandExists = require('command-exists');
8+
const args = process.argv;
9+
10+
function main() {
11+
const bin = path.resolve(path.join(path.dirname(__filename), '..', 'bin'));
12+
const funcProc = spawn(bin + '/azfuncopenapi', args.slice(2), {
13+
stdio: [process.stdin, process.stdout, process.stderr, 'pipe']
14+
});
15+
16+
funcProc.on('exit', code => {
17+
process.exit(code);
18+
});
19+
}
20+
21+
main();
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "azure-functions-openapi-tools",
3+
"version": "0.8.0",
4+
"description": "This handles Open API documents from Azure Functions without having to run the function app",
5+
"author": "Aliencube Community",
6+
"license": "MIT",
7+
"preferGlobal": true,
8+
"keywords": [
9+
"azure-functions",
10+
"cli",
11+
"openapi",
12+
"swagger"
13+
],
14+
"homepage": "https://github.com/aliencube/AzureFunctions.Extensions",
15+
"bugs": {
16+
"url": "https://github.com/aliencube/AzureFunctions.Extensions/issues"
17+
},
18+
"repository": {
19+
"type": "git",
20+
"url": "https://github.com/aliencube/AzureFunctions.Extensions.git"
21+
},
22+
"scripts": {
23+
"postinstall": "node lib/install.js",
24+
"prepublishOnly": "node lib/copy-metadata.js"
25+
},
26+
"bin": {
27+
"azfuncopenapi": "lib/main.js"
28+
},
29+
"os": [
30+
"win32",
31+
"darwin",
32+
"linux"
33+
],
34+
"engines": {
35+
"node": ">=6.9.1"
36+
},
37+
"dependencies": {
38+
"chalk": "3.0.0",
39+
"command-exists": "1.2.8",
40+
"glob": "7.1.6",
41+
"https-proxy-agent": "5.0.0",
42+
"progress": "2.0.3",
43+
"rimraf": "3.0.2",
44+
"tmp": "0.1.0",
45+
"unzipper": "0.10.10"
46+
}
47+
}

0 commit comments

Comments
 (0)