-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Diwank Singh Tomer <[email protected]>
- Loading branch information
Showing
9 changed files
with
452 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# Include | ||
!/.replrc.js | ||
|
||
# Temp files | ||
/.tmp/**/* | ||
/cjs/.tmp/**/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// .replrc.js | ||
const assert = require("assert"); | ||
const lodash = require("lodash"); | ||
const chalk = require("chalk"); | ||
|
||
// Load module | ||
const { Mauna } = require("./"); | ||
const pkg = require("./package.json"); | ||
|
||
// Get API keys | ||
const { MAUNA_API_KEY, MAUNA_DEVELOPER_ID } = process.env; | ||
|
||
assert(MAUNA_DEVELOPER_ID, "Please set the MAUNA_DEVELOPER_ID environment variable"); | ||
assert(MAUNA_API_KEY, "Please set the MAUNA_API_KEY environment variable"); | ||
|
||
// 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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env node | ||
|
||
const options = require("../.replrc.js"); | ||
const repl = require("local-repl"); | ||
|
||
repl | ||
.start(options) | ||
.catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.