Skip to content

Commit

Permalink
Auto format (#58)
Browse files Browse the repository at this point in the history
* Add auto formatting packages

* prettier fixes

* eslint fixes

* add github action

* Add google styles to Prettier

* Fix format after merge
  • Loading branch information
danabreo authored Jul 10, 2020
1 parent 5a1274f commit f726c01
Show file tree
Hide file tree
Showing 29 changed files with 1,691 additions and 267 deletions.
17 changes: 17 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
env: {
browser: true,
es2020: true,
node: true,
mocha: true,
},
extends: ['eslint:recommended', 'google', 'prettier'],
parserOptions: {
ecmaVersion: 11,
sourceType: 'module',
},
plugins: ['hbs'],
rules: {
'hbs/check-hbs-template-literals': 2,
},
};
19 changes: 19 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Code Quality Check

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
quality-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: 'Install Dependancies'
run: npm ci
- name: 'Run Linter'
run: npm run lint-check
- name: 'Run Formatter'
run: npm run format-check
121 changes: 121 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# 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
*.lcov

# 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/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# 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
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# VSCode
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
.vscode

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# Mac OS
.DS_Store
15 changes: 15 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"bracketSpacing": false,
"printWidth": 100,
"singleQuote": true,
"jsxBracketSameLine": true,
"overrides": [
{
"files": "*.handlebars",
"options": {
"parser": "html",
"printWidth": 100
}
}
]
}
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
# Node.js skeleton repo for Google STEP Intern Program

## Get started
## Get started

You need to have an active Node.js installation on your laptop before startup this skeleton Node.js server. We recommend to install `nvm` [(Node Version Manager)](https://github.com/nvm-sh/nvm) to manage your local Node.js builds.

To install `nvm`:
To install `nvm`:

```
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
```

To install LTS version (`node v12.18.0`) of Node.js with `nvm`:

```
nvm install 12.18.0
```

To verify the LTS version is successfully installed:

```
node -v
```

## Install and Launch

To install and launch this skeleton server on your local instance, first run
```npm install```
`npm install`

then run
then run

```npm start```
`npm start`

After few seconds, your local instance of this skeleton server should be available at `http://localhost:3000`.
After few seconds, your local instance of this skeleton server should be available at `http://localhost:3000`.
39 changes: 22 additions & 17 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
const PROD_WARNING_MESSAGE = `
██  ██  █████  ██████  ███  ██ ██ ███  ██  ██████  ██ 
██  ██ ██   ██ ██   ██ ████  ██ ██ ████  ██ ██       ██ 
Expand All @@ -10,37 +11,40 @@ You are running the app using production config (Firestore Database, Map API key
If you are developing the app locally, please use "npm run dev" to start the app.
`;
/* eslint-enable */

// Show production warning message and load API keys.
if (process.env.NODE_ENV === 'production') {
console.log(PROD_WARNING_MESSAGE);
require('dotenv').config({path: ".env.prod"});
require('dotenv').config({path: '.env.prod'});
} else {
require('dotenv').config({path: ".env.dev"});
require('dotenv').config({path: '.env.dev'});
}

// Module dependencies.
const express = require('express');
const http = require('http');
const path = require('path');
const handlebars = require('express-handlebars')
const handlebars = require('express-handlebars');
const passport = require('passport');
const cookieSession = require('cookie-session');
require('./passport-auth');

var app = express();
const app = express();

// Environments configs.
// Environments configs.
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.engine('handlebars', handlebars());
app.set('view engine', 'handlebars');
app.use(express.urlencoded());
app.use('/static', express.static('public'));
app.use(cookieSession({
name: 'auth-session',
keys: ['key1', 'key2'],
}));
app.use(
cookieSession({
name: 'auth-session',
keys: ['key1', 'key2'],
})
);
app.use(passport.initialize());
app.use(passport.session());

Expand All @@ -52,24 +56,25 @@ const isLoggedIn = (req, res, next) => {
// TODO: Redirect users back to login page.
res.sendStatus(401);
}
}
};

// Routes.
app.get('/', (req, res) => res.render('landing'));

const discover = require('./routes/discover')
const discover = require('./routes/discover');
app.get('/discover', discover.view);
app.get('/discover/:filter', discover.getOrganizations);

const dashboard = require('./routes/dashboard');
app.get('/dashboard/:page?', isLoggedIn, dashboard.view);

app.get('/auth/google',
passport.authenticate('google', {scope: ['profile']}));
app.get('/auth/google', passport.authenticate('google', {scope: ['profile']}));

app.get('/auth/google/callback',
passport.authenticate('google', {failureRedirect: '/'}),
(req, res) => res.redirect('/dashboard'));
app.get(
'/auth/google/callback',
passport.authenticate('google', {failureRedirect: '/'}),
(req, res) => res.redirect('/dashboard')
);

app.get('/auth/logout', (req, res) => {
req.session = null;
Expand All @@ -82,7 +87,7 @@ app.get('/data', data.view);

http.createServer(app).listen(app.get('port'), function () {
console.log('Express server listening on port ' + app.get('port'));
app.emit("app_started");
app.emit('app_started');
});

// Exporting for running unit tests.
Expand Down
28 changes: 14 additions & 14 deletions gcp/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
steps:
- name: node
entrypoint: npm
args: ['install']
- name: node
entrypoint: npm
args: ["run", "create-env-dev"]
env:
- 'MAPS_KEY=${_MAPS_PROD_KEY}'
- 'PASSPORT_CLIENT_ID=${_PASSPORT_DEV_CLIENT_ID}'
- 'PASSPORT_CLIENT_SECRET=${_PASSPORT_DEV_CLIENT_SECRET}'
- 'BASE_URL=${_BASE_URL}'
- name: node
entrypoint: npm
args: ['test']
- name: node
entrypoint: npm
args: ['install']
- name: node
entrypoint: npm
args: ['run', 'create-env-dev']
env:
- 'MAPS_KEY=${_MAPS_PROD_KEY}'
- 'PASSPORT_CLIENT_ID=${_PASSPORT_DEV_CLIENT_ID}'
- 'PASSPORT_CLIENT_SECRET=${_PASSPORT_DEV_CLIENT_SECRET}'
- 'BASE_URL=${_BASE_URL}'
- name: node
entrypoint: npm
args: ['test']
28 changes: 14 additions & 14 deletions gcp/clouddeploy.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
steps:
- name: node
entrypoint: npm
args: ['install']
- name: node
entrypoint: npm
args: ["run", "create-env-prod"]
env:
- 'MAPS_KEY=${_MAPS_PROD_KEY}'
- 'PASSPORT_CLIENT_ID=${_PASSPORT_PROD_CLIENT_ID}'
- 'PASSPORT_CLIENT_SECRET=${_PASSPORT_PROD_CLIENT_SECRET}'
- 'BASE_URL=${_BASE_URL}'
- name: "gcr.io/cloud-builders/gcloud"
args: ["app", "deploy"]
timeout: 1800s
- name: node
entrypoint: npm
args: ['install']
- name: node
entrypoint: npm
args: ['run', 'create-env-prod']
env:
- 'MAPS_KEY=${_MAPS_PROD_KEY}'
- 'PASSPORT_CLIENT_ID=${_PASSPORT_PROD_CLIENT_ID}'
- 'PASSPORT_CLIENT_SECRET=${_PASSPORT_PROD_CLIENT_SECRET}'
- 'BASE_URL=${_BASE_URL}'
- name: 'gcr.io/cloud-builders/gcloud'
args: ['app', 'deploy']
timeout: 1800s
timeout: 3000s
Loading

0 comments on commit f726c01

Please sign in to comment.