From 7e221d3108fe372e1264f8f9a3fb50bdf0cb6816 Mon Sep 17 00:00:00 2001 From: Harvey Sanders Date: Tue, 30 Jan 2024 17:27:47 +0000 Subject: [PATCH] Add dotenv, dev greenlight URL, cleanup --- .devcontainer/devcontainer.json | 9 ++++++++- .eslintrc.js | 2 +- .gitignore | 3 ++- config.js | 6 ++++++ controller/greenlight.js | 6 +++--- index.js | 2 +- package-lock.json | 14 +++++++++++++- package.json | 1 + test/test-auto-install-projects.js | 12 ++++++------ test/test-projects.js | 8 ++++---- 10 files changed, 45 insertions(+), 18 deletions(-) create mode 100644 config.js diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 666be2b..9c81633 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,7 +3,14 @@ { "name": "Node.js", // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "mcr.microsoft.com/devcontainers/javascript-node:1-20-bullseye" + "image": "mcr.microsoft.com/devcontainers/javascript-node:1-20-bullseye", + "customizations": { + "vscode": { + "extensions": [ + "esbenp.prettier-vscode" + ] + } + } // Features to add to the dev container. More info: https://containers.dev/features. // "features": {}, diff --git a/.eslintrc.js b/.eslintrc.js index 5087b3d..1ae2bad 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,7 +3,7 @@ module.exports = { plugins: ['import'], rules: { // enable additional rules - quotes: ['error', 'single'], + quotes: ['error', 'single', { "avoidEscape": true }], semi: ['error', 'always'], // disable rules from base configurations diff --git a/.gitignore b/.gitignore index 49277e3..7d7109f 100644 --- a/.gitignore +++ b/.gitignore @@ -43,4 +43,5 @@ test/files/environment/projects .secrets user -auth \ No newline at end of file +auth +.env* diff --git a/config.js b/config.js new file mode 100644 index 0000000..12c98f3 --- /dev/null +++ b/config.js @@ -0,0 +1,6 @@ +const { GREENLIGHT_HOST, NODE_ENV } = process.env; + +module.exports = { + isDevMode: NODE_ENV === 'development', + devGreenlightHost: GREENLIGHT_HOST || 'http://localhost:3000' +}; diff --git a/controller/greenlight.js b/controller/greenlight.js index 3840037..72b5442 100644 --- a/controller/greenlight.js +++ b/controller/greenlight.js @@ -2,11 +2,11 @@ const clc = require('cli-color'); const rp = require('request-promise'); const github = require('./github'); +const { devGreenlightHost, isDevMode } = require('../config'); -// TODO: Switch URI for live version -const LOCALHOST = 'http://localhost:3000'; const GREENLIGHT = 'https://greenlight.operationspark.org'; -const URI = GREENLIGHT; +// TODO: Switch URI for live version +const URI = isDevMode ? devGreenlightHost : GREENLIGHT; module.exports.URI = URI; diff --git a/index.js b/index.js index 90370af..9975287 100755 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ #! /usr/bin/env node 'use strict'; - +require('dotenv').config(); const program = require('commander'); const fs = require('fs'); const pjson = require('./package.json'); diff --git a/package-lock.json b/package-lock.json index b837763..162ae2e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "cli-view": "^1.0.0", "commander": "^2.11.0", "cross-env": "^7.0.3", + "dotenv": "^16.4.1", "express": "^4.15.3", "fs-extra": "^11.2.0", "fs-json": "^0.1.2", @@ -1161,6 +1162,17 @@ "sentence-case": "^1.1.2" } }, + "node_modules/dotenv": { + "version": "16.4.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.1.tgz", + "integrity": "sha512-CjA3y+Dr3FyFDOAMnxZEGtnW9KBR2M0JvvUtXNW+dYJL5ROWxP9DUHCwgFqpMk0OXCc0ljhaNTr2w/kutYIcHQ==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/motdotla/dotenv?sponsor=1" + } + }, "node_modules/ecc-jsbn": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", @@ -1766,7 +1778,7 @@ "node_modules/express/node_modules/raw-body": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.2.tgz", - "integrity": "sha1-vNYMd9Prk83gBQKVw/N5OJvIj4k=", + "integrity": "sha512-Ss0DsBxqLxCmQkfG5yazYhtbVVTJqS9jTsZG2lhrNwqzOk2SUC7O/NB/M//CkEBqsrtmlNgJCPccJGuYSFr6Vg==", "dependencies": { "bytes": "3.0.0", "http-errors": "1.6.2", diff --git a/package.json b/package.json index f6a962b..758cf1b 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "cli-view": "^1.0.0", "commander": "^2.11.0", "cross-env": "^7.0.3", + "dotenv": "^16.4.1", "express": "^4.15.3", "fs-extra": "^11.2.0", "fs-json": "^0.1.2", diff --git a/test/test-auto-install-projects.js b/test/test-auto-install-projects.js index 77a5745..5ca4861 100644 --- a/test/test-auto-install-projects.js +++ b/test/test-auto-install-projects.js @@ -17,20 +17,20 @@ const projects = proxyquire('../controller/projects', { } }); -const readAndParse = path => JSON.parse(fs.readFileSync(path)); -//recursively grabs projects +const readAndParse = path => JSON.parse(fs.readFileSync(path, 'utf-8')); +// recursively grabs projects describe('#installProject()', function () { - dummySession.PROJECT.forEach((project) => { + dummySession.PROJECT.forEach(project => { it(`should install project for ${project.name}`, function (done) { projects.installProject(project).then(function (results) { - expect(results).to.be.an.object; + expect(results).to.be.an('object'); expect(results.name).to.exist; expect(results._id).to.exist; expect(results.desc).to.exist; expect(results.url).to.exist; done(); }); - }) - }); + }); }); +}); diff --git a/test/test-projects.js b/test/test-projects.js index 02ca125..24450f6 100644 --- a/test/test-projects.js +++ b/test/test-projects.js @@ -92,7 +92,7 @@ describe('projects', function () { projects .selectProject({ session: dummySession, projectAction: 'install' }) .then(function (project) { - expect(project).to.be.an.object; + expect(project).to.be.an('object'); expect(project.name).to.equal('Function Master'); expect(project._id).to.exist; expect(project._session).to.exist; @@ -107,7 +107,7 @@ describe('projects', function () { projects .selectProject({ session: dummySession, projectAction: 'install' }) .then(function (project) { - expect(project).to.be.an.object; + expect(project).to.be.an('object'); expect(project.name).to.equal('Function Master'); expect(project._id).to.exist; expect(project._session).to.exist; @@ -129,7 +129,7 @@ describe('projects', function () { it('should install project', function (done) { projects.installProject(dummySession.PROJECT[2]).then(function (project) { - expect(project).to.be.an.object; + expect(project).to.be.an('object'); expect(project.name).to.equal('Matchy'); expect(project._id).to.exist; expect(project._session).to.exist; @@ -141,7 +141,7 @@ describe('projects', function () { it('should install project', function (done) { projects.installProject(dummySession.PROJECT[3]).then(function (project) { - expect(project).to.be.an.object; + expect(project).to.be.an('object'); expect(project.name).to.equal('Function Master'); expect(project._id).to.exist; expect(project._session).to.exist;