import path = require ( 'path' ) ; import fs = require ( 'fs-promise' ) ; import Promise = require ( 'bluebird' ) ; import * as vscode from 'vscode' ; export interface staticResource { name : string ; path : string ; } export function promiseList ( ) { let staticResourcesPath = buildStaticResourcesPath ( ) ; let listStaticResourcesInWorkspace = fs . readdir ( staticResourcesPath ) . then ( staticResourcesFromFileList , console . error ) ; return listStaticResourcesInWorkspace ; } function buildStaticResourcesPath ( ) { let workspaceRoot = vscode . workspace . rootPath ; let staticResourcesPath = path . join ( workspaceRoot , 'src' , 'staticresources' ) ; return staticResourcesPath ; } function staticResourcesFromFileList ( fileList ) { let staticResources = [ ] ; for ( let fileName of fileList ) { if ( isStaticResource ( fileName ) ) { staticResources . push ( getStaticResourceFrom ( fileName ) ) ; } } return Promise . all ( staticResources ) ; } function isStaticResource ( fileName ) { return ! ( fileName . startsWith ( '.' ) || fileName . includes ( '-meta.xml' ) ) ; } function getStaticResourceFrom ( fileName ) { let staticResourcesPath = buildStaticResourcesPath ( ) ; let staticResourcePath = path . join ( staticResourcesPath , fileName ) ; let staticResourceInfo = { name : fileName , path : staticResourcePath } ; return Promise . resolve ( staticResourceInfo ) ; }