11import path from 'path'
22import fsp from 'fs/promises'
33import * as cheerio from 'cheerio'
4- import * as prettier from 'prettier'
54import debug from 'debug'
65import getData from './getData.js'
76import downloadFiles from './downloadFiles.js'
@@ -15,9 +14,9 @@ const downloadPage = (url, outputDir = process.cwd()) => {
1514 log ( 'download page %s to %s' , url , outputDir )
1615
1716 const absOutputDir = getAbsolutePath ( outputDir )
18- const fileName = generateName ( url ) + '.html'
17+ const fileName = generateName ( url )
1918 const filePath = path . join ( absOutputDir , fileName )
20- const filesDirName = generateName ( url ) + '_files'
19+ const filesDirName = generateName ( url ) . replace ( '.html' , '_files' )
2120 const filesDirPath = path . join ( absOutputDir , filesDirName )
2221
2322 return fsp . access ( absOutputDir )
@@ -37,12 +36,8 @@ const downloadPage = (url, outputDir = process.cwd()) => {
3736 . then ( ( ) => $ )
3837 } )
3938 . then ( ( $ ) => {
40- log ( 'files downloaded, format HTML' )
41- return prettier . format ( $ . html ( ) , { parser : 'html' } )
42- } )
43- . then ( ( formattedHtml ) => {
4439 log ( 'write to file %s' , filePath )
45- return fsp . writeFile ( filePath , formattedHtml )
40+ return fsp . writeFile ( filePath , $ . html ( ) )
4641 } )
4742 . then ( ( ) => {
4843 log ( 'done, output file is %s' , filePath )
@@ -56,6 +51,9 @@ const downloadPage = (url, outputDir = process.cwd()) => {
5651 if ( err . code === 'EACCES' ) {
5752 throw new Error ( `ERROR: No access to output directory - ${ outputDir } ` )
5853 }
54+ if ( err . message . startsWith ( 'Cant get ' ) ) {
55+ throw err
56+ }
5957 throw new Error ( `ERROR: ${ err . message } ` )
6058 } )
6159}
0 commit comments