July 2017
Intermediate to advanced
300 pages
5h 43m
English
Other modules, such as FileListView, DirListView, and TitleBarPath, consume the data from the filesystem, such as directory list, file list, and the current path. So we need to create a service that will provide this data:
./js/Service/Dir.js
const fs = require( "fs" ), { join, parse } = require( "path" ); class DirService { constructor( dir = null ){ this.dir = dir || process.cwd(); } static readDir( dir ) { const fInfoArr = fs.readdirSync( dir, "utf-8" ).map(( fileName ) => { const filePath = join( dir, fileName ), stats = DirService.getStats( filePath ); if ( stats === false ) { return false; } return { fileName, stats }; }); return fInfoArr.filter( item => item !== ...Read now
Unlock full access