Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
feat(scripts): update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
r17x committed Jun 29, 2022
1 parent 8e2e94c commit df16caa
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 28 deletions.
1 change: 0 additions & 1 deletion .local/bin/npmsearch

This file was deleted.

66 changes: 41 additions & 25 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
## Scripts (personal)

### Migrate to `ReScript`
```shell
for file in src/**/*.re;
do
CURRENT_FILE=$(pwd)/$file; NEW_FILE="$(echo $CURRENT_FILE | sed -e "s/\.re/\.res/g")"; ./node_modules/.bin/bsc -format $CURRENT_FILE > $NEW_FILE; rm -f $CURRENT_FILE;
done;
```
### Benchmark `zsh configuration`

```shell
for i in $(seq 1 10); do /usr/bin/time zsh -i -c exit; done

0.46 real 0.31 user 0.13 sys
0.45 real 0.31 user 0.12 sys
0.43 real 0.30 user 0.12 sys
0.44 real 0.31 user 0.12 sys
0.44 real 0.30 user 0.12 sys
0.43 real 0.30 user 0.11 sys
0.43 real 0.30 user 0.11 sys
0.43 real 0.30 user 0.12 sys
0.43 real 0.30 user 0.12 sys
0.44 real 0.30 user 0.12 sys
```
# Development and Build Scripts

## Updating Icons

The `src/svg` directory is the single source of truth for svgs. They should not already be optimized and can be the original svg export straight out of an svg editor. A build step before releasing will optimize the source svgs (remove comments, reduce the size, etc) and ensure they'll work within `ion-icon`.


## Build Locally

After an svg has been updated, added or deleted from the `src/svg` directory, run:

npm run build

The build command will optimize all of the icons and generate the files to be distributed. After the build command, all of the optimized svgs are saved in `dist/ionicons/svg`. Additionally the `dist` directory contains the distribution files for the `ion-icon` web component.


## Svg Symbols Cheatsheet

After a build, a new `www/cheatsheet.html` file will be created. This version uses svg symbols rather than `ion-icon`.


## ion-icon Component Preview

To see the `ion-icon` component in action, run:

npm start


## Release Steps

npm run release.prepare

The release script will ask what version to use. After the script completes, double check the `www/cheatsheet.html` to ensure everything is good to go.

Next, update `CHANGELOG.md`, then commit and push your changes Github.

Next run:

npm run release

Triple check the version number is correct, and choose which tag this should be released as. If it's a pre-release, it should be `dev`.
Empty file modified scripts/bin/clean_docker
100644 → 100755
Empty file.
4 changes: 3 additions & 1 deletion scripts/bin/clean_nodejs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/env bash
#!/usr/bin/env bash

`rm -rf $HOME/{w0,me,evl}/**/node_modules`
command_exists notify-send && notify-send \
"[CLEAN]: remove ALL node_modules in {w0,me,evl}"
command_exists osascript && osascript -e \
'display notification "hello world!" with title "Clean" subtitle "clean node_modules in ~/{w0,me,evl}"'
23 changes: 23 additions & 0 deletions scripts/bin/export-brew
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

command -v brew &>/dev/null || {
echo "Error [1]: brew not installed in your sysyem"
exit 1
}

BREW_DUMP="$HOME/.Brewfile"
BREW_DUMP_BACKUPS="$HOME/.Brewfile_bak"
BREW_DUMP_BACKUP="$BREW_DUMP_BACKUPS/$(date +%F).Brewfile"

if [[ -f "$BREW_DUMP" ]]; then
command mkdir -p "$BREW_DUMP_BACKUPS" && cp "$BREW_DUMP" "$BREW_DUMP_BACKUP"
if [[ -f "$BREW_DUMP_BACKUP" ]]; then
rm -f "$BREW_DUMP" && brew bundle dump --file="$BREW_DUMP"
fi
fi

# sync with git

yadm add $BREW_DUMP &&
yadm commit -m "chore(OSX): update brewfile" &&
yadm push origin master
2 changes: 1 addition & 1 deletion scripts/bin/gpg-restart
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ gpgconf --kill gpg-agent
killall gpg-agent
gpg-agent --homedir "${GNUPGHOME:-$HOME/.gnupg}" \
--daemon \
--pinentry-program "$(brew --prefix)/bin/pinentry-mac"
--pinentry-program /Users/r17/.nix-profile/Applications/pinentry-mac.app/Contents/MacOS/pinentry-mac
13 changes: 13 additions & 0 deletions scripts/bin/media-convert
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# MP4 - 1080p
# ffmpeg -i input.mov -preset slow -codec:a libfdk_aac -b:a 128k -codec:v libx264 -pix_fmt yuv420p -b:v 4500k -minrate 4500k -maxrate 9000k -bufsize 9000k -vf scale=-1:1080 output.mp4

# MP4 - 720p
# ffmpeg -i input.mov -preset slow -codec:a libfdk_aac -b:a 128k -codec:v libx264 -pix_fmt yuv420p -b:v 2500k -minrate 1500k -maxrate 4000k -bufsize 5000k -vf scale=-1:720 output.mp4

