capture-website-cli 项目教程

capture-website-cli 项目教程

capture-website-cliCapture screenshots of websites from the command-line项目地址:https://gitcode.com/gh_mirrors/ca/capture-website-cli

1. 项目的目录结构及介绍

capture-website-cli 是一个用于从命令行捕获网站屏幕截图的工具。以下是其基本的目录结构:

capture-website-cli/
├── bin/
│   └── capture-website
├── lib/
│   └── index.js
├── test/
│   └── test.js
├── .editorconfig
├── .gitattributes
├── .gitignore
├── .npmrc
├── .travis.yml
├── license
├── package.json
├── readme.md

目录结构介绍

  • bin/: 包含可执行文件 capture-website,这是命令行接口的入口点。
  • lib/: 包含主要的 JavaScript 文件 index.js,这是项目的核心逻辑所在。
  • test/: 包含测试文件 test.js,用于项目的单元测试。
  • .editorconfig, .gitattributes, .gitignore, .npmrc, .travis.yml: 这些是项目配置文件,用于不同的开发和部署环境。
  • license: 项目的许可证文件。
  • package.json: 项目的 npm 配置文件,包含依赖、脚本等信息。
  • readme.md: 项目的说明文档。

2. 项目的启动文件介绍

项目的启动文件位于 bin/ 目录下的 capture-website 文件。这是一个可执行的脚本文件,用于启动 capture-website-cli 工具。

#!/usr/bin/env node
'use strict';
const meow = require('meow');
const captureWebsite = require('capture-website');
const {promisify} = require('util');
const fs = require('fs');
const path = require('path');
const writeFile = promisify(fs.writeFile);

const cli = meow(`
	Usage
	  $ capture-website <url|file>

	Options
	  --output, -o  Image file path (writes it to stdout if omitted)
	  --width, -w  Page width [default: 1280]
	  --height, -h  Page height [default: 800]
	  --type, -t  Image type: png|jpeg|webp [default: png]
	  --quality, -q  Image quality: 0...1 (Only for JPEG and WebP) [default: 1]
	  --scale-factor, -s  Scale the webpage \`n\` times [default: 2]
	  --list-devices  Output a list of supported devices to emulate
	  --emulate-device  Capture as if it were captured on the given device
	  --full-page  Capture the full scrollable page not just the viewport
	  --no-default-background  Make the default background transparent
	  --timeout  Seconds before giving up trying to load the page Specify \`0\` to disable [default: 60]
	  --delay  Seconds to wait after the page finished loading before capturing the screenshot
`, {
	flags: {
		output: {
			type: 'string',
			alias: 'o'
		},
		width: {
			type: 'number',
			alias: 'w'
		},
		height: {
			type: 'number',
			alias: 'h'
		},
		type: {
			type: 'string',
			alias: 't'
		},
		quality: {
			type: 'number',
			alias: 'q'
		},
		scaleFactor: {
			type: 'number',
			alias: 's'
		},
		listDevices: {
			type: 'boolean'
		},
		emulateDevice: {
			type: 'string'
		},
		fullPage: {
			type: 'boolean'
		},
		noDefaultBackground: {
			type: 'boolean'
		},
		timeout: {
			type: 'number'
		},
		delay: {
			type: 'number'
		}
	}
});

(async () => {
	const {input, flags} = cli;

	if (flags.listDevices) {
		console.log(await captureWebsite.devices);
		return;
	}

	const result = await captureWebsite.file(input[0], flags);

	if (flags.output) {
		await writeFile(flags.

capture-website-cliCapture screenshots of websites from the command-line项目地址:https://gitcode.com/gh_mirrors/ca/capture-website-cli

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

柯玫艺Harriet

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值