From 14c2d5fc831b436fdd09fff82f0eda6b834b649d Mon Sep 17 00:00:00 2001 From: Deepesh Nair Date: Mon, 5 Oct 2020 20:06:12 +0530 Subject: [PATCH] fix(#718): Installation documentation for using One Platform (#728) * fix(#718): Added README and Lerna in scripts * fix(#718): Added platform.js to copy all the .env.example files to .env file * fix(#718): Added script to post-install --- README.md | 32 +++++++++++++++++++++++++++++--- package.json | 4 +++- platform.js | 14 ++++++++++++++ 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 platform.js diff --git a/README.md b/README.md index 5be7a8ec4..d9f0244c9 100644 --- a/README.md +++ b/README.md @@ -14,12 +14,38 @@ An integrated application hosting platform which allows you to host your SPAs. I - Notifications Framework - Feedback Framework -## Install +### Prerequisites +- Docker [Download](https://www.docker.com/get-started) + +## Installation + +### Install node_modules for all the packages +#### PS: The below script also copies `.env.example` to `.env` for all the services ```sh npm install -# OR -lerna bootstrap +``` + +### Environment Config + +Copy all the `.env.example` to `.env` and add the following fields + +- For SPAs (packages ending with *-spa) + 1. Add API_URL and set the url to .env + +- For services (packages ending with *-service) + 1. Add database path in DB_PATH + 2. Add database name in DB_NAME + 3. Add database username in DB_USER + 4. Add database password in DB_PASSWORD + +#### Example +```properties +## Database +DB_PATH=localhost +DB_NAME=platform +DB_USER=admin +DB_PASSWORD=admin ``` ## Using docker-compose for local development diff --git a/package.json b/package.json index f54e0da89..8485db709 100644 --- a/package.json +++ b/package.json @@ -36,9 +36,11 @@ }, "homepage": "https://github.com/1-Platform/one-platform#readme", "scripts": { + "lerna": "lerna", "test": "echo \"Error: no test specified\" && exit 1", "cli-microservice": "sh cli-init.sh", - "deploy": "sh deploy.sh" + "deploy": "sh deploy.sh", + "postinstall": "npm run lerna bootstrap && node platform.js" }, "devDependencies": { "@typescript-eslint/eslint-plugin": "4.3.0", diff --git a/platform.js b/platform.js new file mode 100644 index 000000000..2d3a2acd9 --- /dev/null +++ b/platform.js @@ -0,0 +1,14 @@ +console.log( 'Copying .env.example to .env for the services: Started' ); +const fs = require( 'fs' ); +const path = require( 'path' ); +const { COPYFILE_EXCL } = fs.constants; +const dir = 'packages'; +fs.readdir( dir, (err, list) => { + const services = list.filter( folder => folder.endsWith( '-service' ) ); + services.forEach(service => { + const pathToEnv = dir + '/' + service + '/'; + fs.copyFile( pathToEnv + '.env.example', pathToEnv + '.env', COPYFILE_EXCL, ( error ) => error ); + path.dirname( service ); + }) +} ); +console.log( 'Copying .env.example to .env for the services: Completed' );