Skip to content

Commit 932285b

Browse files
WIP - added spectacle cli
1 parent 020ca06 commit 932285b

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

bin/args.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const yargs = require('yargs');
2+
const fs = require('fs');
3+
4+
// Validate and normalize.
5+
const validate = parser => {
6+
const { argv } = parser;
7+
const { mdx } = argv;
8+
9+
return Promise.resolve().then(() =>
10+
new Promise((resolve, reject) => {
11+
fs.readFile(mdx, (err, data) => {
12+
if (err) {
13+
reject(err);
14+
} else {
15+
resolve(data);
16+
}
17+
});
18+
}).then(buf => buf.toString('utf8'))
19+
);
20+
};
21+
22+
const args = () =>
23+
yargs
24+
.usage(`Usage: spectacle -m <file>`)
25+
26+
// MDX File
27+
.option('mdx', {
28+
alias: 'm',
29+
describe: 'Path to mdx file from which a presentation will be generated.',
30+
default: 'slides.mdx',
31+
required: false,
32+
type: 'string'
33+
})
34+
35+
// Logistical
36+
.help()
37+
.alias('help', 'h')
38+
.version()
39+
.alias('version', 'v')
40+
.strict();
41+
42+
module.exports = {
43+
parse: () => validate(args())
44+
};

bin/cli.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env node
2+
3+
const parse = require('./args').parse;
4+
5+
const main = () =>
6+
Promise.resolve()
7+
// Parse arguments.
8+
.then(parse)
9+
.then(out => {
10+
console.log(out);
11+
})
12+
.catch(err => {
13+
// Try to get full stack, then full string if not.
14+
console.error(err.stack || err.toString());
15+
16+
process.exit(1);
17+
});
18+
19+
if (require.main === module) {
20+
main();
21+
}

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
"test": "jest --verbose",
1818
"check": ""
1919
},
20+
"bin": {
21+
"spectacle": "./bin/cli.js"
22+
},
2023
"author": "",
2124
"license": "MIT",
2225
"repository": {

0 commit comments

Comments
 (0)