PicGo / PicGo-Core

:zap:A tool for pictures uploading. Both CLI & API supports.
https://picgo.github.io/PicGo-Core-Doc/
MIT License
832 stars 84 forks source link

picgo开发插件错误 #50

Closed dhyz closed 4 years ago

dhyz commented 4 years ago

我按文档:

ggbang@DESKTOP-K2EEVD4:~/repo$ picgo -h
Usage: picgo [options] [command]

Options:
  -v, --version                        output the version number
  -d, --debug                          debug mode
  -s, --silent                         silent mode
  -c, --config <path>                  set config path
  -p, --proxy <url>                    set proxy for uploading
  -h, --help                           output usage information

Commands:
  install|add [options] <plugins...>   install picgo plugin
  uninstall|rm <plugins...>            uninstall picgo plugin
  update <plugins...>                  update picgo plugin
  set|config <module> [name]           configure config of picgo modules
  upload|u [input...]                  upload, go go go
  use [module]                         use modules of picgo
  init [options] <template> [project]  create picgo plugin's development templates

ggbang@DESKTOP-K2EEVD4:~/repo$ picgo init plugin picgo-plugin-test
[PicGo INFO]: Template files are downloading...
[PicGo SUCCESS]: Template files are downloaded!
? Plugin name: test
? Plugin description: test
? author: 
? Choose modules you want to develop: (Press <space> to select, <a> to toggle all, <i
> to invert selection)
? Your plugin is just used in CLI? No
? Use TS or JS? ts
? Your plugin has some shortcut for GUI? No
[PicGo SUCCESS]: 
Generate template files successfully!
Please cd /home/ggbang/repo/picgo-plugin-test, and then

npm install

# or

yarn
[PicGo SUCCESS]: Done!

ggbang@DESKTOP-K2EEVD4:~/repo$ cd /home/ggbang/repo/picgo-plugin-test

ggbang@DESKTOP-K2EEVD4:~/repo/picgo-plugin-test$ npm install

npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this

> ejs@2.7.4 postinstall /home/ggbang/repo/picgo-plugin-test/node_modules/ejs
> node ./postinstall.js

Thank you for installing EJS: built with the Jake JavaScript build tool (https://jakejs.com/)

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN picgo-plugin-test@1.0.0 No repository field.

added 541 packages from 357 contributors in 14.582s

19 packages are looking for funding
  run `npm fund` for details

接着我在src/index.ts中放入如下代码:

import picgo from 'picgo'

const handle = ctx => {
  let output = ctx.output
  for (let i in output) {
    output[i].imgUrl = 'https://xxxxx.jpg'
  }
  return ctx
}

export = (ctx: picgo) => {
  const register = () => {
    ctx.helper.uploader.register('test', { handle })
  }
  return {
    register,
    uploader: 'test'
  }
}

接着复制文件夹到配置文件所在目录并安装

ggbang@DESKTOP-K2EEVD4:~/repo$ cp -r picgo-plugin-test ~/.picgo/picgo-plugin-test

ggbang@DESKTOP-K2EEVD4:~/.picgo$ npm install ./picgo-plugin-test
npm notice created a lockfile as package-lock.json. You should commit this file.
+ picgo-plugin-test@1.0.0
added 1 package in 1.545s

19 packages are looking for funding
  run `npm fund` for details

但当我测试时,错误发生了:

ggbang@DESKTOP-K2EEVD4:~/.picgo$ picgo use
[PicGo ERROR]: { Error: Cannot find module '/home/ggbang/.picgo/node_modules/picgo-plugin-test'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at PluginLoader.getPlugin (/usr/local/lib/node_modules/picgo/dist/src/lib/PluginLoader.js:93:16)
    at PluginLoader.registerPlugin (/usr/local/lib/node_modules/picgo/dist/src/lib/PluginLoader.js:63:22)
    at PluginLoader.load (/usr/local/lib/node_modules/picgo/dist/src/lib/PluginLoader.js:54:18)
    at PicGo.init (/usr/local/lib/node_modules/picgo/dist/src/core/PicGo.js:73:31)
    at new PicGo (/usr/local/lib/node_modules/picgo/dist/src/core/PicGo.js:40:14)
    at Object.<anonymous> (/usr/local/lib/node_modules/picgo/bin/picgo:12:15) code: 'MODULE_NOT_FOUND' }
? Use an uploader (Use arrow keys)
❯ smms 
  tcyun 
  github 
  qiniu 
  imgur 
  aliyun 
  upyun

请问我是否搞错了哪一步,谢谢?

以下是~/.picgo下的文件 1

Molunerfinn commented 4 years ago

查看你插件的package.json里有一个main字段: https://github.com/PicGo/picgo-plugin-pic-migrater/blob/dev/package.json#L5

所以你需要在picgo-plugin-test下运行一下npm run build生成一下dist目录,有js才能运行,现在你只有ts文件自然是运行不了的

dhyz commented 4 years ago

Got it,thx!