zhangyuhan 3 жил өмнө
parent
commit
73e135c588

+ 6 - 1
.eslintrc

@@ -2,5 +2,10 @@
   "extends": [
     "oclif",
     "oclif-typescript"
-  ]
+  ],
+  "rules": {
+    "@typescript-eslint/no-require-imports": "off",
+    "@typescript-eslint/dot-notation": "off",
+    "object-curly-spacing": "off"
+  }
 }

+ 4 - 4
src/commands/hello/index.ts

@@ -1,4 +1,4 @@
-import {Command, Flags} from '@oclif/core'
+import { Command, Flags } from '@oclif/core'
 
 export default class Hello extends Command {
   static description = 'Say hello'
@@ -10,13 +10,13 @@ hello friend from oclif! (./src/commands/hello/index.ts)
   ]
 
   static flags = {
-    from: Flags.string({char: 'f', description: 'Whom is saying hello', required: true}),
+    from: Flags.string({ char: 'f', description: 'Whom is saying hello', required: true }),
   }
 
-  static args = [{name: 'person', description: 'Person to say hello to', required: true}]
+  static args = [{ name: 'person', description: 'Person to say hello to', required: true }]
 
   async run(): Promise<void> {
-    const {args, flags} = await this.parse(Hello)
+    const { args, flags } = await this.parse(Hello)
 
     this.log(`hello ${args.person} from ${flags.from}! (./src/commands/hello/index.ts)`)
   }

+ 1 - 1
src/commands/hello/world.ts

@@ -1,4 +1,4 @@
-import {Command} from '@oclif/core'
+import { Command } from '@oclif/core'
 
 export default class World extends Command {
   static description = 'Say hello world'

+ 18 - 17
src/commands/init/index.ts

@@ -1,13 +1,12 @@
-import {Command, Flags} from '@oclif/core'
-import {Templates} from "../../global"
-import DownloadRemoteProjectTemplate, { FormatParams} from '@jianyu/dl-template'
+import { Command, Flags } from '@oclif/core'
+import DownloadRemoteProjectTemplate, { FormatParams } from '@jianyu/dl-template'
+import { Templates } from '../../global'
 const path = require('path')
 
 declare global {
   var TEMPLATES: Templates
 }
 
-
 export default class Init extends Command {
   static description = '初始化项目'
 
@@ -21,15 +20,15 @@ export default class Init extends Command {
     from: Flags.string({ char: 'f', description: '指定拉取模版的名称', required: true }),
   }
 
-  static args = [{name: 'dir', description: '目录名,同时用于项目名', required: true}]
+  static args = [{ name: 'dir', description: '目录名,同时用于项目名', required: true }]
 
   async run(): Promise<void> {
-    const {args, flags} = await this.parse(Init)
+    const { args, flags } = await this.parse(Init)
     const TemplateNames = Object.keys(TEMPLATES)
     const canNext = TemplateNames.includes(flags.from)
 
     if (!canNext) {
-      this.error( `没有找到对应的模版配置, 可用的模版为 [${TemplateNames.join(',')}]`)
+      this.error(`没有找到对应的模版配置, 可用的模版为 [${TemplateNames.join(',')}]`)
     }
 
     const { repo, assets, title } = TEMPLATES[flags.from]
@@ -41,27 +40,29 @@ export default class Init extends Command {
       getTransformLinks: (params: FormatParams) => {
         let url = ''
         switch (params.type) {
-          case 'gitlab-jh': {
-            url = `http://192.168.3.207:20080/${params.group}/${params.name}/-/archive/${params.checkout}/${params.name}-${params.checkout}.zip`
-            if (params.path) {
-              url += `?path=${params.path}`
-            }
-            break
+        case 'gitlab-jh': {
+          url = `http://192.168.3.207:20080/${params.group}/${params.name}/-/archive/${params.checkout}/${params.name}-${params.checkout}.zip`
+          if (params.path) {
+            url += `?path=${params.path}`
           }
+
+          break
         }
+        }
+
         return url
-      }
+      },
     })
 
     await dl.get({
       repository: repo,
       remoteFolder: assets,
-      destinationFolder: destinationFolder
+      destinationFolder,
     }).then(() => {
       this.log(`🎉 初始化 ${flags.from} ${title}项目模版创建成功`)
-      this.log(`👉 使用下面这些命令开始项目:`)
+      this.log('👉 使用下面这些命令开始项目:')
       this.log(`$ cd ${args.dir}`)
-      this.log(`$ yarn`)
+      this.log('$ yarn')
     })
   }
 }

+ 8 - 5
src/global.d.ts

@@ -1,12 +1,15 @@
 export interface RepoTemplate {
-  title: string,
-  'git-server': string,
-  repo: string,
-  branch?: string,
+  title: string
+  'git-server': string
+  repo: string
+  branch?: string
   assets?: string
 }
 
-export type Templates = {
+export interface Templates {
   [propName: string]: RepoTemplate
 }
 
+declare global {
+  var TEMPLATES: Templates
+}

+ 1 - 1
src/index.ts

@@ -1,3 +1,3 @@
 import './global'
 
-export {run} from '@oclif/core'
+export { run } from '@oclif/core'

+ 1 - 1
test/commands/hello/index.test.ts

@@ -1,4 +1,4 @@
-import {expect, test} from '@oclif/test'
+import { expect, test } from '@oclif/test'
 
 describe('hello', () => {
   test

+ 1 - 1
test/commands/hello/world.test.ts

@@ -1,4 +1,4 @@
-import {expect, test} from '@oclif/test'
+import { expect, test } from '@oclif/test'
 
 describe('hello world', () => {
   test

+ 1 - 1
test/commands/init.test.ts

@@ -1,4 +1,4 @@
-import {expect, test} from '@oclif/test'
+import { expect, test } from '@oclif/test'
 
 describe('init', () => {
   test