🎉 Initial commit

This commit is contained in:
Tiana Lemesle 2021-08-24 11:01:08 +02:00
commit 40053b9c5c
7 changed files with 3185 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.idea
node_modules

3
config.json Normal file
View File

@ -0,0 +1,3 @@
{
"url": "https://example.com"
}

1
index.js Normal file
View File

@ -0,0 +1 @@
document.querySelector('h1').textContent += ' running inside Tauri !';

14
init.js Normal file
View File

@ -0,0 +1,14 @@
const
{ spawn } = require('child_process'),
{
name,
description
} = require('./package.json');
spawn('./node_modules/.bin/tauri', [
'init',
'--ci',
`--app-name=${name}`,
'--dist-dir=../dist',
'--dev-path=../dist',
`--window-title=${description}`
]);

18
package.json Normal file
View File

@ -0,0 +1,18 @@
{
"name": "tauri-webview-template",
"description": "Tauri Webview Template",
"version": "0.1.0",
"main": "index.js",
"repository": "https://git.kaki87.net/KaKi87/tauri-webview-template",
"author": "KaKi87 <KaKi87@pm.me>",
"license": "MIT",
"devDependencies": {
"@tauri-apps/cli": "^1.0.0-beta.10",
"outdent": "^0.8.0"
},
"scripts": {
"init-app": "node ./init.js",
"start-app": "node ./run.js && ./node_modules/.bin/tauri dev",
"build-app": "node ./run.js && ./node_modules/.bin/tauri build"
}
}

31
run.js Normal file
View File

@ -0,0 +1,31 @@
const
{ mkdir, writeFile, readFile } = require('fs'),
{ join: joinPath } = require('path'),
outdent = require('outdent'),
{ description } = require('./package.json'),
{ url } = require('./config.json'),
mainRustFilePath = joinPath(__dirname, './src-tauri/src/main.rs');
(async () => {
try { await new Promise(resolve => mkdir(joinPath(__dirname, './dist'), resolve)); } catch {}
await new Promise(resolve => writeFile(joinPath(__dirname, './dist/index.html'), outdent `
<!DOCTYPE html>
<html lang="en">
<head>
<title>${description}</title>
<script>
window.location.replace('${url}');
</script>
</head>
</html>
`, 'utf8', resolve));
const mainRustFileContent = await new Promise(resolve => readFile(mainRustFilePath, 'utf8', (_, data) => resolve(data)));
await new Promise(resolve => writeFile(
mainRustFilePath,
mainRustFileContent.replace(
/^(\s+tauri::Builder::default\(\)).*$/m,
'$1.on_page_load(|window, _| { window.eval(include_str!("../../index.js")); })'
),
'utf8',
resolve
));
})();

3116
yarn.lock Normal file

File diff suppressed because it is too large Load Diff