Pārlūkot izejas kodu

feat(tauri.js) automatically detect current tauri version for template (#697)

Lucas Fernandes Nogueira 5 gadi atpakaļ
vecāks
revīzija
ce8a7b8f6a

+ 1 - 0
cli/tauri.js/package.json

@@ -102,6 +102,7 @@
     "lockfile-lint": "4.3.6",
     "promise": "8.1.0",
     "raw-loader": "4.0.1",
+    "toml-loader": "^1.0.0",
     "ts-loader": "7.0.5",
     "typescript": "3.9.5",
     "webpack": "4.43.0",

+ 10 - 1
cli/tauri.js/src/template/index.ts

@@ -1,3 +1,4 @@
+import { CargoManifest } from './../types/cargo'
 import { existsSync, removeSync, writeFileSync } from 'fs-extra'
 import { join, normalize, resolve } from 'path'
 import { TauriConfig } from 'types'
@@ -69,9 +70,17 @@ Run \`tauri init --force template\` to overwrite.`)
       : join('..', tauriPath, 'tauri') // we received a relative path
     return resolvedPath.replace(/\\/g, '/')
   }
+
+  const resolveCurrentTauriVersion = (): string => {
+    // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-member-access
+    const tauriManifest = require('../../../../tauri/Cargo.toml') as CargoManifest
+    const version = tauriManifest.package.version
+    return version.substring(0, version.lastIndexOf('.'))
+  }
+
   const tauriDep = tauriPath
     ? `{ path = "${resolveTauriPath(tauriPath)}" }`
-    : null
+    : `{ version = "${resolveCurrentTauriVersion()}" }`
 
   try {
     removeSync(dir)

+ 5 - 2
cli/tauri.js/webpack.config.js

@@ -14,8 +14,7 @@ module.exports = {
   mode: process.env.NODE_ENV || 'development',
   devtool: 'source-map',
   module: {
-    rules: [
-      {
+    rules: [{
         test: /\.tsx?$/,
         use: 'ts-loader',
         exclude: /node_modules/
@@ -23,6 +22,10 @@ module.exports = {
       {
         test: /templates[\\/](tauri|mutation-observer)\.js/,
         use: 'raw-loader'
+      },
+      {
+        test: /\.toml?$/,
+        use: 'toml-loader'
       }
     ]
   },

+ 12 - 0
cli/tauri.js/yarn.lock

@@ -8938,6 +8938,18 @@ to-regex@^3.0.1, to-regex@^3.0.2:
     regex-not "^1.0.2"
     safe-regex "^1.1.0"
 
+toml-loader@^1.0.0:
+  version "1.0.0"
+  resolved "https://registry.yarnpkg.com/toml-loader/-/toml-loader-1.0.0.tgz#05249b9294b623601148260caa480b22a653a19a"
+  integrity sha1-BSSbkpS2I2ARSCYMqkgLIqZToZo=
+  dependencies:
+    toml "^2.2.2"
+
+toml@^2.2.2:
+  version "2.3.6"
+  resolved "https://registry.yarnpkg.com/toml/-/toml-2.3.6.tgz#25b0866483a9722474895559088b436fd11f861b"
+  integrity sha512-gVweAectJU3ebq//Ferr2JUY4WKSDe5N+z0FvjDncLGyHmIDoxgY/2Ie4qfEIDm4IS7OA6Rmdm7pdEEdMcV/xQ==
+
 tough-cookie@^2.3.3, tough-cookie@~2.5.0:
   version "2.5.0"
   resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.5.0.tgz#cd9fb2a0aa1d5a12b473bd9fb96fa3dcff65ade2"