Skip to content

Commit

Permalink
Merge pull request #889 from equinor/feat/install-without-client-folder
Browse files Browse the repository at this point in the history
🔨 Update install script so it works for projects where client folder isn't a thing
  • Loading branch information
mariush2 authored Dec 2, 2024
2 parents 5ae6e66 + cf22754 commit 84d6696
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 26 deletions.
27 changes: 25 additions & 2 deletions config/config_files/check_config_workflow/generate_check_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,38 @@ curl -s "https://raw.githubusercontent.com/equinor/amplify-component-lib/main/co
# Loop through the list from check_config/list.txt
list=$(curl -s "https://raw.githubusercontent.com/equinor/amplify-component-lib/main/config/config_files/check_config_workflow/list.txt")

aclIgnorePath="./.acl-ignore"
if [ -d "client" ]
then
aclIgnorePath="./client/.acl-ignore"
fi

while read line;
do
read var1 var2 var3 <<< "$line"
if grep -q $var1 "./client/.acl-ignore"; then
if grep -q $var1 $aclIgnorePath; then
printf -- "$var1 in .acl-ignore, skipping...\n"
else
workingDir=$var2
if [ ! -d "./client" ]
then
if [[ $var2 =~ "client/" ]]
then
workingDir=${var2#"client/"}
else
workingDir=${var2#"client"}
fi
fi

if [[ $workingDir == "" ]]
then
workingDir="."
fi


newLine="
- name: Compare remote $var1 to local
working-directory: $var2
working-directory: $workingDir
run: diff $var1 <(curl $var3)"
echo "$newLine" >> ".github/workflows/check_config.yaml"
fi
Expand Down
13 changes: 7 additions & 6 deletions config/install-deployment-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
printf -- "Running frontend configuration script\n"
printf -- "-------------------------------------\n\n"

currentDir=$(basename "$PWD")

if [ $currentDir != "client" ]
if [ ! -d ".github" ]
then
printf -- "Not in ./client folder, moving to it...\n"
cd ./client || exit 1
cd ..
fi

cd ..
if [ ! -d ".github" ]
then
printf -- "Couldn't found .github folder, stopping...n\n"
exit 1
fi

printf -- "Downloading client github actions specific to deployment from github to radix...\n"
workflowsList=$(curl -s "https://raw.githubusercontent.com/equinor/amplify-component-lib/main/config/github_actions_deployment_list.txt")
Expand Down
31 changes: 22 additions & 9 deletions config/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ printf -- "Running frontend configuration script\n"
printf -- "-------------------------------------\n\n"

currentDir=$(basename "$PWD")

if [ $currentDir != "client" ]
hasClientFolder=0
if [ $currentDir != "client" ] && [ -d "client" ]
then
printf -- "Not in ./client folder, moving to it...\n\n"
cd ./client
hasClientFolder=1
elif [ $currentDir !== "client" ]
then
printf -- "Not in ./client folder, moving to it...\n"
cd ./client || exit 1
printf -- "Not in client folder and client folder doesn't exist.\n"
printf -- "Downloading config files to where you are now\n\n"
fi

printf -- "Downloading config files...\n"
Expand Down Expand Up @@ -80,17 +85,25 @@ do
fi
done

cd ../..

printf -- "Going into root folder...\n"
if hasClientFolder -eq 1; then
cd ../..
else
cd ..
fi

printf -- "Downloading client github actions...\n"
workflowsList=$(curl -s "https://raw.githubusercontent.com/equinor/amplify-component-lib/main/config/github_actions_list.txt")

aclIgnorePath="./.acl-ignore"
if hasClientFolder -eq 1; then
aclIgnorePath="./client/.acl-ignore"
fi

for line in $workflowsList
do
fileName=$(echo $line | rev | cut -d '/' -f 1 | rev)
if grep -q $fileName "./client/.acl-ignore"; then
if grep -q $fileName $aclIgnorePath; then
printf -- "$fileName in .acl-ignore, skipping...\n"
else
printf -- "Downloading $fileName file...\n"
Expand All @@ -101,14 +114,14 @@ done
printf -- "Generating .github/workflows/check_config.yaml...\n"
bash <(curl -s https://raw.githubusercontent.com/equinor/amplify-component-lib/main/config/config_files/check_config_workflow/generate_check_config.sh)

if grep -q "CODEOWNERS" "./client/.acl-ignore"; then
if grep -q "CODEOWNERS" $aclIgnorePath; then
printf -- "CODEOWNERS .acl-ignore, skipping...\n"
else
printf -- "Downloading CODEOWNERS file...\n"
curl -s "https://raw.githubusercontent.com/equinor/amplify-component-lib/main/config/config_files/CODEOWNERS" > .github/CODEOWNERS
fi

if grep -q ".pre-commit-config.yaml" "./client/.acl-ignore"; then
if grep -q ".pre-commit-config.yaml" $aclIgnorePath; then
printf -- ".pre-commit-config.yaml in .acl-ignore, skipping...\n"
else
printf -- "Downloading .pre-commit-config.yaml file...\n"
Expand Down
24 changes: 15 additions & 9 deletions tooling/build-and-use.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { runTask } from './taskrunner.mjs';
import chalk from 'chalk';
import { readdir } from 'fs/promises';
import { readdir} from 'fs/promises';
import { existsSync } from 'fs';
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

Expand Down Expand Up @@ -87,39 +88,44 @@ async function runTasks() {
)
);

let nodeModulesDir = `../${selectedDir}/node_modules`
if (existsSync(`../${selectedDir}/client`)) {
nodeModulesDir = `../${selectedDir}/client/node_modules`
}

await runTask({
command: `rm -rf ../${selectedDir}/client/node_modules/.vite`,
command: `rm -rf ${nodeModulesDir}/.vite`,
name: `Removing ${chalk.bold.greenBright(
'.vite'
)} folder from ${chalk.bold.greenBright(
`${selectedDir}/client/node_modules`
`${nodeModulesDir}`
)}`,
});

await runTask({
command: `rm -rf ../${selectedDir}/client/node_modules/.cache`,
command: `rm -rf ${nodeModulesDir}/.cache`,
name: `Removing ${chalk.bold.greenBright(
'.cache'
)} folder from ${chalk.bold.greenBright(
`${selectedDir}/client/node_modules`
`${nodeModulesDir}`
)}`,
});

await runTask({
command: `rm -rf ../${selectedDir}/client/node_modules/@equinor/amplify-component-lib/dist`,
command: `rm -rf ${nodeModulesDir}/@equinor/amplify-component-lib/dist`,
name: `Removing old ${chalk.bold.greenBright(
'amplify-component-lib/dist'
)} folder from ${chalk.bold.greenBright(
`${selectedDir}/client/node_modules`
`${nodeModulesDir}`
)}`,
});

await runTask({
command: `cp -r ./dist ../${selectedDir}/client/node_modules/@equinor/amplify-component-lib/dist`,
command: `cp -r ./dist ${nodeModulesDir}/@equinor/amplify-component-lib/dist`,
name: `Copying newly built ${chalk.bold.greenBright(
'dist'
)} folder into ${chalk.bold.greenBright(
`${selectedDir}/client/node_modules`
`${nodeModulesDir}`
)}`,
});

Expand Down

0 comments on commit 84d6696

Please sign in to comment.