Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ node_modules
.vscode
samples/invalid-fablo-config.json
.DS_Store
dist
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
FROM node:18-alpine3.16

RUN apk add --no-cache sudo shfmt
RUN npm install --global --silent yo

# copy fablo files
COPY generators /fablo/generators
COPY dist /fablo/dist
COPY package.json /fablo/package.json
COPY package-lock.json /fablo/package-lock.json

Expand All @@ -29,6 +28,8 @@ RUN adduser -D -u 501 yeoman && \
ENV HOME /network/workspace

COPY docker-entrypoint.sh /fablo/docker-entrypoint.sh
COPY bin /fablo/bin
COPY bin/run.js /fablo/bin/run.mjs
COPY docs /fablo/docs
COPY README.md /fablo/README.md
COPY samples /fablo/samples/
Expand Down
3 changes: 3 additions & 0 deletions bin/dev.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node --loader ts-node/esm --no-warnings=ExperimentalWarning "%~dp0\dev" %*
5 changes: 5 additions & 0 deletions bin/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env -S node --loader ts-node/esm --disable-warning=ExperimentalWarning

import {execute} from '@oclif/core'

await execute({development: true, dir: import.meta.url})
3 changes: 3 additions & 0 deletions bin/run.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\run" %*
5 changes: 5 additions & 0 deletions bin/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

import {execute} from '@oclif/core'

await execute({dir: import.meta.url})
42 changes: 22 additions & 20 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,39 @@

set -e

