Эх сурвалжийг харах

chore(mode) cleanup (#23)

* feat(mode) cleanup

* fix(cli) fix bin entry
Lucas Fernandes Nogueira 6 жил өмнө
parent
commit
9981da93ed

+ 0 - 5
lib/tauri.js

@@ -1,8 +1,3 @@
-<%
-  if (typeof(confName) === 'undefined') {
-    confName = 'quasar.conf.js'
-  }
-%>
 /**
  * THIS FILE IS GENERATED AUTOMATICALLY.
  * DO NOT EDIT.

+ 3 - 6
tauri/bin/tauri-build.js → mode/bin/tauri-build.js

@@ -25,18 +25,15 @@ if (argv.help) {
 
 const appPaths = require('../helpers/app-paths'),
   Runner = require('../runner'),
-  Injector = require('../injector'),
   tauri = new Runner(appPaths),
-  injector = new Injector(appPaths),
   tauriConfig = require('../helpers/tauri-config')({
     ctx: {
       debug: argv.debug
     }
   })
-const {bundle, ...cfg} = tauriConfig.tauri,
-  cfgDir = injector.configDir()
-writeFileSync(path.join(cfgDir, 'config.json'), JSON.stringify(cfg))
-writeFileSync(path.join(cfgDir, 'bundle.json'), JSON.stringify(bundle))
+ 
+require('../generator').generate(tauriConfig.tauri)
+require('../entry').generate(appPaths.tauriDir, tauriConfig, true)
 
 require('../helpers/generator')(tauriConfig)
 tauri.build(tauriConfig)

+ 2 - 6
tauri/bin/tauri-dev.js → mode/bin/tauri-dev.js

@@ -24,9 +24,7 @@ if (argv.help) {
 
 const appPaths = require('../helpers/app-paths'),
   Runner = require('../runner'),
-  Injector = require('../injector'),
   tauri = new Runner(appPaths),
-  injector = new Injector(appPaths),
   tauriConfig = require('../helpers/tauri-config')({
     ctx: {
       debug: true
@@ -36,9 +34,7 @@ const appPaths = require('../helpers/app-paths'),
 const { bundle, ...cfg } = tauriConfig.tauri,
   cfgDir = injector.configDir()
 
-writeFileSync(path.join(cfgDir, 'config.json'), JSON.stringify(cfg))
-writeFileSync(path.join(cfgDir, 'bundle.json'), JSON.stringify(bundle))
-
-require('../helpers/generator')(tauriConfig)
+require('../generator').generate(tauriConfig.tauri)
+require('../entry').generate(appPaths.tauriDir, tauriConfig, true)
 
 tauri.run(tauriConfig)

+ 1 - 2
tauri/bin/tauri-init.js → mode/bin/tauri-init.js

@@ -22,8 +22,7 @@ if (argv.help) {
     process.exit(0)
 }
 
-const Injector = require('../injector'),
-  injector = new Injector(appPaths)
+require('../template').inject(appPaths.tauriDir)
 if (injector.injectTemplate()) {
   log('Tauri template successfully installed')
 }

+ 0 - 0
tauri/bin/tauri.js → mode/bin/tauri.js


+ 5 - 5
tauri/helpers/generator.js → mode/entry.js

@@ -1,13 +1,13 @@
 const compileTemplate = require('lodash.template'),
-  { readFileSync, writeFileSync } = require('fs'),
-  appPaths = require('./app-paths'),
+  { readFileSync, writeFileSync
+  } = require('fs'),
   path = require('path')
 
-module.exports = cfg => {
+module.exports.generate = (outDir, cfg, tauri = false) => {
   const apiTemplate = readFileSync(path.resolve(__dirname, '../../lib/tauri.js'), 'utf-8')
   const apiContent = compileTemplate(apiTemplate)({
     ...cfg,
-    confName: 'tauri.conf.js'
+    confName: `${tauri ? 'tauri' : 'quasar'}.conf.js`
   })
-  writeFileSync(appPaths.resolve.tauri('tauri.js'), apiContent, 'utf-8')
+  writeFileSync(path.join(outDir, 'tauri.js'), apiContent, 'utf-8')
 }

+ 11 - 0
mode/generator.js

@@ -0,0 +1,11 @@
+const 
+  path = require('path'),
+  { writeFileSync } = require('fs')
+
+module.exports.generate = tauriConfig => {
+  const 
+    { bundle, ...cfg } = tauriConfig,
+    outDir = path.resolve(__dirname, '../..')
+  writeFileSync(path.join(outDir, 'config.json'), JSON.stringify(cfg))
+  writeFileSync(path.join(outDir, 'bundle.json'), JSON.stringify(bundle))
+}

+ 0 - 0
tauri/helpers/app-paths.js → mode/helpers/app-paths.js


+ 0 - 0
tauri/helpers/logger.js → mode/helpers/logger.js


+ 0 - 0
tauri/helpers/on-shutdown.js → mode/helpers/on-shutdown.js


+ 0 - 0
tauri/helpers/spawn.js → mode/helpers/spawn.js


+ 0 - 0
tauri/helpers/tauri-config.js → mode/helpers/tauri-config.js


+ 15 - 9
tauri/runner.js → mode/runner.js

@@ -1,16 +1,18 @@
 const
   chokidar = require('chokidar'),
-  debounce = require('lodash.debounce')
+  debounce = require('lodash.debounce'),
+  path = require('path')
 
 const
   { spawn } = require('./helpers/spawn'),
   log = require('./helpers/logger')('app:tauri')
   onShutdown = require('./helpers/on-shutdown'),
-  { readFileSync, writeFileSync } = require('fs-extra')
+  { readFileSync, writeFileSync } = require('fs-extra'),
+  generator = require('./generator')
 
 class TauriRunner {
-  constructor(appPaths) {
-    this.appPaths = appPaths
+  constructor({ modeDir }) {
+    this.modeDir = modeDir
     this.pid = 0
     this.tauriWatcher = null
 
@@ -35,6 +37,8 @@ class TauriRunner {
       this.__whitelistApi(cfg, toml)
     })
 
+    generator.generate(cfg.tauri)
+
     this.url = url
 
     const args = ['--url', url]
@@ -49,9 +53,9 @@ class TauriRunner {
     // Start watching for tauri app changes
     this.tauriWatcher = chokidar
       .watch([
-        this.appPaths.resolve.tauri('src'),
-        this.appPaths.resolve.tauri('Cargo.toml'),
-        this.appPaths.resolve.tauri('build.rs')
+        path.join(this.modeDir, 'src'),
+        path.join(this.modeDir, 'Cargo.toml'),
+        path.join(this.modeDir, 'build.rs')
       ], {
         watchers: {
           chokidar: {
@@ -72,6 +76,8 @@ class TauriRunner {
       this.__whitelistApi(cfg, toml)
     })
 
+    generator.generate(cfg.tauri)
+
     const features = []
     if (cfg.tauri.embeddedServer.active) {
       features.push('embedded-server')
@@ -116,7 +122,7 @@ class TauriRunner {
         cargoArgs.concat(['--']).concat(extraArgs) :
         cargoArgs,
 
-        this.appPaths.tauriDir,
+        this.modeDir,
 
         code => {
           if (code) {
@@ -160,7 +166,7 @@ class TauriRunner {
 
   __manipulateToml(callback) {
     const toml = require('@iarna/toml'),
-      tomlPath = this.appPaths.resolve.tauri('Cargo.toml'),
+      tomlPath = path.join(this.modeDir, 'Cargo.toml'),
       tomlFile = readFileSync(tomlPath),
       tomlContents = toml.parse(tomlFile)
 

+ 29 - 0
mode/template.js

@@ -0,0 +1,29 @@
+const { copySync, renameSync, existsSync, mkdirSync } = require('fs-extra'),
+  path = require('path')
+
+module.exports.inject = injectPath => {
+  if (existsSync(injectPath)) {
+    console.log(`Tauri dir (${injectPath}) not empty.`)
+    return false
+  }
+  mkdirSync(injectPath)
+  copySync(path.resolve(__dirname, '../templates/rust'), injectPath)
+  const files = require('fast-glob').sync(['**/_*'], {
+    cwd: injectPath
+  })
+  for (const rawPath of files) {
+    const targetRelativePath = rawPath.split('/').map(name => {
+      // dotfiles are ignored when published to npm, therefore in templates
+      // we need to use underscore instead (e.g. "_gitignore")
+      if (name.charAt(0) === '_' && name.charAt(1) !== '_') {
+        return `.${name.slice(1)}`
+      }
+      if (name.charAt(0) === '_' && name.charAt(1) === '_') {
+        return `${name.slice(1)}`
+      }
+      return name
+    }).join('/')
+    renameSync(path.join(injectPath, rawPath), path.join(injectPath, targetRelativePath))
+  }
+  return true
+}

