Skip to content

Commit a83a57a

Browse files
committed
feat(cli): add initial cli file
1 parent aa8a2c7 commit a83a57a

File tree

6 files changed

+965
-57
lines changed

6 files changed

+965
-57
lines changed

package.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
"main": "dist/mosia.umd.js",
1616
"module": "dist/mosia.es5.js",
1717
"typings": "dist/types/mosia.d.ts",
18+
"bin": {
19+
"mosia": "dist/cli.umd.js"
20+
},
1821
"files": [
1922
"dist"
2023
],
@@ -87,6 +90,7 @@
8790
},
8891
"devDependencies": {
8992
"@types/jest": "^22.0.0",
93+
"@types/meow": "^3.6.2",
9094
"@types/node": "^9.3.0",
9195
"all-contributors-cli": "^4.10.1",
9296
"colors": "^1.1.2",
@@ -104,18 +108,28 @@
104108
"rimraf": "^2.6.1",
105109
"rollup": "^0.55.0",
106110
"rollup-plugin-commonjs": "^8.0.2",
111+
"rollup-plugin-copy": "^0.2.3",
107112
"rollup-plugin-node-resolve": "^3.0.0",
108113
"rollup-plugin-sourcemaps": "^0.4.2",
109114
"rollup-plugin-typescript2": "^0.10.0",
110115
"semantic-release": "^12.2.4",
116+
"travis-deploy-once": "^4.3.3",
111117
"ts-jest": "^22.0.0",
112118
"ts-node": "^4.1.0",
113119
"tslint": "^5.8.0",
114120
"tslint-config-prettier": "^1.1.0",
115121
"tslint-config-standard": "^7.0.0",
116122
"typedoc": "^0.9.0",
117123
"typescript": "^2.6.2",
118-
"validate-commit-msg": "^2.12.2",
119-
"travis-deploy-once": "^4.3.3"
124+
"validate-commit-msg": "^2.12.2"
125+
},
126+
"dependencies": {
127+
"chalk": "^2.3.0",
128+
"conf": "^1.4.0",
129+
"core-js": "^2.5.3",
130+
"get-stdin": "^5.0.1",
131+
"meow": "^4.0.0",
132+
"ora": "^1.3.0",
133+
"update-notifier": "^2.3.0"
120134
}
121135
}

rollup.config.ts

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,42 @@
1-
import resolve from 'rollup-plugin-node-resolve'
2-
import commonjs from 'rollup-plugin-commonjs'
3-
import sourceMaps from 'rollup-plugin-sourcemaps'
4-
import camelCase from 'lodash.camelcase'
5-
import typescript from 'rollup-plugin-typescript2'
1+
import resolve from "rollup-plugin-node-resolve"
2+
import commonjs from "rollup-plugin-commonjs"
3+
import sourceMaps from "rollup-plugin-sourcemaps"
4+
import camelCase from "lodash.camelcase"
5+
import typescript from "rollup-plugin-typescript2"
66

7-
const pkg = require('./package.json')
7+
const pkg = require("./package.json")
88

9-
const libraryName = 'mosia'
9+
const libraryName = "mosia"
1010

11-
export default {
12-
input: `src/${libraryName}.ts`,
13-
output: [
14-
{ file: pkg.main, name: camelCase(libraryName), format: 'umd' },
15-
{ file: pkg.module, format: 'es' },
16-
],
17-
sourcemap: true,
18-
// Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash')
19-
external: [],
20-
watch: {
21-
include: 'src/**',
11+
export default [
12+
{
13+
input: `src/cli.js`,
14+
output: { file: "dist/cli.umd.js", format: "umd" },
2215
},
23-
plugins: [
24-
// Compile TypeScript files
25-
typescript(),
26-
// Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs)
27-
commonjs(),
28-
// Allow node_modules resolution, so you can use 'external' to control
29-
// which external modules to include in the bundle
30-
// https://github.com/rollup/rollup-plugin-node-resolve#usage
31-
resolve(),
16+
{
17+
input: `src/${libraryName}.ts`,
18+
output: [
19+
{ file: pkg.main, name: camelCase(libraryName), format: "umd" },
20+
{ file: pkg.module, format: "es" }
21+
],
22+
sourcemap: true,
23+
// Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash')
24+
external: [],
25+
watch: {
26+
include: "src/**"
27+
},
28+
plugins: [
29+
// Compile TypeScript files
30+
typescript(),
31+
// Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs)
32+
commonjs(),
33+
// Allow node_modules resolution, so you can use 'external' to control
34+
// which external modules to include in the bundle
35+
// https://github.com/rollup/rollup-plugin-node-resolve#usage
36+
resolve(),
3237

33-
// Resolve source maps to the original source
34-
sourceMaps(),
35-
],
36-
}
38+
// Resolve source maps to the original source
39+
sourceMaps()
40+
]
41+
}
42+
]

src/cli.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const meow = require('meow')
2+
const Mosia = require('./mosia.umd')
3+
4+
const cli = () => {
5+
return meow(`
6+
Usage
7+
$ mosia <command>
8+
9+
mosia
10+
`)
11+
}
12+
13+
const mosia = new Mosia()
14+
mosia.cmd(cli())

src/mosia.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// Import here Polyfills if needed. Recommended core-js (npm i -D core-js)
2-
// import "core-js/fn/array.find"
3-
// ...
4-
export default class DummyClass {}
1+
import meow from 'meow'
2+
3+
export default class Mosia {
4+
cmd(input: meow.Result) {
5+
console.log(input)
6+
}
7+
}

test/mosia.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import DummyClass from '../src/mosia'
1+
import Mosia from '../src/mosia'
22

33
/**
44
* Dummy test
55
*/
6-
describe('Dummy test', () => {
6+
describe('Mosia test', () => {
77
it('works if true is truthy', () => {
88
expect(true).toBeTruthy()
99
})
1010

1111
it('DummyClass is instantiable', () => {
12-
expect(new DummyClass()).toBeInstanceOf(DummyClass)
12+
expect(new Mosia()).toBeInstanceOf(Mosia)
1313
})
1414
})

0 commit comments

Comments
 (0)