Resolve dependency module requiring

* es5 style module exports
* remove script tag require
* webpack config ProvidePlugin

Note that this commit only fix JavaScript module loading runtime error.
This commit is contained in:
Yukai Huang 2016-10-08 20:02:30 +08:00
parent 0be342c44d
commit 963a435ae1
9 changed files with 175 additions and 59 deletions

View file

@ -64,6 +64,7 @@
"morgan": "^1.7.0", "morgan": "^1.7.0",
"mysql": "^2.11.1", "mysql": "^2.11.1",
"node-uuid": "^1.4.7", "node-uuid": "^1.4.7",
"ot": "0.0.15",
"passport": "^0.3.2", "passport": "^0.3.2",
"passport-dropbox-oauth2": "^1.1.0", "passport-dropbox-oauth2": "^1.1.0",
"passport-facebook": "^2.1.1", "passport-facebook": "^2.1.1",
@ -84,6 +85,7 @@
"sequelize-cli": "^2.4.0", "sequelize-cli": "^2.4.0",
"shortid": "2.2.6", "shortid": "2.2.6",
"socket.io": "1.4.8", "socket.io": "1.4.8",
"socket.io-client": "^1.4.8",
"sqlite3": "^3.1.4", "sqlite3": "^3.1.4",
"store": "^1.3.20", "store": "^1.3.20",
"string": "^3.3.1", "string": "^3.3.1",

View file