+ 1 - 2
package.json

@@ -2,9 +2,8 @@
   "name": "@quasar/tauri",
   "version": "1.0.0-alpha.0",
   "description": "Multi-binding collection of libraries and templates for building Tauri",
-  "main": "tauri/lib.js",
   "bin": {
-    "tauri": "tauri/bin/tauri.js"
+    "tauri": "mode/bin/tauri.js"
   },
   "scripts": {
     "test": "echo \"Error: no test specified\" && exit 1"

+ 0 - 41
tauri/injector.js

@@ -1,41 +0,0 @@
-const { copySync, renameSync, existsSync, mkdirSync } = require('fs-extra'),
-  path = require('path')
-
-class TauriInjector {
-  constructor(appPaths) {
-    this.appPaths = appPaths
-  }
-
-  configDir() {
-    return path.resolve(__dirname, '..')
-  }
-
-  injectTemplate() {
-    if (existsSync(this.appPaths.tauriDir)) {
-      console.log(`Tauri dir (${this.appPaths.tauriDir}) not empty.`)
-      return false
-    }
-    mkdirSync(this.appPaths.tauriDir)
-    copySync(path.resolve(__dirname, '../templates/rust'), this.appPaths.tauriDir)
-    const files = require('fast-glob').sync(['**/_*'], {
-      cwd: this.appPaths.tauriDir
-    })
-    for (const rawPath of files) {
-      const targetRelativePath = rawPath.split('/').map(name => {
-        // dotfiles are ignored when published to npm, therefore in templates
-        // we need to use underscore instead (e.g. "_gitignore")
-        if (name.charAt(0) === '_' && name.charAt(1) !== '_') {
-          return `.${name.slice(1)}`
-        }
-        if (name.charAt(0) === '_' && name.charAt(1) === '_') {
-          return `${name.slice(1)}`
-        }
-        return name
-      }).join('/')
-      renameSync(this.appPaths.resolve.tauri(rawPath), this.appPaths.resolve.tauri(targetRelativePath))
-    }
-    return true
-  }
-}
-
-module.exports = TauriInjector

+ 0 - 9
tauri/lib.js

@@ -1,9 +0,0 @@
-const TauriRunner = require('./runner'),
-  TauriInjector = require('./injector'),
-  path = require('path')
-
-module.exports = {
-  runner: TauriRunner,
-  injector: TauriInjector,
-  apiTemplatePath: path.resolve(__dirname, '../lib/tauri.js')
-}