Skip to content

Commit

Permalink
feat: ✨ improve cli
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgrv committed Sep 16, 2024
1 parent 1da67d1 commit 0a86d99
Show file tree
Hide file tree
Showing 4 changed files with 7,158 additions and 255 deletions.
54 changes: 38 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
<!-- @format -->

# Dev Container Features

This repository contains a collection of features that can be used to enhance the development experience in a [Visual Studio Code Dev Container](https://code.visualstudio.com/docs/remote/containers). The features are organized in separate folders and can be used individually.

## Installation

Run as much as needed:

```sh
npx tomgrv/devcontainer-features -- --all
```

To restrict to stubs:

```sh
npx tomgrv/devcontainer-features -- --stubs
```

To specify features:

```sh
npx tomgrv/devcontainer-features -- gitutils
```

## Features Overview

### GitVersion
Expand All @@ -16,17 +38,17 @@ More information about GitVersion can be found on the [GitVersion GitHub page](h

Configure developpement environnement in one step in conjunction with following packages:

* @commitlint/cli
* @commitlint/config-conventional
* @commitlint/core
* @commitlint/cz-commitlint
* commitizen
* conventional-changelog-cli
* devmoji
* git-precommit-checks
* lint-staged
* prettier
* sort-package-json
- @commitlint/cli
- @commitlint/config-conventional
- @commitlint/core
- @commitlint/cz-commitlint
- commitizen
- conventional-changelog-cli
- devmoji
- git-precommit-checks
- lint-staged
- prettier
- sort-package-json

### GitUtils

Expand All @@ -36,8 +58,8 @@ The following utilities are included: [./src/gitutils/alias.json](./src/gitutils

#### 🖥️ Interactive Utilities

- `git fixup` - Amend the specified commit with current changes and rebase
- `git fixauthor` - Amend commits with specified author and rebase
- `git fixup` - Amend the specified commit with current changes and rebase
- `git fixauthor` - Amend commits with specified author and rebase

#### 🚀 GitFlow

Expand All @@ -47,9 +69,9 @@ Configure developpement environnement in one step with:

Shortcuts are also added to the `git` command to make it easier to use the `git-flow` commands:

- `git beta` is a shortcut for `git flow release start`
- `git hfix` is a shortcut for `git flow hotfix start`
- `git prod` is a shortcut for `git flow release finish` and `git flow hotfix finish`
- `git beta` is a shortcut for `git flow release start`
- `git hfix` is a shortcut for `git flow hotfix start`
- `git prod` is a shortcut for `git flow release finish` and `git flow hotfix finish`

Those shortcuts work in cunjunction with the `gitversion` utility to automatically update the version number of the application.

Expand Down
133 changes: 77 additions & 56 deletions local-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,33 @@
cd $(git rev-parse --show-toplevel) >/dev/null

### Load all features locally installable
features=$(jq -r '.config.local[]' package.json)
features=""
stubs="0"

### Handles arguments
if [ -n "$1" ]; then

case $1 in
--help)
echo "Usage: $0 [--help] [<feature>]"
echo "Usage: $0 [--help|--stubs|--all|<features>]"
exit
;;
--all)
echo "All selected" | npx --yes chalk-cli --stdin green
stubs=1
features=$(jq -r '.config.local[]' package.json)
break;
;;
--stubs)
echo "Stubs selected" | npx --yes chalk-cli --stdin green
stubs=1
;;
--*)
echo "Wrong arguments: See --help" | npx --yes chalk-cli --stdin red
exit
;;
*)
echo "Selected features: $*" | npx --yes chalk-cli --stdin blue
echo "Features selected: $*" | npx --yes chalk-cli --stdin green
features=$*
;;
esac
Expand All @@ -23,74 +39,79 @@ fi
### Stash all changes including untracked files
stash=$(git stash -u && echo true)

### Merge all files from stub folder to root with git merge-file
echo "Merging stubs files" | npx --yes chalk-cli --stdin blue
for file in $(find ./stubs -type f); do

