A React app that displays a summary of FX rates.
It uses fixer.io API
Fixer is an open-source, simple, and lightweight API for current and historical foreign exchange (forex) rates published by the European Central Bank.The API updates rates daily around 4PM CET every working day. Historical rates go back to 1st January, 1999.
This app was created as an individual proyect to understand the groundings of SPAs, React, SASS, gulp and other dependencies. Due to the large ammount of information, the tools used may not be fully exploited or may contain bizarre inconsistencies to the expert eye, comments and Pull Requests are very much welcomed.
This application comes with no warranty of any kind. Its data is obtained through fixer.io which in turn comes with no warranty as well.
Once you have access to the code, and have installed npm (C9 have it installed
by default), you need only to execute the following commands.
First install gulp and jest, as they are needed in the process.
npm install -g gulp
npm install -g jestNOTE: You may need to prefix
sudofor this commands to work:sudo npm install -g gulp.
Download the corresponding npm packages. These packages are specified in the
package.json file. The command will create a node_modules directory.
npm installCreate the dev folder and open a listening port.
npm startOr create the production's dist folder and open a listening port.
gulp productionnpm testNOTE: This npm command is defined in the
package.json, it will runjest --watch. Changes to.jsand.test.jsfiles will trigger the execution of their individual tests. Run all test withjestor pressingawhile its interface is open.
Build dev directory and listen with browserSync:
npm startThis will transform all JSX into JS, and SASS into CSS.
The resulting JS is inserted in a build.js file.
The resulting CSS is inserted in a styles.min.css file.
The corresponding changes to the index.html tags are made automatically.
NOTE:
npm startwill execute thegulpscript, which in turn executes gulp's'default'task. You can see this task in thegulpfile.jsfile. This command behaves exactly asgulporgulp default. A port to listen and display this directory is created throughbrowsersync. Thegulpfile.jsis instructed to refresh all browsers when there is a change in theappdirectory, getting live feedback o changes.
Build dist directory and listen with browserSync:
gulp productionThis will transform all JSX into JS, and SASS into CSS. It will
concatenate and minify all .js files into a single build.min.js file.
It will also concatenate and minify all .css files (previously transformed
from .scss files) into a single styles.min.css file. The corresponding
changes to the index.html file, regarding <script> and <link> tags are
automatically made to match the created compact version.
The process of code transformation is carried out with gulp, the instructions
are found in the gulpfile.js file. The tool
pump is used for easier
debugging of the gulpfile.js.
This is the process executed with the shell command gulp, in this proyect
it is executed also with npm start.
The tasks executed are:
'sass''transform''replaceHTML-dev'copy-public-dev''serve'
Take all the files in the app/css directory with a .scss file extension.
The files will be compacted and minified, a sourcemap is needed to debug this
file, otherwise errors will be shown as relative to the minified .css file
which are useless for development intentions. This is done with
sourcemaps.init() and sourcemaps.write().
Take all .scss files and transform them into readable CSS code.
gulp-clean-css is used to eliminate unnecesary code in the resulting .css
file, making it lighter and thus faster to load for the browser.
Concatenate all the code into a single file called styles.min.css. Finally
place this file in the dev folder and reload all browsers with browsersync
to see their effect.
A 'watcher' is created with watchify and browserify. This watcher needs
only to receive the first .js file and will find all the other ones through
the import instructions.
All the JSX code is transformed into readable JS with babelify. Babelify in
turn uses the presets react and env (in package.json) to know how to
behave.
Debug is set to true and the options cache, packageCache and fullPaths
are needed for watchify to properly work.
When there is an 'update', the bundle function will be executed. This
function contains the same code as the 'transform' gulp task.
The 'transform' task creates a "bundle" of these JS files and writes the
output inside the dev directory, with the filename build.js.
As JS and CSS files are concatenated into new compact versions, the index.html
file needs to know where they are located and how they are named.
The index.html file is taken, and the code inside the <!-- build:js -->
and <!-- build:css --> tags is changed to point to the correct created files.
This process takes all files inside the public directory and copies them
exactly into the dev folder.
A server is connected with gulp-connect. browser-sync is initialized.
Gulp will watch changes with the gulp.watch commands. Changes to SCSS files
will trigger the transformation of SCSS into the single CSS file and reload
browserSync. Changes to JS files trigger only the browserSync to reload, as its
transformation process is handled with the watcher.on('change', bundle)
instruction.
Changes to the index.html file trigger its copy and tag replacement, followed
by the reload of browserSync.
The production process is very similar to the default.
The JS build process is different: it will create an uglified version for a lighter file and faster browser performance.
The CSS does not need sourcemaps for debugging (as debugging is unnecesary in the production environment), and so they are not created.
The difference of copying the index.html and public files is only in the
destination directory dist.
A server is connected to show files in the dist directory and browserSync
initialized. No watching and reloading tasks are used in production.
You can recreate the behavior of this app by installing its corresponding
packages individually. Packages were managed with npm. The app was created
from scratch in a C9 environment, with a 'blank' template.
- npm install -g gulp
- npm install -g jest
- npm init
- npm install --save react react-dom
- npm install --save-dev babel-cli babel-preset-env babel-preset-react
- npm install --save-dev pump
- npm install --save-dev gulp
- npm install --save-dev gulp-sass
- npm install --save-dev browser-sync
- npm install --save-dev gulp-sourcemaps
- npm install --save-dev gulp-uglify
- npm install --save-dev gulp-clean-css
- npm install --save-dev gulp-html-replace
- npm install --save-dev gulp-connect
- npm install --save-dev vinyl-source-stream
- npm install --save-dev browserify
- npm install --save-dev watchify
- npm install --save-dev gulp-streamify
- npm install --save-dev babelify
- npm install --save-dev gulp-concat
- npm install --save-dev babel-jest
- npm install --save-dev jest
- npm install --save-dev jest-cli
- npm install --save-dev enzyme
- npm install --save-dev enzyme-adapter-react-16
- npm install --save-dev envify
- npm install --save-dev fusioncharts react-fusioncharts
- Gettin started with React
- Getting started with Babel
- Getting started with Gulp
- Easier gulpfile debugging with pump
- Building React applications with Gulp and Browserify
- Display and reload the app with Browsersync
- Getting started with Jest
- Expand Jest test suite with Enzyme
- Color pallete creation with coolors.co
- FusionCharts with React