-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.replrc.js
90 lines (70 loc) · 2.12 KB
/
.replrc.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
83
84
85
86
87
88
89
90
// .replrc.js
const lodash = require("lodash");
const chalk = require("chalk");
// Load module
const { Mauna } = require("./");
const { ensureEnv } = require("./cjs/utils/ensureEnv");
const pkg = require("./package.json");
// Get API keys
ensureEnv("MAUNA_DEVELOPER_ID", 1);
ensureEnv("MAUNA_API_KEY", 1);
const { MAUNA_API_KEY, MAUNA_DEVELOPER_ID } = process.env;
// Create client
const client = new Mauna({
apiKey: MAUNA_API_KEY,
developerId: MAUNA_DEVELOPER_ID
});
// Context
const clientPromise = client.initialize()
.then(c => (console.clear(), c));
const apiPromise = clientPromise.then(c => c.api);
const context = {
lodash,
MAUNA_API_KEY,
MAUNA_DEVELOPER_ID,
Mauna,
pkg,
// Authorize and return client
client: clientPromise,
api: apiPromise
};
// Theme
const theme = {
heading: chalk.bold.yellow,
link: chalk.underline.cyanBright,
normal: chalk.white,
code: chalk.greenBright,
logo: chalk.bgYellowBright.black,
codeTemplate: chalk.greenBright.italic.dim,
};
// Banner
const logo = theme.logo(`
• ┌────────────────────────────────────┐ •
• │ |\\\\/| /\\\\ |_| |\\\\| /\\\\ /\\\\ | │ •
• └────────────────────────────────────┘ •
`);
const title = theme.heading(`Welcome to ${theme.logo(" Mauna ")} SDK playground!`);
const instructions = theme.normal(`To try out an api, simply run:`);
const code_sample = theme.code(
`await api.${theme.codeTemplate("<api_name>")}({ ${theme.codeTemplate("<api_params>")} })`
);
const docs = theme.normal(
`You can see the list of APIs at ${theme.link("https://github.com/mauna-ai/sdk#readme")}`
);
const varsInfo = chalk.dim("Globals: " + theme.code(Object.keys(context).join(", ")));
const banner = `
${logo}
${title}
${instructions} ${code_sample}
${docs}
${varsInfo}
`;
const prompt = (context, pkg) => chalk`{dim ${pkg.name} ${pkg.version} > }`;
// REPL Config
console.log(chalk`{cyan.bold Logging you in...}`);
module.exports = {
banner,
prompt,
context,
enableAwait: true
};