Merge branch 't216-refactor-common' into 'frontend-next'

T216 refactor common

See merge request !5
This commit is contained in:
Yukai Huang 2017-01-15 03:45:19 +00:00
commit 75e28a1d5e
14 changed files with 45 additions and 69 deletions

View file

@ -16,7 +16,6 @@
],
"array-callback-return": "error",
"arrow-body-style": "error",
"arrow-parens": "error",
"arrow-spacing": "error",
"block-scoped-var": "off",
"block-spacing": "error",
@ -123,7 +122,7 @@
"no-extend-native": "error",
"no-extra-bind": "error",
"no-extra-label": "error",
"no-extra-parens": "error",
"no-extra-parens": "warn",
"no-floating-decimal": "error",
"no-global-assign": "error",
"no-implicit-coercion": "error",
@ -195,7 +194,7 @@
"no-unneeded-ternary": "error",
"no-unsafe-negation": "error",
"no-unused-expressions": "error",
"no-use-before-define": "error",
"no-use-before-define": "warn",
"no-useless-call": "error",
"no-useless-computed-key": "error",
"no-useless-concat": "error",

1
.gitignore vendored
View file

@ -18,7 +18,6 @@ backups/
# ignore config files
config.json
public/js/config.js
.sequelizerc
# ignore webpack build

View file

@ -97,19 +97,9 @@ Configuration files
There are some configs you need to change in the files below
```
./config.json --- for server settings
./public/js/config.js --- for client settings
./config.json ----application settings
```
Client settings `config.js`
---
| variables | example values | description |
| --------- | ------ | ----------- |
| debug | `true` or `false` | set debug mode, show more logs |
| domain | `localhost` | domain name |
| urlpath | `hackmd` | sub url path, like: `www.example.com/<urlpath>` |
Environment variables (will overwrite other server configs)
---
@ -158,7 +148,7 @@ Environment variables (will overwrite other server configs)
| HMD_S3_REGION | `ap-northeast-1` | AWS S3 region |
| HMD_S3_BUCKET | no example | AWS S3 bucket name |
Server settings `config.json`
Application settings `config.json`
---
| variables | example values | description |
@ -207,7 +197,7 @@ Third-party integration api key settings
| ------- | --------- | ----------- |
| facebook, twitter, github, gitlab, dropbox, google, ldap | environment variables or `config.json` | for signin |
| imgur | environment variables or `config.json` | for image upload |
| google drive, dropbox | `public/js/config.js` | for export and import |
| google drive(`google/apiKey`, `google/clientID`), dropbox(`dropbox/appKey`) | `config.json` | for export and import |
Third-party integration oauth callback urls
---

View file

@ -28,8 +28,6 @@ EOF
EOF
cp public/js/config.js.example public/js/config.js
# build app
npm run build
fi

View file

@ -21,10 +21,6 @@ if [ ! -f config.json ]; then
cp config.json.example config.json
fi
if [ ! -f publis/js/config.js ]; then
cp public/js/config.js.example public/js/config.js
fi
if [ ! -f .sequelizerc ]; then
cp .sequelizerc.example .sequelizerc
fi

View file

