[Startup Engineering] HW3+Part 3: Write SSJS headless grader

I was refer to here.

But it printed result twice.

[sourcecode language="bash"]

ubuntu@ip-172-31-5-125:~/bitstarter$ ./grader.js --checks checks.json --url http://fathomless-tor-9565.herokuapp.com/
require.main else :
{
".about": true,
".blank": true,
".faq": true,
".footer": true,
".heading": true,
".logo": true,
".navigation": true,
".order": true,
".pitch": true,
".section1": true,
".section2": true,
".social": true,
".subheading": true,
".thermometer": true,
".video": true,
"h1": true
}
require.main else :
{
".about": true,
".blank": true,
".faq": true,
".footer": true,
".heading": true,
".logo": true,
".navigation": true,
".order": true,
".pitch": true,
".section1": true,
".section2": true,
".social": true,
".subheading": true,
".thermometer": true,
".video": true,
"h1": true
}

[/sourcecode]

so, I modified below.

[sourcecode language="javascript"]

if(require.main == module) {
program
.option('-c, --checks <check_file>', 'Path to checks.json', clone(assertFileExists), CHECKSFILE_DEFAULT)
.option('-f, --file <html_file>', 'Path to index.html', clone(assertFileExists), HTMLFILE_DEFAULT)
.option('-u, --url <url>', 'path to herokuapp url', clone(assertURLExists))
// .option('-u, --url <url>', 'path to herokuapp url', clone(assertURLExists), CHECKSURL_DEFAULT)
.parse(process.argv);

if(!program.url){ //original logic. file existing - index.html
var checkJson = checkHtmlFile(program.file, program.checks);
var outJson = JSON.stringify(checkJson, null, 4);
console.log("required.main if : n" + outJson);
} else { // added
// rest.get(program.url).on('complete', function(result){
var checkJson = checkURL(program.url, program.checks);
var outJson = JSON.stringify(checkJson, null, 4);
console.log("require.main else : n" + outJson);
};

} else {
exports.checkHtmlFile = checkHtmlFile;
}

[/sourcecode]

RESULT :

[sourcecode language="bash"]

ubuntu@ip-172-31-5-125:~/bitstarter$ ./grader.js --checks checks.json --url http://fathomless-tor-9565.herokuapp.com/
require.main else :
{
".about": false,
".blank": false,
".faq": false,
".footer": false,
".heading": false,
".logo": false,
".navigation": false,
".order": false,
".pitch": false,
".section1": false,
".section2": false,
".social": false,
".subheading": false,
".thermometer": false,
".video": false,
"h1": false
}
ubuntu@ip-172-31-5-125:~/bitstarter$
[/sourcecode]

적게 일하고 많이 버는 법을 늘 고민합니다. 일이 되게 하는 것에 간혹 목숨을 겁니다. 지금은 우아한형제들과 함께 일하고 있어요.