Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

[#170234614] refactor build system and docs #66

Merged
merged 4 commits into from Dec 12, 2019

Conversation

gunzip
Copy link
Collaborator

@gunzip gunzip commented Dec 11, 2019

This PR lets you run the frontend application seamlessy with or without docker with hot module reloading enabled in both cases.

README.md Outdated

# Bring up the Docker test environment (build the frontend, pull the backend and the SPID test environment)
docker-compose up
# run yarn inside docker container
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i had to chmod +x ./scripts/yarn.sh

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

README.md Outdated

# Bring up the Docker test environment (build the frontend, pull the backend and the SPID test environment)
docker-compose up
# run yarn inside docker container
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead # Launch docker image and run yarn inside docker

for me was not trivial to understand without going into the scripts


```shell
yarn start-with-mock
cp env.example .env
# edit .env file
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the copied env.example into .env the mocked server and the app should work without any changes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it should

Copy link
Collaborator

@giux78 giux78 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docker part seems not to work properly. At least following the steps in the README. Seems that or the port are not exposed from the containers but the host from localhost seems unreachable. The browser is not able to find the provided url and keep trying.

Instead the part without docker works.

@digitalcitizenship
Copy link

Warnings
⚠️ This PR changes a total of 634 LOCs, that is more than a reasonable size of 250. Consider splitting the pull request into smaller ones.
Messages
📖 🎉 - congrats on your new release

Affected stories

  • 🌟 #170234614: Come DEV voglio poter sviluppare in locale il frontend utilizzando dei dati fittizi

New dependencies added: dotenv-cli, npm-run-all, parcel-plugin-html-externals and shx.

dotenv-cli

Author: entropitor

Description: A global executable to run applications with the ENV variables loaded by dotenv

Homepage: https://github.com/entropitor/dotenv-cli#readme

Createdover 4 years ago
Last Updated21 days ago
LicenseMIT
Maintainers1
Releases10
Direct Dependenciescross-spawn, dotenv, dotenv-expand and minimist
README

dotenv-cli

Installing

NPM

$ npm install -g dotenv-cli

Yarn

$ yarn global add dotenv-cli

Usage

$ dotenv <command with arguments>

This will load the variables from the .env file in the current working directory and then run the command (using the new set of environment variables).

Custom .env files

Another .env file could be specified using the -e flag:

$ dotenv -e .env2 <command with arguments>

Multiple .env files can be specified, and will be processed in order:

$ dotenv -e .env3 -e .env4 <command with arguments>

Check env variable

If you want to check the value of an environment variable, use the -p flag

$ dotenv -p NODE_ENV

Flags to the underlying command

If you want to pass flags to the inner command use -- after all the flags to dotenv-cli.

E.g. the following command without dotenv-cli:

mvn exec:java -Dexec.args="-g -f"

will become the following command with dotenv-cli:

$ dotenv -- mvn exec:java -Dexec.args="-g -f"

or in case the env file is at .my-env

$ dotenv -e .my-env -- mvn exec:java -Dexec.args="-g -f"

Variable expansion

We support expanding env variables inside .env files (See dotenv-expand npm package for more information)

For example:

IP=127.0.0.1
PORT=1234
APP_URL=http://${IP}:${PORT}

Using the above example .env file, process.env.APP_URL would be http://127.0.0.1:1234.

License

MIT

npm-run-all

Author: Toru Nagashima

Description: A CLI tool to run multiple npm-scripts in parallel or sequential.

Homepage: https://github.com/mysticatea/npm-run-all

Createdover 4 years ago
Last Updated13 days ago
LicenseMIT
Maintainers1
Releases58
Direct Dependenciesansi-styles, chalk, cross-spawn, memorystream, minimatch, pidtree, read-pkg, shell-quote and string.prototype.padend
Keywordscli, command, commandline, tool, npm, npm-scripts, run, sequential, serial, parallel and task
README
index npm-run-all run-s run-p Node API

npm-run-all

npm version
Downloads/month
Build Status
Build status
Coverage Status
Dependency Status

A CLI tool to run multiple npm-scripts in parallel or sequential.

⤴️ Motivation

  • Simplify. The official npm run-script command cannot run multiple scripts, so if we want to run multiple scripts, it's redundant a bit. Let's shorten it by glob-like patterns.

    Before: npm run clean && npm run build:css && npm run build:js && npm run build:html

    After: npm-run-all clean build:*
  • Cross platform. We sometimes use & to run multiple command in parallel, but cmd.exe (npm run-script uses it by default) does not support the &. Half of Node.js users are using it on Windows, so the use of & might block contributions. npm-run-all --parallel works well on Windows as well.

💿 Installation

$ npm install npm-run-all --save-dev
# or
$ yarn add npm-run-all --dev
  • It requires Node@>=4.

📖 Usage

CLI Commands

This npm-run-all package provides 3 CLI commands.

The main command is npm-run-all.
We can make complex plans with npm-run-all command.

Both run-s and run-p are shorthand commands.
run-s is for sequential, run-p is for parallel.
We can make simple plans with those commands.

Yarn Compatibility

If a script is invoked with Yarn, npm-run-all will correctly use Yarn to execute the plan's child scripts.

Node API

This npm-run-all package provides Node API.

📰 Changelog

🍻 Contributing

Welcome♡

Bug Reports or Feature Requests

Please use GitHub Issues.

Correct Documents

Please use GitHub Pull Requests.

I'm not familiar with English, so I especially thank you for documents' corrections.

Implementing

Please use GitHub Pull Requests.

There are some npm-scripts to help developments.

  • npm test - Run tests and collect coverage.
  • npm run clean - Delete temporary files.
  • npm run lint - Run ESLint.
  • npm run watch - Run tests (not collect coverage) on every file change.

parcel-plugin-html-externals

Author: stoically

Description: ParcelJS plugin to ignore certain script and stylesheet link tags in html files marked as externals

Homepage: https://github.com/stoically/parcel-plugin-html-externals#readme

Created5 months ago
Last Updated5 months ago
LicenseMIT
Maintainers1
Releases3
Direct Dependenciesminimatch
README

ParcelJS plugin to ignore certain script and stylesheet link tags in html files marked as externals.

Parcel will probably support externals out of the box in the future, related issue here.

Install

npm install --save-dev parcel-plugin-html-externals

Usage

Put an externals key into your package.json, e.g.

{
  "externals": {
    "vendor/**/*": false
  }
}

will ignore all script / stylesheet link tags whose src / href attribute starts with vendor/, e.g

<script src="vendor/thirdparty.min.js"></script>

The externals key can be a string or any glob accepted by minimatch,
the value must be false to trigger ignoring.

Caveats

The plugin monkey patches Parcel internals by extending the HTMLAsset class and proxying its ast walker, so it might just break in an upcoming version.

License

MIT

shx

Author: Unknown

Description: Portable Shell Commands for Node

Homepage: https://github.com/shelljs/shx#readme

Createdover 3 years ago
Last Updatedover 1 year ago
LicenseMIT
Maintainers2
Releases11
Direct Dependencieses6-object-assign, minimist and shelljs
Keywordsshelljs, shell, unix, bash, sh, exec, cli and zsh
README

Shx

Travis
AppVeyor
Codecov
npm version
npm downloads

shx is a wrapper around ShellJS Unix
commands, providing an easy solution for simple Unix-like, cross-platform
commands in npm package scripts.

Difference Between ShellJS and shx

  • ShellJS: Good for writing long scripts, all in JS, running via NodeJS (e.g. node myScript.js).
  • shx: Good for writing one-off commands in npm package scripts (e.g. "clean": "shx rm -rf out/").

Install

npm install shx --save-dev

This will allow using shx in your package.json scripts.

Usage

Command Line

If you'd like to use shx on the command line, install it globally with the -g flag.
The following code can be run either a Unix or Windows command line:

$ shx pwd                       # ShellJS commands are supported automatically
/home/username/path/to/dir

$ shx ls                        # files are outputted one per line
file.txt
file2.txt

$ shx rm *.txt                  # a cross-platform way to delete files!

$ shx ls

$ shx echo "Hi there!"
Hi there!

$ shx touch helloworld.txt

$ shx cp helloworld.txt foobar.txt

$ shx mkdir sub

$ shx ls
foobar.txt
helloworld.txt
sub

$ shx rm -r sub                 # options work as well

$ shx --silent ls fakeFileName  # silence error output

All commands internally call the ShellJS corresponding function, guaranteeing
cross-platform compatibility.

package.json

ShellJS is good for writing long scripts. If you want to write bash-like,
platform-independent scripts, we recommend you go with that.

However, shx is ideal for one-liners inside package.json:

{
  "scripts": {
    "clean": "shx rm -rf build dist && shx echo Done"
  }
}

Unsupported Commands

Due to the differences in execution environments between ShellJS and shx (JS vs CLI) some commands are not supported:

Unsupported command Recommend workaround
shx cd Just use plain old cd (it's the same on windows too)
shx pushd Just use plain old pushd. Use forward slashes and double-quote the path. (e.g. pushd "../docs". This would fail on Windows without the quotes)
shx popd Just use plain old popd
shx dirs No workaround
shx set See below
shx exit Just use plain old exit
shx exec Instead of shx exec cmd, just use plain old cmd
shx ShellString No workaround (but why would you want this?)

Shx options

Shx allows you to modify its behavior by passing arguments. Here's a list of
supported options:

set flag shell.config setting shx command Effect
-e config.fatal = true Not supported Exit upon first error
-v config.verbose = true shx --verbose cd foo Log the command as it's run
-f config.noglob = true shx --noglob cat '*.txt' Don't expand wildcards
N/A config.silent = true shx --silent cd noexist Don't show error output

Team

Nate Fischer Ari Porad Levi Thomason
Nate Fischer Ari Porad Levi Thomason

Generated by 🚫 dangerJS against 979f3f5

@gunzip
Copy link
Collaborator Author

gunzip commented Dec 12, 2019

The docker part seems not to work properly. At least following the steps in the README. Seems that or the port are not exposed from the containers but the host from localhost seems unreachable. The browser is not able to find the provided url and keep trying.

this sounds odd since the ports are exposed inside docker-compose.yml. can you please do some debugging ? (which OS are you running as host ?)

Instead the part without docker works.

@giux78
Copy link
Collaborator

giux78 commented Dec 12, 2019

Sorry, on my tired mac os x has taken some minutes before completely start with docker. In the end works also the docker compose. Great!!!!!

@giux78 giux78 self-requested a review December 12, 2019 09:34
Copy link
Collaborator

@giux78 giux78 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works both docker and locally

| IO_ONBOARDING_PA_API_HOST | The hostname of the APIs url | string |
| IO_ONBOARDING_PA_API_PORT | The port for of APIs url | string |
| IO_ONBOARDING_PA_SHOW_FAKE_IDP | Show or hide fake IDP button in SPID dropdown button (0 to hide, 1 to show) | string |
| IO_ONBOARDING_PA_IS_MOCK_ENV | Front end is running with mock backend or with real APIs (0 for real APIs, 1 for mock backend) | string |

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing env variable IO_ONBOARDING_PA_SESSION_TOKEN_DOMAIN that defines session token domain used to delete token when logging out

README.md Outdated
$ yarn install
```
To read the variable values inside the frontend application, use
`window._env_.IO_ONBOARDING_PA_YOUR_VAR`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Env variables can also be read with getConfig method in config.ts class

env.example Outdated
@@ -5,3 +5,6 @@ IO_ONBOARDING_PA_API_HOST=http://localhost
IO_ONBOARDING_PA_API_PORT=3000
IO_ONBOARDING_PA_SHOW_FAKE_IDP=1
IO_ONBOARDING_PA_IS_MOCK_ENV=0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be 1 in mocked backend

@gunzip gunzip merged commit 8dd1b8a into master Dec 12, 2019
@gunzip gunzip deleted the 170234614-refactor-docker branch December 12, 2019 12:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
4 participants