@ -489,6 +489,8 @@ function exportToRawHTML(view) {
saveAs(blob, filename); saveAs(blob, filename);
} }
var common = require('./common.js');
var serverurl = common.serverurl;
//extract markdown body to html and compile to template //extract markdown body to html and compile to template
function exportToHTML(view) { function exportToHTML(view) {
var title = renderTitle(ui.area.markdown); var title = renderTitle(ui.area.markdown);
@ -794,7 +796,10 @@ emojify.setConfig({
ignore_emoticons: true ignore_emoticons: true
}); });
var md = window.markdownit('default', { var markdownit = require('markdown-it');
var markdownitContainer = require('markdown-it-container');
var md = markdownit('default', {
html: true, html: true,
breaks: true, breaks: true,
langPrefix: "", langPrefix: "",
@ -802,25 +807,27 @@ var md = window.markdownit('default', {
typographer: true, typographer: true,
highlight: highlightRender highlight: highlightRender
}); });
md.use(window.markdownitAbbr);
md.use(window.markdownitFootnote); md.use(require('markdown-it-abbr'));
md.use(window.markdownitDeflist); md.use(require('markdown-it-footnote'));
md.use(window.markdownitMark); md.use(require('markdown-it-deflist'));
md.use(window.markdownitIns); md.use(require('markdown-it-mark'));
md.use(window.markdownitSub); md.use(require('markdown-it-ins'));
md.use(window.markdownitSup); md.use(require('markdown-it-sub'));
md.use(window.markdownitMathjax); md.use(require('markdown-it-sup'));
md.use(window.markdownitImsize); md.use(require('markdown-it-mathjax'));
md.use(require('markdown-it-imsize'));
function renderContainer(tokens, idx, options, env, self) { function renderContainer(tokens, idx, options, env, self) {
tokens[idx].attrJoin('role', 'alert'); tokens[idx].attrJoin('role', 'alert');
tokens[idx].attrJoin('class', 'alert'); tokens[idx].attrJoin('class', 'alert');
tokens[idx].attrJoin('class', 'alert-' + tokens[idx].info.trim()); tokens[idx].attrJoin('class', 'alert-' + tokens[idx].info.trim());
return self.renderToken.apply(self, arguments); return self.renderToken.apply(self, arguments);
} }
md.use(window.markdownitContainer, 'success', { render: renderContainer }); md.use(markdownitContainer, 'success', { render: renderContainer });
md.use(window.markdownitContainer, 'info', { render: renderContainer }); md.use(markdownitContainer, 'info', { render: renderContainer });
md.use(window.markdownitContainer, 'warning', { render: renderContainer }); md.use(markdownitContainer, 'warning', { render: renderContainer });
md.use(window.markdownitContainer, 'danger', { render: renderContainer }); md.use(markdownitContainer, 'danger', { render: renderContainer });
md.renderer.rules.image = function (tokens, idx, options, env, self) { md.renderer.rules.image = function (tokens, idx, options, env, self) {
tokens[idx].attrJoin('class', 'raw'); tokens[idx].attrJoin('class', 'raw');
@ -865,6 +872,9 @@ md.renderer.rules.fence = function (tokens, idx, options, env, self) {
+ '</code></pre>\n'; + '</code></pre>\n';
}; };
/* Defined regex markdown it plugins */
var Plugin = require('markdown-it-regexp');
//youtube //youtube
var youtubePlugin = new Plugin( var youtubePlugin = new Plugin(
// regexp to match // regexp to match
@ -1012,3 +1022,22 @@ md.use(tocPlugin);
md.use(slidesharePlugin); md.use(slidesharePlugin);
md.use(speakerdeckPlugin); md.use(speakerdeckPlugin);
md.use(pdfPlugin); md.use(pdfPlugin);
module.exports = {
md: md,
createtime: createtime,
lastchangetime: lastchangetime,
updateLastChange: updateLastChange,
lastchangeui: lastchangeui,
lastchangeuser: lastchangeuser,
postProcess: postProcess,
finishView: finishView,
autoLinkify: autoLinkify,
deduplicatedHeaderId: deduplicatedHeaderId,
renderTOC: renderTOC,
renderTitle: renderTitle,
renderFilename: renderFilename,
generateToc: generateToc,
smoothHashScroll: smoothHashScroll,
scrollToHash: scrollToHash
};

View file

@ -1,3 +1,13 @@
var store = require('store');
var common = require('./common');
var checkIfAuth = common.checkIfAuth;
var urlpath = common.urlpath;
var extra = require('./extra');
var renderFilename = extra.renderFilename;
var md = extra.md;
var migrateHistoryFromTempCallback = null; var migrateHistoryFromTempCallback = null;
migrateHistoryFromTemp(); migrateHistoryFromTemp();
@ -366,3 +376,7 @@ function parseToHistory(list, notehistory, callback) {
} }
callback(list, notehistory); callback(list, notehistory);
} }
module.exports = {
writeHistory: writeHistory
}

View file

@ -18,15 +18,14 @@ require('bootstrap');
require('codemirror/keymap/vim'); require('codemirror/keymap/vim');
require('codemirror/keymap/emacs'); require('codemirror/keymap/emacs');
require('codemirror/keymap/sublime'); require('codemirror/keymap/sublime');
require('codemirror/addon/display/panel');
require('../vendor/inlineAttachment/inline-attachment');
require('../vendor/inlineAttachment/codemirror.inline-attachment');
require('../vendor/codemirror-spell-checker/spell-checker.min');
/* operational transformation */ /* operational transformation */
require('../vendor/ot/ot.min'); require('ot/lib/socketio-adapter');
require('ot/lib/codemirror-adapter');
require('ot/lib/undo-manager');
require('../vendor/ot/editor-client');
/* other vendors plugin */
require('markdown-it'); require('markdown-it');
require('markdown-it-abbr'); require('markdown-it-abbr');
require('markdown-it-footnote'); require('markdown-it-footnote');
@ -40,14 +39,13 @@ require('markdown-it-mathjax');
require('markdown-it-regexp'); require('markdown-it-regexp');
require('markdown-it-imsize'); require('markdown-it-imsize');
/* other vendors plugin */
require('gist-embed'); require('gist-embed');
require('lz-string');
require('string'); require('string');
require('highlight.js'); require('highlight.js');
require('prismjs'); require('prismjs');
require('prismjs/components/prism-wiki'); require('prismjs/components/prism-wiki');
require('js-cookie'); require('js-cookie');
require('emojify.js');
require('to-markdown'); require('to-markdown');
require('raphael'); require('raphael');
@ -63,11 +61,48 @@ require('visibilityjs');
require('list.js'); require('list.js');
require('../vendor/md-toc'); require('../vendor/md-toc');
require('randomcolor'); require('randomcolor');
require('keymaster');
var common = require('./common.js'); var common = require('./common.js');
var urlpath = common.urlpath;
var debug = common.debug;
var version = common.version;
var serverurl = common.serverurl; var serverurl = common.serverurl;
var GOOGLE_API_KEY = common.GOOGLE_API_KEY;
var GOOGLE_CLIENT_ID = common.GOOGLE_CLIENT_ID;
var DROPBOX_APP_KEY = common.DROPBOX_APP_KEY;
var noteurl = common.noteurl;
var checkLoginStateChanged = common.checkLoginStateChanged;
var syncScroll = require('./syncscroll');
var setupSyncAreas = syncScroll.setupSyncAreas;
var clearMap = syncScroll.clearMap;
var syncScrollToEdit = syncScroll.syncScrollToEdit;
var extra = require('./extra');
var md = extra.md;
var createtime = extra.createtime;
var updateLastChange = extra.updateLastChange;
var postProcess = extra.postProcess;
var finishView = extra.finishView;
var lastchangetime = extra.lastchangetime;
var autoLinkify = extra.autoLinkify;
var generateToc = extra.generateToc;
var smoothHashScroll = extra.smoothHashScroll;
var lastchangeuser = extra.lastchangeuser;
var deduplicatedHeaderId = extra.deduplicatedHeaderId;
var renderTOC = extra.renderTOC;
var renderTitle = extra.renderTitle;
var renderFilename = extra.renderFilename;
var scrollToHash = extra.scrollToHash;
var history = require('./history');
var writeHistory = history.writeHistory;
var pretty = require('./pretty');
var renderer = require('./render');
var preventXSS = renderer.preventXSS;
var defaultTextHeight = 20; var defaultTextHeight = 20;
var viewportMargin = 20; var viewportMargin = 20;
@ -349,7 +384,7 @@ var supportExtraTags = [
} }
} }
]; ];
var modeType = { window.modeType = {
edit: { edit: {
name: "edit" name: "edit"
}, },
@ -389,7 +424,7 @@ var visibleSM = false;
var visibleMD = false; var visibleMD = false;
var visibleLG = false; var visibleLG = false;
var isTouchDevice = 'ontouchstart' in document.documentElement; var isTouchDevice = 'ontouchstart' in document.documentElement;
var currentMode = defaultMode; window.currentMode = defaultMode;
var currentStatus = statusType.offline; var currentStatus = statusType.offline;
var lastInfo = { var lastInfo = {
needRestore: false, needRestore: false,

View file

@ -1,3 +1,16 @@
var extra = require('./extra')
var md = extra.md;
var finishView = extra.finishView;
var autoLinkify = extra.autoLinkify;
var deduplicatedHeaderId = extra.deduplicatedHeaderId;
var renderTOC = extra.renderTOC;
var generateToc = extra.generateToc;
var smoothHashScroll = extra.smoothHashScroll;
var postProcess = extra.postProcess;
var lastchangeui = extra.lastchangeui;
var updateLastChange = extra.updateLastChange;
var preventXSS = require('./render').preventXSS;
var markdown = $(".markdown-body"); var markdown = $(".markdown-body");
var text = $('<textarea/>').html(markdown.html()).text(); var text = $('<textarea/>').html(markdown.html()).text();
var lastMeta = md.meta; var lastMeta = md.meta;
@ -110,3 +123,7 @@ function scrollToBottom() {
scrollTop: $(document.body)[0].scrollHeight scrollTop: $(document.body)[0].scrollHeight
}, 100, "linear"); }, 100, "linear");
} }
module.exports = {
scrollToBottom: scrollToBottom
}

