tauri/maskfile.md
Noah Klayman 1d66d00506
chore: improve contributor experience (#1264)
* chore: update install commands in setup scripts

* chore(examples/api): add `tauri` script

* chore(contributing.md): update to match new developments

* fix(scripts/setup): typo

* chore(examples): replace communication with helloworld

* remove deno submodule as it was added on accident

* fix(examples/helloword): add __tauri.js to .gitignore

* fix(examples): helloworld example with `cargo run`, change dev path

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
2021-02-21 08:48:08 -08:00

4.8 KiB

Shorthand Commands

prepare

Setup all stuffs needed for running the examples

git clone --recursive git@github.com:tauri-apps/examples.git \
|| (cd examples && git pull origin dev; cd ..) 		# always prepare up-to-date examples in case it's already available

cargo build
cargo install cargo-web 			# used by example rust/yew

. .scripts/setup.sh
# Setup Environment to execute in the tauri directory.
$CWD = [Environment]::CurrentDirectory
Push-Location $MyInvocation.MyCommand.Path
[Environment]::CurrentDirectory = $PWD
# send git stderr to powershell stdout
$env:GIT_REDIRECT_STDERR = '2>&1'

# if the examples path doesn't exist.
if (-Not (Test-Path $CWD\examples -PathType Any)) {
  Start-Job -ScriptBlock {
    # Setup Environment to execute in the tauri directory.
    $CWD = [Environment]::CurrentDirectory
    Push-Location $MyInvocation.MyCommand.Path
    [Environment]::CurrentDirectory = $PWD

    #clone the examples repo into the examples folder
    git clone --recursive https://github.com/tauri-apps/examples.git $CWD\examples
  } | Receive-Job -AutoRemoveJob -Wait
}

# Enter the examples folder and pull the latest data from origin/dev
cd examples; git pull origin dev; cd ..

# build and install everything Rust related.
cargo build
cargo install cargo-web

. .scripts/setup.ps1

run

tauri-mask-run-example

run example (example)

Run specific example in dev mode

shopt -s globstar

cd examples/**/$example 2>/dev/null \
|| cd examples/**/$example/$example 	# workaround for rust/yew/todomvc/todomvc

case "$PWD" in
*/node/*)
  yarn && yarn tauri:dev
;;
*/rust/*)
  cargo web deploy
  [ $example = `basename $(dirname $PWD)` ] && cd ..

  yarn add tauri@link:../../../cli/tauri.js
  yarn && yarn tauri dev
;;
*)
  echo unknown project $(dirname $example)/$example
;;
esac
param(
  [string] $example_name
)

# Setup Environment to execute in the tauri directory.
$CWD = [Environment]::CurrentDirectory
Push-Location $MyInvocation.MyCommand.Path
[Environment]::CurrentDirectory = $PWD

# get the example paths.
$example_path = Get-ChildItem examples\*\*\$env:example

# if the example path is null get the todomvc path.
if ($example_path -eq $null) {
  $example_path = Get-ChildItem examples\*\*\*\$env:example\$env:example
}

# if the example path is still null get the helloworld example path.
if ($example_path -eq $null) {
  $example_path = Get-ChildItem examples\tauri\*\$env:example
}

# switch on the parent folder name.
switch ($example_path.parent) {
  # if node, run yarn.
  {"vanillajs" -Or "react" -Or "svelte" -Or "vue"} {
    cd $example_path.FullName; yarn; yarn tauri:dev
  }
  # if rust, run cargo web deploy
  "yew" {
    cd $example_path.FullName; cargo web deploy
  }
  # if tauri run the helloworld example from the tauri folder.
  "tauri" {
    cd $CWD/tauri/examples/helloworld/src-tauri; cargo run
  }
  # transpiled are not supported yet.
  "transpiled" {
    Write-Output("Example not supported yet")
  }
}

list

list examples

List all available examples

find examples/*/*/* -maxdepth 0 -type d -not -path '*.git*' \
-exec sh -c 'echo $(basename $(dirname {}))/$(basename {})' \;
# Setup Environment to execute in the tauri directory.
$CWD = [Environment]::CurrentDirectory
Push-Location $MyInvocation.MyCommand.Path
[Environment]::CurrentDirectory = $PWD

# initialize the examples list.
$examples = @()

# get the helloworld example
$examples += Get-ChildItem examples/*/* -Filter helloworld
# get the rest of the examples.
$examples += Get-ChildItem examples/*/* -Directory -Exclude ('src*', 'public', 'test*', 'source', 'lib', 'web', 'dist', 'node_*')

# print out the examples.
foreach($e in $examples) {
  Write-Output("$($e.Name):  $($e.Parent)/$($e.Name)")
}

clean

Remove installed dependencies and reset examples in case something gone wrong

cargo uninstall tauri-bundler
cargo clean

shopt -s globstar
rm -r **/node_modules

cd examples
git checkout -- . 	# discard all unstaged changes
git clean -dfX 		# remove all untracked files & directories
# Setup Environment to execute in the tauri directory.
$CWD = [Environment]::CurrentDirectory
Push-Location $MyInvocation.MyCommand.Path
[Environment]::CurrentDirectory = $PWD

# uninstall the bundler and clean up any artifacts.
cargo uninstall tauri-bundler
cargo clean

# find any node_module folders.
$node_paths = Get-ChildItem -Path examples\ -Filter node_modules -Recurse -ErrorAction SilentlyContinue -Force

if (-Not $node_paths -eq $null) {
# delete all of the node_module folders.
  foreach ($path in $node_paths) {
    $path.Delete()
  }
  # enter the examples folder and remove any changes.
  cd $CWD/examples; git checkout -- .; git clean -dfX
}