### Get middle part of the path
folder=$(dirname ${file#./stubs/})
if [ "$stubs" -eq "1" ]; then

### Create folder if not exists
mkdir -p $folder
### Merge all files from stub folder to root with git merge-file
echo "Merging stubs files" | npx --yes chalk-cli --stdin blue
for file in $(find ./stubs -type f); do

### Merge file
echo "Merge $folder/$(basename $file)" | npx --yes chalk-cli --stdin yellow
git merge-file -p $file $folder/$(basename $file) ${folder#./}/$(basename $file) >$folder/$(basename $file)
done
### Get middle part of the path
folder=$(dirname ${file#./stubs/})

### Find all file with a trailing slash outside dist folder, make sure they are added to .gitignore and remove the trailing slash
echo "Add files to .gitignore" | npx --yes chalk-cli --stdin blue
for file in $(find . -type f -name "#*" -not -path "./stubs/*" -not -path "./node_modules/*" -not -path "./vendors/*"); do
### Create folder if not exists
mkdir -p $folder

echo "Add $file to .gitignore" | npx --yes chalk-cli --stdin yellow

### Remove trailing # and leading ./#
clean=${file#./#}
### Merge file
echo "Merge $folder/$(basename $file)" | npx --yes chalk-cli --stdin yellow
git merge-file -p $file $folder/$(basename $file) ${folder#./}/$(basename $file) >$folder/$(basename $file)
done

### Add to .gitignore if not already there
grep -qxF $clean .gitignore || echo "$clean" >>.gitignore
### Find all file with a trailing slash outside dist folder, make sure they are added to .gitignore and remove the trailing slash
echo "Add files to .gitignore" | npx --yes chalk-cli --stdin blue
for file in $(find . -type f -name "#*" -not -path "./stubs/*" -not -path "./node_modules/*" -not -path "./vendors/*"); do

### Rename file
mv $file $clean
done
echo "Add $file to .gitignore" | npx --yes chalk-cli --stdin yellow

### Ask eventualy to deploy in container if this is not already the case
if [ "$CODESPACES" != "true" ] && [ "$REMOTE_CONTAINERS" != "true" ]; then
### Remove trailing # and leading ./#
clean=${file#./#}

echo "You are not in a container" | npx --yes chalk-cli --stdin green
### Add to .gitignore if not already there
grep -qxF $clean .gitignore || echo "$clean" >>.gitignore

### Call the install.sh script in all selected features
for feature in $features; do
if [ -f "./src/$feature/install.sh" ]; then
### Run the install.sh script
echo "Running src/$feature/install.sh..." | npx --yes chalk-cli --stdin blue
bash ./src/$feature/install.sh /tmp
else
echo "$feature not found" | npx --yes chalk-cli --stdin red
fi
### Rename file
mv $file $clean
done
fi

### Call the configure.sh script in all selected features
for feature in $features; do
if [ -f "./src/$feature/configure.sh" ]; then
### Run the install.sh script
echo "Running src/$feature/configure.sh..." | npx --yes chalk-cli --stdin blue
bash /tmp/$feature/configure.sh
else
echo "$feature not found" | npx --yes chalk-cli --stdin red
fi
done
else
echo "You are in a container: use devutils as devcontainer features:" | npx --yes chalk-cli --stdin magenta
for feature in $features; do
echo "ghcr.io/tomgrv/devcontainer-features/$feature"
done | npx --yes chalk-cli --stdin magenta
exit
if [ -n "$features" ]; then
### Ask eventualy to deploy in container if this is not already the case
if [ "$CODESPACES" != "true" ] && [ "$REMOTE_CONTAINERS" != "true" ]; then

echo "You are not in a container" | npx --yes chalk-cli --stdin green

### Call the install.sh script in all selected features
for feature in $features; do
if [ -f "./src/$feature/install.sh" ]; then
### Run the install.sh script
echo "Running src/$feature/install.sh..." | npx --yes chalk-cli --stdin blue
bash ./src/$feature/install.sh /tmp
else
echo "$feature not found" | npx --yes chalk-cli --stdin red
fi
done

### Call the configure.sh script in all selected features
for feature in $features; do
if [ -f "./src/$feature/configure.sh" ]; then
### Run the install.sh script
echo "Running src/$feature/configure.sh..." | npx --yes chalk-cli --stdin blue
bash /tmp/$feature/configure.sh
else
echo "$feature not found" | npx --yes chalk-cli --stdin red
fi
done
else
echo "You are in a container: use devutils as devcontainer features:" | npx --yes chalk-cli --stdin magenta
for feature in $features; do
echo "ghcr.io/tomgrv/devcontainer-features/$feature"
done | npx --yes chalk-cli --stdin magenta
exit
fi
fi

### Stage non withespace changes
git ls-files --others --exclude-standard | xargs -I {} bash -c 'if [ -s "{}" ]; then git add "{}"; fi'
git diff -w --no-color | git apply --cached --ignore-whitespace
git diff -w --no-color | git apply --cached --ignore-whitespace --allow-empty
git checkout -- . && git reset && git add .

### Unstash changes
Expand Down
Loading

0 comments on commit 0a86d99

Please sign in to comment.