leviwheatcroft / metalsmith-debug-ui

browser based ui for metalsmith debugging
21 stars 3 forks source link

Broken with gulp-metalsmith #5

Closed HaoZeke closed 6 years ago

HaoZeke commented 6 years ago

Hi, I have a setup with gulp-metalsmith so I have tried both patching it outside the function and in the function but neither manages to get any output...

The function is

import ms from 'gulp-metalsmith';
import { patch } from 'metalsmith-debug-ui';

patch(ms);

export function metal(cb) {

patch(ms);

return gulp.src(paths.watchFor.gulp)
  .pipe(
    ms({
      // Metalsmith's root directory, for example for locating templates, defaults to CWD 
        root: paths.contentFrom.root,
      // Don't delete stuff
        clean: false,
      // Files to exclude from the build 
        ignore: ['src/*.tmp'],
      // Parsing frontmatter, defaults to true 
        frontmatter: true,
      // Metalsmith plugins to use: 
        use: [

        // Put plugins

      // Initial Metalsmith metadata, defaults to {} 
      metadata: {
        site_name: 'Grimoire',
      },
      // List of JSON files that contain page definitions 
      // true means "all JSON files", see the section below 
      //json: ['src/pages.json']
    }))
    .pipe(gulp.dest(paths.outputTo.root))
    .pipe(bs.stream());
cb();
};
leviwheatcroft commented 6 years ago

Not really surprising TBH.

I've just had a quick look at gulp-metalsmith, correct me if I'm wrong but it's not really a metalsmith plugin, but something that works a bit like metalsmith and has a similar api. I mean it doesn't have metalsmith as a dependency, so when you import ms from 'gulp-metalsmith' you don't really have a metalsmith instance at all.

debug-ui is unlike most plugins in that it has to modify the metalsmith instance to copy the data after each plugin is run.

As a workaround you might try the report function instead of patching the ms instance. report works a bit more like other metalsmith plugins, and doesn't modify the ms instance. No guarantee it will work though.

I'm reluctant to spend any time trying to make this compatible with gulp-metalsmith.

HaoZeke commented 6 years ago

Unfortunately the report plugin didn't work either..

[16:14:10] Failed to load external module @babel/register
[16:14:10] Requiring external module babel-register
[16:14:29] Using gulpfile ~/Github/Pandoc/grimoire/gulpfile.babel.js
[16:14:29] Starting 'metal'...
[16:14:32] 'metal' errored after 2.73 s
[16:14:32] TypeError in plugin 'gulp-metalsmith'
Message:
    metalsmith.write is not a function
Details:
    domainEmitter: [object Object]
    domain: [object Object]
    domainThrown: false
Stack:
TypeError: metalsmith.write is not a function
    at writeData (/home/haozeke/Github/Pandoc/grimoire/node_modules/metalsmith-debug-ui/dist/index.js:208:16)
    at Ware.<anonymous> (/home/haozeke/Github/Pandoc/grimoire/node_modules/metalsmith-debug-ui/dist/index.js:106:5)
    at Ware.<anonymous> (/home/haozeke/Github/Pandoc/grimoire/node_modules/wrap-fn/index.js:75:16)
    at Ware.<anonymous> (/home/haozeke/Github/Pandoc/grimoire/node_modules/wrap-fn/index.js:57:27)
    at next (/home/haozeke/Github/Pandoc/grimoire/node_modules/ware/lib/index.js:85:20)
    at /home/haozeke/Github/Pandoc/grimoire/node_modules/wrap-fn/index.js:121:18
    at /home/haozeke/Github/Pandoc/grimoire/node_modules/metalsmith-autotoc/index.js:130:7
    at done (/home/haozeke/Github/Pandoc/grimoire/node_modules/metalsmith-autotoc/node_modules/async/lib/async.js:132:19)
    at /home/haozeke/Github/Pandoc/grimoire/node_modules/metalsmith-autotoc/node_modules/async/lib/async.js:32:16
    at /home/haozeke/Github/Pandoc/grimoire/node_modules/metalsmith-autotoc/index.js:127:9
    at /home/haozeke/Github/Pandoc/grimoire/node_modules/metalsmith-autotoc/node_modules/async/lib/async.js:122:13
    at _each (/home/haozeke/Github/Pandoc/grimoire/node_modules/metalsmith-autotoc/node_modules/async/lib/async.js:46:13)
    at Object.async.each (/home/haozeke/Github/Pandoc/grimoire/node_modules/metalsmith-autotoc/node_modules/async/lib/async.js:121:9)
    at Ware.<anonymous> (/home/haozeke/Github/Pandoc/grimoire/node_modules/metalsmith-autotoc/index.js:111:11)
    at Ware.<anonymous> (/home/haozeke/Github/Pandoc/grimoire/node_modules/wrap-fn/index.js:45:19)
    at next (/home/haozeke/Github/Pandoc/grimoire/node_modules/ware/lib/index.js:85:20)

I do understand it's probably not worth the trouble and effort, I'll refactor my gulpfile to call the metalsmith cli instead..

Though I don't see any information on it working with the json format...