Skip to content

Commit

Permalink
Let process exit itself
Browse files Browse the repository at this point in the history
  • Loading branch information
gamalielhere committed Aug 22, 2018
1 parent 678c231 commit 7714360
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 32 deletions.
18 changes: 2 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,8 @@ jobs:
- stage: check contract format
script:
- |
contractErrors=$(node checkContract.js);
if [[ $contractErrors != 0 ]]; then
echo "Formatting errors! Please check your object keys spellings, commas and or other things that might invalidate your JSON and try again";
exit 1;
else
echo "No errors";
exit 0;
fi
node checkContract.js;
- stage: check token format
script:
- |
tokenErrors=$(node checkToken.js);
if [[ $tokenErrors != 0 ]]; then
echo "Formatting errors! Please check your object keys spellings, commas and or other things that might invalidate your JSON and try again";
exit 1;
else
echo "No errors";
exit 0;
fi
node checkToken.js;
15 changes: 7 additions & 8 deletions checkContract.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require("fs");
const contractsDirectory = "./src/contracts/";
const Schema = require("validate");
const fs = require('fs');
const contractsDirectory = './src/contracts/';
const Schema = require('validate');
const contract = new Schema({
name: {
type: String,
Expand All @@ -20,20 +20,19 @@ const contract = new Schema({
}
});

let errors = 0;

function run() {
let errors = 0;
fs.readdirSync(contractsDirectory).forEach(folder => {
fs.readdirSync(`${contractsDirectory}/${folder}`).forEach(file => {
const obj = JSON.parse(
fs.readFileSync(`${contractsDirectory}/${folder}/${file}`, "utf8")
fs.readFileSync(`${contractsDirectory}/${folder}/${file}`, 'utf8')
);
if (contract.validate(obj) === false) {
errors++;
process.exit(1);
}
});
});
return errors;
process.exit(0);
}

run();
13 changes: 5 additions & 8 deletions checkToken.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require("fs");
const tokensDirectory = "./src/tokens/";
const Schema = require("validate");
const fs = require('fs');
const tokensDirectory = './src/tokens/';
const Schema = require('validate');
const token = new Schema({
symbol: {
type: String,
Expand Down Expand Up @@ -93,20 +93,17 @@ const token = new Schema({
}
});

let errors = 0;

function run() {
fs.readdirSync(tokensDirectory).forEach(folder => {
fs.readdirSync(`${tokensDirectory}/${folder}`).forEach(file => {
const obj = JSON.parse(
fs.readFileSync(`${tokensDirectory}/${folder}/${file}`, "utf8")
fs.readFileSync(`${tokensDirectory}/${folder}/${file}`, 'utf8')
);
if (token.validate(obj) === false) {
errors++;
process.exit(1);
}
});
});
return errors;
}

run();

0 comments on commit 7714360

Please sign in to comment.