ipfs-shipyard / ipfs-deploy

Zero-Config CLI to Deploy Static Websites to IPFS
Other
1.16k stars 122 forks source link

Log output now printed to stdout. #215

Closed kevincox closed 3 years ago

kevincox commented 3 years ago

Previously only the final CID was printed to stdout. This was really useful because you could simply redirect the CID to a file. However now all long output is printed to stdout. Since this log output is intended for humans not robots it is better suited for stderr.

Compare the difference:

% npx ipfs-deploy@8.0.1 d >/tmp/cid
βœ” 🚚  Directory d weighs 447.8 KiB.
βœ” πŸ“Œ  Added and pinned to Infura with hash:
β„Ή πŸ”—  QmNX4bXbY6UCnaNLS3YSjhXWJ8cg94ozhVz28aLiiZjYrs (​https://ipfs.infura.io/ipfs/QmNX4bXbY6UCnaNLS3YSjhXWJ8cg94ozhVz28aLiiZjYrs/​)
βœ– ⚠️  Could not copy URL to clipboard.

  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚                                                                                                                                     β”‚
  β”‚ Error: Couldn't find the `xsel` binary and fallback didn't work. On Debian/Ubuntu you can install xsel with: sudo apt install xsel  β”‚
  β”‚                                                                                                                                     β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
βœ” πŸ„  Opened URL on web browser (call with -O to disable):
β„Ή πŸ”—  https://ipfs.infura.io/ipfs/QmNX4bXbY6UCnaNLS3YSjhXWJ8cg94ozhVz28aLiiZjYrs/ (​https://ipfs.infura.io/ipfs/QmNX4bXbY6UCnaNLS3YSjhXWJ8cg94ozhVz28aLiiZjYrs/​)
% cat /tmp/cid
QmNX4bXbY6UCnaNLS3YSjhXWJ8cg94ozhVz28aLiiZjYrs
% npx ipfs-deploy@10.0.1 d >/tmp/cid
Error: Couldn't find the `xsel` binary and fallback didn't work. On Debian/Ubuntu you can install xsel with: sudo apt install xsel
    at makeError (/home/kevincox/.npm/_npx/6535/lib/node_modules/ipfs-deploy/node_modules/clipboardy/lib/linux.js:14:11)
    at xselWithFallbackSync (/home/kevincox/.npm/_npx/6535/lib/node_modules/ipfs-deploy/node_modules/clipboardy/lib/linux.js:43:10)
    at Object.copySync (/home/kevincox/.npm/_npx/6535/lib/node_modules/ipfs-deploy/node_modules/clipboardy/lib/linux.js:53:3)
    at Object.exports.writeSync (/home/kevincox/.npm/_npx/6535/lib/node_modules/ipfs-deploy/node_modules/clipboardy/index.js:45:14)
    at copyToClipboard (/home/kevincox/.npm/_npx/6535/lib/node_modules/ipfs-deploy/src/deploy.js:104:16)
    at deploy (/home/kevincox/.npm/_npx/6535/lib/node_modules/ipfs-deploy/src/deploy.js:254:5)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async main (/home/kevincox/.npm/_npx/6535/lib/node_modules/ipfs-deploy/src/cli.js:174:17) {
  fallbackError: Error: spawnSync /home/kevincox/.npm/_npx/6535/lib/node_modules/ipfs-deploy/node_modules/clipboardy/fallbacks/linux/xsel ENOENT
      at Object.spawnSync (internal/child_process.js:1074:20)
      at Object.spawnSync (child_process.js:626:24)
      at Function.module.exports.sync (/home/kevincox/.npm/_npx/6535/lib/node_modules/ipfs-deploy/node_modules/execa/index.js:334:30)
      at xselWithFallbackSync (/home/kevincox/.npm/_npx/6535/lib/node_modules/ipfs-deploy/node_modules/clipboardy/lib/linux.js:41:17)
      at Object.copySync (/home/kevincox/.npm/_npx/6535/lib/node_modules/ipfs-deploy/node_modules/clipboardy/lib/linux.js:53:3)
      at Object.exports.writeSync (/home/kevincox/.npm/_npx/6535/lib/node_modules/ipfs-deploy/node_modules/clipboardy/index.js:45:14)
      at copyToClipboard (/home/kevincox/.npm/_npx/6535/lib/node_modules/ipfs-deploy/src/deploy.js:104:16)
      at deploy (/home/kevincox/.npm/_npx/6535/lib/node_modules/ipfs-deploy/src/deploy.js:254:5)
      at processTicksAndRejections (internal/process/task_queues.js:95:5)
      at async main (/home/kevincox/.npm/_npx/6535/lib/node_modules/ipfs-deploy/src/cli.js:174:17) {
    errno: -2,
    code: 'ENOENT',
    syscall: 'spawnSync /home/kevincox/.npm/_npx/6535/lib/node_modules/ipfs-deploy/node_modules/clipboardy/fallbacks/linux/xsel',
    path: '/home/kevincox/.npm/_npx/6535/lib/node_modules/ipfs-deploy/node_modules/clipboardy/fallbacks/linux/xsel',
    spawnargs: [ '--clipboard', '--input' ],
    stdout: null,
    stderr: null,
    failed: true,
    signal: null,
    cmd: '/home/kevincox/.npm/_npx/6535/lib/node_modules/ipfs-deploy/node_modules/clipboardy/fallbacks/linux/xsel --clipboard --input',
    timedOut: false
  }
}
% cat /tmp/cid
πŸ“‚  Deploying d directory.
πŸ“¦  Calculating size of d…
🚚  Directory d weighs 447.8 KiB.
βš™οΈ   Validating pinners configurations…
βš™οΈ   Validating DNS providers configurations…
πŸ“   Uploading and pinning to Infura…
πŸ“Œ  Added and pinned to Infura with CID:
πŸ”—  QmNX4bXbY6UCnaNLS3YSjhXWJ8cg94ozhVz28aLiiZjYrs (​https://ipfs.infura.io/ipfs/QmNX4bXbY6UCnaNLS3YSjhXWJ8cg94ozhVz28aLiiZjYrs​)
πŸ“‹  Copying HTTP gateway URL to clipboard…
⚠️  Could not copy URL to clipboard.

QmNX4bXbY6UCnaNLS3YSjhXWJ8cg94ozhVz28aLiiZjYrs
kevincox commented 3 years ago

Side note: A workaround is using -q to disable the logs, however it is a shame to lose the logs.

hacdias commented 3 years ago

Hmm, indeed. I really didn't know we should write logs and messages to stderr and thought stdout should be the default. I searched the Internet and it seems there's mixed opinions regarding that. Is there any particular reason why informative logs should be on the stderr? I guess if we consider them debugging, yes.

I can make a PR for this soon.

kevincox commented 3 years ago

Yes, that is what stderr is for. It is for human readable output.

For example when you install packages and smilar npx writes the logs to stderr so that something like npx sometool >result will properly store the output of tool, the the logs and errors of npx itself. Many tools work like this for example nix-build will write the logs to stderr and the result path to stdout. That is why there are two output streams. There is one for the output of the program (which in this case appear to just be the hash) and another stream for helpful messages such as logs and errors.

Basically stdout is for robots (and humans too) and stderr is for humans.

hacdias commented 3 years ago

Here's a PR: https://github.com/ipfs-shipyard/ipfs-deploy/pull/216

Thanks for explaining this!