فهرست منبع

chore(cli.js): propagate all commands to cli.rs except `icon` and `deps` (#1604)

Lucas Fernandes Nogueira 4 سال پیش
والد
کامیت
9eccb2af28
2فایلهای تغییر یافته به همراه31 افزوده شده و 51 حذف شده
  1. 31 42
      tooling/cli.js/bin/tauri.js
  2. 0 9
      tooling/cli.js/test/jest/__tests__/tauri.spec.js

+ 31 - 42
tooling/cli.js/bin/tauri.js

@@ -31,32 +31,10 @@ const tauri = async function (command) {
     command = command[0]
   }
 
-  if (rustCliCmds.includes(command)) {
-    const { runOnRustCli } = require('../dist/helpers/rust-cli')
-    if (process.argv && !process.env.test) {
-      process.argv.splice(0, 3)
-    }
-    ;(
-      await runOnRustCli(
-        command,
-        (process.argv || []).filter((v) => v !== '--no-update-notifier')
-      )
-    ).promise.then(() => {
-      if (command === 'init' && !process.argv.some((arg) => arg === '--ci')) {
-        const {
-          installDependencies
-        } = require('../dist/api/dependency-manager')
-        return installDependencies()
-      }
-    })
-  } else {
-    if (
-      !command ||
-      command === '-h' ||
-      command === '--help' ||
-      command === 'help'
-    ) {
-      console.log(`
+  const help =
+    !command || command === '-h' || command === '--help' || command === 'help'
+  if (help) {
+    console.log(`
         ${chalk.cyan(`
       :oooodddoooo;     ;oddl,      ,ol,       ,oc,  ,ldoooooooc,    ,oc,
       ';;;cxOx:;;;'    ;xOxxko'     :kx:       lkd,  :xkl;;;;:okx:   lkd,
@@ -77,25 +55,36 @@ ${chalk.yellow('Options')}
 --version, -v  Displays the Tauri CLI version
       `)
 
-      process.exit(0)
-      // eslint-disable-next-line no-unreachable
-      return false // do this for node consumers and tests
+    process.exit(0)
+    // eslint-disable-next-line no-unreachable
+    return false // do this for node consumers and tests
+  } else if (command === '-v' || command === '--version') {
+    console.log(`${pkg.version}`)
+    return false // do this for node consumers and tests
+  } else if (cmds.includes(command)) {
+    if (process.argv && !process.env.test) {
+      process.argv.splice(2, 1)
     }
-
-    if (command === '-v' || command === '--version') {
-      console.log(`${pkg.version}`)
-      return false // do this for node consumers and tests
+    console.log(`[tauri]: running ${command}`)
+    require(`./tauri-${command}`)
+  } else {
+    const { runOnRustCli } = require('../dist/helpers/rust-cli')
+    if (process.argv && !process.env.test) {
+      process.argv.splice(0, 3)
     }
-
-    if (cmds.includes(command)) {
-      if (process.argv && !process.env.test) {
-        process.argv.splice(2, 1)
+    ;(
+      await runOnRustCli(
+        command,
+        (process.argv || []).filter((v) => v !== '--no-update-notifier')
+      )
+    ).promise.then(() => {
+      if (command === 'init' && !process.argv.some((arg) => arg === '--ci')) {
+        const {
+          installDependencies
+        } = require('../dist/api/dependency-manager')
+        return installDependencies()
       }
-      console.log(`[tauri]: running ${command}`)
-      require(`./tauri-${command}`)
-    } else {
-      console.log(`Invalid command ${command}. Use one of ${cmds.join(', ')}.`)
-    }
+    })
   }
 }
 

+ 0 - 9
tooling/cli.js/test/jest/__tests__/tauri.spec.js

@@ -17,15 +17,6 @@ describe('[CLI] cli.js', () => {
     jest.clearAllMocks()
   })
 
-  it('will not run an unavailable command', async () => {
-    jest.spyOn(console, 'log')
-    tauri('foo')
-    expect(console.log.mock.calls[0][0].split('.')[0]).toBe(
-      'Invalid command foo'
-    )
-    jest.clearAllMocks()
-  })
-
   it('gets you help', async () => {
     jest.spyOn(console, 'log')
     const tests = ['--help', '-h', 'invalid command']