@@ -160,9 +160,8 @@ export async function copyProject(
160160async function renameOrCopyProject (
161161 storage : commonStorage . Storage , project : Project , newProjectName : string ,
162162 rename : boolean ) : Promise < void > {
163- const modulePathPrefix = storageNames . makeModulePathPrefix ( project . projectName ) ;
164163 const pathToModuleContent = await storage . listModules (
165- ( modulePath : string ) => modulePath . startsWith ( modulePathPrefix ) ) ;
164+ storageNames . makeModulePathRegexPattern ( project . projectName ) ) ;
166165
167166 for ( const modulePath in pathToModuleContent ) {
168167 const className = storageNames . getClassName ( modulePath ) ;
@@ -183,9 +182,9 @@ async function renameOrCopyProject(
183182 */
184183export async function deleteProject (
185184 storage : commonStorage . Storage , project : Project ) : Promise < void > {
186- const modulePathPrefix = storageNames . makeModulePathPrefix ( project . projectName ) ;
187185 const pathToModuleContent = await storage . listModules (
188- ( modulePath : string ) => modulePath . startsWith ( modulePathPrefix ) ) ;
186+ storageNames . makeModulePathRegexPattern ( project . projectName ) ) ;
187+
189188 for ( const modulePath in pathToModuleContent ) {
190189 await storage . deleteModule ( modulePath ) ;
191190 }
@@ -287,14 +286,8 @@ export async function copyModuleInProject(
287286async function renameOrCopyModule (
288287 storage : commonStorage . Storage , project : Project , newClassName : string ,
289288 oldModule : storageModule . Module , rename : boolean ) : Promise < string > {
290- const pathToModuleContent = await storage . listModules (
291- ( modulePath : string ) => modulePath === oldModule . modulePath ) ;
292- if ( ! ( oldModule . modulePath in pathToModuleContent ) ) {
293- throw new Error ( 'Failed to find module with path ' + oldModule . modulePath ) ;
294- }
295-
296289 const newModulePath = storageNames . makeModulePath ( project . projectName , newClassName ) ;
297- const moduleContentText = pathToModuleContent [ oldModule . modulePath ] . getModuleContentText ( ) ;
290+ const moduleContentText = await storage . fetchModuleContentText ( oldModule . modulePath ) ;
298291 await storage . saveModule ( newModulePath , moduleContentText ) ;
299292 if ( rename ) {
300293 // For rename, delete the old module.
@@ -404,10 +397,9 @@ export function findModuleByModulePath(project: Project, modulePath: string): st
404397 * Produce the blob for downloading a project.
405398 */
406399export async function downloadProject (
407- storage : commonStorage . Storage , projectName : string ) : Promise < string > {
408- const modulePathPrefix = storageNames . makeModulePathPrefix ( projectName ) ;
400+ storage : commonStorage . Storage , project : Project ) : Promise < string > {
409401 const pathToModuleContent = await storage . listModules (
410- ( modulePath : string ) => modulePath . startsWith ( modulePathPrefix ) ) ;
402+ storageNames . makeModulePathRegexPattern ( project . projectName ) ) ;
411403
412404 const classNameToModuleContentText : { [ className : string ] : string } = { } ; // value is module content text
413405 for ( const modulePath in pathToModuleContent ) {
0 commit comments