From f1cee2a5d0acd3d365544d674a0195ad689007f7 Mon Sep 17 00:00:00 2001 From: Stanislav Popov Date: Mon, 20 Jul 2020 12:11:22 +0500 Subject: [PATCH] feat: open file after scan on Windows and MacOS, --open-file --- README.md | 5 +++-- src/index.js | 11 ++++++++++- src/scrap-site.js | 2 ++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2918c09..65d791e 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ Options: --out-dir Output directory (default: ".") --csv Skip scan, only convert csv to xlsx --no-color No console colors + --open-file Open file after scan (default: yes on Windows and MacOS) --no-console-validate Don't output validate messages in console -V, --version output the version number -h, --help display help for command @@ -79,7 +80,7 @@ Options: - Title is right-aligned to reveal the common part - Validation of some columns (status, request time, description length) -### Fields list (20.04.2020): +### Fields list (20.07.2020): - url - mixed_content_url - canonical @@ -99,6 +100,7 @@ Options: - h2_count - h3_count - h4_count +- canonical_count - images - images_without_alt - images_alt_empty @@ -215,7 +217,6 @@ site-audit-seo -d 1 -u https://example -f '{ "title": "$(`title`).text()" }' ## TODO: - Unique links -- Scraper freezes when scrap doc in 2 threads - [Offline w3c validation](https://www.npmjs.com/package/html-validator) - [Words count](/~https://github.com/IonicaBizau/count-words) - [Sentences count](/~https://github.com/NaturalNode/natural) diff --git a/src/index.js b/src/index.js index 6a9995d..fa53648 100644 --- a/src/index.js +++ b/src/index.js @@ -5,6 +5,8 @@ const { program } = require('commander'); const packageJson = require('../package.json'); const scrapSite = require('./scrap-site'); const saveAsXlsx = require('./save-as-xlsx'); +const { exec } = require('child_process'); +const os = require('os'); const list = val => { return val ? val.split(',') : []; @@ -28,6 +30,7 @@ program .option('--out-dir ', `Output directory`, '.') .option('--csv ', `Skip scan, only convert csv to xlsx`) .option('--no-color', `No console colors`) + .option('--open-file', `Open file after scan (default: yes on Windows and MacOS)`) .option('--no-console-validate', `Don't output validate messages in console`) .name("site-audit-seo") .version(packageJson.version) @@ -35,12 +38,17 @@ program .parse(process.argv); async function start() { + if(program.openFile === undefined) { + program.openFile = ['darwin', 'win32'].includes(os.platform()); + } + if(program.csv) { const csvPath = program.csv const xlsxPath = csvPath.replace(/\.csv$/, '.xlsx'); try { saveAsXlsx(csvPath, xlsxPath); - console.log(`${xlsxPath} saved`) + console.log(`${xlsxPath} saved`); + if(program.openFile) exec(`"${xlsxPath}"`); } catch(e) { console.error(e) } @@ -79,6 +87,7 @@ async function start() { docsExtensions: program.docsExtensions, // расширения, которые будут добавлены в таблицу outDir: program.outDir, // папка, куда сохраняются csv color: program.color, // раскрашивать консоль + openFile: program.openFile, // открыть файл после сканирования fields: program.fields, // дополнительные поля removeCsv: program.removeCsv, // удалять csv после генерации xlsx consoleValidate: program.consoleValidate, // выводить данные валидации в консоль diff --git a/src/scrap-site.js b/src/scrap-site.js index d50445a..218ca0f 100644 --- a/src/scrap-site.js +++ b/src/scrap-site.js @@ -5,6 +5,7 @@ const HCCrawler = require('@popstas/headless-chrome-crawler'); const CSVExporter = require('@popstas/headless-chrome-crawler/exporter/csv'); const url = require('url'); const {validateResults, getValidationSum} = require('./validate'); +const { exec } = require('child_process'); const DEBUG = true; // выключить, если не нужны console.log на каждый запрос (не будет видно прогресс) @@ -357,6 +358,7 @@ module.exports = async (baseUrl, options = {}) => { console.log(`\n${color.yellow}Saved to ${xlsxPath}${color.reset}`); console.log(`Finish: ${t} sec (${perPage} per page)`); + if(options.openFile) exec(`"${xlsxPath}"`); }; let isSuccess = true;