Skip to content

Instantly share code, notes, and snippets.

@autonome
Last active September 26, 2024 08:27
Show Gist options
  • Save autonome/b6919ce7114c2b0d9832b1ec793811a5 to your computer and use it in GitHub Desktop.
Save autonome/b6919ce7114c2b0d9832b1ec793811a5 to your computer and use it in GitHub Desktop.
helpers in my .zshrc for working on https://github.com/web-platform-dx/web-features
# list features, sorted by size
alias wf="wc -l features/*.dist | sort"
# list spec-generated draft, sorted by size
alias wfd="wc -l features/draft/spec/*.dist | sort"
# count number of keys in a feature
#
# pass a feature path (from repo root)
# eg:
#
# $ wfcount features/draft/spec/html.yml
function wfcount {
grep -ihr '^ - ' "$1" | wc -l
}
# build and test all (test runs dist)
alias wft="npm run test"
# build
alias wfb="npm run dist"
# build only one feature
alias wff="npm run dist -- "
# filter completed features and spec drafts by name
alias wfsn="wc -l features/*.dist features/draft/spec/*.dist | grep "
# filter groups
function wfsg {
grep -ilr "$1" groups/
}
# search completed features and spec drafts
function wfs {
grep -ilr "$1" features/
}
# grep -ilr "^name:.*API" features
# search open prs on github
function wfspr {
gh pr list -S '"$1"'
}
# pass a feature file path and rebuild it when it changes
# eg:
#
# $ wfw features/xhr.yml
#
function wfw {
fswatch -o "$1" | xargs -n1 -I {} npm run dist -- "$1"
}
# scaffold a new feature .yml from a provided identifier
#
# eg:
#
# $ wfscaffold OffscreenCanvasRenderingContext2D
function wfscaffold {
featureId="$1"
dirPath="features/"
featurePath="${dirPath}${featureId}.yml"
distPath="${featurePath}.dist"
echo $featurePath
# remove any existing file
rm "${featurePath}"
#git checkout main -b $featureId
cat > "${featurePath}"<< EOF
name: ${featureId}
description: ${featureId} does stuff
spec: https://example.com
#caniuse:
#group:
#status:
# compute_from:
compat_features:
EOF
grep -hir --include=\*.yml "${featureId}" features | grep '^ - ' >> "${featurePath}"
#git add "${featurePath}"
touch "${distPath}"
#git add "${distPath}"
# try generating (don't do before git add, b/c could fail)
npm run dist -- "${featurePath}"
}
# rename feature+dist files and git add/remove
# move/rename features and their .dist files around quickly and easily
#
# the params are paths to .yml file names, from repo root:
#
# oldPath is path to a file currently checked in to the repo
#
# newpath is where you want the oldPath file moved to, in git
#
# for example, move a feature back into draft:
#
# wfmv features/oldfile.yml features/draft/newfile.yml
#
function wfmv {
oldPath="$1"
newPath="$2"
echo $oldPath $newPath
mv "${oldPath}" "${newPath}"
git add "${newPath}"
git rm "${oldPath}"
mv "${oldPath}".dist "${newPath}".dist
git add "${newPath}".dist
git rm "${oldPath}".dist
}
# create pr for newly drafted feature
# TODO: finish
function wfcpr {
# current branch name
CB=$(git branch --show-current)
gh pr create \
-R web-platform-dx/web-features \
-B main -d -t "Add ${CB}" \
-H $(gh api user -q ".login"):$CB
#-H $(gh api user -q ".login"):$CB \
#--dry-run
}
# old, not really using now
function wfdraft {
featureId="$1"
featureFilename="${featureId}".yml
featuresPath=features/
draftsPath="${featuresPath}"draft/spec/
draftFeaturePath="${draftsPath}""${featureFilename}"
featurePath="${featuresPath}""${featureFilename}"
echo $featurePath
#git checkout main
#git pull upstream main
#git checkout main -b $featureId
# Move the .yml and .yml.dist files to the features directory.
mv "${draftFeaturePath}" "${featurePath}"
git add "${featurePath}"
git rm "${draftFeaturePath}"
mv "${draftFeaturePath}".dist "${featurePath}".dist
git add "${featurePath}".dist
git rm "${draftFeaturePath}".dist
# Remove the draft_date field from the .yml file.
sed -i '' '1d' "${featurePath}"
# TODO: commit, push and PR w/ template?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment