chore(mode) cleanup (#23)

* feat(mode) cleanup

* fix(cli) fix bin entry
This commit is contained in:
Lucas Fernandes Nogueira 2019-08-21 18:35:52 -03:00 committed by nothingismagick
parent 9fb1c017a3
commit 9981da93ed
17 changed files with 67 additions and 85 deletions

View File

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

View File

@ -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)

View File

@ -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)

View File

@ -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')
}

View File

@ -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
mode/generator.js Normal file
View File

@ -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))
}

View File

@ -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
mode/template.js Normal file
View File

@ -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
}

View File

@ -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"

View File

@ -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

View File

@ -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')
}