Kevin van Zonneveld 9 лет назад
Родитель
Сommit
06796278a1
5 измененных файлов с 99 добавлено и 96 удалено
  1. 2 2
      package.json
  2. 16 16
      website/build-documentation.js
  3. 55 55
      website/build-examples.js
  4. 14 15
      website/themes/uppy/source/js/common.js
  5. 12 8
      website/update.js

+ 2 - 2
package.json

@@ -12,8 +12,8 @@
     "build": "npm run build:lib && npm run build:umd && npm run build:umd:min && npm run build:css",
     "clean": "rm -rf lib && rm -rf dist",
     "docs": "cd website && node build-documentation.js",
-    "lint": "eslint src/**/*.js src/*.js test/*.js test/spec/*.js website/src/examples/*/*.es6",
-    "fix": "eslint src/**/*.js src/*.js test/*.js test/spec/*.js website/src/examples/*/*.es6 --fix",
+    "lint": "eslint src/**/*.js src/*.js test/*.js test/spec/*.js website/themes/uppy/source/js/common.js website/*.js website/src/examples/*/*.es6",
+    "fix": "eslint src/**/*.js src/*.js test/*.js test/spec/*.js website/themes/uppy/source/js/common.js website/*.js website/src/examples/*/*.es6 --fix",
     "server": "browser-sync start --config .browsersync.js",
     "start": "npm run build && npm run web",
     "test:phantom": "zuul test/spec/upload.js --phantom",

+ 16 - 16
website/build-documentation.js

@@ -1,23 +1,23 @@
-var documentation = require('documentation');
-var documentationFormatter = documentation.formats['md'];
-var remark = require('remark');
-var inject = require('mdast-util-inject');
-var chalk = require('chalk');
-var fs = require('fs');
+var documentation = require('documentation')
+var documentationFormatter = documentation.formats['md']
+var remark = require('remark')
+var inject = require('mdast-util-inject')
+var chalk = require('chalk')
+var fs = require('fs')
 
-var docOrder = ['Core', 'Utils', 'Translator', 'Plugin'];
+var docOrder = ['Core', 'Utils', 'Translator', 'Plugin']
 
 documentation('../src/index.js', {order: docOrder}, function (err, comments) {
-  if (err) console.log(err);
+  if (err) console.log(err)
 
   documentationFormatter(comments, {}, function (err, output) {
-    if (err) console.log(err);
+    if (err) console.log(err)
 
-    var inputMarkdownContent = remark.parse(fs.readFileSync('src/api/docs.md', 'utf-8'));
-    var newStuff = remark.parse(output);
-    inject('Uppy Core & Plugins', inputMarkdownContent, newStuff);
+    var inputMarkdownContent = remark.parse(fs.readFileSync('src/api/docs.md', 'utf-8'))
+    var newStuff = remark.parse(output)
+    inject('Uppy Core & Plugins', inputMarkdownContent, newStuff)
 
-    fs.writeFileSync('src/api/docs.md', remark.stringify(inputMarkdownContent));
-    console.info(chalk.green('✓ documentation generated'));
-  });
-});
+    fs.writeFileSync('src/api/docs.md', remark.stringify(inputMarkdownContent))
+    console.info(chalk.green('✓ documentation generated'))
+  })
+})

+ 55 - 55
website/build-examples.js

@@ -20,49 +20,49 @@
  * before announcing a changed file.  It's removed from
  * the array when it has been bundled.
  */
