Adding in Dominator recipe (#1912)

* Adding in Dominator recipe

* Running prettifier

* add dominator to cta tests

* update postinit message

* add `src-tauri` as a worksapce member

Co-authored-by: amrbashir <48618675+amrbashir@users.noreply.github.com>
This commit is contained in:
Pauan 2021-08-02 04:47:31 +02:00 committed by GitHub
parent d22da650ef
commit af3cc7d7f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 232 additions and 3 deletions

View File

@ -26,7 +26,7 @@ jobs:
matrix:
node: ["14", "16"]
manager: ["6", "7"]
recipe: ["vanillajs", "cra", "vite", "ngcli", "svelte"]
recipe: ["vanillajs", "cra", "vite", "ngcli", "svelte", "dominator"]
exclude:
- node: "16"
manager: "6"

View File

@ -11,6 +11,7 @@ import { cra } from './recipes/react'
import { vuecli } from './recipes/vue-cli'
import { vanillajs } from './recipes/vanilla'
import { vite } from './recipes/vite'
import { dominator } from './recipes/dominator'
import { ngcli } from './recipes/ng-cli'
import { svelte } from './recipes/svelte'
import { install, checkPackageManager } from './dependency-manager'
@ -116,7 +117,15 @@ interface Responses {
installApi: boolean
}
const allRecipes: Recipe[] = [vanillajs, cra, vite, vuecli, ngcli, svelte]
const allRecipes: Recipe[] = [
vanillajs,
cra,
vite,
vuecli,
ngcli,
svelte,
dominator
]
const recipeByShortName = (name: string): Recipe | undefined =>
allRecipes.find((r) => r.shortName === name)

View File

@ -0,0 +1,58 @@
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import { join } from 'path'
// @ts-expect-error
import scaffe from 'scaffe'
import { Recipe } from '../types/recipe'
export const dominator: Recipe = {
descriptiveName: {
name: 'Dominator (https://crates.io/crates/dominator/)',
value: 'Dominator'
},
shortName: 'dominator',
configUpdate: ({ cfg, packageManager }) => ({
...cfg,
distDir: `../dist`,
devPath: 'http://localhost:10001/',
beforeDevCommand: `${packageManager === 'yarn' ? 'yarn' : 'npm run'} start`,
beforeBuildCommand: `${
packageManager === 'yarn' ? 'yarn' : 'npm run'
} build`
}),
extraNpmDevDependencies: [],
extraNpmDependencies: [],
preInit: async ({ cwd, cfg }) => {
const { appName, windowTitle } = cfg
const templateDir = join(__dirname, '../src/templates/dominator')
const variables = {
name: appName,
title: windowTitle
}
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
await scaffe.generate(templateDir, join(cwd, appName), {
overwrite: true,
variables
})
} catch (err) {
console.log(err)
}
},
postInit: async ({ cfg, packageManager }) => {
console.log(`
Your installation completed.
$ cd ${cfg.appName}.
$ ${packageManager} install
$ ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri ${
packageManager === 'npm' ? '--' : ''
} dev
`)
return await Promise.resolve()
}
}

View File

@ -0,0 +1,5 @@
node_modules
/dist/js
/target
/wasm-pack.log
/yarn-error.log

View File

@ -0,0 +1,23 @@
[package]
name = "<%= name %>"
version = "1.0.0"
categories = ["wasm"]
edition = "2018"
[profile.release]
lto = true
[lib]
crate-type = ["cdylib"]
[workspace]
members = [
"src-tauri"
]
[dependencies]
console_error_panic_hook = "0.1.6"
dominator = "0.5.17"
wasm-bindgen = "0.2.74"
futures-signals = "0.3.20"
once_cell = "1.7.2"

View File

@ -0,0 +1,16 @@
{
"name": "<%= name %>",
"scripts": {
"tauri": "tauri",
"build": "rimraf dist/js && rollup --config",
"start": "rimraf dist/js && rollup --config --watch"
},
"devDependencies": {
"@wasm-tool/rollup-plugin-rust": "^1.0.6",
"rimraf": "^3.0.2",
"rollup": "^2.50.2",
"rollup-plugin-livereload": "^2.0.0",
"rollup-plugin-serve": "^1.1.0",
"rollup-plugin-terser": "^7.0.2"
}
}

View File

@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title><%= title %></title>
<style>
html,
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
</style>
</head>
<body>
<h1><%= name %></h1>
<script src="js/index.js"></script>
</body>
</html>

View File

@ -0,0 +1,32 @@
import rust from '@wasm-tool/rollup-plugin-rust'
import serve from 'rollup-plugin-serve'
import livereload from 'rollup-plugin-livereload'
import { terser } from 'rollup-plugin-terser'
const is_watch = !!process.env.ROLLUP_WATCH
export default {
input: {
index: './Cargo.toml'
},
output: {
dir: 'dist/js',
format: 'iife',
sourcemap: true
},
plugins: [
rust({
serverPath: 'js/'
}),
is_watch &&
serve({
contentBase: 'dist',
open: true
}),
is_watch && livereload('dist'),
!is_watch && terser()
]
}

View File

@ -0,0 +1,52 @@
use wasm_bindgen::prelude::*;
use std::sync::Arc;
use once_cell::sync::Lazy;
use futures_signals::signal::{Mutable, SignalExt};
use dominator::{Dom, html, class, clone, events};
#[derive(Debug)]
struct App {
message: Mutable<String>,
}
impl App {
fn new() -> Arc<Self> {
Arc::new(Self {
message: Mutable::new("Hello world!".to_string()),
})
}
fn render(app: Arc<Self>) -> Dom {
// Define CSS styles
static CLASS: Lazy<String> = Lazy::new(|| class! {
.style("font-size", "20px")
.style("color", "hsl(110, 70%, 70%)")
});
// Create the DOM nodes
html!("div", {
.class(&*CLASS)
.text_signal(app.message.signal_cloned().map(|message| {
format!("Message: {}", message)
}))
.event(clone!(app => move |_: events::Click| {
app.message.set_neq("Goodbye!".to_string());
}))
})
}
}
#[wasm_bindgen(start)]
pub fn main_js() -> Result<(), JsValue> {
#[cfg(debug_assertions)]
console_error_panic_hook::set_once();
let app = App::new();
dominator::append_dom(&dominator::body(), App::render(app));
Ok(())
}

View File

@ -15,7 +15,7 @@ const api = path.resolve('../api/')
const manager = process.env.TAURI_RUN_MANAGER ?? 'npm'
const recipes = process.env.TAURI_RECIPE
? [process.env.TAURI_RECIPE]
: ['vanillajs', 'cra', 'vite', 'vuecli', 'ngcli', 'svelte']
: ['vanillajs', 'cra', 'vite', 'vuecli', 'ngcli', 'svelte', 'dominator']
const timeoutLong = 900000
const timeoutLittleLonger = 930000
const logOut = false ? 'inherit' : 'pipe'
@ -149,6 +149,13 @@ describe('CTA', () => {
tauri: 'tauri'
})
)
},
dominator: () => {
expect(packageFileOutput['scripts']).toEqual(
expect.objectContaining({
tauri: 'tauri'
})
)
}
}