Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors generated when running Hexo API commands under Gulp #4192

Open
alexlibby opened this issue Mar 18, 2020 · 1 comment
Open

Errors generated when running Hexo API commands under Gulp #4192

alexlibby opened this issue Mar 18, 2020 · 1 comment

Comments

@alexlibby
Copy link

@alexlibby alexlibby commented Mar 18, 2020

Check List

Please check followings before submitting a new issue.

  • I have already read Docs page & Troubleshooting page
  • I have already searched existing issues and they are not help to me
  • I examined error or warning messages and it's difficult to solve
  • Using the latest version of Hexo (run hexo version to check)
  • Node.js is higher than 8.6.0

Expected behavior

I've written a Gulp file to automate the cleaning and regeneration of Hexo content in my blog - it is reproduced below:

var gulp = require('gulp');
var del = require('del');
var Hexo = require('hexo');

gulp.task('clean', function() {
    return del(['public/**/*']);
});

var hexo = new Hexo(process.cwd(), {});

gulp.task('generate', function(cb) {
  hexo.init().then(function() {
    return hexo.call('generate', {
        watch: false
    });
  }).then(function() {
    return hexo.exit();
  }).then(function() {
    return cb()
  }).catch(function(err) {
    console.log(err);
    hexo.exit(err);
    return cb(err);
  })
});

gulp.task('deploy', function() {
  return hexo.init().then(function() {
    return hexo.call('deploy', {
      watch: false
    }).then(function() {
      return hexo.exit();
    }).catch(function(err) {
      return hexo.exit(err);
    });
  });
});

gulp.task('restart', async function() {
  return hexo.init().then(function() {
    return hexo.call('server', {}).then(function() {
      return hexo.exit();
    }).catch(function(err) {
      return hexo.exit(err);
    });
  });
});

gulp.task('default', gulp.series('clean', 'generate', 'deploy', 'restart'));

This should run the same as running hexo clean && hexo generate && hexo server (or the shorthand equivalent), by simply running gulp.

Actual behavior

If I run the gulp file as-is, I see these errors appear - I'm not sure if this is because I'm running under Gulp - anyone any advice?

[21:01:54] Using gulpfile c:\myblog\gulpfile.js
[21:01:54] Starting 'default'...
[21:01:54] Starting 'clean'...
[21:01:54] Finished 'clean' after 53 ms
[21:01:54] Starting 'generate'...
INFO  Start processing
INFO  Files loaded in 112 ms
INFO  Generated: sitemap.xml
INFO  Generated: index.html
INFO  Generated: Test-Page/index.html
INFO  Generated: archives/index.html
INFO  Generated: uncategorized/Test-Post-with-YouTube/index.html
INFO  Generated: Rivalries/Test-Post-with-Video/index.html
INFO  Generated: categories/Sports/index.html
INFO  Generated: tags/Injury/index.html
INFO  Generated: page/2/index.html
INFO  Generated: uncategorized/Test-Post-with-Image/cruiseboat.jpg
INFO  Generated: archives/2020/02/index.html
INFO  Generated: images/avatar.png
INFO  Generated: Rivalries/Test-Post-with-Video/cruiseboat.jpg
INFO  Generated: images/cruiseboat.jpg
INFO  Generated: uncategorized/My-Books/index.html
INFO  Generated: tags/Fight/index.html
INFO  Generated: uncategorized/Test-Post/index.html
INFO  Generated: categories/Rivalries/index.html
INFO  Generated: tags/test/index.html
INFO  Generated: tags/hexo/index.html
INFO  Generated: tags/youtube/index.html
INFO  Generated: tags/media/index.html
INFO  Generated: tags/post/index.html
INFO  Generated: tags/new/index.html
INFO  Generated: uncategorized/Test-Post-with-Image/index.html
INFO  Generated: archives/2020/index.html
INFO  Generated: tags/Shocking/index.html
INFO  Generated: uncategorized/hello-world/index.html
INFO  Generated: fonts/HomemadeApple-webfont.woff
INFO  Generated: Sports/Baseball/Test-Post-for-SoundCloud/index.html
INFO  Generated: categories/Sports/Baseball/index.html
INFO  Generated: css/styles.css
INFO  Generated: img/coffee.jpg
INFO  33 files generated in 689 ms
[21:01:55] Finished 'generate' after 1.3 s
[21:01:55] Starting 'deploy'...
[21:01:55] Finished 'deploy' after 39 ms
[21:01:55] Starting 'restart'...
INFO  Start processing
ERROR Process failed: _posts/2020-02-22-Test-Post-with-Image/cruiseboat.jpg
TypeError: str must be a string!
    at slugize (c:\myblog\node_modules\hexo-util\lib\slugize.js:10:38)
    at Hexo.postPermalinkFilter (c:\myblog\node_modules\hexo\lib\plugins\filter\post_permalink.js:14:17)
    at Filter.execSync (c:\myblog\node_modules\hexo\lib\extend\filter.js:76:30)
    at Hexo.execFilterSync (c:\myblog\node_modules\hexo\lib\hexo\index.js:470:31)
    at _Document.<anonymous> (c:\myblog\node_modules\hexo\lib\models\post.js:49:22)
    at _Document.path (c:\myblog\node_modules\warehouse\lib\types\virtual.js:59:24)
    at _Document.<anonymous> (c:\myblog\node_modules\hexo\lib\models\post_asset.js:23:22)
    at _Document.path (c:\myblog\node_modules\warehouse\lib\types\virtual.js:59:24)
    at _Document.toObject (c:\myblog\node_modules\warehouse\lib\document.js:73:44)
    at _Model._replaceById (c:\myblog\node_modules\warehouse\lib\model.js:308:25)
    at c:\myblog\node_modules\warehouse\lib\model.js:211:21
    at tryCatcher (c:\myblog\node_modules\bluebird\js\release\util.js:16:23)
    at c:\myblog\node_modules\bluebird\js\release\using.js:185:26
    at bound (domain.js:419:14)
    at runBound (domain.js:432:12)
    at tryCatcher (c:\myblog\node_modules\bluebird\js\release\util.js:16:23)
