Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const fs = require('fs');
const glob = require('glob');

let files;
let confirmall = false;

const app = express()
app.use(cors());
Expand All @@ -20,23 +21,31 @@ app.get('/', (req, res) => {
app.post('/save', (req, res) => {
const changes = req.body;

// Prompt to confirm.
console.log([
`\nA-Frame Inspector from ${req.hostname} has requested the following changes:\n`,
`${prettyPrintChanges(changes)}`,
'Do you allow the A-Frame Inspector Watcher to write these updates directly ' +
'within this directory?'
].join('\n'));

const prompt = new Confirm('Y/n');
prompt.run().then(answer => {
// Denied.
if (!answer) { res.sendStatus(403); }

// Accepted.
sync(changes);
res.sendStatus(200);
});
if (confirmall) {
sync(changes);
console.log('The following changes have been made:');
console.log(`${prettyPrintChanges(changes)}`);
res.sendStatus(200);
} else {

// Prompt to confirm.
console.log([
`\nA-Frame Inspector from ${req.hostname} has requested the following changes:\n`,
`${prettyPrintChanges(changes)}`,
'Do you allow the A-Frame Inspector Watcher to write these updates directly ' +
'within this directory?'
].join('\n'));

const prompt = new Confirm('Y/n');
prompt.run().then(answer => {
// Denied.
if (!answer) { res.sendStatus(403); }

// Accepted.
sync(changes);
res.sendStatus(200);
});
}
});

function prettyPrintChanges (changes) {
Expand Down Expand Up @@ -177,6 +186,12 @@ function getWorkingFiles () {
process.argv.forEach(function (val, index, array) {
if (index < 2) { return; }

if (val === '-confirmall') {
console.log('-confirmall flag added; user will NOT be prompted on file saves from AFrame Inspector.');
confirmall = true;
return;
}

if (fs.lstatSync(val).isDirectory()) {
if (!val.endsWith('/')) { val += '/'; }
val += '**/*.html';
Expand Down