From ca59d866284bcd5ad45dea90ce628dde00bcd346 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Wed, 5 Oct 2016 10:57:10 +0800 Subject: Remove config files from version control --- .gitignore | 7 +++- .sequelizerc | 8 ----- config.json | 52 ----------------------------- public/js/common.js | 95 ----------------------------------------------------- 4 files changed, 6 insertions(+), 156 deletions(-) delete mode 100644 .sequelizerc delete mode 100644 config.json delete mode 100644 public/js/common.js diff --git a/.gitignore b/.gitignore index 794cf9ee..f6c8d5da 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,9 @@ tmp/ backups/ *.pid *.log -*.sqlite \ No newline at end of file +*.sqlite + +# ignore config files +config.json +public/js/common.js +.sequelizerc diff --git a/.sequelizerc b/.sequelizerc deleted file mode 100644 index 29a0d145..00000000 --- a/.sequelizerc +++ /dev/null @@ -1,8 +0,0 @@ -var path = require('path'); - -module.exports = { - 'config': path.resolve('config.json'), - 'migrations-path': path.resolve('lib', 'migrations'), - 'models-path': path.resolve('lib', 'models'), - 'url': 'change this' -} \ No newline at end of file diff --git a/config.json b/config.json deleted file mode 100644 index 35efcd25..00000000 --- a/config.json +++ /dev/null @@ -1,52 +0,0 @@ -{ - "development": { - "domain": "localhost", - "db": { - "username": "", - "password": "", - "database": "hackmd", - "host": "localhost", - "port": "3306", - "dialect": "mysql" - } - }, - "production": { - "domain": "localhost", - "db": { - "username": "", - "password": "", - "database": "hackmd", - "host": "localhost", - "port": "5432", - "dialect": "postgres" - }, - "facebook": { - "clientID": "change this", - "clientSecret": "change this" - }, - "twitter": { - "consumerKey": "change this", - "consumerSecret": "change this" - }, - "github": { - "clientID": "change this", - "clientSecret": "change this" - }, - "gitlab": { - "baseURL": "change this", - "clientID": "change this", - "clientSecret": "change this" - }, - "dropbox": { - "clientID": "change this", - "clientSecret": "change this" - }, - "google": { - "clientID": "change this", - "clientSecret": "change this" - }, - "imgur": { - "clientID": "change this" - } - } -} \ No newline at end of file diff --git a/public/js/common.js b/public/js/common.js deleted file mode 100644 index 11c32acc..00000000 --- a/public/js/common.js +++ /dev/null @@ -1,95 +0,0 @@ -//common -var domain = ''; // domain name -var urlpath = ''; // sub url path, like: www.example.com/ -//settings -var debug = false; - -var GOOGLE_API_KEY = ''; -var GOOGLE_CLIENT_ID = ''; - -var DROPBOX_APP_KEY = ''; - -var port = window.location.port; -var serverurl = window.location.protocol + '//' + (domain ? domain : window.location.hostname) + (port ? ':' + port : '') + (urlpath ? '/' + urlpath : ''); -var noteid = urlpath ? window.location.pathname.slice(urlpath.length + 1, window.location.pathname.length).split('/')[1] : window.location.pathname.split('/')[1]; -var noteurl = serverurl + '/' + noteid; - -var version = '0.4.4'; - -var checkAuth = false; -var profile = null; -var lastLoginState = getLoginState(); -var lastUserId = getUserId(); -var loginStateChangeEvent = null; - -function resetCheckAuth() { - checkAuth = false; -} - -function setLoginState(bool, id) { - Cookies.set('loginstate', bool, { - expires: 365 - }); - if (id) { - Cookies.set('userid', id, { - expires: 365 - }); - } else { - Cookies.remove('userid'); - } - lastLoginState = bool; - lastUserId = id; - checkLoginStateChanged(); -} - -function checkLoginStateChanged() { - if (getLoginState() != lastLoginState || getUserId() != lastUserId) { - if(loginStateChangeEvent) - loginStateChangeEvent(); - return true; - } else { - return false; - } -} - -function getLoginState() { - var state = Cookies.get('loginstate'); - return state === "true" || state === true; -} - -function getUserId() { - return Cookies.get('userid'); -} - -function clearLoginState() { - Cookies.remove('loginstate'); -} - -function checkIfAuth(yesCallback, noCallback) { - var cookieLoginState = getLoginState(); - if (checkLoginStateChanged()) - checkAuth = false; - if (!checkAuth || typeof cookieLoginState == 'undefined') { - $.get(serverurl + '/me') - .done(function (data) { - if (data && data.status == 'ok') { - profile = data; - yesCallback(profile); - setLoginState(true, data.id); - } else { - noCallback(); - setLoginState(false); - } - }) - .fail(function () { - noCallback(); - }) - .always(function () { - checkAuth = true; - }); - } else if (cookieLoginState) { - yesCallback(profile); - } else { - noCallback(); - } -} \ No newline at end of file -- cgit v1.2.3 From 0e63fe1fa0e1cfd4a2bb8d052514e64e762056e5 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Wed, 5 Oct 2016 10:58:05 +0800 Subject: Create example config --- .sequelizerc.example | 8 ++++ config.json.example | 52 +++++++++++++++++++++++++ public/js/common.js.example | 95 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+) create mode 100644 .sequelizerc.example create mode 100644 config.json.example create mode 100644 public/js/common.js.example diff --git a/.sequelizerc.example b/.sequelizerc.example new file mode 100644 index 00000000..29a0d145 --- /dev/null +++ b/.sequelizerc.example @@ -0,0 +1,8 @@ +var path = require('path'); + +module.exports = { + 'config': path.resolve('config.json'), + 'migrations-path': path.resolve('lib', 'migrations'), + 'models-path': path.resolve('lib', 'models'), + 'url': 'change this' +} \ No newline at end of file diff --git a/config.json.example b/config.json.example new file mode 100644 index 00000000..22fd5c92 --- /dev/null +++ b/config.json.example @@ -0,0 +1,52 @@ +{ + "development": { + "domain": "localhost", + "db": { + "username": "", + "password": "", + "database": "hackmd", + "host": "localhost", + "port": "3306", + "dialect": "mysql" + } + }, + "production": { + "domain": "localhost", + "db": { + "username": "", + "password": "", + "database": "hackmd", + "host": "localhost", + "port": "5432", + "dialect": "postgres" + }, + "facebook": { + "clientID": "change this", + "clientSecret": "change this" + }, + "twitter": { + "consumerKey": "change this", + "consumerSecret": "change this" + }, + "github": { + "clientID": "change this", + "clientSecret": "change this" + }, + "gitlab": { + "baseURL": "change this", + "clientID": "change this", + "clientSecret": "change this" + }, + "dropbox": { + "clientID": "change this", + "clientSecret": "change this" + }, + "google": { + "clientID": "change this", + "clientSecret": "change this" + }, + "imgur": { + "clientID": "change this" + } + } +} diff --git a/public/js/common.js.example b/public/js/common.js.example new file mode 100644 index 00000000..11c32acc --- /dev/null +++ b/public/js/common.js.example @@ -0,0 +1,95 @@ +//common +var domain = ''; // domain name +var urlpath = ''; // sub url path, like: www.example.com/ +//settings +var debug = false; + +var GOOGLE_API_KEY = ''; +var GOOGLE_CLIENT_ID = ''; + +var DROPBOX_APP_KEY = ''; + +var port = window.location.port; +var serverurl = window.location.protocol + '//' + (domain ? domain : window.location.hostname) + (port ? ':' + port : '') + (urlpath ? '/' + urlpath : ''); +var noteid = urlpath ? window.location.pathname.slice(urlpath.length + 1, window.location.pathname.length).split('/')[1] : window.location.pathname.split('/')[1]; +var noteurl = serverurl + '/' + noteid; + +var version = '0.4.4'; + +var checkAuth = false; +var profile = null; +var lastLoginState = getLoginState(); +var lastUserId = getUserId(); +var loginStateChangeEvent = null; + +function resetCheckAuth() { + checkAuth = false; +} + +function setLoginState(bool, id) { + Cookies.set('loginstate', bool, { + expires: 365 + }); + if (id) { + Cookies.set('userid', id, { + expires: 365 + }); + } else { + Cookies.remove('userid'); + } + lastLoginState = bool; + lastUserId = id; + checkLoginStateChanged(); +} + +function checkLoginStateChanged() { + if (getLoginState() != lastLoginState || getUserId() != lastUserId) { + if(loginStateChangeEvent) + loginStateChangeEvent(); + return true; + } else { + return false; + } +} + +function getLoginState() { + var state = Cookies.get('loginstate'); + return state === "true" || state === true; +} + +function getUserId() { + return Cookies.get('userid'); +} + +function clearLoginState() { + Cookies.remove('loginstate'); +} + +function checkIfAuth(yesCallback, noCallback) { + var cookieLoginState = getLoginState(); + if (checkLoginStateChanged()) + checkAuth = false; + if (!checkAuth || typeof cookieLoginState == 'undefined') { + $.get(serverurl + '/me') + .done(function (data) { + if (data && data.status == 'ok') { + profile = data; + yesCallback(profile); + setLoginState(true, data.id); + } else { + noCallback(); + setLoginState(false); + } + }) + .fail(function () { + noCallback(); + }) + .always(function () { + checkAuth = true; + }); + } else if (cookieLoginState) { + yesCallback(profile); + } else { + noCallback(); + } +} \ No newline at end of file -- cgit v1.2.3 From 79f64d0503a77873dddaa307de0f67f83129dc55 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Wed, 5 Oct 2016 11:21:19 +0800 Subject: Create bin/setup script --- bin/setup | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 bin/setup diff --git a/bin/setup b/bin/setup new file mode 100755 index 00000000..461acabd --- /dev/null +++ b/bin/setup @@ -0,0 +1,41 @@ +#!/bin/bash + +# run command at repo root +CURRENT_PATH=$PWD +cd $(git rev-parse --show-toplevel) + +if ! type npm > /dev/null +then + echo "npm is not installed, please install via nvm(recommended) or package manager" + echo "setup will not be run" + exit 0 +fi + +if ! type bower > /dev/null +then + echo "bower is not installed, install via npm" + npm install -g bower +fi + +echo "copy config files" +cp config.json.example config.json +cp public/js/common.js.example public/js/common.js +cp .sequelizerc.example .sequelizerc + +echo "install npm and bower packages" +npm install && bower install + +cat << EOF + + +Edit the following config file to setup hackmd server and client. +Read more info at https://github.com/hackmdio/hackmd#configuration-files + +- config.json +- public/js/common.js +- .sequelizerc + +EOF + +# change directory back +cd $CURRENT_PATH -- cgit v1.2.3 From 5dfa83d350d38991ebaf12f0890bd91f726c670d Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Wed, 5 Oct 2016 12:07:07 +0800 Subject: Update config description --- bin/setup | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/setup b/bin/setup index 461acabd..c29117af 100755 --- a/bin/setup +++ b/bin/setup @@ -31,9 +31,9 @@ cat << EOF Edit the following config file to setup hackmd server and client. Read more info at https://github.com/hackmdio/hackmd#configuration-files -- config.json -- public/js/common.js -- .sequelizerc +* config.json -- server config +* public/js/common.js -- client config +* .sequelizerc -- db config EOF -- cgit v1.2.3 From 934ed7c0d97958118b79e6c3da35fd1fae6b8e17 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Wed, 5 Oct 2016 12:12:21 +0800 Subject: Copy config only when file not exist --- bin/setup | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/bin/setup b/bin/setup index c29117af..f0d860dc 100755 --- a/bin/setup +++ b/bin/setup @@ -18,9 +18,17 @@ then fi echo "copy config files" -cp config.json.example config.json -cp public/js/common.js.example public/js/common.js -cp .sequelizerc.example .sequelizerc +if [ ! -f config.json ]; then + cp config.json.example config.json +fi + +if [ ! -f publis/js/common.js ]; then + cp public/js/common.js.example public/js/common.js +fi + +if [ ! -f .sequelizerc ]; then + cp .sequelizerc.example .sequelizerc +fi echo "install npm and bower packages" npm install && bower install -- cgit v1.2.3 From 6f53d40d6afedbaa65ffbb89c60313ab807a83ce Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Wed, 5 Oct 2016 12:12:45 +0800 Subject: Update README get started section --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7e7b1f80..b5ca1869 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Get started --- 1. Download a release and unzip or clone into a directory -2. Enter the directory and type `npm install && bower install`, which will install all the dependencies +2. Enter the directory and type `bin/setup`, which will install all the dependencies and create config file 3. Setup the configs, see more below 4. Setup environment variables which will overwrite the configs 5. Run the server as you like (node, forever, pm2) -- cgit v1.2.3 From 69c14a274df76f9cba566c67a8721e737c69c2f4 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Wed, 5 Oct 2016 14:09:39 +0800 Subject: Do not recommend anything in setup script --- bin/setup | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/setup b/bin/setup index f0d860dc..66279e81 100755 --- a/bin/setup +++ b/bin/setup @@ -6,8 +6,11 @@ cd $(git rev-parse --show-toplevel) if ! type npm > /dev/null then - echo "npm is not installed, please install via nvm(recommended) or package manager" - echo "setup will not be run" + cat << EOF +npm is not installed, please install Node.js and npm. +Read more on Node.js official website: https://nodejs.org +Setup will not be run +EOF exit 0 fi -- cgit v1.2.3 From ec8fb1931b38008e9a434244819c46d866448af3 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Wed, 5 Oct 2016 14:17:32 +0800 Subject: Update REAME setup script description --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b5ca1869..3443e1d5 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Get started --- 1. Download a release and unzip or clone into a directory -2. Enter the directory and type `bin/setup`, which will install all the dependencies and create config file +2. Enter the directory and type `bin/setup`, which will install npm/bower dependencies and create configs. The setup script is written in Bash, you would need bash as a prerequisite. 3. Setup the configs, see more below 4. Setup environment variables which will overwrite the configs 5. Run the server as you like (node, forever, pm2) -- cgit v1.2.3