Skip to content

Commit

Permalink
Merge pull request #1161 from assemblee-virtuelle/next
Browse files Browse the repository at this point in the history
Release v0.6.0
  • Loading branch information
srosset81 authored Mar 19, 2024
2 parents aeee7f7 + 061c278 commit 4da9a60
Show file tree
Hide file tree
Showing 479 changed files with 36,731 additions and 18,766 deletions.
36 changes: 36 additions & 0 deletions .git-hooks/post-index-change
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# Catch cases where the work dir changed after a git command.
# In that cases, run ./scripts/on-workdir-changed.sh


function in_rebase {
git_dir=$(git rev-parse --git-dir)
# Check if git_dir/rebase-merge or /rebase_apply exist.
# Then return the result
return $([ -d "$git_dir/rebase-merge" ] || [ -d "$git_dir/rebase-apply" ])
}

ROOT_DIR=$(git rev-parse --show-toplevel)
cd "$ROOT_DIR"

# If in rebase, this hook is called multiple times.
# Skip here and wait for post-rewrite to have been called.
if in_rebase; then
exit 0
fi


# Get first argument. If it is 1, this indicates, working dir files have changed.
if [ "$1" = 1 ] ; then
./scripts/on-workdir-changed.sh
fi









14 changes: 14 additions & 0 deletions .git-hooks/post-rewrite
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# Catch cases where the work dir changed after a git rebase.
# In that cases, run ./scripts/on-workdir-changed.sh


# If coming from a rewrite-rebase ($1 == rebase), run on-workdir-changed.
if [ "$1" = "rebase" ] ; then
# cd to root directory
ROOT_DIR=$(git rev-parse --show-toplevel)
cd "$ROOT_DIR"

./scripts/on-workdir-changed.sh
fi
69 changes: 13 additions & 56 deletions .git-hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,77 +3,34 @@
# This script runs the linter and prettier for staged files
# in the middleware and frontend packages.


# Skip, if flag is set.
if [ "$SKIP_PRECOMMIT_CHECKS" = true ] || [ "$SKIP_PRECOMMIT_CHECKS" = 1 ] ; then
echo "=== Skipping pre-commit prettier run ==="
exit 0
fi

# cd to root directory.
ROOT_DIR=$(git rev-parse --show-toplevel)
cd "$ROOT_DIR"


# Select staged files.
FILES="$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g')"
FILES="$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g' | xargs -r realpath | sed 's/.*/"&"/')"
[ -z "$FILES" ] && echo "=== Nothing to do ===" && exit 0

## Run scripts

echo "======================"
echo "=== Running linter ==="
echo "======================"

MIDDLEWARE_FILES="$(echo "$FILES" | grep -E "src/middleware" | xargs -r realpath)"
FRONTEND_FILES="$(echo "$FILES" | grep -E "src/frontend" | xargs -r realpath)"

LINT_FILE_TYPES="js|jsx|ts|tsx"
LINT_MIDDLEWARE_FILES=$(echo "$MIDDLEWARE_FILES" | grep -E "\.($LINT_FILE_TYPES)$")
LINT_FRONTEND_FILES=$(echo "$FRONTEND_FILES" | grep -E "\.($LINT_FILE_TYPES)$")

# Function to evaluate the linter results
function evaluate_linter_results {
if [ $? == 1 ]; then
echo "================================================================="
echo "The linter found some errors. Please fix them before committing."
echo "You can skip pre-commit checks by setting \$SKIP_PRECOMMIT_CHECKS"
echo "================================================================="
exit 1
elif [ $? -ge 2 ]; then
echo "==============================================================================="
echo "Something went wrong running the linter. Have you bootstrapped the project yet?"
echo "You can skip pre-commit checks by setting \$SKIP_PRECOMMIT_CHECKS"
echo "==============================================================================="
exit 1
fi
}

cd "$ROOT_DIR"/src/middleware
yarn run lint-files $LINT_MIDDLEWARE_FILES
evaluate_linter_results

cd "$ROOT_DIR"/src/frontend
yarn run lint-files $LINT_FRONTEND_FILES
evaluate_linter_results

cd "$ROOT_DIR"


echo "========================"
echo "=== Running prettier ==="
echo "========================"

# Run prettier on all staged files.
cd "$ROOT_DIR"/src/middleware
echo "$MIDDLEWARE_FILES" | xargs npx prettier --write --ignore-unknown
cd "$ROOT_DIR"/src/frontend
echo "$FRONTEND_FILES" | xargs npx prettier --write --ignore-unknown
cd "$ROOT_DIR"
./scripts/run-linter.sh $FILES
if [ $? != 0 ]; then
exit $?
fi

./scripts/run-prettier.sh $FILES
if [ $? != 0 ]; then
echo "========================================================================"
echo "Something went wrong running prettier. Have you run \`npm install\` yet?"
echo "You can skip pre-commit checks by setting \$SKIP_PRECOMMIT_CHECKS"
echo "========================================================================"
exit 1
exit $?
fi

echo "=== Prettier done ==="

# Add back the modified/prettified files to staging
echo "$FILES" | xargs -r git add
Expand Down
11 changes: 11 additions & 0 deletions .git-hooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# Skip pre-push checks if SKIP_PREPUSH_CHECKS is set.
if [ "$SKIP_PREPUSH_CHECKS" = true ] || [ "$SKIP_PREPUSH_CHECKS" = 1 ] ; then
echo "=== Skipping pre-push checks ==="
exit 0
fi