-var createStream = require('fs').createWriteStream;
-var glob = require('multi-glob').glob;
-var chalk = require('chalk');
-var path = require('path');
-var mkdirp = require('mkdirp');
-var notifier = require('node-notifier');
-var babelify = require('babelify');
-var browserify = require('browserify');
-var watchify = require('watchify');
-
-var webRoot = __dirname;
-var uppyRoot = path.dirname(webRoot);
-
-var srcPattern = webRoot + '/src/examples/**/app.es6';
-var dstPattern = webRoot + '/public/examples/**/app.js';
-
-var watchifyEnabled = process.argv[2] === 'watch';
-var browserifyPlugins = [];
+var createStream = require('fs').createWriteStream
+var glob = require('multi-glob').glob
+var chalk = require('chalk')
+var path = require('path')
+var mkdirp = require('mkdirp')
+var notifier = require('node-notifier')
+var babelify = require('babelify')
+var browserify = require('browserify')
+var watchify = require('watchify')
+
+var webRoot = __dirname
+var uppyRoot = path.dirname(webRoot)
+
+var srcPattern = webRoot + '/src/examples/**/app.es6'
+var dstPattern = webRoot + '/public/examples/**/app.js'
+
+var watchifyEnabled = process.argv[2] === 'watch'
+var browserifyPlugins = []
 if (watchifyEnabled) {
-  browserifyPlugins.push(watchify);
+  browserifyPlugins.push(watchify)
 }
 
 // Instead of 'watch', build-examples.js can also take a path as cli argument.
 // In this case we'll only bundle the specified path/pattern
 if (!watchifyEnabled && process.argv[2]) {
-  srcPattern = process.argv[2];
+  srcPattern = process.argv[2]
   if (process.argv[3]) {
-    dstPattern = process.argv[3];
+    dstPattern = process.argv[3]
   }
 }
 
 // Find each app.es6 file with glob.
