import path = require ( 'path' ) ; import fs = require ( 'fs-promise' ) ; import Promise = require ( 'bluebird' ) ; import * as vscode from 'vscode' ; export interface resourceBundle { name : string ; path : string ; } export function promiseList ( ) { let resourceBundlesPath = buildResourceBundlesPath ( ) ; let listResourceBundlesInWorkspace = fs . readdir ( resourceBundlesPath ) . then ( resourceBundlesFromFileList , console . error ) ; return listResourceBundlesInWorkspace ; } function buildResourceBundlesPath ( ) { let workspaceRoot = vscode . workspace . rootPath ; let resourceBundlesPath = path . join ( workspaceRoot , 'resource-bundles' ) ; return resourceBundlesPath ; } function resourceBundlesFromFileList ( fileList ) { let resourceBundles = [ ] ; for ( let fileName of fileList ) { if ( isResourceBundle ( fileName ) ) { resourceBundles . push ( getResourceBundleFrom ( fileName ) ) ; } } return Promise . all ( resourceBundles ) ; } function isResourceBundle ( fileName ) { return ! fileName . startsWith ( '.' ) ; } function getResourceBundleFrom ( fileName ) { let resourceBundlesPath = buildResourceBundlesPath ( ) ; let resourceBundlePath = path . join ( resourceBundlesPath , fileName ) ; let resourceBundleInfo = { name : fileName , path : resourceBundlePath } ; return Promise . resolve ( resourceBundleInfo ) ; }