Skip to content

Commit

Permalink
feat: open file after scan on Windows and MacOS, --open-file
Browse files Browse the repository at this point in the history
  • Loading branch information
popstas committed Jul 20, 2020
1 parent 0276288 commit f1cee2a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Options:
--out-dir <dir> Output directory (default: ".")
--csv <path> 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
Expand All @@ -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
Expand All @@ -99,6 +100,7 @@ Options:
- h2_count
- h3_count
- h4_count
- canonical_count
- images
- images_without_alt
- images_alt_empty
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(',') : [];
Expand All @@ -28,19 +30,25 @@ program
.option('--out-dir <dir>', `Output directory`, '.')
.option('--csv <path>', `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)
.usage("-u https://example.com")
.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)
}
Expand Down Expand Up @@ -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, // выводить данные валидации в консоль
Expand Down
2 changes: 2 additions & 0 deletions src/scrap-site.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 на каждый запрос (не будет видно прогресс)

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f1cee2a

Please sign in to comment.