View file

@ -51,3 +51,7 @@ var filterXSSOptions = {
function preventXSS(html) { function preventXSS(html) {
return filterXSS(html, filterXSSOptions); return filterXSS(html, filterXSSOptions);
} }
module.exports = {
preventXSS: preventXSS
}

View file

@ -1,5 +1,8 @@
// Inject line numbers for sync scroll. // Inject line numbers for sync scroll.
var extra = require('./extra');
var md = extra.md;
function addPart(tokens, idx) { function addPart(tokens, idx) {
if (tokens[idx].map && tokens[idx].level === 0) { if (tokens[idx].map && tokens[idx].level === 0) {
var startline = tokens[idx].map[0] + 1; var startline = tokens[idx].map[0] + 1;
@ -99,10 +102,12 @@ function renderContainer(tokens, idx, options, env, self) {
addPart(tokens, idx); addPart(tokens, idx);
return self.renderToken.apply(self, arguments); return self.renderToken.apply(self, arguments);
} }
md.use(window.markdownitContainer, 'success', { render: renderContainer });
md.use(window.markdownitContainer, 'info', { render: renderContainer }); var markdownitContainer = require('markdown-it-container');
md.use(window.markdownitContainer, 'warning', { render: renderContainer }); md.use(markdownitContainer, 'success', { render: renderContainer });
md.use(window.markdownitContainer, 'danger', { render: renderContainer }); md.use(markdownitContainer, 'info', { render: renderContainer });
md.use(markdownitContainer, 'warning', { render: renderContainer });
md.use(markdownitContainer, 'danger', { render: renderContainer });
var syncscroll = true; var syncscroll = true;
@ -361,3 +366,9 @@ function syncScrollToView(event, preventAnimate) {
function editScrollingTimeoutInner() { function editScrollingTimeoutInner() {
editScrolling = false; editScrolling = false;
} }
module.exports = {
setupSyncAreas: setupSyncAreas,
clearMap: clearMap,
syncScrollToEdit: syncScrollToEdit
};

View file

@ -22,13 +22,12 @@
<script src="<%- url %>/vendor/mermaid/dist/mermaid.min.js" defer></script> <script src="<%- url %>/vendor/mermaid/dist/mermaid.min.js" defer></script>
<% } %> <% } %>
<script src="<%- url %>/vendor/idle.min.js" defer></script> <script src="<%- url %>/vendor/idle.min.js" defer></script>
<script src="<%- url %>/vendor/codemirror/codemirror.min.js" defer></script>
<script src="<%- url %>/vendor/codemirror-spell-checker/spell-checker.min.js" defer></script>
<script src="<%- url %>/vendor/inlineAttachment/inline-attachment.js" defer></script>
<script src="<%- url %>/vendor/inlineAttachment/codemirror.inline-attachment.js" defer></script>
<script src="<%- url %>/vendor/xss.min.js" defer></script> <script src="<%- url %>/vendor/xss.min.js" defer></script>
<script src="<%- url %>/build/js/app.js" defer></script> <script src="<%- url %>/build/js/app.js" defer></script>
<script src="<%- url %>/js/google-drive-upload.js" defer></script> <script src="<%- url %>/js/google-drive-upload.js" defer></script>
<script src="<%- url %>/js/google-drive-picker.js" defer></script> <script src="<%- url %>/js/google-drive-picker.js" defer></script>
<script src="<%- url %>/js/common.js" defer></script>
<script src="<%- url %>/js/extra.js" defer></script>
<script src="<%- url %>/js/render.js" defer></script>
<script src="<%- url %>/js/history.js" defer></script>
<script src="<%- url %>/js/reveal-markdown.js" defer></script> <script src="<%- url %>/js/reveal-markdown.js" defer></script>
<script src="<%- url %>/js/syncscroll.js" defer></script>

View file

@ -12,7 +12,12 @@ module.exports = {
"window.jQuery": "jquery", "window.jQuery": "jquery",
Visibility: "visibilityjs", Visibility: "visibilityjs",
Cookies: "js-cookie", Cookies: "js-cookie",
CodeMirror: "codemirror" CodeMirror: "codemirror",
emojify: "emojify.js",
ot: "ot",
io: "socket.io-client",
LZString: "lz-string",
key: "keymaster"
}), }),
new webpack.DefinePlugin({ new webpack.DefinePlugin({
"require.specified": "require.resolve" "require.specified": "require.resolve"