Skip to content

Commit

Permalink
clean up postinstall and improve readme
Browse files Browse the repository at this point in the history
  • Loading branch information
nikgraf committed Aug 17, 2017
1 parent 6fb2369 commit 9a6a088
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 56 deletions.
4 changes: 1 addition & 3 deletions README.md
Expand Up @@ -22,7 +22,7 @@ This example contains multiple services. Each of them can be run separately to d

## Install

Clone down the repository and run `npm install` in the root directory
Make sure to have the Serverless Framework installed via `npm install -g serverless`. Then clone down the repository and run `npm install` in the root directory. This command runs `npm install` in each service and the frontend app.

## Step by Step Guide

Expand All @@ -31,7 +31,6 @@ Clone down the repository and run `npm install` in the root directory
To get started cd into the users service at [services/users](https://github.com/serverless/event-gateway-example/tree/master/services/users) and run

```bash
npm install
serverless run
```

Expand All @@ -55,7 +54,6 @@ Serverless Function 'users-register' finished
Next up open another terminal and cd into the directory of the emails service at [services/emails](https://github.com/serverless/event-gateway-example/tree/master/services/emails). There also run

```bash
npm install
serverless run
```

Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -4,7 +4,6 @@
"description": "[![serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com)",
"main": "index.js",
"scripts": {
"start": "cd frontend && npm start",
"postinstall": "node postinstall.js"
},
"repository": {
Expand Down
107 changes: 55 additions & 52 deletions postinstall.js
@@ -1,70 +1,73 @@
/* streamline exmple setup ⊂◉‿◉つ */
const path = require('path')
const globby = require('globby')
const chalk = require('chalk')
const path = require('path');
const globby = require('globby');
const chalk = require('chalk');
const ora = require('ora');
const exec = require('child_process').exec
const exec = require('child_process').exec;

console.log(`Welcome to the serverless gateway project`)
console.log('Hold tight while we install the dependancies for you')
console.log(`Welcome to the Serverless Event Gateway example`);
console.log('Hold tight while we install the dependencies for you');

globby([ "{,!(node_modules)/**/}package.json", '!node_modules{,/**}', '!*/**/node_modules{,/**}']).then(paths => {
globby([
'{,!(node_modules)/**/}package.json',
'!node_modules{,/**}',
'!*/**/node_modules{,/**}'
]).then(paths => {
// Now run npm install
const files = paths.filter((i) =>{
return i !== 'package.json'
})
const files = paths.filter(i => {
return i !== 'package.json';
});

const command = `npm install`
let count = 0
files.forEach((p) => {
var t = path.join(__dirname, p)
var dirPath = path.dirname(t)
var dirName = path.basename(dirPath)
var niceName = path.basename(path.dirname(dirPath)) + '/' + dirName
//console.log(path.dirname(t))
let spinner = ora('Installing dependancies').start();
const command = `npm install`;
let count = 0;
files.forEach(p => {
var t = path.join(__dirname, p);
var dirPath = path.dirname(t);
var dirName = path.basename(dirPath);
var niceName = path.basename(path.dirname(dirPath)) + '/' + dirName;
let spinner = ora('Installing dependencies').start();
spinner.color = 'yellow';
spinner.text = `Installing dependancies for ${niceName}`;
spinner.text = `Installing dependencies for ${niceName}`;

if (niceName === 'event-gateway-example/frontend') {
setTimeout(() => {
spinner.text = `Still Installing dependancies for ${niceName}. Hang tight`;
spinner.text = `Still Installing dependencies for ${niceName}. Hang tight`;
}, 15000);
}

const child = exec(command, {
cwd: path.dirname(t),
stdio: [0, 1, 2]
}, (error, stdout, stderr) => {
if (error) {
console.warn(error)
const child = exec(
command,
{
cwd: path.dirname(t),
stdio: [0, 1, 2]
},
(error, stdout, stderr) => {
if (error) {
console.warn(error);
}
}
})
child.stdout.on('data', (data) => {
// console.log(data)
})
child.stderr.on('data', (data) => {
// console.log('err', data)
})
child.on('close', (code) => {
);
child.stdout.on('data', data => {});
child.stderr.on('data', data => {});
child.on('close', code => {
spinner.color = 'green';
spinner.text = `Successfully installed dependancies ${niceName}`;
spinner.succeed()
// console.log(`${path.dirname(t)} successfully installed`)
spinner.stop()
count++
spinner.text = `Successfully installed dependencies ${niceName}`;
spinner.succeed();
spinner.stop();
count++;
if (count === files.length) {
// ALL done
console.log(chalk.green('You are all set'))
console.log('---------')
console.log(chalk.yellow('To run the gateway: '))
console.log('- cd into a /service folder')
console.log('- then run `sls run`')
console.log('---------')
console.log(chalk.yellow('To run the frontend run:'))
console.log('`npm start`')
process.exit(0)
console.log(chalk.green('You are all set'));
console.log('---------');
console.log(chalk.yellow('To run a service with the gateway: '));
console.log('- cd into a service folder e.g. services/users');
console.log('- then run `sls run`');
console.log('---------');
console.log(chalk.yellow('To run the frontend run:'));
console.log('- cd into ./frontend');
console.log('- then run `npm start`');
process.exit(0);
}
})
})
})
});
});
});

0 comments on commit 9a6a088

Please sign in to comment.