Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 4 additions & 20 deletions src/storage/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
*/

import JSZip from 'jszip';
import * as semver from 'semver';

import * as commonStorage from './common_storage';
import * as storageModule from './module';
import * as storageModuleContent from './module_content';
import * as storageNames from './names';
import { upgradeProjectIfNecessary } from './upgrade_project';

// Types, constants, and functions related to projects, regardless of where the projects are stored.

Expand All @@ -37,7 +37,7 @@ export type Project = {
};

const NO_VERSION = '0.0.0';
const CURRENT_VERSION = '0.0.1';
export const CURRENT_VERSION = '0.0.1';

type ProjectInfo = {
version: string,
Expand All @@ -62,7 +62,7 @@ export async function listProjectNames(storage: commonStorage.Storage): Promise<
*/
export async function fetchProject(
storage: commonStorage.Storage, projectName: string): Promise<Project> {
await updateProjectIfNecessary(storage, projectName);
await upgradeProjectIfNecessary(storage, projectName);

const modulePaths: string[] = await storage.listFilePaths(
storageNames.makeModulePathRegexPattern(projectName));
Expand Down Expand Up @@ -545,7 +545,7 @@ async function deleteProjectInfo(
await storage.deleteFile(projectInfoPath);
}

async function fetchProjectInfo(
export async function fetchProjectInfo(
storage: commonStorage.Storage, projectName: string): Promise<ProjectInfo> {
const projectInfoPath = storageNames.makeProjectInfoPath(projectName);
let projectInfo: ProjectInfo;
Expand All @@ -560,19 +560,3 @@ async function fetchProjectInfo(
}
return projectInfo;
}

// TODO(lizlooney): Move updateProjectIfNecessary to it's own file.
async function updateProjectIfNecessary(
storage: commonStorage.Storage, projectName: string): Promise<void> {
const projectInfo = await fetchProjectInfo(storage, projectName);
if (semver.lt(projectInfo.version, CURRENT_VERSION)) {
switch (projectInfo.version) {
case '0.0.0':
// Project was saved without a project.info.json file.
// Nothing needs to be done to update to '0.0.1';
projectInfo.version = '0.0.1';
break;
}
await saveProjectInfo(storage, projectName);
}
}
41 changes: 41 additions & 0 deletions src/storage/upgrade_project.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @license
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @author [email protected] (Liz Looney)
*/

import * as semver from 'semver';

import * as commonStorage from './common_storage';
import * as storageProject from './project';


export async function upgradeProjectIfNecessary(
storage: commonStorage.Storage, projectName: string): Promise<void> {
const projectInfo = await storageProject.fetchProjectInfo(storage, projectName);
if (semver.lt(projectInfo.version, storageProject.CURRENT_VERSION)) {
switch (projectInfo.version) {
case '0.0.0':
// Project was saved without a project.info.json file.
// Nothing needs to be done to upgrade to '0.0.1';
projectInfo.version = '0.0.1';
break;
}
await storageProject.saveProjectInfo(storage, projectName);
}
}