Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zarathustra323 committed Apr 25, 2019
0 parents commit fd2b791
Show file tree
Hide file tree
Showing 8 changed files with 3,799 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
extends: 'airbnb-base',
plugins: [
'import'
],
rules: {
'no-underscore-dangle': [ 'error', { allow: ['_id'] } ],
},
};
84 changes: 84 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/
58 changes: 58 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const {
parallel,
src,
watch,
} = require('gulp');
const cache = require('gulp-cached');
const eslint = require('gulp-eslint');
const log = require('fancy-log');
const {
green,
magenta,
cyan,
red,
yellow,
} = require('chalk');
const { spawn } = require('child_process');

let isFirstRun = true;
let node;
const server = async () => {
if (node) node.kill();
isFirstRun = false;
node = await spawn('node', ['src/index.js'], { stdio: ['inherit', 'inherit', 'inherit', 'ipc'] });
node.on('message', (msg) => {
if (msg.event === 'ready') {
log(`Server ${green('ready')} on ${yellow(msg.location)}`);
}
});
node.on('close', (code, signal) => {
const exited = [];
if (code) exited.push(`code ${magenta(code)}`);
if (signal) exited.push(`signal ${magenta(signal)}`);
log(`Process ${green('exited')} with ${exited.join(' ')}`);
});
};

const lintScripts = () => src(['src/**/*.js'])
.pipe(cache('lint'))
.pipe(eslint())
.pipe(eslint.format());


const serve = () => {
const watcher = watch(
['src/**/*.js'],
{ queue: false, ignoreInitial: false },
parallel(lintScripts, server),
);
watcher.on('add', (path) => {
if (!isFirstRun) log(`File ${green(path)} was ${green('added')}`);
});
watcher.on('change', path => log(`File ${green(path)} was ${cyan('changed')}`));
watcher.on('unlink', path => log(`File ${green(path)} was ${red('removed')}.`));
};

exports.default = serve;
exports.serve = serve;
exports['lint:js'] = lintScripts;
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "projector-button",
"version": "1.0.0",
"main": "src/index.js",
"license": "MIT",
"private": true,
"scripts": {
"dev": "node_modules/.bin/gulp"
},
"devDependencies": {
"chalk": "^2.4.2",
"eslint": "^5.16.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.17.2",
"fancy-log": "^1.3.3",
"gulp": "^4.0.1",
"gulp-cached": "^1.1.1",
"gulp-eslint": "^5.0.0"
},
"dependencies": {
"envalid": "^5.0.0",
"express": "^4.16.4",
"node-fetch": "^2.3.0"
}
}
12 changes: 12 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const express = require('express');
const { USERNAME, PASSWORD } = require('./env');

const app = express();

const createAuth = () => Buffer.from(`${USERNAME}:${PASSWORD}`).toString('base64');

app.get('/', (req, res) => {
res.json({ ping: 'pong', auth: createAuth() });
});

module.exports = app;
17 changes: 17 additions & 0 deletions src/env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { makeValidator, cleanEnv } = require('envalid');

const nonemptystr = makeValidator((v) => {
const err = new Error('Expected a non-empty string');
if (v === undefined || v === null || v === '') {
throw err;
}
const trimmed = String(v).trim();
if (!trimmed) throw err;
return trimmed;
});

module.exports = cleanEnv(process.env, {
USERNAME: nonemptystr({ desc: 'The projector username.' }),
PASSWORD: nonemptystr({ desc: 'The projector password.' }),
PROJECTOR_URI: nonemptystr({ desc: 'The projector URI.' }),
});
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const app = require('./app');

const port = process.env.PORT || 4999;
app.listen(port, () => {
if (process.send) process.send({ event: 'ready', location: `http://0.0.0.0:${port}` });
});
Loading

0 comments on commit fd2b791

Please sign in to comment.