-glob(srcPattern, function(err, files) {
-  if (err) throw new Error(err);
+glob(srcPattern, function (err, files) {
+  if (err) throw new Error(err)
 
   if (watchifyEnabled) {
-    console.log('--> Watching examples..');
+    console.log('--> Watching examples..')
   }
 
-  var muted = [];
+  var muted = []
 
   // Create a new watchify instance for each file.
-  files.forEach(function(file) {
+  files.forEach(function (file) {
     var browseFy = browserify(file, {
       cache       : {},
       packageCache: {},
@@ -74,21 +74,21 @@ glob(srcPattern, function(err, files) {
       .require(uppyRoot + '/src/index.js', { expose: 'uppy' })
       .require(uppyRoot + '/src/core/index.js', { expose: 'uppy/core' })
       .require(uppyRoot + '/src/plugins/index.js', { expose: 'uppy/plugins' })
-      .transform(babelify);
+      .transform(babelify)
 
     // Listeners for changes, errors, and completion.
     browseFy
       .on('update', bundle)
       .on('error', onError)
-      .on('file', function(file, id, parent) {
+      .on('file', function (file, id, parent) {
         // When file completes, unmute it.
-        muted = muted.filter(function(mutedId) {
-          return id !== mutedId;
-        });
-      });
+        muted = muted.filter(function (mutedId) {
+          return id !== mutedId
+        })
+      })
 
     // Call bundle() manually to start watch processes.
-    bundle();
+    bundle()
 
     /**
      * Creates bundle and writes it to static and public folders.
@@ -96,43 +96,43 @@ glob(srcPattern, function(err, files) {
      * @param  {[type]} ids [description]
      * @return {[type]}     [description]
      */
-    function bundle(ids) {
-      ids = ids || [];
-      ids.forEach(function(id) {
+    function bundle (ids) {
+      ids = ids || []
+      ids.forEach(function (id) {
         if (!isMuted(id, muted)) {
-          console.info(chalk.cyan('change:'), id);
-          muted.push(id);
+          console.info(chalk.cyan('change:'), id)
+          muted.push(id)
         }
-      });
+      })
 
-      var exampleName = path.basename(path.dirname(file));
-      var output      = dstPattern.replace('**', exampleName);
-      var parentDir   = path.dirname(output);
+      var exampleName = path.basename(path.dirname(file))
+      var output      = dstPattern.replace('**', exampleName)
+      var parentDir   = path.dirname(output)
 
-      mkdirp.sync(parentDir);
+      mkdirp.sync(parentDir)
 
-      console.info(chalk.green('✓ building:'), chalk.green(path.relative(process.cwd(), file)));
+      console.info(chalk.green('✓ building:'), chalk.green(path.relative(process.cwd(), file)))
 
       var bundle = browseFy.bundle()
         .on('error', onError)
 
-      bundle.pipe(createStream(output));
+      bundle.pipe(createStream(output))
     }
-  });
-});
+  })
+})
 
 /**
  * Logs to console and shows desktop notification on error.
  * Calls `this.emit(end)` to stop bundling.
  * @param  {object} err Error object
  */
-function onError(err) {
-  console.error(chalk.red('✗ error:'), chalk.red(err.message));
+function onError (err) {
+  console.error(chalk.red('✗ error:'), chalk.red(err.message))
   notifier.notify({
-    'title': 'Build failed:',
+    'title'  : 'Build failed:',
     'message': err.message
   })
-  this.emit('end');
+  this.emit('end')
 }
 
 /**
@@ -142,8 +142,8 @@ function onError(err) {
  * @param  {Array<string>}  list Muted files array
  * @return {Boolean}      True if file is muted
  */
-function isMuted(id, list) {
-  return list.reduce(function(prev, curr) {
-    return prev || (curr === id);
-  }, false);
+function isMuted (id, list) {
+  return list.reduce(function (prev, curr) {
+    return prev || (curr === id)
+  }, false)
 }

+ 14 - 15
website/themes/uppy/source/js/common.js

@@ -1,5 +1,4 @@
 (function () {
-
   var each = [].forEach
 
   var main = document.querySelector('.js-MainContent')
@@ -69,8 +68,8 @@
     allLinks.forEach(makeLinkClickable)
 
     // init smooth scroll
-    smoothScroll.init({
-      speed: 400,
+    window.smoothScroll.init({
+      speed : 400,
       offset: window.innerWidth > 720
         ? 40
         : 58
@@ -85,9 +84,9 @@
     var top = doc && doc.scrollTop || body.scrollTop
     var headerHeight = header.offsetHeight
     if (top > headerHeight) {
-      addClass(main, 'fix-sidebar');
+      addClass(main, 'fix-sidebar')
     } else {
-      removeClass(main, 'fix-sidebar');
+      removeClass(main, 'fix-sidebar')
     }
     if (animating || !allLinks) return
     var last
@@ -100,8 +99,9 @@
         last = link
       }
     }
-    if (last)
-    setActive(last.id)
+    if (last) {
+      setActive(last.id)
+    }
   }
 
   function makeLink (h) {
@@ -160,19 +160,19 @@
     wrapper.appendChild(link)
   }
 
-  function addClass(el, className) {
+  function addClass (el, className) {
     if (el.classList) {
-      el.classList.add(className);
+      el.classList.add(className)
     } else {
-      el.className += ' ' + className;
+      el.className += ' ' + className
     }
   }
 
-  function removeClass(el, className) {
+  function removeClass (el, className) {
     if (el.classList) {
-      el.classList.remove(className);
+      el.classList.remove(className)
     } else {
-      el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
+      el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ')
     }
   }
 
@@ -197,5 +197,4 @@
   //     // TODO when 1.x is out
   //   }
   // })
-
-})();
+})()

+ 12 - 8
website/update.js

@@ -1,16 +1,16 @@
 var fs = require('fs')
 var path  = require('path')
-var chalk = require('chalk');
+var chalk = require('chalk')
 
-var webRoot  = __dirname;
-var uppyRoot = path.dirname(__dirname);
+var webRoot  = __dirname
+var uppyRoot = path.dirname(__dirname)
 
 var configPath = webRoot + '/_config.yml'
 var config     = fs.readFileSync(configPath, 'utf-8')
 var version    = require(uppyRoot + '/package.json').version
 
 // Inject current Uppy version and sizes in website's _config.yml
-var sizes     = {};
+var sizes     = {}
 var locations = {
   min: uppyRoot + '/dist/uppy.js',
   gz : uppyRoot + '/dist/uppy.js',
@@ -29,7 +29,7 @@ fs.writeFileSync(
   config
     .replace(/uppy_version: .*/, 'uppy_version: ' + version)
     .replace(/uppy_(\w+)_size:.*/g, function (m, p1) {
-      return 'uppy_' + p1 + '_size: "' + (sizes[p1] || 99999 ) + '"'
+      return 'uppy_' + p1 + '_size: "' + (sizes[p1] || 99999) + '"'
     })
 )
 
@@ -48,7 +48,11 @@ fs.writeFileSync(
 // console.info(chalk.green('✓ injected: '), chalk.dim('uppy.css build into site'));
 
 // Copy latest uppy version into website so the CDN example can use it
-var exec = require('child_process').exec;
+var exec = require('child_process').exec
 exec('cp -fR ./dist/. ./website/themes/uppy/source/uppy', function (error, stdout, stderr) {
-  console.info(chalk.green('✓ injected: '), chalk.dim('uppy umd build into site'));
-});
+  if (error) {
+    console.error(chalk.red('x failed to inject: '), chalk.dim('uppy umd build into site'))
+    return
+  }
+  console.info(chalk.green('✓ injected: '), chalk.dim('uppy umd build into site'))
+})