Skip to content

Commit 68caa46

Browse files
authored
Add export from zip support' (#10051)
* Add export from zip support' * Emojis are fun * More minor fixes
1 parent 63808e3 commit 68caa46

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/commands/studio-export.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,45 @@ import { migrate, MigrateOptions } from "../firebase_studio/migrate";
55
import * as path from "path";
66
import * as experiments from "../experiments";
77
import { FirebaseError } from "../error";
8+
import { unzip } from "../unzip";
9+
import * as fs from "fs";
810

911
export const command = new Command("studio:export <path>")
1012
.description(
11-
"Bootstrap Firebase Studio apps for migration to Antigravity. Run on the unzipped folder from the Firebase Studio download.",
13+
"Bootstrap Firebase Studio apps for migration to Antigravity. Run on the unzipped folder from the Firebase Studio download, or directly on the downloaded zip file.",
1214
)
1315
.option("--no-start-agy", "skip starting the Antigravity IDE after migration")
1416
.action(async (exportPath: string, options: Options) => {
1517
experiments.assertEnabled("studioexport", "export Studio apps");
1618
if (!exportPath) {
1719
throw new FirebaseError("Must specify a path for migration.", { exit: 1 });
1820
}
19-
const rootPath = path.resolve(exportPath);
20-
logger.info(`Exporting Studio apps from ${rootPath} to Antigravity...`);
21+
22+
let rootPath = path.resolve(exportPath);
23+
24+
if (fs.existsSync(rootPath) && fs.statSync(rootPath).isFile() && rootPath.endsWith(".zip")) {
25+
logger.info(`⏳ Unzipping ${rootPath}...`);
26+
const parsedPath = path.parse(rootPath);
27+
let extractDirName = parsedPath.name;
28+
if (!extractDirName || extractDirName === ".") {
29+
extractDirName = "studio-export";
30+
}
31+
const extractPath = path.join(parsedPath.dir, extractDirName);
32+
await unzip(rootPath, extractPath);
33+
34+
// Studio exports usually contain a single top-level directory.
35+
// E.g., `Export-12345/`. Let's check if we should dive into it
36+
const extractedItems = fs.readdirSync(extractPath);
37+
if (
38+
extractedItems.length === 1 &&
39+
fs.statSync(path.join(extractPath, extractedItems[0])).isDirectory()
40+
) {
41+
rootPath = path.join(extractPath, extractedItems[0]);
42+
} else {
43+
rootPath = extractPath;
44+
}
45+
}
46+
47+
logger.info(`⏳ Exporting Studio apps from ${rootPath} to Antigravity...`);
2148
await migrate(rootPath, options as MigrateOptions);
2249
});

src/firebase_studio/migrate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ export async function extractMetadata(
136136
logger.info(`✅ Detected Firebase Project: ${projectId}`);
137137
} else {
138138
// TODO need a mitigation here
139-
logger.info(`✅ Failed to determine the Firebase Project ID`);
139+
logger.info(
140+
`❌ Failed to determine the Firebase Project ID. You can set a project later with 'firebase use <project-id>' or by setting the '--project' flag.`,
141+
);
140142
}
141143

142144
// Extract App Name and Blueprint Content

0 commit comments

Comments
 (0)