mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-20 00:52:41 +03:00
b93bded180
* feat(cli) init tauri mode Signed-off-by: Daniel Thompson-Yvetot <denjell@quasar.dev> * feat(cli:init) add force & logging flags, full JSDoc Signed-off-by: Daniel Thompson-Yvetot <denjell@quasar.dev> * feat(cli:init) remove console.log Signed-off-by: Daniel Thompson-Yvetot <denjell@quasar.dev> * feat(cli:dev) get rust compile to finish Signed-off-by: Daniel Thompson-Yvetot <denjell@quasar.dev> * feat(cli:build) get rust compile to finish Signed-off-by: Daniel Thompson-Yvetot <denjell@quasar.dev> * feat(cli) set template with current working defaults Signed-off-by: Daniel Thompson-Yvetot <denjell@quasar.dev> * chore(version) bump Signed-off-by: Daniel Thompson-Yvetot <denjell@quasar.dev> * fix(typo) Signed-off-by: Daniel Thompson-Yvetot <denjell@quasar.dev> * fix(template): missing name warning Signed-off-by: Daniel Thompson-Yvetot <denjell@quasar.dev> * fix(bundler): correct repository link Signed-off-by: Daniel Thompson-Yvetot <denjell@quasar.dev> * feat(lib|cli) read config from tauriDir * chore(cli) remove console.log statement * fix(embedded-server) JS content type * feat(template): add rust2018 flag * feat(cli): cleanup
92 lines
2.8 KiB
JavaScript
92 lines
2.8 KiB
JavaScript
const { copySync, renameSync, existsSync, mkdirSync, removeSync } = require('fs-extra'),
|
|
{ resolve, join, normalize } = require('path'),
|
|
logger = require('./helpers/logger'),
|
|
log = logger('app:tauri', 'green'),
|
|
warn = logger('app:tauri (template)', 'red')
|
|
|
|
const injectConfFile = (injectPath, force, logging) => {
|
|
const dir = normalize(join(injectPath, '..'))
|
|
const path = join(dir, 'tauri.conf.js')
|
|
if (existsSync(path) && force !== 'conf' && force !== 'all') {
|
|
warn(`tauri.conf.js found in ${path}
|
|
Run \`tauri init --force conf\` to overwrite.`)
|
|
if (!force) return false
|
|
} else {
|
|
try {
|
|
removeSync(path)
|
|
copySync(resolve(__dirname, '../templates/conf/tauri.conf.js'), path)
|
|
} catch (e) {
|
|
if (logging) console.log(e)
|
|
return false
|
|
} finally {
|
|
if (logging) log('Successfully wrote tauri.conf.js')
|
|
}
|
|
}
|
|
}
|
|
|
|
const injectTemplate = (injectPath, force, logging) => {
|
|
if (existsSync(injectPath) && force !== 'template' && force !== 'all') {
|
|
warn(`Tauri dir (${injectPath}) not empty.
|
|
Run \`tauri init --force template\` to overwrite.`)
|
|
if (!force) return false
|
|
}
|
|
try {
|
|
removeSync(injectPath)
|
|
mkdirSync(injectPath)
|
|
copySync(resolve(__dirname, '../templates/rust'), injectPath)
|
|
} catch (e) {
|
|
if (logging) console.log(e)
|
|
return false
|
|
}
|
|
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('/')
|
|
try {
|
|
renameSync(join(injectPath, rawPath), join(injectPath, targetRelativePath))
|
|
} catch (e) {
|
|
if (logging) console.log(e)
|
|
return false
|
|
} finally {
|
|
if (logging) log('Successfully wrote tauri template files')
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {string} injectPath
|
|
* @param {string} type ['conf'|'template'|'all']
|
|
* @param {string|boolean} [force=false] - One of[false|'conf'|'template'|'all']
|
|
* @param {boolean} [logging=false]
|
|
* @returns {boolean}
|
|
*/
|
|
const inject = (injectPath, type, force = false, logging = false) => {
|
|
if (typeof type !== 'string' || typeof injectPath !== 'string') {
|
|
warn('- internal error. Required params missing.')
|
|
return false
|
|
}
|
|
if (type === 'conf' || type === 'all') {
|
|
injectConfFile(injectPath, force, logging)
|
|
}
|
|
if (type === 'template' || type === 'all') {
|
|
injectTemplate(injectPath, force, logging)
|
|
}
|
|
return true
|
|
}
|
|
|
|
module.exports = {
|
|
inject
|
|
}
|