ERROR Process failed: _posts/2020-02-22-Test-Post-with-Video/cruiseboat.jpg
TypeError: str must be a string!
    at slugize (c:\myblog\node_modules\hexo-util\lib\slugize.js:10:38)
    at Hexo.postPermalinkFilter (c:\myblog\node_modules\hexo\lib\plugins\filter\post_permalink.js:14:17)
    at Filter.execSync (c:\myblog\node_modules\hexo\lib\extend\filter.js:76:30)
    at Hexo.execFilterSync (c:\myblog\node_modules\hexo\lib\hexo\index.js:470:31)
    at _Document.<anonymous> (c:\myblog\node_modules\hexo\lib\models\post.js:49:22)
    at _Document.path (c:\myblog\node_modules\warehouse\lib\types\virtual.js:59:24)
    at _Document.<anonymous> (c:\myblog\node_modules\hexo\lib\models\post_asset.js:23:22)
    at _Document.path (c:\myblog\node_modules\warehouse\lib\types\virtual.js:59:24)
    at _Document.toObject (c:\myblog\node_modules\warehouse\lib\document.js:73:44)
    at _Model._replaceById (c:\myblog\node_modules\warehouse\lib\model.js:308:25)
    at c:\myblog\node_modules\warehouse\lib\model.js:211:21
    at tryCatcher (c:\myblog\node_modules\bluebird\js\release\util.js:16:23)
    at c:\myblog\node_modules\bluebird\js\release\using.js:185:26
    at bound (domain.js:419:14)
    at runBound (domain.js:432:12)
    at tryCatcher (c:\myblog\node_modules\bluebird\js\release\util.js:16:23)
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
TypeError: str must be a string!
    at slugize (c:\myblog\node_modules\hexo-util\lib\slugize.js:10:38)
    at Hexo.postPermalinkFilter (c:\myblog\node_modules\hexo\lib\plugins\filter\post_permalink.js:14:17)
    at Filter.execSync (c:\myblog\node_modules\hexo\lib\extend\filter.js:76:30)
    at Hexo.execFilterSync (c:\myblog\node_modules\hexo\lib\hexo\index.js:470:31)
    at _Document.<anonymous> (c:\myblog\node_modules\hexo\lib\models\post.js:49:22)
    at _Document.path (c:\myblog\node_modules\warehouse\lib\types\virtual.js:59:24)
    at c:\myblog\node_modules\hexo\lib\plugins\generator\post.js:8:13
    at Array.map (<anonymous>)
    at Hexo.postGenerator (c:\myblog\node_modules\hexo\lib\plugins\generator\post.js:7:16)
    at Hexo.tryCatcher (c:\myblog\node_modules\bluebird\js\release\util.js:16:23)
    at Hexo.<anonymous> (c:\myblog\node_modules\bluebird\js\release\method.js:15:34)
    at c:\myblog\node_modules\hexo\lib\hexo\index.js:390:22
    at bound (domain.js:419:14)
    at runBound (domain.js:432:12)
    at tryCatcher (c:\myblog\node_modules\bluebird\js\release\util.js:16:23)
    at MappingPromiseArray._promiseFulfilled (c:\myblog\node_modules\bluebird\js\release\map.js:68:38)