# MP4 - 480p
# ffmpeg -i input.mov -preset slow -codec:a libfdk_aac -b:a 128k -codec:v libx264 -pix_fmt yuv420p -b:v 1000k -minrate 500k -maxrate 2000k -bufsize 2000k -vf scale=854:480 output.mp4

# MP4 - 360p
# ffmpeg -i input.mov -preset slow -codec:a libfdk_aac -b:a 128k -codec:v libx264 -pix_fmt yuv420p -b:v 750k -minrate 400k -maxrate 1000k -bufsize 1500k -vf scale=-1:360 output.mp4
144 changes: 144 additions & 0 deletions scripts/bin/npmsearch
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#!/usr/bin/env zsh

declare -a args
declare -a packages
declare savedev=0
declare global=0

declare -a colors
colors[red]=$(tput setaf 1)
colors[green]=$(tput setaf 2)
colors[reset]=$(tput sgr0)

usage() {
LESS=-FEXR less <<-HELP
npmsearch [options] [packages]
searches npm for packages
-r, --remove
list and remove packages from package.json
to increase the amount of packages shown when searching, try:
npm config set searchlimit 40
HELP
}

color() {
local color="$1"; shift
printf '%s' "${colors[$color]}"
printf '%s\n' "$@"
printf '%s' "${colors[reset]}"
}

err() { color red "$@" >&2; return 1; }

die() {
(( $# > 0 )) && err "$@"
exit 1
}

has() {
local v c
if [[ $1 = '-v' ]]; then
v=1
shift
fi
for c; do c="${c%% *}"
if ! command -v "$c" &> /dev/null; then
(( v > 0 )) && err "$c not found"
return 1
fi
done
}

select_from() {
local cmd='command -v'
for a; do
case "$a" in
-c) cmd="$2"; shift 2 ;;
esac
done
for c; do
if $cmd "${c%% *}" &> /dev/null; then
echo "$c"
return 0
fi
done
return 1
}

has -v fzf npm || die

fzf() {
command fzf --inline-info --ansi --reverse +s --no-hscroll "$@"
}

if [[ $1 = '-h' || $1 = '--help' ]]; then
usage
exit
fi

if [[ $1 = '-r' || $1 = '--remove' ]]; then
shift
mapfile -t rm < <(
jq -r '{dependencies, devDependencies} | .[] | keys | .[]' package.json |
fzf -m --cycle -e --reverse --query="$*")
(( ${#rm} > 0 )) && $(select_from 'yarn remove' 'npm uninstall') "${rm[@]}"
die
fi

printf '%ssearching...%s\r' "${colors[green]}" "${colors[reset]}"
search=$(npm search --json "$*") || exit

search=$(jq -r '.[] | "\(.name)|\(.version)|\(.description)"' <<< "$search" | column -t -s'|')

mapfile -t packages < <(fzf --multi \
--bind='ctrl-x:toggle-preview' \
--expect='ctrl-g,ctrl-d,enter,ctrl-v,esc' \
--preview-window='hidden:down' \
--preview="npm -s --json view {1} | jq -C \"del(.users, .time, .versions)\"" \
--header='C-d saves as devDependency, C-g installs globally, C-v for specific version, C-x for more info, ' \
<<< "$search")

key="${packages[0]}"
case "${key,,}" in
esc) die ;;
ctrl-d) savedev=1 ;;
ctrl-g) global=1 ;;
ctrl-v)
package="${packages[1]%% *}"
mapfile -t version < <(
npm -s --json view "$package" |
jq -r '.versions[]' | # label with .dist-tags?
fzf --header="choose version for $package | C-d saves as devDependency" --tac --expect='ctrl-d,esc')
key="${version[0]}"
case "${key,,}" in
esc) die ;;
ctrl-d) savedev=1 ;;
esac
packages=( "${package}@${version[1]}" )
;;
esac

(( ${#packages[@]} > 0 )) || die 'no packages to install'

if (( ${#packages[@]} > 1 )); then
packages=( "${packages[@]:1}" )
packages=( "${packages[@]%% *}" )
fi

printf '%sinstalling...%s\r' "${colors[green]}" "${colors[reset]}"
if (( global > 0 )); then
npm install -g "${args[@]}" "${packages[@]}"
elif has yarn; then
(( savedev > 0 )) && args+=( -D )
yarn add "${args[@]}" "${packages[@]}"
else
if (( savedev > 0 )); then
args+=( -D )
else
args+=( -S )
fi
npm i "${args[@]}" "${packages[@]}"
fi
1 change: 1 addition & 0 deletions scripts/bin/test-perf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/usr/bin/env sh
13 changes: 13 additions & 0 deletions scripts/bin/toggle-nvim-lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash


FILE="~/.config/nvim/init.lua"

if [[ -f ~/.config/nvim/init.lua ]]; then
mv ~/.config/nvim/__init.vim ~/.config/nvim/init.vim
mv ~/.config/nvim/init.lua ~/.config/nvim/__init.lua
else
echo 11
mv ~/.config/nvim/init.vim ~/.config/nvim/__init.vim
mv ~/.config/nvim/__init.lua ~/.config/nvim/init.lua
fi

0 comments on commit df16caa

Please sign in to comment.