@ -45,11 +45,13 @@
},
"dropbox": {
"clientID": "change this",
"clientSecret": "change this"
"clientSecret": "change this",
"appKey": "change this"
},
"google": {
"clientID": "change this",
"clientSecret": "change this"
"clientSecret": "change this",
"apiKey": "change this"
},
"ldap": {
"url": "ldap://change_this",

View file

@ -90,11 +90,11 @@ var gitlab = (process.env.HMD_GITLAB_CLIENTID && process.env.HMD_GITLAB_CLIENTSE
var dropbox = (process.env.HMD_DROPBOX_CLIENTID && process.env.HMD_DROPBOX_CLIENTSECRET) ? {
clientID: process.env.HMD_DROPBOX_CLIENTID,
clientSecret: process.env.HMD_DROPBOX_CLIENTSECRET
} : config.dropbox || false;
} : (config.dropbox && config.dropbox.clientID && config.dropbox.clientSecret) || false;
var google = (process.env.HMD_GOOGLE_CLIENTID && process.env.HMD_GOOGLE_CLIENTSECRET) ? {
clientID: process.env.HMD_GOOGLE_CLIENTID,
clientSecret: process.env.HMD_GOOGLE_CLIENTSECRET
} : config.google || false;
} : (config.google && config.google.clientID && config.google.clientSecret) || false;
var ldap = config.ldap || (
process.env.HMD_LDAP_URL ||
process.env.HMD_LDAP_BINDDN ||

View file

@ -1,11 +0,0 @@
module.exports = {
domain: '', // domain name
urlpath: '', // sub url path, like: www.example.com/<urlpath>
// settings
debug: false,
GOOGLE_API_KEY: '',
GOOGLE_CLIENT_ID: '',
DROPBOX_APP_KEY: ''
};

View file

@ -9,7 +9,7 @@ import {
getLoginState,
resetCheckAuth,
setloginStateChangeEvent
} from './common';
} from './lib/common/login';
import {
clearDuplicatedHistory,

View file

@ -11,7 +11,7 @@ import PDFObject from 'pdfobject';
import S from 'string';
import { saveAs } from 'file-saver';
require('./common');
require('./lib/common/login');
require('../vendor/md-toc');
var Viz = require("viz.js");

View file

@ -1,9 +1,13 @@
import store from 'store';
import S from 'string';
import {
checkIfAuth
} from './lib/common/login';
import {
checkIfAuth,
urlpath
} from './common';
} from './lib/config';
window.migrateHistoryFromTempCallback = null;

View file

@ -19,7 +19,10 @@ var List = require('list.js');
import {
checkLoginStateChanged,
setloginStateChangeEvent,
setloginStateChangeEvent
} from './lib/common/login';
import {
debug,
DROPBOX_APP_KEY,
GOOGLE_API_KEY,
@ -28,7 +31,7 @@ import {
noteurl,
urlpath,
version
} from './common';
} from './lib/config';
import {
autoLinkify,

View file

@ -1,21 +1,4 @@
// import config from './config';
import {
domain, // domain name
urlpath, // sub url path, like: www.example.com/<urlpath>
debug,
GOOGLE_API_KEY,
GOOGLE_CLIENT_ID,
DROPBOX_APP_KEY
} from './config';
//common
export const port = window.location.port;
window.serverurl = `${window.location.protocol}//${domain ? domain : window.location.hostname}${port ? ':' + port : ''}${urlpath ? '/' + urlpath : ''}`;
export const noteid = urlpath ? window.location.pathname.slice(urlpath.length + 1, window.location.pathname.length).split('/')[1] : window.location.pathname.split('/')[1];
export const noteurl = `${serverurl}/${noteid}`;
export const version = '0.5.0';
import { serverurl } from '../config';
let checkAuth = false;
let profile = null;
@ -49,7 +32,7 @@ export function setLoginState(bool, id) {
export function checkLoginStateChanged() {
if (getLoginState() != lastLoginState || getUserId() != lastUserId) {
if(loginStateChangeEvent) {
if (loginStateChangeEvent) {
loginStateChangeEvent();
}
return true;
@ -101,12 +84,6 @@ export function checkIfAuth(yesCallback, noCallback) {
}
export default {
domain,
urlpath,
debug,
GOOGLE_API_KEY,
GOOGLE_CLIENT_ID,
DROPBOX_APP_KEY,
checkAuth,
profile,
lastLoginState,

View file

@ -0,0 +1,19 @@
import configJson from '../../../../config.json'; // root path json config
const config = 'production' === process.env.NODE_ENV ? configJson.production : configJson.development;
export const GOOGLE_API_KEY = (config.google && config.google.apiKey) || '';
export const GOOGLE_CLIENT_ID = (config.google && config.google.clientID) || '';
export const DROPBOX_APP_KEY = (config.dropbox && config.dropbox.appKey) || '';
export const domain = config.domain || ''; // domain name
export const urlpath = config.urlpath || ''; // sub url path, like: www.example.com/<urlpath>
export const debug = config.debug || false;
export const port = window.location.port;
export const serverurl = `${window.location.protocol}//${domain ? domain : window.location.hostname}${port ? ':' + port : ''}${urlpath ? '/' + urlpath : ''}`;
window.serverurl = serverurl;
export const noteid = urlpath ? window.location.pathname.slice(urlpath.length + 1, window.location.pathname.length).split('/')[1] : window.location.pathname.split('/')[1];
export const noteurl = `${serverurl}/${noteid}`;
export const version = '0.5.0';