'use strict' ; import * as parseGlob from 'parse-glob' ; import * as globToRegExp from 'glob-to-regexp' ; import { Uri } from 'vscode' ; import { IConfig } from '../spgo' ; import { UrlHelper } from '../util/urlHelper' ; import { FileHelper } from '../util/fileHelper' ; import { ISPPullOptions } from 'sppull' ; export class DownloadFileOptionsFactory { public glob : any ; constructor ( path ) { this . glob = parseGlob ( path ) ; } public createFileOptions ( siteUrl , config ) { let dlRootFolder = FileHelper . ensureCorrectPathSeparator ( config . sourceRoot + siteUrl . toString ( ) . replace ( config . sharePointSiteUrl , '' ) ) ; let options = { spBaseFolder : UrlHelper . ensureLeadingWebSlash ( siteUrl . path ) , dlRootFolder : dlRootFolder } ; let globPattern = options . spBaseFolder === '/' ? this . glob . orig : options . spBaseFolder + this . glob . orig ; if ( this . glob . is . glob ) { options . spRootFolder = this . glob . base . replace ( '/**/' , '/' ) ; options . fileRegExp = globToRegExp ( globPattern , { flags : 'i' , globstar : this . glob . is . globstar , extended : this . glob . orig . indexOf ( '|' ) >= 0 } ) ; } else { options . spRootFolder = UrlHelper . formatWebFolder ( this . glob . orig ) ; } options . recursive = this . glob . is . globstar ; options . createEmptyFolders = false ; return options ; } }