Browse Source

We'll need a real renderer, otherwise Hexo deletes artifacts in one-off builds

Kevin van Zonneveld 9 years ago
parent
commit
b9f0111f3a

+ 1 - 1
package.json

@@ -20,7 +20,7 @@
     "web:clean": "cd website && ./node_modules/.bin/hexo clean",
     "web:build": "cd website && node update.js && ./node_modules/.bin/hexo generate",
     "web:deploy": "npm run web:install && npm run web:build && ./bin/web-deploy",
-    "web:install": "cd website && rm -rf node_modules/hexo-uppyexamplebuilder && npm install",
+    "web:install": "cd website && rm -rf node_modules/hexo-renderer-uppyexamples && npm install",
     "web:preview": "cd website && ./node_modules/.bin/hexo server --debug",
     "web": "npm run web:install && npm run web:build && npm run web:preview"
   },

+ 8 - 4
website/build-examples.js

@@ -7,9 +7,10 @@
  *
  * Run as:
  *
- * build-examples.js        # to build all examples one-off
- * build-examples.js watch  # to keep rebuilding examples with an internal watchify
- * build-examples.js <path> # to build just one example app.es6
+ * build-examples.js               # to build all examples one-off
+ * build-examples.js watch         # to keep rebuilding examples with an internal watchify
+ * build-examples.js <path>        # to build just one example app.es6
+ * build-examples.js <path> <path> # to build just one example app.es6 to a specific location
  *
  * Note:
  * Since each example is dependent on Uppy's source,
@@ -45,6 +46,9 @@ if (watchifyEnabled) {
 // In this case we'll only bundle the specified path/pattern
 if (!watchifyEnabled && process.argv[2]) {
   srcPattern = process.argv[2];
+  if (process.argv[3]) {
+    dstPattern = process.argv[3];
+  }
 }
 
 // Find each app.es6 file with glob.
@@ -107,7 +111,7 @@ glob(srcPattern, function(err, files) {
 
       mkdirp.sync(parentDir);
 
-      console.info(chalk.green('✓ building:'), chalk.green(path.relative(process.cwd(), output)));
+      console.info(chalk.green('✓ building:'), chalk.green(path.relative(process.cwd(), file)));
 
       var bundle = browseFy.bundle()
         .on('error', onError)

+ 1 - 1
website/package.json

@@ -9,7 +9,7 @@
     "autoprefixer": "^6.1.2",
     "hexo": "^3.1.1",
     "hexo-browsersync": "^0.2.0",
-    "hexo-uppyexamplebuilder": "file:./private_modules/hexo-uppyexamplebuilder",
+    "hexo-renderer-uppyexamples": "file:./private_modules/hexo-renderer-uppyexamples",
     "hexo-deployer-git": "0.0.4",
     "hexo-generator-archive": "^0.1.2",
     "hexo-generator-category": "^0.1.2",

+ 17 - 5
website/private_modules/hexo-uppyexamplebuilder/index.js → website/private_modules/hexo-renderer-uppyexamples/index.js

@@ -4,11 +4,13 @@
 // that script then writes the public/**/*.js files.
 var exec             = require('child_process').exec;
 var path             = require('path');
+var fs               = require('fs');
 var webRoot          = path.dirname(path.dirname(__dirname));
 var uppyRoot         = path.dirname(webRoot);
 var browserifyScript = webRoot + '/build-examples.js'
 
-hexo.extend.renderer.register('es6', 'es6', function(data, options, callback) {
+
+hexo.extend.renderer.register('es6', 'js', function(data, options, callback) {
   if (!data || !data.path) {
     return callback(null);
   }
@@ -17,14 +19,24 @@ hexo.extend.renderer.register('es6', 'es6', function(data, options, callback) {
     callback(null, data.text);
   }
 
-  var cmd = 'node ' + browserifyScript + ' ' + data.path + ' --colors';
-  // hexo.log.i('hexo-uppyexamplebuilder: change detected in examples. running: ' + cmd);
+  var slug    = data.path.replace(/[^a-zA-Z0-9\_\.]/g, '-');
+  var dstPath = '/tmp/' + slug + '.js';
+  var cmd     = 'node ' + browserifyScript + ' ' + data.path + ' ' + dstPath + ' --colors';
+  // hexo.log.i('hexo-renderer-uppyexamples: change detected in examples. running: ' + cmd);
   exec(cmd, function(err, stdout, stderr) {
     if (err) {
       return callback(err);
     }
 
-    hexo.log.i('hexo-uppyexamplebuilder: ' + stdout.trim());
-    callback(null, data.text);
+    hexo.log.i('hexo-renderer-uppyexamples: ' + stdout.trim());
+
+    fs.readFile(dstPath, 'utf-8', function(err, data) {
+      if (err) {
+        return callback(err);
+      }
+      hexo.log.i('hexo-renderer-uppyexamples: read: ' + dstPath);
+
+      callback(null, data);
+    });
   });
 });

+ 1 - 1
website/private_modules/hexo-uppyexamplebuilder/package.json → website/private_modules/hexo-renderer-uppyexamples/package.json

@@ -1,5 +1,5 @@
 {
-  "name": "hexo-uppyexamplebuilder",
+  "name": "hexo-renderer-uppyexamples",
   "version": "0.0.1",
   "private": true,
   "main": "index"