executeYeomanCommand() {
executeOclifCommand() {
command_with_params=$1

# cleanup yeoman files after execution
# shellcheck disable=SC2064
trap "rm -rf \"$yeoman_target_dir/.cache\" \"$yeoman_target_dir/.config\" \"$yeoman_target_dir/.npm\"" EXIT
ls -la /fablo/
ls -la /fablo/bin/

if [ "$(id -u)" = 0 ]; then
# root user detected, running as yeoman user
sudo chown -R yeoman:yeoman "$yeoman_target_dir"
# root user detected, running as yeoman user (keeping for compatibility)
sudo chown -R yeoman:yeoman "$target_dir"
# shellcheck disable=SC2086
(cd "$yeoman_target_dir" && sudo -E -u yeoman yo --no-insight $command_with_params)
sudo chown -R root:root "$yeoman_target_dir"
(cd "$target_dir" && sudo -E -u yeoman node /fablo/bin/run.mjs $command_with_params)
sudo chown -R root:root "$target_dir"
else
# shellcheck disable=SC2086
(cd "$yeoman_target_dir" && yo --no-insight $command_with_params)
(cd "$target_dir" && node /fablo/bin/run.mjs $command_with_params)
fi
}

formatGeneratedFiles() {
# Additional script and yaml formatting
#
# Why? Yeoman output may contain some additional whitespaces or the formatting
# Why? Generated output may contain some additional whitespaces or the formatting
# might not be ideal. Keeping those whitespaces, however, might be useful
# in templates to improve the brevity. That's why we need additional formatting.
# Since the templates should obey good practices, we don't use linters here
# (i.e. shellcheck and yamllint).
echo "Formatting generated files"
shfmt -i=2 -l -w "$yeoman_target_dir" >/dev/null
shfmt -i=2 -l -w "$target_dir" >/dev/null

for yaml in "$yeoman_target_dir"/**/*.yaml; do
for yaml in "$target_dir"/**/*.yaml; do

# the expansion failed, no yaml files found
if [ "$yaml" = "$yeoman_target_dir/**/*.yaml" ]; then
if [ "$yaml" = "$target_dir/**/*.yaml" ]; then
break
fi

Expand All @@ -48,16 +47,19 @@ formatGeneratedFiles() {
done
}

yeoman_target_dir="/network/workspace"
yeoman_command=${1:-Fablo:setup-network}
target_dir="/network/workspace"
oclif_command=${1:-setup-network}

# This part of output will be replaces with empty line. It breaks parsing of yeoman generator output.
# See also: https://github.com/yeoman/generator/issues/1294
annoying_yeoman_info="No change to package.json was detected. No package manager install will be executed."
# Map old yeoman command format to oclif format
case "$oclif_command" in
"Fablo:setup-network"|"fablo:setup-network")
oclif_command="setup-network"
;;
esac

# Execute the command
executeYeomanCommand "$yeoman_command" 2>&1 | sed "s/$annoying_yeoman_info//g"
executeOclifCommand "$oclif_command"

if echo "$yeoman_command" | grep "setup-network"; then
if echo "$oclif_command" | grep -q "setup-network"; then
formatGeneratedFiles
fi
2 changes: 1 addition & 1 deletion e2e-network/docker/test-01-v3-simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export FABLO_HOME

networkUp() {
"$FABLO_HOME/fablo-build.sh"
(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" init node dev)
(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" init)
(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" up)
}

Expand Down
9 changes: 9 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {includeIgnoreFile} from '@eslint/compat'
import oclif from 'eslint-config-oclif'
import prettier from 'eslint-config-prettier'
import path from 'node:path'
import {fileURLToPath} from 'node:url'

const gitignorePath = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '.gitignore')

export default [includeIgnoreFile(gitignorePath), ...oclif, prettier]
2 changes: 1 addition & 1 deletion fablo-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if [ "$(command -v nvm)" = "nvm" ]; then
fi

npm install
npm run build:dist
npm run build

# if --push is passed, then build for all platforms and push the image to the registry
if [ "${1:-''}" = "--push" ]; then
Expand Down
14 changes: 7 additions & 7 deletions fablo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -231,31 +231,31 @@ useVersion() {
set +e
curl -Lf https://github.com/hyperledger-labs/fablo/releases/download/"$version"/fablo.sh -o "$0" && chmod +x "$0"
else
executeOnFabloDocker "fablo:list-versions"
executeOnFabloDocker "list-versions"
fi
}

initConfig() {
printSplash
executeOnFabloDocker "fablo:init $1 $2"
executeOnFabloDocker "init $1 $2"
cp -R -i "$FABLO_TEMP_DIR/." "$COMMAND_CALL_ROOT/"
}

validateConfig() {
local fablo_config=${1:-$(getDefaultFabloConfig)}
executeOnFabloDocker "fablo:validate" "" "$fablo_config"
executeOnFabloDocker "validate" "" "$fablo_config"
}

extendConfig() {
local fablo_config=${1:-$(getDefaultFabloConfig)}
executeOnFabloDocker "fablo:extend-config" "" "$fablo_config"
executeOnFabloDocker "extend-config" "" "$fablo_config"
}

exportNetworkTopology() {
local fablo_config=${1:-$(getDefaultFabloConfig)}
local output_file=${2:-network-topology.mmd}

executeOnFabloDocker "fablo:export-network-topology /network/fablo-config.json $output_file" "$(dirname "$output_file")" "$fablo_config"
executeOnFabloDocker "export-network-topology /network/fablo-config.json $output_file" "$(dirname "$output_file")" "$fablo_config"
}

generateNetworkConfig() {
Expand All @@ -269,7 +269,7 @@ generateNetworkConfig() {
echo " FABLO_NETWORK_ROOT: $fablo_target"

mkdir -p "$fablo_target"
executeOnFabloDocker "fablo:setup-network" "$fablo_target" "$fablo_config"
executeOnFabloDocker "setup-network" "$fablo_target" "$fablo_config"
if [ -f "$fablo_target/hooks/post-generate.sh" ]; then
chmod +x "$fablo_target/hooks/post-generate.sh" || true
("$fablo_target/hooks/post-generate.sh")
Expand Down Expand Up @@ -366,7 +366,7 @@ elif [ "$COMMAND" = "help" ] || [ "$COMMAND" = "--help" ]; then
printHelp

elif [ "$COMMAND" = "version" ]; then
executeOnFabloDocker "fablo:version $2"
executeOnFabloDocker "version $2"

elif [ "$COMMAND" = "use" ]; then
useVersion "$2"
Expand Down
Loading
Loading