Skip to content

Commit

Permalink
Merge branch 'master' into migrate-tslint-to-eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
shisama committed Aug 7, 2020
2 parents 0e108c3 + d514c45 commit 6b8496d
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 37 deletions.
10 changes: 1 addition & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
- Fixes issue where `Authorization` header was missing from callable functions in the emulator (#2459).
- Improve support for the Node.js 12 (Beta) runtime in the Functions emulator.
- Allow specifying the config (`firebase.json`) file using the `--config`/`-c` flag.
- Fixes issue where `emulators:exec` could fail to shut down cleanly (#2477).
- Fixes issue where database emulator did not properly load initial rules (#2483).
- Allow starting the UI with `emulators:exec` using the `--ui` flag.
- Fixes issue where multiple CLI instances compete for the same log (#2464).
- Fixes issue where emulators run from `npm` scripts could not be shut down cleanly (#2507).
- Replace `eslint` with `tslint` as the default linter in new Cloud Functions for Firebase directories. (#1663)
- Replace `eslint` with `tslint` as the default linter in new Cloud Functions for Firebase directories. (#1663)
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firebase-tools",
"version": "8.6.0",
"version": "8.7.0",
"description": "Command-Line Interface for Firebase",
"main": "./lib/index.js",
"bin": {
Expand Down
5 changes: 5 additions & 0 deletions src/deploy/hosting/convertConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,10 @@ module.exports = function(config) {
out.appAssociation = config.appAssociation;
}

// i18n config
if (_.has(config, "i18n")) {
out.i18n = config.i18n;
}

return out;
};
18 changes: 18 additions & 0 deletions src/deploy/hosting/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

const _ = require("lodash");
const clc = require("cli-color");
const path = require("path");

const api = require("../../api");
const convertConfig = require("./convertConfig");
const deploymentTool = require("../../deploymentTool");
const { FirebaseError } = require("../../error");
const utils = require("../../utils");
const fsutils = require("../../fsutils");
const { normalizedHostingConfigs } = require("../../hosting/normalizedHostingConfigs");
const { resolveProjectPath } = require("../../projectPath");
Expand Down Expand Up @@ -67,6 +69,22 @@ module.exports = function(context, options) {
);
}

if (cfg.i18n) {
if (!cfg.i18n.root) {
throw new FirebaseError("The root in the i18n config can't be empty.");
} else {
const i18nPath = path.join(cfg.public, cfg.i18n.root);
if (!fsutils.dirExistsSync(resolveProjectPath(options, i18nPath))) {
utils.logLabeledWarning(
"hosting",
`Couldn't find specified i18n root directory ${clc.bold(
cfg.i18n.root
)} in public directory ${clc.bold(cfg.public)}.`
);
}
}
}

versionCreates.push(
api
.request("POST", "/v1beta1/sites/" + deploy.site + "/versions", {
Expand Down
79 changes: 63 additions & 16 deletions src/emulator/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,62 @@ export function shouldStart(options: any, name: Emulators): boolean {
return emulatorInTargets;
}

function findExportMetadata(importPath: string): ExportMetadata | undefined {
const pathIsDirectory = fs.lstatSync(importPath).isDirectory();
if (!pathIsDirectory) {
return;
}

// If there is an export metadata file, we always prefer that
const importFilePath = path.join(importPath, HubExport.METADATA_FILE_NAME);
if (fileExistsSync(importFilePath)) {
return JSON.parse(fs.readFileSync(importFilePath, "utf8").toString()) as ExportMetadata;
}

const fileList = fs.readdirSync(importPath);

// The user might have passed a Firestore export directly
const firestoreMetadataFile = fileList.find((f) => f.endsWith(".overall_export_metadata"));
if (firestoreMetadataFile) {
const metadata: ExportMetadata = {
version: EmulatorHub.CLI_VERSION,
firestore: {
version: "prod",
path: importPath,
metadata_file: `${importPath}/${firestoreMetadataFile}`,
},
};

EmulatorLogger.forEmulator(Emulators.FIRESTORE).logLabeled(
"BULLET",
"firestore",
`Detected non-emulator Firestore export at ${importPath}`
);

return metadata;
}

// The user might haved passed a directory containing RTDB json files
const rtdbDataFile = fileList.find((f) => f.endsWith(".json"));
if (rtdbDataFile) {
const metadata: ExportMetadata = {
version: EmulatorHub.CLI_VERSION,
database: {
version: "prod",
path: importPath,
},
};

EmulatorLogger.forEmulator(Emulators.DATABASE).logLabeled(
"BULLET",
"firestore",
`Detected non-emulator Database export at ${importPath}`
);

return metadata;
}
}

export async function startAll(options: any, noUi: boolean = false): Promise<void> {
// Emulators config is specified in firebase.json as:
// "emulators": {
Expand Down Expand Up @@ -285,24 +341,15 @@ export async function startAll(options: any, noUi: boolean = false): Promise<voi
version: "unknown",
};
if (options.import) {
const importFilePath = path.join(path.resolve(options.import), HubExport.METADATA_FILE_NAME);
if (fileExistsSync(importFilePath)) {
exportMetadata = JSON.parse(
fs
.readFileSync(
path.join(path.resolve(options.import), HubExport.METADATA_FILE_NAME),
"utf8"
)
.toString()
) as ExportMetadata;
const importDir = path.resolve(options.import);
const foundMetadata = await findExportMetadata(importDir);
if (foundMetadata) {
exportMetadata = foundMetadata;
} else {
// could happen when an export was interrupted mid-export...
EmulatorLogger.forEmulator(Emulators.HUB).logLabeled(
"WARN",
"emulators",
`Import/Export metadata file does not exist. ${clc.bold(
"Skipping data import!"
)} Metadata file location: ${importFilePath}`
`Could not find import/export metadata file, ${clc.bold("skipping data import!")}`
);
}
}
Expand Down Expand Up @@ -397,7 +444,7 @@ export async function startAll(options: any, noUi: boolean = false): Promise<voi

if (exportMetadata.firestore) {
const importDirAbsPath = path.resolve(options.import);
const exportMetadataFilePath = path.join(
const exportMetadataFilePath = path.resolve(
importDirAbsPath,
exportMetadata.firestore.metadata_file
);
Expand Down Expand Up @@ -486,7 +533,7 @@ export async function startAll(options: any, noUi: boolean = false): Promise<voi

if (exportMetadata.database) {
const importDirAbsPath = path.resolve(options.import);
const databaseExportDir = path.join(importDirAbsPath, exportMetadata.database.path);
const databaseExportDir = path.resolve(importDirAbsPath, exportMetadata.database.path);

const files = fs.readdirSync(databaseExportDir).filter((f) => f.endsWith(".json"));
for (const f of files) {
Expand Down
23 changes: 13 additions & 10 deletions src/emulator/hubExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ import { FirebaseError } from "../error";
import { EmulatorHub } from "./hub";
import { getDownloadDetails } from "./downloadableEmulators";

export interface FirestoreExportMetadata {
version: string;
path: string;
metadata_file: string;
}

export interface DatabaseExportMetadata {
version: string;
path: string;
}
export interface ExportMetadata {
version: string;
firestore?: {
version: string;
path: string;
metadata_file: string;
};
database?: {
version: string;
path: string;
};
firestore?: FirestoreExportMetadata;
database?: DatabaseExportMetadata;
}

export class HubExport {
Expand Down Expand Up @@ -68,7 +71,7 @@ export class HubExport {
}

const metadataPath = path.join(this.exportPath, HubExport.METADATA_FILE_NAME);
fs.writeFileSync(metadataPath, JSON.stringify(metadata));
fs.writeFileSync(metadataPath, JSON.stringify(metadata, undefined, 2));
}

private async exportFirestore(metadata: ExportMetadata): Promise<void> {
Expand Down

0 comments on commit 6b8496d

Please sign in to comment.