cd "$ROOT_DIR"

./scripts/run-typecheck.sh
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ lerna-debug.log
/.idea
/data
*.swp
.parcel-cache
.classpath
.project
.settings
# conflict
*.orig
.nx
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.cjs.js
*.es.js
**/dist/**
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SemApps

SemApps (from *Sem*antic *App*lications) is a semantic web toolbox, allowing to create applications compliant with most major semantic web specifications: LDP, SPARQL, ActivityPub, WAC, WebID.
SemApps (from *Sem*antic *App*lications) is a semantic web toolbox, allowing to create applications compliant with most major semantic web specifications: LDP, SPARQL, ActivityPub, WAC, WebID.

## What's in the box ?

Expand Down
9 changes: 9 additions & 0 deletions scripts/on-workdir-changed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

# This script is called when a git command possibly modified files in the working dir.


ROOT_DIR=$(git rev-parse --show-toplevel)
cd "$ROOT_DIR"

./scripts/run-yalc-publish.sh
48 changes: 48 additions & 0 deletions scripts/run-linter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# Script to run linter before commit.
# This is called by `.git-hooks/pre-commit`


echo "=== Running linter ==="

cd $(git rev-parse --show-toplevel)

FILES="$@"
ROOT_DIR=$(git rev-parse --show-toplevel)

MIDDLEWARE_FILES="$(echo "$FILES" | grep -E "src/middleware" | xargs -r realpath | sed 's/.*/"&"/')"
FRONTEND_FILES="$(echo "$FILES" | grep -E "src/frontend" | xargs -r realpath | sed 's/.*/"&"/')"

LINT_FILE_TYPES="js|jsx|ts|tsx"
LINT_MIDDLEWARE_FILES=$(echo "$MIDDLEWARE_FILES" | grep -E "\.($LINT_FILE_TYPES)$")
LINT_FRONTEND_FILES=$(echo "$FRONTEND_FILES" | grep -E "\.($LINT_FILE_TYPES)$")

# Function to evaluate the linter results
function evaluate_linter_results {
if [ $? == 1 ]; then
echo "⛔ The linter found some errors. Please fix them before committing."
echo " You can skip pre-commit checks by setting \$SKIP_PRECOMMIT_CHECKS"
exit 1
elif [ $? -ge 2 ]; then
echo "⛔ Something went wrong running the linter. Have you run \`yarn\` yet?"
echo " You can skip pre-commit checks by setting \$SKIP_PRECOMMIT_CHECKS"
exit 1
fi
}


# Run linter on middleware and frontend files

cd "$ROOT_DIR"/src/middleware
yarn run lint-files $LINT_MIDDLEWARE_FILES
evaluate_linter_results

cd "$ROOT_DIR"/src/frontend
yarn run lint-files $LINT_FRONTEND_FILES
evaluate_linter_results


echo "✅ Linter successful!"

exit 0
32 changes: 32 additions & 0 deletions scripts/run-prettier.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# Script to run prettier on staged files before commit.
# This is called by `.git-hooks/pre-commit`


echo "=== Running prettier ==="

FILES="$@"

ROOT_DIR=$(git rev-parse --show-toplevel)

MIDDLEWARE_FILES="$(echo "$FILES" | grep -E "src/middleware" | xargs -r realpath | sed 's/.*/"&"/')"
FRONTEND_FILES="$(echo "$FILES" | grep -E "src/frontend" | xargs -r realpath | sed 's/.*/"&"/')"


# Run prettier on all given files.
cd "$ROOT_DIR"/src/middleware
echo "$MIDDLEWARE_FILES" | xargs npx prettier --write --ignore-unknown
cd "$ROOT_DIR"/src/frontend
echo "$FRONTEND_FILES" | xargs npx prettier --write --ignore-unknown
cd "$ROOT_DIR"

if [ $? != 0 ]; then
echo "⛔ Something went wrong running prettier. Have you run \`npm install\` yet?"
echo " You can skip pre-commit checks by setting \$SKIP_PRECOMMIT_CHECKS"
exit 1
fi

echo "✅ Prettier done!"

exit 0
17 changes: 17 additions & 0 deletions scripts/run-typecheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# Script to typecheck frontend code.
# Called by pre-push hook.

ROOT_DIR=$(git rev-parse --show-toplevel)
cd "$ROOT_DIR"/src/frontend

echo "=== Running typecheck for frontend ==="

yarn typecheck > /dev/null
if [ $? -ne 0 ]; then
echo "⛔ Typecheck failed! To see the errors, run \`yarn typecheck\` in the frontend directory."
echo " You can skip pre-push checks by setting \$SKIP_PREPUSH_CHECKS=true"
exit 1
fi
echo "✅ Typecheck successful!"
22 changes: 22 additions & 0 deletions scripts/run-yalc-publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# Script to run yalc:publish.
# Called by on-workdir-changed.sh


if [ "$SKIP_YALC_PUBLISH" = true ] || [ "$SKIP_YALC_PUBLISH" = 1 ] ; then
echo "=== Skipping yalc:publish ==="
exit 0
fi


echo === Running yalc:publish ===

ROOT_DIR=$(git rev-parse --show-toplevel)
cd "$ROOT_DIR"/src/frontend

# Run yalc:publish. If not available, just print an info message.
yarn yalc:publish &> /dev/null || \
echo "⚠️ yarn or yalc is not installed. Skipping yalc:publish"

exit 0
Loading

0 comments on commit 4da9a60

Please sign in to comment.