Skip to content

Commit df760a9

Browse files
mschinissivakumar-kailasam
authored andcommitted
feat(cli): Adds index cli
1 parent 6ba25bd commit df760a9

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "algolia-index-update-scripts",
3-
"version": "0.1.0",
4-
"description": "This project reindexes algolia with the latest API documentation.",
3+
"version": "1.0.0",
4+
"description": "This project reindexes algolia with the latest API & Guides documentation.",
55
"main": "index.js",
66
"scripts": {
7-
"seed:api": "node ./build/api.js",
87
"build": "webpack",
9-
"start": "yarn run build && yarn run seed",
8+
"cli": "node ./build/index.js",
9+
"start": "yarn run build && yarn run cli",
1010
"test": ""
1111
},
1212
"repository": {
@@ -24,6 +24,7 @@
2424
"babel-plugin-transform-object-rest-spread": "^6.26.0",
2525
"bluebird": "^3.5.1",
2626
"chalk": "^2.2.0",
27+
"commander": "^2.17.1",
2728
"dotenv": "^4.0.0",
2829
"file-system": "^2.2.2",
2930
"json-loader": "^0.5.7",

src/index.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Dependencies
2+
import program from 'commander';
3+
import packageJson from '../package.json';
4+
// Library
5+
import { run as runGuides } from './guides';
6+
import { run as runApi } from './api';
7+
8+
9+
program
10+
.version(packageJson.version, '-v, --version')
11+
.description(packageJson.description)
12+
.option('-p, --project <project>', 'Project name. Accepts "api" or "guides"');
13+
14+
program.on('--help', function() {
15+
console.log(`
16+
Examples:
17+
$ yarn start -p api
18+
$ yarn start -p guides
19+
`);
20+
});
21+
22+
program.parse(process.argv);
23+
24+
function cli() {
25+
switch (program.project) {
26+
case 'guides':
27+
return runGuides();
28+
case 'api':
29+
return runApi();
30+
default:
31+
throw new Error('Invalid --project property');
32+
}
33+
}
34+
35+
cli();

webpack.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ const path = require('path');
22

33
module.exports = {
44
entry: {
5-
api: './src/api.js'
5+
index: './src/index.js',
6+
api: './src/api.js',
7+
guides: './src/guides.js'
68
},
79
output: {
810
path: path.resolve(__dirname, 'build'),

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,10 @@ combined-stream@^1.0.5, combined-stream@~1.0.5:
906906
dependencies:
907907
delayed-stream "~1.0.0"
908908

909+
commander@^2.17.1:
910+
version "2.17.1"
911+
resolved "https://registry.yarnpkg.com/commander/-/commander-2.17.1.tgz#bd77ab7de6de94205ceacc72f1716d29f20a77bf"
912+
909913
commondir@^1.0.1:
910914
version "1.0.1"
911915
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"

0 commit comments

Comments
 (0)