Skip to content

Commit

Permalink
feat(cli): init
Browse files Browse the repository at this point in the history
  • Loading branch information
WittBulter committed Feb 20, 2019
1 parent 65ff08e commit 87008df
Show file tree
Hide file tree
Showing 4 changed files with 704 additions and 0 deletions.
31 changes: 31 additions & 0 deletions cli/bin/koa2-ts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env node
const fetch = require('node-fetch')
const path = require('path')
const fs = require('fs')
const download = require('download-git-repo')
const args = process.argv.slice(2)
const exit = (text: string): void => {
console.log(text)
process.exit(1)
}

// check args
if (!args || !args.length) exit('you need to specify the project name.')
const to = path.join(process.cwd(), args[0])

// check project name
if (fs.existsSync(to)) exit(`${args[0]} already exists, abort.`)

const install = async(): Promise<void> => {
const response = await fetch('https://raw.githubusercontent.com/just-fine/vue-coffee/master/package.json')
const pkg = await response.text()
const { version } = JSON.parse(pkg)
const url = `https://github.com/DhyanaChina/koa-custom-response/archive/v${version}.zip`
console.log('install...')
download(url, to, { clone: false }, (err: any) => {
if (err) return exit(`${err}. abort.`)
console.log('installed successfully.')
})
}

install().then().catch(e => console.log(e))
21 changes: 21 additions & 0 deletions cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "cli",
"version": "0.1.0",
"main": "./dist/bin/koa2-ts.js",
"bin": {
"koa2-ts": "./dist/bin/koa2-ts.js"
},
"scripts": {
"start": "tsc -w --skipLibCheck -p ./",
"build": "tsc -p ./"
},
"author": "WittBulter ([email protected])",
"license": "MIT",
"dependencies": {
"download-git-repo": "^1.1.0",
"node-fetch": "^2.3.0"
},
"devDependencies": {
"@types/node": "^11.9.4"
}
}
19 changes: 19 additions & 0 deletions cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compileOnSave": false,
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": false,
"outDir": "./dist",
"lib": ["es7"],
"rootDir": "./"
},
"include": [
"./bin/*"
],
"exclude": [
"node_modules"
]
}
Loading

0 comments on commit 87008df

Please sign in to comment.