Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ES6 Support #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added ES6 Support
Bhavesh27 committed Oct 18, 2020

Verified

This commit was signed with the committer’s verified signature.
darcyclarke Darcy Clarke
commit a8234350a6918c26ceb61a5520dae0815819cce3
5 changes: 5 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": [
"@babel/preset-env"
]
}
7 changes: 4 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"extends": [
"eslint:recommended",
"eslint:recommended"
],
"parserOptions": {
"ecmaVersion": 2018
"sourceType": "module",
"ecmaVersion": 2020
},
"env": {
"es6": true,
"node": true
}
}
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ngrok
node_modules/
.env
.env
dist
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Ignore directories
node_modules
docs
docs
dist
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -10,6 +10,10 @@
"mongoose": "^5.9.7"
},
"devDependencies": {
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"@babel/node": "^7.12.1",
"@babel/preset-env": "^7.12.1",
"env-cmd": "^10.1.0",
"eslint": "^7.11.0",
"husky": "^4.3.0",
@@ -18,8 +22,9 @@
"nodemon": "^2.0.4"
},
"scripts": {
"start": "node index.js",
"dev": "env-cmd -f .env nodemon index.js",
"start": "node dist",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have auto deployments for Vacabot app using heroku.
And there we have configured npm start as the running script.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which means, this dist has to be created before running

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mukarramali Can you Check once i think heroku builds automatically before deployments.
https://devcenter.heroku.com/changelog-items/1557

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's great.
But we don't have build script in package.json.
You wanna add that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mukarramali In the PR i have already added the build script. PR is good to go.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out babel didn't pick the environment variables.
To test it in your machine, you can first creat .env file as told in README. And then do build and start.
It should through an error as expected env variables aren't present.

"build": "babel vacabot --out-dir dist",
"dev": "env-cmd -f .env nodemon --exec babel-node vacabot/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
@@ -36,7 +41,8 @@
"verbose": true,
"ignore": [
"test/*",
"docs/*"
"docs/*",
"dist/*"
],
"delay": "1000"
},
12 changes: 6 additions & 6 deletions vacabot/actions.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const {
import {
triggerSlack,
templateVacationDialog,
formSubmitData,
} = require("./helpers");
const C = require("./consts");
const Vacation = require("./models/vacation");
const User = require("./models/user");
} from "./helpers"
import C from "./consts"
import Vacation from "./models/vacation"
import User from "./models/user"

async function actionSubmitVacationRequest(user, payload) {
const formData = formSubmitData(payload);
@@ -50,7 +50,7 @@ async function actionCheckVacationBalance(responseUrl, query) {
});
}

module.exports = {
export default {
actionCheckVacationBalance,
actionDenyVacationRequest,
actionOpenCreateVacation,
2 changes: 1 addition & 1 deletion vacabot/consts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = Object.freeze({
export default Object.freeze({
SET_MANAGER: 'SET_MANAGER',
OPEN_DIALOG_CREATE_VACATION: 'OPEN_DIALOG_CREATE_VACATION',
CHECK_VACATION: 'CHECK_VACATION',
6 changes: 3 additions & 3 deletions vacabot/db.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var mongoose = require("mongoose");
const C = require("./consts");
import mongoose from "mongoose"
import C from "./consts"

const db = mongoose.createConnection(C.DB_CONNECTION_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
});

module.exports = db;
export default db;
6 changes: 3 additions & 3 deletions vacabot/helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const https = require("https");
const C = require("./consts");
import https from "https"
import C from "./consts"

function triggerSlack(url, reqBody) {
return new Promise((resolve, reject) => {
@@ -217,7 +217,7 @@ function logAction(action) {
console.log(`========${action}========`)
}

module.exports = {
export default {
triggerSlack,
templateApprovalPayload,
templateVacationDialog,
18 changes: 9 additions & 9 deletions index.js → vacabot/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
const http = require("http");
const { parse } = require("querystring");
const {
import http from "http"
import { parse } from "querystring"
import {
predictAction,
predictInteraction,
logAction
} = require("./vacabot/helpers");
const {
} from "./helpers"
import {
actionCheckVacationBalance,
actionDenyVacationRequest,
actionOpenCreateVacation,
actionSubmitVacationRequest,
actionUpdateManager
} = require("./vacabot/actions");
const C = require("./vacabot/consts");
const User = require("./vacabot/models/user");
} from "./actions"
import C from "./consts"
import User from "./models/user"

function serverHandler(req, res) {
let body = [];
@@ -24,7 +24,7 @@ function serverHandler(req, res) {
try {
body = parse(Buffer.concat(body).toString());
mainHandler(body);
} catch(err) {
} catch (err) {
console.error(err);
}
res.writeHead(200, { "content-type": "application/json" });
14 changes: 7 additions & 7 deletions vacabot/models/user.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { Schema } = require("mongoose");
import { Schema } from "mongoose"

const db = require("../db");
const { triggerSlack } = require("../helpers");
const C = require("../consts");
import db from "../db"
import { triggerSlack } from "../helpers"
import C from "../consts"

const userSchema = new Schema({
userId: { type: "String", required: true, unique: true },
@@ -52,11 +52,11 @@ userSchema.methods.updateVacationBalance = function (days) {
};

userSchema.methods.theirManager = function () {
return this.model("User").findOne({teamId: this.teamId, ifManager: true})
return this.model("User").findOne({ teamId: this.teamId, ifManager: true })
}

userSchema.methods.setAsManager = async function () {
this.model("User").updateOne({teamId: this.teamId, ifManager: true}, {ifManager: false})
this.model("User").updateOne({ teamId: this.teamId, ifManager: true }, { ifManager: false })
this.ifManager = true;
this.save();
}
@@ -83,4 +83,4 @@ User.createIfNotExists = async function ({
return user;
};

module.exports = User;
export default User;
12 changes: 6 additions & 6 deletions vacabot/models/vacation.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { Schema } = require("mongoose");
import { Schema } from "mongoose"

const db = require("../db");
const { triggerSlack, templateApprovalPayload } = require("../helpers");
const C = require("../consts");
import db from "../db"
import { triggerSlack, templateApprovalPayload } from "../helpers"
import C from "../consts"

const vacationSchema = new Schema({
user: {
@@ -22,7 +22,7 @@ vacationSchema.methods.reduceVacationBalance = function () {

vacationSchema.methods.notifyManager = function () {
this.user.theirManager().then((manager) => {
if(!manager) {
if (!manager) {
this.user.getChannelId().then((channelId) => {
triggerSlack(C.POST_MSG_URL, {
channel: channelId,
@@ -65,4 +65,4 @@ vacationSchema.methods.denied = function () {

const Vacation = db.model("Vacation", vacationSchema);

module.exports = Vacation;
export default Vacation;
2,057 changes: 2,045 additions & 12 deletions yarn.lock

Large diffs are not rendered by default.