(node:9972) [DEP0097] DeprecationWarning: Using a domain property in MakeCallback is deprecated. Use the async_context variant of MakeCallback or the AsyncResource class instead.
[21:01:55] Finished 'restart' after 155 ms
[21:01:55] Finished 'default' after 1.55 s

I also see a deprecation notice appearing - this seems to be coming from the restart task, yet when I run this task on its own (see below), the task works OK, without any issues.

How to reproduce?

  1. Clone the code at https://github.com/alexlibby/hexo/ (I've tried to give readonly access to Hexojs/core, but your user ID doesn't seem to be recognised?)
  2. Change to the working folder where you cloned the repo
  3. Run gulp at the command line to get the errors.
  4. Run gulp restart - this works fine on its own.
  5. Comment out ,'restart' in the last line of the gulp file, then run gulp - this works OK.

Environment & Settings

Node.js & npm version

Node - 12.5.0
NPM - 6.3.4
Note: This is being run on Windows 10

Your site _config.yml (Optional)

Your theme _config.yml (Optional)

Hexo and Plugin version(npm ls --depth 0)

hexo-site@0.0.0 c:\myblog
+-- del@5.1.0
+-- gulp@4.0.2
+-- hexo@4.2.0
+-- hexo-generator-archive@1.0.0
+-- hexo-generator-category@1.0.0
+-- hexo-generator-index@1.0.0
+-- hexo-generator-sitemap@2.0.0
+-- hexo-generator-tag@1.0.0
+-- hexo-lazyload-image@1.0.6
+-- hexo-renderer-ejs@1.0.0
+-- hexo-renderer-marked@2.0.0
+-- hexo-renderer-sass@0.4.0
+-- hexo-renderer-stylus@1.1.0
+-- hexo-server@1.0.0
+-- hexo-tag-owl@1.2.2
+-- hexo-tag-soundcloud@1.0.2
+-- hexo-tag-spotify@1.1.0
`-- hexo-tag-youtube-responsive@0.4.2

Your package.json package.json

{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "build": "hexo generate",
    "clean": "hexo clean",
    "deploy": "hexo deploy",
    "server": "hexo server",
    "restart": "hexo generate && hexo server"
  },
  "hexo": {
    "version": "4.2.0"
  },
  "dependencies": {
    "del": "^5.1.0",
    "hexo": "^4.0.0",
    "hexo-generator-archive": "^1.0.0",
    "hexo-generator-category": "^1.0.0",
    "hexo-generator-index": "^1.0.0",
    "hexo-generator-sitemap": "^2.0.0",
    "hexo-generator-tag": "^1.0.0",
    "hexo-lazyload-image": "^1.0.6",
    "hexo-renderer-ejs": "^1.0.0",
    "hexo-renderer-marked": "^2.0.0",
    "hexo-renderer-sass": "^0.4.0",
    "hexo-renderer-stylus": "^1.1.0",
    "hexo-server": "^1.0.0",
    "hexo-tag-owl": "^1.2.2",
    "hexo-tag-soundcloud": "^1.0.2",
    "hexo-tag-spotify": "^1.1.0",
    "hexo-tag-youtube-responsive": "^0.4.2"
  },
  "devDependencies": {
    "gulp": "^4.0.2"
  }
}

Others

@alexlibby

This comment has been minimized.

Copy link
Author

@alexlibby alexlibby commented Mar 28, 2020

FYI - I've managed to get something working with Grunt; if anyone wants the code, here it is:

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    shell: {
      clean: {
        command: 'hexo clean'
      },
      generate: {
        command: 'hexo generate'
      },
      startserver: {
        command: 'hexo server -no-optional'
      }
    }
  });

  // Load the plugin that provides the "uglify" task.
  grunt.loadNpmTasks('grunt-shell');

  // Default task(s).
  grunt.registerTask('default', ['shell']);
};

It uses the grunt-shell command to run each command; so far, initial indications are that it is recreating the database / public files fine, and restarts the server with no issue. I've included the -no-optional tag as I use Windows, but that may not be needed for Mac or Linux users.

It would be nice to know if Gulp can do something similar - have you had any success in investigating what's going on with my original code and why it's failing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.