11var request = require ( 'request' ) ,
22 fs = require ( 'fs' ) ,
3+ myHost = 'http://cssinliner.dev/' ,
34 myBody = null ,
4- myHost = null ,
5+ myPath = null ,
6+ myOutput = 'output' ,
57 myPrefix = '- ' ;
68
7- request ( 'http://cssinliner.dev/examples/example.php' ,
8- function ( err , response , body ) {
9- if ( err ) return console . log ( err ) ;
9+ process . argv . forEach (
10+ function ( val , index , array ) {
11+ if ( index == 2 ) myPath = val ;
12+ if ( index == 3 ) myOutput = val ;
13+ }
14+ ) ;
1015
11- myBody = body ;
12- console . log ( myPrefix + 'Its works' ) ;
13-
14- fs . writeFile ( 'my-result.html' , myBody ,
15- function ( err ) {
16- if ( err ) {
17- return console . log ( err ) ;
18- }
16+ if ( myPath != null ) {
17+ try {
18+ stats = fs . lstatSync ( myPath ) ;
19+ if ( stats . isDirectory ( ) ) {
20+
21+ request ( myHost + myPath + '/' + myPath + '.php' ,
22+ function ( err , response , body ) {
1923
20- console . log ( myPrefix + 'The file was saved!' ) ;
21- }
22- ) ;
23- }
24- ) ;
24+ if ( err ) console . log ( err ) ;
25+
26+ myBody = body ;
27+ console . log ( myPrefix + 'Its works' ) ;
28+
29+ fs . writeFile ( myPath + '/' + myOutput + '.html' , myBody ,
30+ function ( err ) {
31+ if ( err ) {
32+ return console . log ( err ) ;
33+ }
34+
35+ console . log ( myPrefix + 'The file was saved!' ) ;
36+ }
37+ ) ;
38+ }
39+ ) ;
40+
41+ }
42+ } catch ( e ) {
43+ console . log ( e ) ;
44+ }
45+ }
0 commit comments