Просмотр исходного кода

Merge pull request #40 from crowi/remove-bower

Remove bower
Sotaro KARASAWA 10 лет назад
Родитель
Сommit
297cbc8a29

+ 2 - 0
README.md

@@ -1,3 +1,5 @@
+![Crowi](http://res.cloudinary.com/hrscywv4p/image/upload/c_limit,f_auto,h_900,q_80,w_1200/v1/199673/https_www_filepicker_io_api_file_VpYEP32ZQyCZ85u6XCXo_zskpra.png)
+
 Crowi - The Simple & Powerful Communication Tool Based on Wiki
 ================================================================
 

+ 0 - 32
bower.json

@@ -1,32 +0,0 @@
-{
-  "name": "crowi",
-  "version": "1.2.0",
-  "description": "Crocos' Wiki implementation in node.js",
-  "authors": [
-    "Sotaro KARASAWA <sotarok@crocos.co.jp>",
-    "Keisuke SATO <riaf@me.com>"
-  ],
-  "keywords": [
-    "wiki"
-  ],
-  "license": "MIT",
-  "private": true,
-  "ignore": [
-    "**/.*",
-    "node_modules",
-    "bower_components",
-    "test",
-    "tests"
-  ],
-  "dependencies": {
-    "bootstrap-sass-official": "~3.3.1",
-    "fontawesome": "~4.2.0",
-    "jquery.cookie": "~1.4.1",
-    "marked": "~0.3.3",
-    "reveal.js": "~3.0.0",
-    "jquery": "~2.1.3",
-    "highlightjs": "~8.4.0",
-    "inline-attachment": "~2.0.1",
-    "jquery-selection": "~1.0.1"
-  }
-}

+ 48 - 18
gulpfile.js

@@ -8,6 +8,8 @@ var concat = require('gulp-concat');
 var rename = require('gulp-rename');
 var uglify = require('gulp-uglify');
 var jshint = require('gulp-jshint');
+var source = require('vinyl-source-stream');
+var browserify = require('browserify');
 
 var stylish = require('jshint-stylish');
 
@@ -29,27 +31,30 @@ var css = {
   src: dirs.cssSrc + '/' + pkg.name + '.scss',
   main: dirs.cssDist + '/crowi-main.css',
   dist: dirs.cssDist + '/crowi.css',
+  revealSrc: dirs.cssSrc + '/' + pkg.name + '-reveal.scss',
+  revealDist: dirs.cssDist + '/crowi-reveal.css',
   watch: ['resource/css/*.scss'],
 };
 
 var js = {
+  browserify: {
+    crowi: 'resource/js/crowi.js', // => crowi-bundled.js
+    crowiPresentation: 'resource/js/crowi-presentation.js', // => crowi-presentation.js
+  },
   src: [
-    'bower_components/jquery/dist/jquery.js',
-    'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap.js',
-    'bower_components/inline-attachment/src/inline-attachment.js',
-    'bower_components/inline-attachment/src/jquery.inline-attachment.js',
+    'node_modules/jquery/dist/jquery.js',
+    'node_modules/bootstrap-sass/assets/javascripts/bootstrap.js',
+    'node_modules/inline-attachment/src/inline-attachment.js',
     'node_modules/socket.io-client/socket.io.js',
-    'bower_components/marked/lib/marked.js',
-    'bower_components/jquery.cookie/jquery.cookie.js',
-    'bower_components/jquery-selection/src/jquery.selection.js',
-    'bower_components/highlightjs/highlight.pack.js',
-    'resource/js/crowi.js'
+    'node_modules/jquery.cookie/jquery.cookie.js',
+    'resource/thirdparty-js/jquery.selection.js',
+    dirs.jsDist + '/crowi-bundled.js',
   ],
   dist: dirs.jsDist + '/crowi.js',
   revealSrc: [
-    'bower_components/reveal.js/lib/js/head.min.js',
-    'bower_components/reveal.js/lib/js/html5shiv.js',
-    'bower_components/reveal.js/js/reveal.js'
+    'node_modules/reveal.js/lib/js/head.min.js',
+    'node_modules/reveal.js/lib/js/html5shiv.js',
+    dirs.jsDist + '/crowi-presentation.js',
   ],
   revealDist: dirs.jsDist + '/crowi-reveal.js',
   formSrc: [
@@ -63,12 +68,24 @@ var js = {
 };
 
 var cssIncludePaths = [
-  'bower_components/bootstrap-sass-official/assets/stylesheets',
-  'bower_components/fontawesome/scss',
-  'bower_components/reveal.js/css'
+  'node_modules/bootstrap-sass/assets/stylesheets',
+  'node_modules/font-awesome/scss',
+  'node_modules/reveal.js/css'
 ];
 
-gulp.task('js:concat', function() {
+gulp.task('js:browserify', function() {
+  browserify({entries: js.browserify.crowiPresentation})
+    .bundle()
+    .pipe(source('crowi-presentation.js'))
+    .pipe(gulp.dest(dirs.jsDist));
+
+  return browserify({entries: js.browserify.crowi})
+    .bundle()
+    .pipe(source('crowi-bundled.js'))
+    .pipe(gulp.dest(dirs.jsDist));
+});
+
+gulp.task('js:concat', ['js:browserify'], function() {
   gulp.src(js.revealSrc)
     .pipe(concat('crowi-reveal.js'))
     .pipe(gulp.dest(dirs.jsDist));
@@ -115,23 +132,36 @@ gulp.task('test', function() {
 });
 
 gulp.task('css:sass', function() {
+  gulp.src(css.revealSrc) // reveal
+    .pipe(sass({
+        outputStyle: 'nesed',
+        sourceComments: 'map',
+        includePaths: cssIncludePaths
+    }).on('error', sass.logError))
+    .pipe(gulp.dest(dirs.cssDist));
+
   return gulp.src(css.src)
     .pipe(sass({
         outputStyle: 'nesed',
         sourceComments: 'map',
         includePaths: cssIncludePaths
     }).on('error', sass.logError))
-    .pipe(rename({suffix: '-main'}))
+    .pipe(rename({suffix: '-main'})) // create -main.css to prepare concating with highlight.js's css
     .pipe(gulp.dest(dirs.cssDist));
 });
 
 gulp.task('css:concat', ['css:sass'], function() {
-  return gulp.src([css.main, 'bower_components/highlightjs/styles/tomorrow-night.css'])
+  return gulp.src([css.main, 'node_modules/highlight.js/styles/tomorrow-night.css'])
     .pipe(concat('crowi.css'))
     .pipe(gulp.dest(dirs.cssDist))
 });
 
 gulp.task('css:min', ['css:concat'], function() {
+  gulp.src(css.revealDist)
+    .pipe(cssmin())
+    .pipe(rename({suffix: '.min'}))
+    .pipe(gulp.dest(dirs.cssDist));
+
   return gulp.src(css.dist)
     .pipe(cssmin())
     .pipe(rename({suffix: '.min'}))

+ 4 - 32
lib/views/page_presentation.html

@@ -7,8 +7,8 @@
     <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
 
 
-    <link rel="stylesheet" type="text/css" href="/css/crowi-reveal.css">
-    <link rel="stylesheet" type="text/css" href="/bower_components/reveal.js/lib/css/zenburn.css">
+    <link rel="stylesheet" type="text/css" href="/css/crowi-reveal{% if env  == 'production' %}.min{% endif %}.css">
+    <link rel="stylesheet" type="text/css" href="/js/reveal.js/lib/css/zenburn.css">
 
     <title>{{ path|path2name }} | {{ path }}</title>
   </head>
@@ -27,35 +27,7 @@
       </div>
     </div>
 
-    <script src="/js/crowi-reveal.js"></script>
-    <script>
-      Reveal.initialize({
-        controls: true,
-        progress: true,
-        history: true,
-        center: true,
-        transition: 'slide',
-
-        // Optional libraries used to extend on reveal.js
-        dependencies: [
-          { src: '/bower_components/reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
-          { src: '/bower_components/reveal.js/plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
-          { src: '/bower_components/reveal.js/plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
-          { src: '/bower_components/reveal.js/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
-          { src: '/bower_components/reveal.js/plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
-          { src: '/bower_components/reveal.js/plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
-        ]
-      });
-
-      Reveal.addEventListener('ready', function(event) {
-        // event.currentSlide, event.indexh, event.indexv
-        $('.reveal section').each(function(e) {
-          var $self = $(this);
-          if ($self.children().length == 1) {
-            $self.addClass('only');
-          }
-        });
-      });
-    </script>
+    <script src="/js/crowi{% if env  == 'production' %}.min{% endif %}.js"></script>
+    <script src="/js/crowi-reveal{% if env  == 'production' %}.min{% endif %}.js"></script>
   </body>
 </html>

+ 13 - 3
package.json

@@ -33,7 +33,8 @@
     "basic-auth-connect": "~1.0.0",
     "bluebird": "~3.0.5",
     "body-parser": "~1.14.1",
-    "bower": "~1.7.1",
+    "bootstrap-sass": "~3.3.6",
+    "browserify": "~12.0.1",
     "cli": "~0.6.0",
     "connect-flash": "~0.1.1",
     "connect-redis": "~2.1.0",
@@ -45,6 +46,7 @@
     "express-form": "~0.12.0",
     "express-session": "~1.12.0",
     "facebook-node-sdk": "=0.1.10",
+    "font-awesome": "~4.5.0",
     "googleapis": "=0.4.7",
     "gulp": "~3.9.0",
     "gulp-concat": "~2.6.0",
@@ -55,8 +57,13 @@
     "gulp-spawn-mocha": "~2.2.1",
     "gulp-uglify": "~1.4.2",
     "gulp-watch": "~4.3.5",
+    "highlight.js": "~9.0.0",
+    "inline-attachment": "git+https://github.com/Rovak/InlineAttachment.git#2.0.2",
+    "jquery": "~2.1.4",
+    "jquery.cookie": "~1.4.1",
     "jshint-stylish": "~2.1.0",
     "kerberos": "0.0.17",
+    "marked": "~0.3.5",
     "method-override": "~2.3.1",
     "mongoose": "4.2.5",
     "mongoose-paginate": "4.2.0",
@@ -65,10 +72,12 @@
     "nodemailer": "~1.2.2",
     "nodemailer-ses-transport": "~1.1.0",
     "redis": "~0.12.1",
+    "reveal.js": "~3.2.0",
     "socket.io": "~1.3.0",
     "socket.io-client": "~1.3.0",
     "swig": "~1.4.0",
-    "time": "~0.11.0"
+    "time": "~0.11.0",
+    "vinyl-source-stream": "~1.1.0"
   },
   "devDependencies": {
     "chai": "~1.10.0",
@@ -81,7 +90,8 @@
   "scripts": {
     "start": "node app.js",
     "test": "gulp test",
-    "postinstall": "bower cache clean && bower install && gulp"
+    "build": "gulp",
+    "postinstall": "gulp"
   },
   "env": {
     "NODE_ENV": "production"

+ 1 - 1
public/fonts

@@ -1 +1 @@
-../bower_components/fontawesome/fonts
+../node_modules/font-awesome/fonts

+ 1 - 1
resource/css/crowi-reveal.scss

@@ -1,4 +1,4 @@
-@import 'reveal';
+@import 'reveal.scss';
 @import 'theme/source/black';
 
 .reveal {

+ 34 - 0
resource/js/crowi-presentation.js

@@ -0,0 +1,34 @@
+var Reveal = require('reveal.js');
+
+if (!window) {
+  window = {};
+}
+window.Reveal = Reveal;
+
+Reveal.initialize({
+  controls: true,
+  progress: true,
+  history: true,
+  center: true,
+  transition: 'slide',
+
+  // Optional libraries used to extend on reveal.js
+  dependencies: [
+    { src: '/js/reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
+    { src: '/js/reveal.js/plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
+    { src: '/js/reveal.js/plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
+    { src: '/js/reveal.js/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
+    { src: '/js/reveal.js/plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
+    { src: '/js/reveal.js/plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
+  ]
+});
+
+Reveal.addEventListener('ready', function(event) {
+  // event.currentSlide, event.indexh, event.indexv
+  $('.reveal section').each(function(e) {
+    var $self = $(this);
+    if ($self.children().length == 1) {
+      $self.addClass('only');
+    }
+  });
+});

+ 7 - 0
resource/js/crowi.js

@@ -3,8 +3,15 @@
 /* Author: Sotaro KARASAWA <sotarok@crocos.co.jp>
 */
 
+var hljs = require('highlight.js');
+var marked = require('marked');
 var Crowi = {};
 
+if (!window) {
+  window = {};
+}
+window.Crowi = Crowi;
+
 Crowi.createErrorView = function(msg) {
   $('#main').prepend($('<p class="alert-message error">' + msg + '</p>'));
 };

+ 354 - 0
resource/thirdparty-js/jquery.selection.js

@@ -0,0 +1,354 @@
+/*!
+ * jQuery.selection - jQuery Plugin
+ *
+ * Copyright (c) 2010-2014 IWASAKI Koji (@madapaja).
+ * http://blog.madapaja.net/
+ * Under The MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+(function($, win, doc) {
+    /**
+     * get caret status of the selection of the element
+     *
+     * @param   {Element}   element         target DOM element
+     * @return  {Object}    return
+     * @return  {String}    return.text     selected text
+     * @return  {Number}    return.start    start position of the selection
+     * @return  {Number}    return.end      end position of the selection
+     */
+    var _getCaretInfo = function(element){
+        var res = {
+            text: '',
+            start: 0,
+            end: 0
+        };
+
+        if (!element.value) {
+            /* no value or empty string */
+            return res;
+        }
+
+        try {
+            if (win.getSelection) {
+                /* except IE */
+                res.start = element.selectionStart;
+                res.end = element.selectionEnd;
+                res.text = element.value.slice(res.start, res.end);
+            } else if (doc.selection) {
+                /* for IE */
+                element.focus();
+
+                var range = doc.selection.createRange(),
+                    range2 = doc.body.createTextRange();
+
+                res.text = range.text;
+
+                try {
+                    range2.moveToElementText(element);
+                    range2.setEndPoint('StartToStart', range);
+                } catch (e) {
+                    range2 = element.createTextRange();
+                    range2.setEndPoint('StartToStart', range);
+                }
+
+                res.start = element.value.length - range2.text.length;
+                res.end = res.start + range.text.length;
+            }
+        } catch (e) {
+            /* give up */
+        }
+
+        return res;
+    };
+
+    /**
+     * caret operation for the element
+     * @type {Object}
+     */
+    var _CaretOperation = {
+        /**
+         * get caret position
+         *
+         * @param   {Element}   element         target element
+         * @return  {Object}    return
+         * @return  {Number}    return.start    start position for the selection
+         * @return  {Number}    return.end      end position for the selection
+         */
+        getPos: function(element) {
+            var tmp = _getCaretInfo(element);
+            return {start: tmp.start, end: tmp.end};
+        },
+
+        /**
+         * set caret position
+         *
+         * @param   {Element}   element         target element
+         * @param   {Object}    toRange         caret position
+         * @param   {Number}    toRange.start   start position for the selection
+         * @param   {Number}    toRange.end     end position for the selection
+         * @param   {String}    caret           caret mode: any of the following: "keep" | "start" | "end"
+         */
+        setPos: function(element, toRange, caret) {
+            caret = this._caretMode(caret);
+
+            if (caret === 'start') {
+                toRange.end = toRange.start;
+            } else if (caret === 'end') {
+                toRange.start = toRange.end;
+            }
+
+            element.focus();
+            try {
+                if (element.createTextRange) {
+                    var range = element.createTextRange();
+
+                    if (win.navigator.userAgent.toLowerCase().indexOf("msie") >= 0) {
+                        toRange.start = element.value.substr(0, toRange.start).replace(/\r/g, '').length;
+                        toRange.end = element.value.substr(0, toRange.end).replace(/\r/g, '').length;
+                    }
+
+                    range.collapse(true);
+                    range.moveStart('character', toRange.start);
+                    range.moveEnd('character', toRange.end - toRange.start);
+
+                    range.select();
+                } else if (element.setSelectionRange) {
+                    element.setSelectionRange(toRange.start, toRange.end);
+                }
+            } catch (e) {
+                /* give up */
+            }
+        },
+
+        /**
+         * get selected text
+         *
+         * @param   {Element}   element         target element
+         * @return  {String}    return          selected text
+         */
+        getText: function(element) {
+            return _getCaretInfo(element).text;
+        },
+
+        /**
+         * get caret mode
+         *
+         * @param   {String}    caret           caret mode
+         * @return  {String}    return          any of the following: "keep" | "start" | "end"
+         */
+        _caretMode: function(caret) {
+            caret = caret || "keep";
+            if (caret === false) {
+                caret = 'end';
+            }
+
+            switch (caret) {
+                case 'keep':
+                case 'start':
+                case 'end':
+                    break;
+
+                default:
+                    caret = 'keep';
+            }
+
+            return caret;
+        },
+
+        /**
+         * replace selected text
+         *
+         * @param   {Element}   element         target element
+         * @param   {String}    text            replacement text
+         * @param   {String}    caret           caret mode: any of the following: "keep" | "start" | "end"
+         */
+        replace: function(element, text, caret) {
+            var tmp = _getCaretInfo(element),
+                orig = element.value,
+                pos = $(element).scrollTop(),
+                range = {start: tmp.start, end: tmp.start + text.length};
+
+            element.value = orig.substr(0, tmp.start) + text + orig.substr(tmp.end);
+
+            $(element).scrollTop(pos);
+            this.setPos(element, range, caret);
+        },
+
+        /**
+         * insert before the selected text
+         *
+         * @param   {Element}   element         target element
+         * @param   {String}    text            insertion text
+         * @param   {String}    caret           caret mode: any of the following: "keep" | "start" | "end"
+         */
+        insertBefore: function(element, text, caret) {
+            var tmp = _getCaretInfo(element),
+                orig = element.value,
+                pos = $(element).scrollTop(),
+                range = {start: tmp.start + text.length, end: tmp.end + text.length};
+
+            element.value = orig.substr(0, tmp.start) + text + orig.substr(tmp.start);
+
+            $(element).scrollTop(pos);
+            this.setPos(element, range, caret);
+        },
+
+        /**
+         * insert after the selected text
+         *
+         * @param   {Element}   element         target element
+         * @param   {String}    text            insertion text
+         * @param   {String}    caret           caret mode: any of the following: "keep" | "start" | "end"
+         */
+        insertAfter: function(element, text, caret) {
+            var tmp = _getCaretInfo(element),
+                orig = element.value,
+                pos = $(element).scrollTop(),
+                range = {start: tmp.start, end: tmp.end};
+
+            element.value = orig.substr(0, tmp.end) + text + orig.substr(tmp.end);
+
+            $(element).scrollTop(pos);
+            this.setPos(element, range, caret);
+        }
+    };
+
+    /* add jQuery.selection */
+    $.extend({
+        /**
+         * get selected text on the window
+         *
+         * @param   {String}    mode            selection mode: any of the following: "text" | "html"
+         * @return  {String}    return
+         */
+        selection: function(mode) {
+            var getText = ((mode || 'text').toLowerCase() === 'text');
+
+            try {
+                if (win.getSelection) {
+                    if (getText) {
+                        // get text
+                        return win.getSelection().toString();
+                    } else {
+                        // get html
+                        var sel = win.getSelection(), range;
+
+                        if (sel.getRangeAt) {
+                            range = sel.getRangeAt(0);
+                        } else {
+                            range = doc.createRange();
+                            range.setStart(sel.anchorNode, sel.anchorOffset);
+                            range.setEnd(sel.focusNode, sel.focusOffset);
+                        }
+
+                        return $('<div></div>').append(range.cloneContents()).html();
+                    }
+                } else if (doc.selection) {
+                    if (getText) {
+                        // get text
+                        return doc.selection.createRange().text;
+                    } else {
+                        // get html
+                        return doc.selection.createRange().htmlText;
+                    }
+                }
+            } catch (e) {
+                /* give up */
+            }
+
+            return '';
+        }
+    });
+
+    /* add selection */
+    $.fn.extend({
+        selection: function(mode, opts) {
+            opts = opts || {};
+
+            switch (mode) {
+                /**
+                 * selection('getPos')
+                 * get caret position
+                 *
+                 * @return  {Object}    return
+                 * @return  {Number}    return.start    start position for the selection
+                 * @return  {Number}    return.end      end position for the selection
+                 */
+                case 'getPos':
+                    return _CaretOperation.getPos(this[0]);
+
+                /**
+                 * selection('setPos', opts)
+                 * set caret position
+                 *
+                 * @param   {Number}    opts.start      start position for the selection
+                 * @param   {Number}    opts.end        end position for the selection
+                 */
+                case 'setPos':
+                    return this.each(function() {
+                        _CaretOperation.setPos(this, opts);
+                    });
+
+                /**
+                 * selection('replace', opts)
+                 * replace the selected text
+                 *
+                 * @param   {String}    opts.text            replacement text
+                 * @param   {String}    opts.caret           caret mode: any of the following: "keep" | "start" | "end"
+                 */
+                case 'replace':
+                    return this.each(function() {
+                        _CaretOperation.replace(this, opts.text, opts.caret);
+                    });
+
+                /**
+                 * selection('insert', opts)
+                 * insert before/after the selected text
+                 *
+                 * @param   {String}    opts.text            insertion text
+                 * @param   {String}    opts.caret           caret mode: any of the following: "keep" | "start" | "end"
+                 * @param   {String}    opts.mode            insertion mode: any of the following: "before" | "after"
+                 */
+                case 'insert':
+                    return this.each(function() {
+                        if (opts.mode === 'before') {
+                            _CaretOperation.insertBefore(this, opts.text, opts.caret);
+                        } else {
+                            _CaretOperation.insertAfter(this, opts.text, opts.caret);
+                        }
+                    });
+
+                /**
+                 * selection('get')
+                 * get selected text
+                 *
+                 * @return  {String}    return
+                 */
+                case 'get':
+                    /* falls through */
+                default:
+                    return _CaretOperation.getText(this[0]);
+            }
+
+            return this;
+        }
+    });
+})(jQuery, window, window.document);