2020 */
2121
2222import JSZip from 'jszip' ;
23+ import * as semver from 'semver' ;
2324
2425import * as commonStorage from './common_storage' ;
2526import * as storageModule from './module' ;
@@ -35,6 +36,7 @@ export type Project = {
3536 opModes : storageModule . OpMode [ ] ,
3637} ;
3738
39+ const NO_VERSION = '0.0.0' ;
3840const CURRENT_VERSION = '0.0.1' ;
3941
4042type ProjectInfo = {
@@ -60,6 +62,8 @@ export async function listProjectNames(storage: commonStorage.Storage): Promise<
6062 */
6163export async function fetchProject (
6264 storage : commonStorage . Storage , projectName : string ) : Promise < Project > {
65+ await updateProjectIfNecessary ( storage , projectName ) ;
66+
6367 const modulePaths : string [ ] = await storage . listFilePaths (
6468 storageNames . makeModulePathRegexPattern ( projectName ) ) ;
6569
@@ -540,3 +544,34 @@ async function deleteProjectInfo(
540544 const projectInfoPath = storageNames . makeProjectInfoPath ( projectName ) ;
541545 await storage . deleteFile ( projectInfoPath ) ;
542546}
547+
548+ async function fetchProjectInfo (
549+ storage : commonStorage . Storage , projectName : string ) : Promise < ProjectInfo > {
550+ const projectInfoPath = storageNames . makeProjectInfoPath ( projectName ) ;
551+ let projectInfo : ProjectInfo ;
552+ try {
553+ const projectInfoContentText = await storage . fetchFileContentText ( projectInfoPath ) ;
554+ projectInfo = parseProjectInfoContentText ( projectInfoContentText ) ;
555+ } catch ( error ) {
556+ // The file doesn't exist.
557+ projectInfo = {
558+ version : NO_VERSION ,
559+ } ;
560+ }
561+ return projectInfo ;
562+ }
563+
564+ async function updateProjectIfNecessary (
565+ storage : commonStorage . Storage , projectName : string ) : Promise < void > {
566+ const projectInfo = await fetchProjectInfo ( storage , projectName ) ;
567+ if ( semver . lt ( projectInfo . version , CURRENT_VERSION ) ) {
568+ switch ( projectInfo . version ) {
569+ case '0.0.0' :
570+ // Project was saved without a project.info.json file.
571+ // Nothing needs to be done to update to '0.0.1';
572+ projectInfo . version = '0.0.1' ;
573+ break ;
574+ }
575+ await saveProjectInfo ( storage , projectName ) ;
576+ }
577+ }
0 commit comments