Skip to content

Commit 17f86a9

Browse files
committed
feat: upgrade cli
1 parent 2fd5858 commit 17f86a9

File tree

4 files changed

+137
-86
lines changed

4 files changed

+137
-86
lines changed

cli/bin/koa2-ts.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env node
2-
const fetch = require('node-fetch')
3-
const path = require('path')
42
const fs = require('fs')
3+
const path = require('path')
4+
const execa = require('execa')
5+
const fetch = require('node-fetch')
56
const download = require('download-git-repo')
67
const args = process.argv.slice(2)
78
const exit = (text: string): void => {
@@ -11,19 +12,38 @@ const exit = (text: string): void => {
1112

1213
// check args
1314
if (!args || !args.length) exit('you need to specify the project name.')
14-
const to = path.join(process.cwd(), args[0])
15+
const projectName = args[0].startsWith('--name=') ? args[0].split('--name=')[1] : null
16+
if (!projectName) exit('param not valid. \ne.g.: --name=hello_world')
17+
const to = path.join(process.cwd(), projectName)
1518

1619
// check project name
17-
if (fs.existsSync(to)) exit(`${args[0]} already exists, abort.`)
20+
if (fs.existsSync(to)) exit(`${projectName} already exists, abort.`)
21+
22+
23+
const installAfter = (project: string, dir: string): void => {
24+
execa.shellSync(`cd ${dir} && rm -rf .netlify .travis.yml .github now.json README_CN.md cli`)
25+
const packagePath = path.join(to, 'package.json')
26+
if (!fs.existsSync(packagePath)) return
27+
let pkg = JSON.parse(fs.readFileSync(packagePath, 'utf-8'))
28+
pkg = Object.assign(pkg, {
29+
name: project,
30+
version: '0.0.1',
31+
})
32+
delete pkg.author
33+
delete pkg.bugs
34+
delete pkg.description
35+
fs.writeFileSync(packagePath, JSON.stringify(pkg, null, '\t'))
36+
}
1837

1938
const install = async(): Promise<void> => {
20-
const response = await fetch('https://raw.githubusercontent.com/just-fine/vue-coffee/master/package.json')
39+
const response = await fetch('https://raw.githubusercontent.com/DhyanaChina/koa2-typescript-guide/master/package.json')
2140
const pkg = await response.text()
2241
const { version } = JSON.parse(pkg)
23-
const url = `https://github.com/DhyanaChina/koa-custom-response/archive/v${version}.zip`
24-
console.log('install...')
42+
const url = `direct:https://github.com/DhyanaChina/koa2-typescript-guide/archive/v${version}.zip`
43+
console.log(`latest version: v${version}, install...`)
2544
download(url, to, { clone: false }, (err: any) => {
2645
if (err) return exit(`${err}. abort.`)
46+
installAfter(projectName, to)
2747
console.log('installed successfully.')
2848
})
2949
}

cli/package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
{
2-
"name": "cli",
3-
"version": "0.1.0",
2+
"name": "koa2-ts",
3+
"version": "0.1.2",
44
"main": "./dist/bin/koa2-ts.js",
55
"bin": {
66
"koa2-ts": "./dist/bin/koa2-ts.js"
77
},
88
"scripts": {
99
"start": "tsc -w --skipLibCheck -p ./",
10-
"build": "tsc -p ./"
10+
"build": "tsc --skipLibCheck -p ./"
1111
},
12+
"files": [
13+
"dist",
14+
"tsconfig.json"
15+
],
1216
"author": "WittBulter ([email protected])",
1317
"license": "MIT",
1418
"dependencies": {
1519
"download-git-repo": "^1.1.0",
20+
"execa": "^1.0.0",
1621
"node-fetch": "^2.3.0"
1722
},
1823
"devDependencies": {

cli/yarn.lock

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ create-error-class@^3.0.0:
111111
dependencies:
112112
capture-stack-trace "^1.0.0"
113113

114+
cross-spawn@^6.0.0:
115+
version "6.0.5"
116+
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"
117+
integrity sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==
118+
dependencies:
119+
nice-try "^1.0.4"
120+
path-key "^2.0.1"
121+
semver "^5.5.0"
122+
shebang-command "^1.2.0"
123+
which "^1.2.9"
124+
114125
decompress-tar@^4.0.0, decompress-tar@^4.1.0, decompress-tar@^4.1.1:
115126
version "4.1.1"
116127
resolved "https://registry.yarnpkg.com/decompress-tar/-/decompress-tar-4.1.1.tgz#718cbd3fcb16209716e70a26b84e7ba4592e5af1"
@@ -191,7 +202,7 @@ duplexer3@^0.1.4:
191202
resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2"
192203
integrity sha1-7gHdHKwO08vH/b6jfcCo8c4ALOI=
193204

194-
end-of-stream@^1.0.0:
205+
end-of-stream@^1.0.0, end-of-stream@^1.1.0:
195206
version "1.4.1"
196207
resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.1.tgz#ed29634d19baba463b6ce6b80a37213eab71ec43"
197208
integrity sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==
@@ -203,6 +214,19 @@ escape-string-regexp@^1.0.2:
203214
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
204215
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
205216

217+
execa@^1.0.0:
218+
version "1.0.0"
219+
resolved "https://registry.yarnpkg.com/execa/-/execa-1.0.0.tgz#c6236a5bb4df6d6f15e88e7f017798216749ddd8"
220+
integrity sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==
221+
dependencies:
222+
cross-spawn "^6.0.0"
223+
get-stream "^4.0.0"
224+
is-stream "^1.1.0"
225+
npm-run-path "^2.0.0"
226+
p-finally "^1.0.0"
227+
signal-exit "^3.0.0"
228+
strip-eof "^1.0.0"
229+
206230
fd-slicer@~1.1.0:
207231
version "1.1.0"
208232
resolved "https://registry.yarnpkg.com/fd-slicer/-/fd-slicer-1.1.0.tgz#25c7c89cb1f9077f8891bbe61d8f390eae256f1e"
@@ -269,6 +293,13 @@ get-stream@^3.0.0:
269293
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14"
270294
integrity sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=
271295

296+
get-stream@^4.0.0:
297+
version "4.1.0"
298+
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-4.1.0.tgz#c1b255575f3dc21d59bfc79cd3d2b46b1c3a54b5"
299+
integrity sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==
300+
dependencies:
301+
pump "^3.0.0"
302+
272303
git-clone@^0.1.0:
273304
version "0.1.0"
274305
resolved "https://registry.yarnpkg.com/git-clone/-/git-clone-0.1.0.tgz#0d76163778093aef7f1c30238f2a9ef3f07a2eb9"
@@ -378,6 +409,11 @@ isarray@~1.0.0:
378409
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
379410
integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=
380411

412+
isexe@^2.0.0:
413+
version "2.0.0"
414+
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
415+
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=
416+
381417
isurl@^1.0.0-alpha5:
382418
version "1.0.0"
383419
resolved "https://registry.yarnpkg.com/isurl/-/isurl-1.0.0.tgz#b27f4f49f3cdaa3ea44a0a5b7f3462e6edc39d67"
@@ -417,6 +453,11 @@ mkdirp@^0.5.1:
417453
dependencies:
418454
minimist "0.0.8"
419455

456+
nice-try@^1.0.4:
457+
version "1.0.5"
458+
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
459+
integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==
460+
420461
node-fetch@^2.3.0:
421462
version "2.3.0"
422463
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.3.0.tgz#1a1d940bbfb916a1d3e0219f037e89e71f8c5fa5"
@@ -430,23 +471,40 @@ npm-conf@^1.1.0:
430471
config-chain "^1.1.11"
431472
pify "^3.0.0"
432473

474+
npm-run-path@^2.0.0:
475+
version "2.0.2"
476+
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-2.0.2.tgz#35a9232dfa35d7067b4cb2ddf2357b1871536c5f"
477+
integrity sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=
478+
dependencies:
479+
path-key "^2.0.0"
480+
433481
object-assign@^4.0.1:
434482
version "4.1.1"
435483
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
436484
integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=
437485

438-
once@^1.3.0, once@^1.4.0:
486+
once@^1.3.0, once@^1.3.1, once@^1.4.0:
439487
version "1.4.0"
440488
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
441489
integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E=
442490
dependencies:
443491
wrappy "1"
444492

493+
p-finally@^1.0.0:
494+
version "1.0.0"
495+
resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae"
496+
integrity sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=
497+
445498
path-is-absolute@^1.0.0:
446499
version "1.0.1"
447500
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
448501
integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18=
449502

503+
path-key@^2.0.0, path-key@^2.0.1:
504+
version "2.0.1"
505+
resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40"
506+
integrity sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=
507+
450508
pend@~1.2.0:
451509
version "1.2.0"
452510
resolved "https://registry.yarnpkg.com/pend/-/pend-1.2.0.tgz#7a57eb550a6783f9115331fcf4663d5c8e007a50"
@@ -489,6 +547,14 @@ proto-list@~1.2.1:
489547
resolved "https://registry.yarnpkg.com/proto-list/-/proto-list-1.2.4.tgz#212d5bfe1318306a420f6402b8e26ff39647a849"
490548
integrity sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk=
491549

550+
pump@^3.0.0:
551+
version "3.0.0"
552+
resolved "https://registry.yarnpkg.com/pump/-/pump-3.0.0.tgz#b4a2116815bde2f4e1ea602354e8c75565107a64"
553+
integrity sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==
554+
dependencies:
555+
end-of-stream "^1.1.0"
556+
once "^1.3.1"
557+
492558
readable-stream@^2.3.0, readable-stream@^2.3.5:
493559
version "2.3.6"
494560
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.6.tgz#b11c27d88b8ff1fbe070643cf94b0c79ae1b0aaf"
@@ -521,6 +587,28 @@ seek-bzip@^1.0.5:
521587
dependencies:
522588
commander "~2.8.1"
523589

590+
semver@^5.5.0:
591+
version "5.6.0"
592+
resolved "https://registry.yarnpkg.com/semver/-/semver-5.6.0.tgz#7e74256fbaa49c75aa7c7a205cc22799cac80004"
593+
integrity sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==
594+
595+
shebang-command@^1.2.0:
596+
version "1.2.0"
597+
resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea"
598+
integrity sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=
599+
dependencies:
600+
shebang-regex "^1.0.0"
601+
602+
shebang-regex@^1.0.0:
603+
version "1.0.0"
604+
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"
605+
integrity sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=
606+
607+
signal-exit@^3.0.0:
608+
version "3.0.2"
609+
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
610+
integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=
611+
524612
string_decoder@~1.1.1:
525613
version "1.1.1"
526614
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8"
@@ -535,6 +623,11 @@ strip-dirs@^2.0.0:
535623
dependencies:
536624
is-natural-number "^4.0.1"
537625

626+
strip-eof@^1.0.0:
627+
version "1.0.0"
628+
resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf"
629+
integrity sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=
630+
538631
strip-outer@^1.0.0:
539632
version "1.0.1"
540633
resolved "https://registry.yarnpkg.com/strip-outer/-/strip-outer-1.0.1.tgz#b2fd2abf6604b9d1e6013057195df836b8a9d631"
@@ -614,6 +707,13 @@ util-deprecate@~1.0.1:
614707
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
615708
integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=
616709

710+
which@^1.2.9:
711+
version "1.3.1"
712+
resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a"
713+
integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==
714+
dependencies:
715+
isexe "^2.0.0"
716+
617717
wrappy@1:
618718
version "1.0.2"
619719
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"

code-of-conduct.md

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)