Skip to content

Commit

Permalink
Merge pull request #1181 from assemblee-virtuelle/use-yalc
Browse files Browse the repository at this point in the history
Try Yalc to fix version mismatch
  • Loading branch information
srosset81 authored Oct 19, 2023
2 parents 9e7e784 + 7ede710 commit 989c321
Show file tree
Hide file tree
Showing 21 changed files with 2,816 additions and 3,780 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
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
54 changes: 54 additions & 0 deletions scripts/run-linter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

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


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

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 "================================================================="
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
}


# 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 done ====="

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

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


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

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 "========================================================================"
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
fi

echo "==== Prettier done ====="

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

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


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
1 change: 0 additions & 1 deletion src/frontend/lerna.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"version": "0.6.0-alpha.2",
"npmClient": "yarn",
"useWorkspaces": true,
"useNx": true,
"packages": ["packages/*", "templates/**"],
"command": {
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"default": {
"runner": "nx/tasks-runners/default",
"options": {
"cacheableOperations": []
"cacheableOperations": ["build", "yalc:publish"]
}
}
},
Expand Down
19 changes: 12 additions & 7 deletions src/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
"license": "Apache-2.0",
"scripts": {
"bootstrap": "lerna bootstrap",
"build": "lerna run build",
"build": "nx run-many --target=build --all",
"version": "lerna version --force-publish='*' --exact --tag-version-prefix='frontend-v'",
"yalc:publish": "lerna exec --parallel --scope @semapps/** -- yalc publish --push --changed",
"publish": "lerna publish from-package --dist-tag latest",
"prettier": "prettier --write '**/*.{js,ts,json}'",
"link-all": "lerna exec --parallel --scope @semapps/** -- yarn link",
"unlink-all": "lerna exec --parallel --scope @semapps/** -- yarn unlink",
"lint": "eslint --ext .js,.jsx,.ts,.tsx .",
"lint-files": "eslint --ext .js,.jsx,.ts,.tsx",
"typecheck": "tsc --noEmit",
"preinstall": "git config core.hooksPath .git-hooks"
"preinstall": "git config core.hooksPath .git-hooks",
"test-watch": "nx watch --all -- nx run $NX_PROJECT_NAME:build"
},
"devDependencies": {
"@parcel/packager-ts": "^2.10.0",
"@parcel/transformer-typescript-types": "^2.10.0",
"parcel": "^2.10.0",
"@types/react": "^18.2.14",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
Expand All @@ -28,10 +31,12 @@
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.3.0",
"lerna": "^3.19.0",
"nx": "16.5.1",
"lerna": "^7.4.1",
"nx": "^16.10.0",
"prettier": "^3.0.3",
"typescript": "^5.1.6"
"typescript": "^5.1.6",
"yalc": "1.0.0-pre.53",
"nodemon": "^3.0.1"
},
"workspaces": [
"packages/*",
Expand Down
8 changes: 3 additions & 5 deletions src/frontend/packages/activitypub-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"dist"
],
"scripts": {
"build": "parcel build",
"watch": "parcel watch"
"build": "parcel build && yalc publish --push --changed",
"watch": "nodemon --watch src --exec 'yarn build'"
},
"dependencies": {
"@semapps/auth-provider": "0.6.0-alpha.2",
Expand All @@ -36,7 +36,5 @@
"publishConfig": {
"access": "public"
},
"devDependencies": {
"parcel": "^2.9.3"
}
"devDependencies": {}
}
8 changes: 3 additions & 5 deletions src/frontend/packages/auth-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"dist"
],
"scripts": {
"build": "parcel build",
"watch": "parcel watch"
"build": "parcel build && yalc publish --push --changed",
"watch": "nodemon --watch src --exec 'yarn build'"
},
"dependencies": {
"@semapps/semantic-data-provider": "0.6.0-alpha.2",
Expand All @@ -34,7 +34,5 @@
"publishConfig": {
"access": "public"
},
"devDependencies": {
"parcel": "^2.9.3"
}
"devDependencies": {}
}
7 changes: 2 additions & 5 deletions src/frontend/packages/date-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"dist"
],
"scripts": {
"build": "yarn typecheck && parcel build",
"watch": "parcel watch",
"build": "parcel build && yalc publish --push --changed",
"watch": "nodemon --watch src --exec 'yarn build'",
"typecheck": "tsc --noEmit"
},
"dependencies": {
Expand All @@ -37,9 +37,6 @@
"devDependencies": {
"@mui/material": "^5.13.1",
"@mui/styles": "^5.13.1",
"@parcel/packager-ts": "^2.9.3",
"@parcel/transformer-typescript-types": "^2.9.3",
"parcel": "^2.9.3",
"react": "^18.2.0",
"react-admin": "^4.11.0",
"react-router-dom": "^6.1.0"
Expand Down
Loading

0 comments on commit 989c321

Please sign in to comment.