Sfoglia il codice sorgente

Added example watching system.

Harry Hedger 9 anni fa
parent
commit
03a913731b
6 ha cambiato i file con 73 aggiunte e 3 eliminazioni
  1. 0 1
      Makefile
  2. 1 2
      package.json
  3. 3 0
      website/_config.yml
  4. 7 0
      website/package.json
  5. 3 0
      website/src/examples/dropbox/src/js/app.js
  6. 59 0
      website/watch.js

+ 0 - 1
Makefile

@@ -11,7 +11,6 @@ website-install:
 .PHONY: website-build
 website-build: website-install
 	@echo "--> Building site.."
-	@npm run build:umd
 	@cd website && node update.js
 	@cd website && ./node_modules/.bin/hexo generate
 

+ 1 - 2
package.json

@@ -13,13 +13,12 @@
     "clean": "rm -rf lib && rm -rf dist",
     "lint": "eslint src/**/*.js",
     "dev": "npm run watch & npm run server",
-    "dev:examples": "npm run watch:examples & npm run server",
     "server": "browser-sync start --config .browsersync.js",
     "test": "bin/test",
     "test:phantom": "zuul test/spec/upload.js --phantom",
     "watch": "npm run watch:css & npm run watch:js",
     "watch:css": "nodemon -e src/scss -x \"npm run build:css\"",
-    "watch:examples": "npm run build:lib && (examples/buildAll node_modules/.bin/watchify & npm run watch:js)",
+    "watch:examples": "node website/watch.js",
     "watch:js": "nodemon --watch src -e js --ignore src/scss -x \"npm run build:lib\""
   },
   "repository": {

+ 3 - 0
website/_config.yml

@@ -122,3 +122,6 @@ markdown:
 #   type: git
 #   branch: gh-pages
 #   repository: git@github.com:transloadit/uppy.git
+
+skip_render:
+  - 'examples/**/*.js'

+ 7 - 0
website/package.json

@@ -18,5 +18,12 @@
     "hexo-server": "^0.1.2",
     "hexo-tag-emojis": "^2.0.0",
     "hexo-util": "^0.2.1"
+  },
+  "devDependencies": {
+    "browserify": "^12.0.1",
+    "chalk": "^1.1.1",
+    "glob": "^6.0.1",
+    "multi-glob": "^1.0.1",
+    "watchify": "^3.6.1"
   }
 }

+ 3 - 0
website/src/examples/dropbox/src/js/app.js

@@ -0,0 +1,3 @@
+import { DropboxPlugin } from '../../../../../../src/plugins'
+
+console.log('pizza');

+ 59 - 0
website/watch.js

@@ -0,0 +1,59 @@
+var fs = require('fs');
+var glob = require('multi-glob').glob;
+var chalk = require('chalk');
+var notifier = require('node-notifier');
+var babelify = require('babelify');
+var browserify = require('browserify');
+var watchify = require('watchify');
+
+var src = 'src/js/app.js';
+var dest = 'static/js/app.js';
+
+var pattern = 'src/examples/**/' + src;
+
+glob([pattern, 'website/' + pattern], function(err, files) {
+  if (err) throw new Error(err);
+
+  var mute = false;
+
+  files.forEach(function(file) {
+    var watcher = browserify(file, {
+      cache: {},
+      packageCache: {},
+      plugin: [watchify]
+    }).transform(babelify);
+
+    watcher
+      .on('update', bundle)
+      .on('error', handleError)
+      .on('log', function(msg) {
+        console.log(chalk.green('✓ done:'), chalk.bold(file), chalk.gray.dim(msg));
+        mute = false;
+      });
+
+    bundle();
+
+    function bundle(id) {
+      if (id && !mute) {
+        console.log(chalk.cyan('change:'), chalk.bold(id[0]));
+        mute = true;
+      }
+      var bundle = watcher.bundle();
+      bundle.pipe(createStream(file.replace(src, dest)));
+      bundle.pipe(createStream('public' + file.slice(3)));
+    }
+  });
+});
+
+function createStream(filepath) {
+  return fs.createWriteStream(filepath);
+}
+
+function handleError(err) {
+  console.log(chalk.red('✗ error:'), err.message);
+  notifier.notify({
+    'title': 'Build failed:',
+    'message': err.message
+  })
+  this.emit('end');
+}