Skip to content

Commit 87008df

Browse files
committed
feat(cli): init
1 parent 65ff08e commit 87008df

File tree

4 files changed

+704
-0
lines changed

4 files changed

+704
-0
lines changed

cli/bin/koa2-ts.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env node
2+
const fetch = require('node-fetch')
3+
const path = require('path')
4+
const fs = require('fs')
5+
const download = require('download-git-repo')
6+
const args = process.argv.slice(2)
7+
const exit = (text: string): void => {
8+
console.log(text)
9+
process.exit(1)
10+
}
11+
12+
// check args
13+
if (!args || !args.length) exit('you need to specify the project name.')
14+
const to = path.join(process.cwd(), args[0])
15+
16+
// check project name
17+
if (fs.existsSync(to)) exit(`${args[0]} already exists, abort.`)
18+
19+
const install = async(): Promise<void> => {
20+
const response = await fetch('https://raw.githubusercontent.com/just-fine/vue-coffee/master/package.json')
21+
const pkg = await response.text()
22+
const { version } = JSON.parse(pkg)
23+
const url = `https://github.com/DhyanaChina/koa-custom-response/archive/v${version}.zip`
24+
console.log('install...')
25+
download(url, to, { clone: false }, (err: any) => {
26+
if (err) return exit(`${err}. abort.`)
27+
console.log('installed successfully.')
28+
})
29+
}
30+
31+
install().then().catch(e => console.log(e))

cli/package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "cli",
3+
"version": "0.1.0",
4+
"main": "./dist/bin/koa2-ts.js",
5+
"bin": {
6+
"koa2-ts": "./dist/bin/koa2-ts.js"
7+
},
8+
"scripts": {
9+
"start": "tsc -w --skipLibCheck -p ./",
10+
"build": "tsc -p ./"
11+
},
12+
"author": "WittBulter ([email protected])",
13+
"license": "MIT",
14+
"dependencies": {
15+
"download-git-repo": "^1.1.0",
16+
"node-fetch": "^2.3.0"
17+
},
18+
"devDependencies": {
19+
"@types/node": "^11.9.4"
20+
}
21+
}

cli/tsconfig.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compileOnSave": false,
3+
"compilerOptions": {
4+
"module": "commonjs",
5+
"noImplicitAny": true,
6+
"removeComments": true,
7+
"preserveConstEnums": true,
8+
"sourceMap": false,
9+
"outDir": "./dist",
10+
"lib": ["es7"],
11+
"rootDir": "./"
12+
},
13+
"include": [
14+
"./bin/*"
15+
],
16+
"exclude": [
17+
"node_modules"
18+
]
19+
}

0 commit comments

Comments
 (0)