Skip to content

Commit cfcd5e9

Browse files
authored
Merge pull request #10 from nib-health-funds/linting
Lint the project using eslint and airbnb base config
2 parents 22c99af + 048b12e commit cfcd5e9

9 files changed

Lines changed: 891 additions & 920 deletions

File tree

.eslintrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "airbnb",
3+
"rules": {
4+
"no-console": "off"
5+
},
6+
"plugins": [
7+
"mocha"
8+
],
9+
"env": {
10+
"mocha": true
11+
}
12+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ node_modules
66
.swo
77
.swp
88
.DS_Store
9+
**/npm-debug.log

hammertime.js

Lines changed: 126 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,126 @@
1-
'use strict';
2-
3-
const instances = require('./src/instances')
4-
const asgs = require('./src/asgs')
5-
6-
module.exports.stop = (event, context, callback) => {
7-
console.log('Stop. Hammertime!');
8-
Promise.all([
9-
stopInstances(),
10-
stopASGs(),
11-
]).then(responses => {
12-
console.log('All instances and ASGs stopped successfully. Good night!');
13-
callback(null, { message: 'Stop: Hammertime successfully completed.' }, event);
14-
}).catch(err => {
15-
console.error(err);
16-
callback(err);
17-
});
18-
};
19-
20-
module.exports.start = (event, context, callback) => {
21-
console.log('Break it down!');
22-
Promise.all([
23-
startInstances(),
24-
startASGs(),
25-
]).then(responses => {
26-
console.log('All instances and ASGs started successfully. Good morning!');
27-
callback(null, { message: 'Start: Hammertime successfully completed.' }, event);
28-
}).catch(err => {
29-
console.error(err);
30-
callback(err);
31-
});
32-
};
33-
34-
function stopInstances() {
35-
return new Promise((resolve, reject) => {
36-
instances.listInstancesToStop()
37-
.then(stoppableInstances => {
38-
console.log("Found the following instances to shut down...");
39-
if (stoppableInstances.length === 0) {
40-
console.log("None! Moving on.");
41-
resolve("No instances to shut down");
42-
}
43-
44-
stoppableInstances.forEach(instance => {
45-
console.log(instance);
46-
});
47-
return instances.tagInstances(stoppableInstances);
48-
})
49-
.then(taggedInstances => {
50-
console.log("Finished tagging instances. Moving on to stop them.");
51-
return instances.stopInstances(taggedInstances);
52-
})
53-
.then(resolve)
54-
.catch(reject);
55-
});
56-
}
57-
58-
function startInstances() {
59-
return new Promise((resolve, reject) => {
60-
instances.listInstancesToStart()
61-
.then(startableInstances => {
62-
console.log(`Found the following ${startableInstances.length} instances to start up...`);
63-
if (startableInstances.length === 0) {
64-
console.log("None! Moving on.");
65-
resolve("No instances to turn on");
66-
}
67-
68-
startableInstances.forEach(instance => {
69-
console.log(instance);
70-
});
71-
return instances.startInstances(startableInstances);
72-
})
73-
.then(startedInstances => {
74-
console.log("Finished starting instances. Moving on to untag them.");
75-
return instances.untagInstances(startedInstances);
76-
})
77-
.then(resolve)
78-
.catch(reject);
79-
});
80-
}
81-
82-
function stopASGs() {
83-
return new Promise((resolve, reject) => {
84-
asgs.listASGsToStop()
85-
.then(stoppableASGs => {
86-
console.log(`Found the following ${stoppableASGs.length} instances to spin down...`);
87-
if (stoppableASGs.length === 0) {
88-
console.log("None! Moving on.");
89-
resolve("No ASGs to spin down");
90-
}
91-
92-
stoppableASGs.forEach(asg => {
93-
console.log(asg.AutoScalingGroupName);
94-
});
95-
return asgs.tagASGs(stoppableASGs);
96-
})
97-
.then(taggedASGs => {
98-
console.log(`Finished tagging ASGs. Moving on to spin down ${taggedASGs.length} of them.`);
99-
return asgs.stopASGs(taggedASGs);
100-
})
101-
.then(resolve)
102-
.catch(reject);
103-
});
104-
}
105-
106-
function startASGs() {
107-
return new Promise((resolve, reject) => {
108-
asgs.listASGsToStart()
109-
.then(startableASGs => {
110-
console.log(`Found the following ${startableASGs.length} instances to start up...`);
111-
if (startableASGs.length === 0) {
112-
console.log("None! Moving on.");
113-
resolve("No ASGs to spin up");
114-
}
115-
116-
startableASGs.forEach(asg => {
117-
console.log(asg.AutoScalingGroupName);
118-
});
119-
return asgs.startASGs(startableASGs);
120-
})
121-
.then(startedASGs => {
122-
console.log(`Finished spinning up ASGs. Moving on to untag ${startedASGs.length} of them.`);
123-
return asgs.untagASGs(startedASGs);
124-
})
125-
.then(resolve)
126-
.catch(reject);
127-
});
128-
}
1+
const instances = require('./src/instances');
2+
const asgs = require('./src/asgs');
3+
4+
function stopInstances() {
5+
return new Promise((resolve, reject) => {
6+
instances.listInstancesToStop()
7+
.then((stoppableInstances) => {
8+
console.log('Found the following instances to shut down...');
9+
if (stoppableInstances.length === 0) {
10+
console.log('None! Moving on.');
11+
resolve('No instances to shut down');
12+
}
13+
14+
stoppableInstances.forEach((instance) => {
15+
console.log(instance);
16+
});
17+
return instances.tagInstances(stoppableInstances);
18+
})
19+
.then((taggedInstances) => {
20+
console.log('Finished tagging instances. Moving on to stop them.');
21+
return instances.stopInstances(taggedInstances);
22+
})
23+
.then(resolve)
24+
.catch(reject);
25+
});
26+
}
27+
28+
function startInstances() {
29+
return new Promise((resolve, reject) => {
30+
instances.listInstancesToStart()
31+
.then((startableInstances) => {
32+
console.log(`Found the following ${startableInstances.length} instances to start up...`);
33+
if (startableInstances.length === 0) {
34+
console.log('None! Moving on.');
35+
resolve('No instances to turn on');
36+
}
37+
38+
startableInstances.forEach((instance) => {
39+
console.log(instance);
40+
});
41+
return instances.startInstances(startableInstances);
42+
})
43+
.then((startedInstances) => {
44+
console.log('Finished starting instances. Moving on to untag them.');
45+
return instances.untagInstances(startedInstances);
46+
})
47+
.then(resolve)
48+
.catch(reject);
49+
});
50+
}
51+
52+
function stopASGs() {
53+
return new Promise((resolve, reject) => {
54+
asgs.listASGsToStop()
55+
.then((stoppableASGs) => {
56+
console.log(`Found the following ${stoppableASGs.length} instances to spin down...`);
57+
if (stoppableASGs.length === 0) {
58+
console.log('None! Moving on.');
59+
resolve('No ASGs to spin down');
60+
}
61+
62+
stoppableASGs.forEach((asg) => {
63+
console.log(asg.AutoScalingGroupName);
64+
});
65+
return asgs.tagASGs(stoppableASGs);
66+
})
67+
.then((taggedASGs) => {
68+
console.log(`Finished tagging ASGs. Moving on to spin down ${taggedASGs.length} of them.`);
69+
return asgs.stopASGs(taggedASGs);
70+
})
71+
.then(resolve)
72+
.catch(reject);
73+
});
74+
}
75+
76+
function startASGs() {
77+
return new Promise((resolve, reject) => {
78+
asgs.listASGsToStart()
79+
.then((startableASGs) => {
80+
console.log(`Found the following ${startableASGs.length} instances to start up...`);
81+
if (startableASGs.length === 0) {
82+
console.log('None! Moving on.');
83+
resolve('No ASGs to spin up');
84+
}
85+
86+
startableASGs.forEach((asg) => {
87+
console.log(asg.AutoScalingGroupName);
88+
});
89+
return asgs.startASGs(startableASGs);
90+
})
91+
.then((startedASGs) => {
92+
console.log(`Finished spinning up ASGs. Moving on to untag ${startedASGs.length} of them.`);
93+
return asgs.untagASGs(startedASGs);
94+
})
95+
.then(resolve)
96+
.catch(reject);
97+
});
98+
}
99+
100+
module.exports.start = (event, context, callback) => {
101+
console.log('Break it down!');
102+
Promise.all([
103+
startInstances(),
104+
startASGs(),
105+
]).then(() => {
106+
console.log('All instances and ASGs started successfully. Good morning!');
107+
callback(null, { message: 'Start: Hammertime successfully completed.' }, event);
108+
}).catch((err) => {
109+
console.error(err);
110+
callback(err);
111+
});
112+
};
113+
114+
module.exports.stop = (event, context, callback) => {
115+
console.log('Stop. Hammertime!');
116+
Promise.all([
117+
stopInstances(),
118+
stopASGs(),
119+
]).then(() => {
120+
console.log('All instances and ASGs stopped successfully. Good night!');
121+
callback(null, { message: 'Stop: Hammertime successfully completed.' }, event);
122+
}).catch((err) => {
123+
console.error(err);
124+
callback(err);
125+
});
126+
};

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"scripts": {
77
"deploy": "node_modules/serverless/bin/serverless deploy --verbose",
88
"destroy": "node_modules/serverless/bin/serverless remove --verbose",
9-
"test": "node_modules/mocha/bin/mocha test/*.test.js"
9+
"lint": "eslint **/*.js",
10+
"test": "npm run lint && npm run test.unit",
11+
"test.unit": "mocha test/*.test.js"
1012
},
1113
"repository": {
1214
"type": "git",
@@ -21,6 +23,12 @@
2123
},
2224
"devDependencies": {
2325
"aws-sdk-mock": "^1.6.1",
26+
"eslint": "^3.15.0",
27+
"eslint-config-airbnb": "^14.1.0",
28+
"eslint-plugin-import": "^2.2.0",
29+
"eslint-plugin-jsx-a11y": "^4.0.0",
30+
"eslint-plugin-mocha": "^4.9.0",
31+
"eslint-plugin-react": "^6.9.0",
2432
"mocha": "^3.2.0"
2533
}
2634
}

schedule.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
module.exports.enabled = () => {
2-
return process.env.SLICE === "master";
3-
}
1+
module.exports.enabled = () => process.env.SLICE === 'master';

0 commit comments

Comments
 (0)