-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·82 lines (65 loc) · 1.67 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env node
const fs = require("fs");
const open = require("open");
const axios = require("axios");
const { prompt } = require("enquirer");
const [_node, _file, ORG_NAME, API_KEY] = process.argv;
const CONFIG = {
organization: ORG_NAME,
baseURL: null,
apiKey: API_KEY
};
const findApiKey = () => {
if (CONFIG.baseURL === null) {
console.error("Missing <baseURL>");
return;
}
open(CONFIG.baseURL);
};
const generateNpmrc = async () => {
const client = axios.create({
baseURL: CONFIG.baseURL,
headers: { "X-Api-Key": CONFIG.apiKey }
});
const { data: auth } = await client.get(
`${CONFIG.baseURL}/${CONFIG.organization}/api/npm/npm/auth/${CONFIG.organization}`
);
return `registry=${CONFIG.baseURL}/${CONFIG.organization}/api/npm/npm/
${auth.trim()}
`;
};
(async () => {
if (!CONFIG.organization) {
const { organization } = await prompt({
type: "input",
name: "organization",
message: "What's your organization name?"
});
CONFIG.organization = organization;
}
CONFIG.baseURL = `https://${CONFIG.organization}.jfrog.io`;
if (!CONFIG.apiKey) {
const { hasApiKey } = await prompt([
{
type: "confirm",
name: "hasApiKey",
message: "Do you have an API Key?"
}
]);
if (!hasApiKey) findApiKey();
const { apiKey } = await prompt([
{
type: "input",
name: "apiKey",
message: "Please enter your API Key"
}
]);
CONFIG.apiKey = apiKey;
}
console.log("Writing .npmrc");
const npmrc = await generateNpmrc();
fs.writeFile(".npmrc", npmrc, err => {
if (err) console.err(err);
console.log("Wrote .npmrc!");
});
})();