Skip to content

Commit

Permalink
feat: now default save as json, now as xlsx
Browse files Browse the repository at this point in the history
  • Loading branch information
popstas committed Aug 22, 2020
1 parent 79aaa68 commit 803727b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function getConfigVal(name, def) {
let val = undefined;
if (config[name] === undefined) val = def;
else val = config[name];
console.log(`config: ${name}: `, val);
// console.log(`config: ${name}: `, val);
return val;
}

Expand All @@ -73,9 +73,9 @@ program
.option('--no-remove-csv', `No delete csv after xlsx generate`, !getConfigVal('removeCsv', true))
.option('--out-dir <dir>', `Output directory`, getConfigVal('outDir', '.'))
.option('--csv <path>', `Skip scan, only convert csv to xlsx`)
.option('--xlsx', `Save as XLSX`, getConfigVal('xlsx', true))
.option('--xlsx', `Save as XLSX`, getConfigVal('xlsx', false))
.option('--gdrive', `Publish sheet to google docs`, getConfigVal('gdrive', false))
.option('--json', `Output results in JSON`, getConfigVal('json', false))
.option('--no-json', `No save as JSON`, !getConfigVal('json', true))
.option('--upload', `Upload JSON to public web`, getConfigVal('upload', false))
.option('--no-color', `No console colors`)
.option('--lang <lang>', `Language (en, ru, default: system language)`, getConfigVal('lang', undefined))
Expand All @@ -88,7 +88,7 @@ program
.parse(process.argv);

async function start() {
if(!program.concurrency === undefined){
if(program.concurrency === undefined){
program.concurrency = getConfigVal('concurrency', os.cpus().length);
}

Expand Down Expand Up @@ -256,7 +256,7 @@ function outBrief(options) {
{
name: 'Save as JSON',
value: (options.json ? 'yes' : 'no'),
comment: (!options.json ? '--json' : '')
comment: (options.json ? '--no-json' : '')
},
{
name: 'Upload JSON',
Expand Down
23 changes: 16 additions & 7 deletions src/start-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,40 @@ const express = require('express')
module.exports = async (jsonPath, webPath=false) => {
const app = express();
const port = 3001;
app.use('/', express.static('./web'));

const jsonUrl = webPath || `http://localhost:${port}/data.json`;
const jsonRaw = fs.readFileSync(jsonPath);

app.get('/', function (req, res, next) {
res.redirect(302, onlineViewLink(jsonUrl));
});

app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
});
app.use('/data.json', (req, res) => {
res.setHeader('Content-Type', 'application/json');
res.send(fs.readFileSync(jsonPath));
// express.static('./web')
res.send(jsonRaw);
});

function onlineViewLink(url) {
return `https://viasite.github.io/site-audit-seo-viewer/?url=${url}`;
}
function outLinks(url) {
console.log(`JSON file: ${url}`);
console.log('');
console.log(`Dev viewer: http://localhost:3000/?url=${url}`);
console.log(`Online viewer: https://viasite.github.io/site-audit-seo-viewer/?url=${url}`);
console.log('\n');
console.log(`Online viewer: ${onlineViewLink(url)}`);
console.log('');
}

if (webPath) outLinks(webPath);
outLinks(jsonUrl);

if(!webPath) {
app.listen(port, () => {
outLinks(`http://localhost:${port}/data.json`);
console.log(`Started server at http://localhost:${port}, press Ctrl+C to exit`)
});
}
}

0 comments on commit 803727b

Please sign in to comment.