From 78f11b62ab658a5a59b291daad7ea5ee08b2bc34 Mon Sep 17 00:00:00 2001 From: Bryan Kendall Date: Thu, 25 Oct 2018 16:19:35 -0700 Subject: [PATCH] Master Sync 10/25 (#970) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add emulator:run * Cleanup * Download emulators if needed * Cleanup * Remove unused dep * Use CACHE_DIR * Allow FIREBASE_EMULATORS_PATH to override the cache dir * Format * Simplify emulator remote storage * Use fs-extra * Hide emulator:run behind preview * Cleanup * Fix URL * Remove old commands * Point at real artifacts * make emulators executable after downloading * Allow --yes flag for emulator * Prompt for emulator download * Linter * Emulator CLI per API Review (#318) * Emulator CLI per API Review * Cleanup * Address comments * Linter * Add a useful error message for when the emulator cannot start because… (#329) * Add a useful error message for when the emulator cannot start because Java is not installed * linter * action item * Add start time to profiler dump (#323) * Set emulator version for initial release (#336) * Typescript (#338) * The path structure layout seems like it changed (#341) * The path structure layout seems like it changed * Update src/auth.js Co-Authored-By: ryanpbrewster * Update functions init templates to v2.1.0 (#969) (#343) --- .eslintignore | 6 +- .gitignore | 2 + .prettierignore | 1 + changelog.txt | 2 + gulpfile.js | 66 --------------- mocha.opts | 4 + package.json | 46 +++++++---- {lib => src}/RulesDeploy.js | 0 {lib => src}/accountExporter.js | 4 +- {lib => src}/accountImporter.js | 6 +- {lib => src}/api.js | 0 {lib => src}/auth.js | 0 bin/firebase => src/bin/firebase.js | 16 ++-- {lib => src}/checkDupHostingKeys.js | 0 {lib => src}/checkFirebaseSDKVersion.js | 0 {lib => src}/checkValidTargetFilters.js | 0 {lib => src}/command.js | 2 +- {commands => src/commands}/auth-export.js | 10 +-- {commands => src/commands}/auth-import.js | 12 +-- {commands => src/commands}/database-get.js | 14 ++-- .../commands}/database-profile.js | 10 +-- {commands => src/commands}/database-push.js | 16 ++-- {commands => src/commands}/database-remove.js | 16 ++-- {commands => src/commands}/database-set.js | 18 ++--- {commands => src/commands}/database-update.js | 18 ++--- {commands => src/commands}/deploy.js | 18 ++--- .../commands}/experimental-functions-shell.js | 8 +- .../commands}/firestore-delete.js | 10 +-- .../commands}/firestore-indexes-list.js | 8 +- .../commands}/functions-config-clone.js | 14 ++-- .../commands}/functions-config-get.js | 10 +-- .../commands}/functions-config-legacy.js | 12 +-- .../commands}/functions-config-set.js | 12 +-- .../commands}/functions-config-unset.js | 14 ++-- .../commands}/functions-delete.js | 16 ++-- {commands => src/commands}/functions-log.js | 12 +-- {commands => src/commands}/functions-shell.js | 8 +- {commands => src/commands}/help.js | 6 +- {commands => src/commands}/hosting-disable.js | 12 +-- {commands => src/commands}/index.js | 9 ++- {commands => src/commands}/init.js | 18 ++--- {commands => src/commands}/kits-install.js | 12 +-- {commands => src/commands}/kits-uninstall.js | 14 ++-- {commands => src/commands}/list.js | 8 +- {commands => src/commands}/login-ci.js | 8 +- {commands => src/commands}/login.js | 12 +-- {commands => src/commands}/logout.js | 12 +-- {commands => src/commands}/open.js | 12 +-- {commands => src/commands}/serve.js | 27 ++++--- src/commands/setup-emulators-database.js | 10 +++ src/commands/setup-emulators-firestore.js | 10 +++ {commands => src/commands}/setup-web.js | 10 +-- {commands => src/commands}/target-apply.js | 8 +- {commands => src/commands}/target-clear.js | 6 +- {commands => src/commands}/target-remove.js | 6 +- {commands => src/commands}/target.js | 8 +- {commands => src/commands}/tools-migrate.js | 14 ++-- {commands => src/commands}/use.js | 12 +-- {lib => src}/config.js | 0 {lib => src}/configstore.js | 0 {lib => src}/deploy/database/index.js | 0 {lib => src}/deploy/database/prepare.js | 0 {lib => src}/deploy/database/release.js | 0 {lib => src}/deploy/firestore/deploy.js | 0 {lib => src}/deploy/firestore/index.js | 0 {lib => src}/deploy/firestore/prepare.js | 0 {lib => src}/deploy/firestore/release.js | 0 {lib => src}/deploy/functions/deploy.js | 0 {lib => src}/deploy/functions/index.js | 0 {lib => src}/deploy/functions/prepare.js | 0 {lib => src}/deploy/functions/release.js | 0 {lib => src}/deploy/hosting/convertConfig.js | 0 {lib => src}/deploy/hosting/deploy.js | 8 +- {lib => src}/deploy/hosting/hashcache.js | 0 {lib => src}/deploy/hosting/index.js | 0 {lib => src}/deploy/hosting/prepare.js | 0 {lib => src}/deploy/hosting/release.js | 0 {lib => src}/deploy/hosting/uploader.js | 2 +- {lib => src}/deploy/index.js | 0 {lib => src}/deploy/lifecycleHooks.js | 0 {lib => src}/deploy/storage/deploy.js | 0 {lib => src}/deploy/storage/index.js | 0 {lib => src}/deploy/storage/prepare.js | 0 {lib => src}/deploy/storage/release.js | 0 {lib => src}/deploymentTool.js | 0 {lib => src}/detectProjectRoot.js | 0 src/emulator/constants.js | 46 +++++++++++ src/emulator/download.js | 23 ++++++ {lib => src}/ensureApiEnabled.js | 0 {lib => src}/ensureDefaultCredentials.js | 0 {lib => src}/error.js | 0 {lib => src}/errorOut.js | 0 {lib => src}/extractTriggers.js | 0 {lib => src}/fetchMOTD.js | 0 {lib => src}/fetchWebSetup.js | 0 {lib => src}/filterTargets.js | 2 +- {lib => src}/firebaseApi.js | 0 {lib => src}/firestore/delete.js | 10 +-- .../firestore/encodeFirestoreValue.js | 0 {lib => src}/firestore/indexes.js | 6 +- {lib => src}/fsAsync.js | 0 {lib => src}/fsutils.js | 0 {lib => src}/functionsConfig.js | 0 {lib => src}/functionsConfigClone.js | 0 {lib => src}/functionsDelete.js | 0 {lib => src}/functionsDeployHelper.js | 0 {lib => src}/functionsEmulator.js | 0 {lib => src}/functionsShellCommandAction.js | 6 +- {lib => src}/gcp/cloudfunctions.js | 0 {lib => src}/gcp/cloudlogging.js | 0 {lib => src}/gcp/firestore.js | 2 +- {lib => src}/gcp/index.js | 0 {lib => src}/gcp/rules.js | 0 {lib => src}/gcp/runtimeconfig.js | 0 {lib => src}/gcp/storage.js | 0 {lib => src}/getInstanceId.js | 0 {lib => src}/getProjectId.js | 0 {lib => src}/getProjectNumber.js | 0 {lib => src}/handlePreviewToggles.js | 0 {lib => src}/hosting/functionsProxy.js | 0 {lib => src}/hosting/implicitInit.js | 0 {lib => src}/hosting/initMiddleware.js | 0 .../hosting/normalizedHostingConfigs.js | 0 {lib => src}/identifierToProjectId.js | 0 index.js => src/index.js | 8 +- {lib => src}/init/features/database.js | 0 {lib => src}/init/features/firestore.js | 0 {lib => src}/init/features/functions/index.js | 0 .../init/features/functions/javascript.js | 0 .../features/functions/npm-dependencies.js | 0 .../init/features/functions/typescript.js | 0 {lib => src}/init/features/hosting.js | 0 {lib => src}/init/features/index.js | 0 {lib => src}/init/features/project.js | 0 {lib => src}/init/features/storage.js | 0 {lib => src}/init/index.js | 0 {lib => src}/kits/deploy.js | 0 {lib => src}/kits/index.js | 0 {lib => src}/kits/pollKits.js | 0 {lib => src}/kits/prepareKitsConfig.js | 0 {lib => src}/kits/prepareKitsUpload.js | 0 lib/listFiles.js => src/listFiles.ts | 16 ++-- {lib => src}/loadCJSON.js | 0 {lib => src}/localFunction.js | 0 {lib => src}/logError.js | 0 {lib => src}/logger.js | 0 {lib => src}/parseBoltRules.js | 0 {lib => src}/parseTriggers.js | 0 {lib => src}/pollOperations.js | 0 {lib => src}/prepareFirebaseRules.js | 0 {lib => src}/prepareFunctionsUpload.js | 0 {lib => src}/prepareUpload.js | 2 +- {lib => src}/previews.js | 1 + {lib => src}/profileReport.js | 8 +- {lib => src}/profiler.js | 0 {lib => src}/prompt.js | 0 {lib => src}/queue.js | 0 {lib => src}/rc.js | 0 {lib => src}/requireAccess.js | 0 {lib => src}/requireAuth.js | 0 {lib => src}/requireConfig.js | 0 {lib => src}/requireInstance.js | 0 {lib => src}/requirePermissions.js | 0 {lib => src}/resolveProjectPath.js | 0 {lib => src}/responseToError.js | 0 {lib => src}/rtdb.js | 0 {lib => src}/scopes.js | 0 src/serve/database.js | 18 +++++ src/serve/firestore.js | 18 +++++ {lib => src}/serve/functions.js | 0 {lib => src}/serve/hosting.js | 0 {lib => src}/serve/index.js | 7 ++ src/serve/javaEmulators.js | 80 +++++++++++++++++++ .../lib => src/test}/accountExporter.spec.js | 4 +- .../lib => src/test}/accountImporter.spec.js | 6 +- {test/lib => src/test}/command.spec.js | 2 +- {test/lib => src/test}/config.spec.js | 4 +- .../lib => src/test}/extractTriggers.spec.js | 2 +- .../fixtures/config-imports/firebase.json | 0 .../fixtures/config-imports/hosting.json | 0 .../test}/fixtures/config-imports/rules.json | 0 .../fixtures/config-imports/unsupported.txt | 0 .../fixtures/dup-top-level/firebase.json | 0 .../test}/fixtures/dup-top-level/rules.json | 0 {test => src/test}/fixtures/fbrc/.firebaserc | 0 .../test}/fixtures/fbrc/conflict/.firebaserc | 0 .../test}/fixtures/fbrc/firebase.json | 0 .../test}/fixtures/fbrc/invalid/.firebaserc | 0 .../test}/fixtures/fbrc/invalid/firebase.json | 0 .../test}/fixtures/ignores/.hiddenfile | 0 .../test}/fixtures/ignores/firebase.json | 0 .../test}/fixtures/ignores/ignored.txt | 0 .../fixtures/ignores/ignored/deeper/index.txt | 0 .../test}/fixtures/ignores/ignored/ignore.txt | 0 .../test}/fixtures/ignores/ignored/index.html | 0 .../test}/fixtures/ignores/index.html | 0 .../test}/fixtures/ignores/present/index.html | 0 .../fixtures/invalid-config/firebase.json | 0 .../fixtures/profiler-data/sample-output.json | 0 .../test}/fixtures/profiler-data/sample.json | 0 .../test}/fixtures/valid-config/firebase.json | 0 {test/lib => src/test}/fsAsync.spec.js | 2 +- .../lib => src/test}/functionsConfig.spec.js | 2 +- .../test}/functionsDeployHelper.spec.js | 2 +- {test => src/test}/helpers/index.js | 2 +- .../test}/identifierToProjectId.spec.js | 6 +- src/test/listFiles.spec.ts | 18 +++++ {test/lib => src/test}/localFunction.spec.js | 2 +- {test/lib => src/test}/profilerReport.spec.js | 4 +- {test/lib => src/test}/rc.spec.js | 4 +- {lib => src}/track.js | 0 {lib => src}/triggerParser.js | 0 {lib => src}/utils.js | 0 {lib => src}/validateJsonRules.js | 0 {lib => src}/validator.js | 0 test/lib/listFiles.spec.js | 22 ----- tsconfig.json | 18 +++++ tslint.json | 19 +++++ 218 files changed, 622 insertions(+), 405 deletions(-) delete mode 100644 gulpfile.js create mode 100644 mocha.opts rename {lib => src}/RulesDeploy.js (100%) rename {lib => src}/accountExporter.js (98%) rename {lib => src}/accountImporter.js (98%) rename {lib => src}/api.js (100%) rename {lib => src}/auth.js (100%) rename bin/firebase => src/bin/firebase.js (88%) rename {lib => src}/checkDupHostingKeys.js (100%) rename {lib => src}/checkFirebaseSDKVersion.js (100%) rename {lib => src}/checkValidTargetFilters.js (100%) rename {lib => src}/command.js (99%) rename {commands => src/commands}/auth-export.js (83%) rename {commands => src/commands}/auth-import.js (94%) rename {commands => src/commands}/database-get.js (92%) rename {commands => src/commands}/database-profile.js (87%) rename {commands => src/commands}/database-push.js (84%) rename {commands => src/commands}/database-remove.js (83%) rename {commands => src/commands}/database-set.js (86%) rename {commands => src/commands}/database-update.js (86%) rename {commands => src/commands}/deploy.js (83%) rename {commands => src/commands}/experimental-functions-shell.js (62%) rename {commands => src/commands}/firestore-delete.js (92%) rename {commands => src/commands}/firestore-indexes-list.js (83%) rename {commands => src/commands}/functions-config-clone.js (84%) rename {commands => src/commands}/functions-config-get.js (80%) rename {commands => src/commands}/functions-config-legacy.js (81%) rename {commands => src/commands}/functions-config-set.js (82%) rename {commands => src/commands}/functions-config-unset.js (80%) rename {commands => src/commands}/functions-delete.js (86%) rename {commands => src/commands}/functions-log.js (89%) rename {commands => src/commands}/functions-shell.js (57%) rename {commands => src/commands}/help.js (86%) rename {commands => src/commands}/hosting-disable.js (81%) rename {commands => src/commands}/index.js (90%) rename {commands => src/commands}/init.js (93%) rename {commands => src/commands}/kits-install.js (89%) rename {commands => src/commands}/kits-uninstall.js (92%) rename {commands => src/commands}/list.js (92%) rename {commands => src/commands}/login-ci.js (84%) rename {commands => src/commands}/login.js (87%) rename {commands => src/commands}/logout.js (82%) rename {commands => src/commands}/open.js (93%) rename {commands => src/commands}/serve.js (59%) create mode 100644 src/commands/setup-emulators-database.js create mode 100644 src/commands/setup-emulators-firestore.js rename {commands => src/commands}/setup-web.js (60%) rename {commands => src/commands}/target-apply.js (85%) rename {commands => src/commands}/target-clear.js (81%) rename {commands => src/commands}/target-remove.js (82%) rename {commands => src/commands}/target.js (85%) rename {commands => src/commands}/tools-migrate.js (90%) rename {commands => src/commands}/use.js (96%) rename {lib => src}/config.js (100%) rename {lib => src}/configstore.js (100%) rename {lib => src}/deploy/database/index.js (100%) rename {lib => src}/deploy/database/prepare.js (100%) rename {lib => src}/deploy/database/release.js (100%) rename {lib => src}/deploy/firestore/deploy.js (100%) rename {lib => src}/deploy/firestore/index.js (100%) rename {lib => src}/deploy/firestore/prepare.js (100%) rename {lib => src}/deploy/firestore/release.js (100%) rename {lib => src}/deploy/functions/deploy.js (100%) rename {lib => src}/deploy/functions/index.js (100%) rename {lib => src}/deploy/functions/prepare.js (100%) rename {lib => src}/deploy/functions/release.js (100%) rename {lib => src}/deploy/hosting/convertConfig.js (100%) rename {lib => src}/deploy/hosting/deploy.js (98%) rename {lib => src}/deploy/hosting/hashcache.js (100%) rename {lib => src}/deploy/hosting/index.js (100%) rename {lib => src}/deploy/hosting/prepare.js (100%) rename {lib => src}/deploy/hosting/release.js (100%) rename {lib => src}/deploy/hosting/uploader.js (98%) rename {lib => src}/deploy/index.js (100%) rename {lib => src}/deploy/lifecycleHooks.js (100%) rename {lib => src}/deploy/storage/deploy.js (100%) rename {lib => src}/deploy/storage/index.js (100%) rename {lib => src}/deploy/storage/prepare.js (100%) rename {lib => src}/deploy/storage/release.js (100%) rename {lib => src}/deploymentTool.js (100%) rename {lib => src}/detectProjectRoot.js (100%) create mode 100644 src/emulator/constants.js create mode 100644 src/emulator/download.js rename {lib => src}/ensureApiEnabled.js (100%) rename {lib => src}/ensureDefaultCredentials.js (100%) rename {lib => src}/error.js (100%) rename {lib => src}/errorOut.js (100%) rename {lib => src}/extractTriggers.js (100%) rename {lib => src}/fetchMOTD.js (100%) rename {lib => src}/fetchWebSetup.js (100%) rename {lib => src}/filterTargets.js (94%) rename {lib => src}/firebaseApi.js (100%) rename {lib => src}/firestore/delete.js (98%) rename {lib => src}/firestore/encodeFirestoreValue.js (100%) rename {lib => src}/firestore/indexes.js (97%) rename {lib => src}/fsAsync.js (100%) rename {lib => src}/fsutils.js (100%) rename {lib => src}/functionsConfig.js (100%) rename {lib => src}/functionsConfigClone.js (100%) rename {lib => src}/functionsDelete.js (100%) rename {lib => src}/functionsDeployHelper.js (100%) rename {lib => src}/functionsEmulator.js (100%) rename {lib => src}/functionsShellCommandAction.js (91%) rename {lib => src}/gcp/cloudfunctions.js (100%) rename {lib => src}/gcp/cloudlogging.js (100%) rename {lib => src}/gcp/firestore.js (98%) rename {lib => src}/gcp/index.js (100%) rename {lib => src}/gcp/rules.js (100%) rename {lib => src}/gcp/runtimeconfig.js (100%) rename {lib => src}/gcp/storage.js (100%) rename {lib => src}/getInstanceId.js (100%) rename {lib => src}/getProjectId.js (100%) rename {lib => src}/getProjectNumber.js (100%) rename {lib => src}/handlePreviewToggles.js (100%) rename {lib => src}/hosting/functionsProxy.js (100%) rename {lib => src}/hosting/implicitInit.js (100%) rename {lib => src}/hosting/initMiddleware.js (100%) rename {lib => src}/hosting/normalizedHostingConfigs.js (100%) rename {lib => src}/identifierToProjectId.js (100%) rename index.js => src/index.js (92%) rename {lib => src}/init/features/database.js (100%) rename {lib => src}/init/features/firestore.js (100%) rename {lib => src}/init/features/functions/index.js (100%) rename {lib => src}/init/features/functions/javascript.js (100%) rename {lib => src}/init/features/functions/npm-dependencies.js (100%) rename {lib => src}/init/features/functions/typescript.js (100%) rename {lib => src}/init/features/hosting.js (100%) rename {lib => src}/init/features/index.js (100%) rename {lib => src}/init/features/project.js (100%) rename {lib => src}/init/features/storage.js (100%) rename {lib => src}/init/index.js (100%) rename {lib => src}/kits/deploy.js (100%) rename {lib => src}/kits/index.js (100%) rename {lib => src}/kits/pollKits.js (100%) rename {lib => src}/kits/prepareKitsConfig.js (100%) rename {lib => src}/kits/prepareKitsUpload.js (100%) rename lib/listFiles.js => src/listFiles.ts (53%) rename {lib => src}/loadCJSON.js (100%) rename {lib => src}/localFunction.js (100%) rename {lib => src}/logError.js (100%) rename {lib => src}/logger.js (100%) rename {lib => src}/parseBoltRules.js (100%) rename {lib => src}/parseTriggers.js (100%) rename {lib => src}/pollOperations.js (100%) rename {lib => src}/prepareFirebaseRules.js (100%) rename {lib => src}/prepareFunctionsUpload.js (100%) rename {lib => src}/prepareUpload.js (96%) rename {lib => src}/previews.js (95%) rename {lib => src}/profileReport.js (98%) rename {lib => src}/profiler.js (100%) rename {lib => src}/prompt.js (100%) rename {lib => src}/queue.js (100%) rename {lib => src}/rc.js (100%) rename {lib => src}/requireAccess.js (100%) rename {lib => src}/requireAuth.js (100%) rename {lib => src}/requireConfig.js (100%) rename {lib => src}/requireInstance.js (100%) rename {lib => src}/requirePermissions.js (100%) rename {lib => src}/resolveProjectPath.js (100%) rename {lib => src}/responseToError.js (100%) rename {lib => src}/rtdb.js (100%) rename {lib => src}/scopes.js (100%) create mode 100644 src/serve/database.js create mode 100644 src/serve/firestore.js rename {lib => src}/serve/functions.js (100%) rename {lib => src}/serve/hosting.js (100%) rename {lib => src}/serve/index.js (84%) create mode 100644 src/serve/javaEmulators.js rename {test/lib => src/test}/accountExporter.spec.js (97%) rename {test/lib => src/test}/accountImporter.spec.js (97%) rename {test/lib => src/test}/command.spec.js (98%) rename {test/lib => src/test}/config.spec.js (96%) rename {test/lib => src/test}/extractTriggers.spec.js (95%) rename {test => src/test}/fixtures/config-imports/firebase.json (100%) rename {test => src/test}/fixtures/config-imports/hosting.json (100%) rename {test => src/test}/fixtures/config-imports/rules.json (100%) rename {test => src/test}/fixtures/config-imports/unsupported.txt (100%) rename {test => src/test}/fixtures/dup-top-level/firebase.json (100%) rename {test => src/test}/fixtures/dup-top-level/rules.json (100%) rename {test => src/test}/fixtures/fbrc/.firebaserc (100%) rename {test => src/test}/fixtures/fbrc/conflict/.firebaserc (100%) rename {test => src/test}/fixtures/fbrc/firebase.json (100%) rename {test => src/test}/fixtures/fbrc/invalid/.firebaserc (100%) rename {test => src/test}/fixtures/fbrc/invalid/firebase.json (100%) rename {test => src/test}/fixtures/ignores/.hiddenfile (100%) rename {test => src/test}/fixtures/ignores/firebase.json (100%) rename {test => src/test}/fixtures/ignores/ignored.txt (100%) rename {test => src/test}/fixtures/ignores/ignored/deeper/index.txt (100%) rename {test => src/test}/fixtures/ignores/ignored/ignore.txt (100%) rename {test => src/test}/fixtures/ignores/ignored/index.html (100%) rename {test => src/test}/fixtures/ignores/index.html (100%) rename {test => src/test}/fixtures/ignores/present/index.html (100%) rename {test => src/test}/fixtures/invalid-config/firebase.json (100%) rename {test => src/test}/fixtures/profiler-data/sample-output.json (100%) rename {test => src/test}/fixtures/profiler-data/sample.json (100%) rename {test => src/test}/fixtures/valid-config/firebase.json (100%) rename {test/lib => src/test}/fsAsync.spec.js (98%) rename {test/lib => src/test}/functionsConfig.spec.js (95%) rename {test/lib => src/test}/functionsDeployHelper.spec.js (98%) rename {test => src/test}/helpers/index.js (84%) rename {test/lib => src/test}/identifierToProjectId.spec.js (88%) create mode 100644 src/test/listFiles.spec.ts rename {test/lib => src/test}/localFunction.spec.js (97%) rename {test/lib => src/test}/profilerReport.spec.js (96%) rename {test/lib => src/test}/rc.spec.js (98%) rename {lib => src}/track.js (100%) rename {lib => src}/triggerParser.js (100%) rename {lib => src}/utils.js (100%) rename {lib => src}/validateJsonRules.js (100%) rename {lib => src}/validator.js (100%) delete mode 100644 test/lib/listFiles.spec.js create mode 100644 tsconfig.json create mode 100644 tslint.json diff --git a/.eslintignore b/.eslintignore index 5d6162d4..549bb33e 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,3 @@ -/templates -/node_modules -/coverage +coverage +node_modules +templates diff --git a/.gitignore b/.gitignore index da92cd08..693d4769 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ yarn.lock .DS_Store .idea *.iml + +lib/ diff --git a/.prettierignore b/.prettierignore index 9dff9645..5982890e 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,2 +1,3 @@ /templates /node_modules +/lib/**/* diff --git a/changelog.txt b/changelog.txt index e69de29b..253abdb4 100644 --- a/changelog.txt +++ b/changelog.txt @@ -0,0 +1,2 @@ +important - As of v6.0.0, the Firebase CLI is transpiled from the `src` directory using TypeScript. Some deep requires of files may have changed, and `npm run build` must be run in the checked out repo directory (or when installed from git via `npm`) before the CLI can be used. +important - As of v6.0.0, the Firebase CLI is only going to be supported with Node >= 6.0.0. diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index 0cef5a8e..00000000 --- a/gulpfile.js +++ /dev/null @@ -1,66 +0,0 @@ -/**************/ -/* REQUIRES */ -/**************/ -var gulp = require("gulp"); - -// File I/O -var exit = require("gulp-exit"); -var eslint = require("gulp-eslint"); - -// Testing -var mocha = require("gulp-mocha"); -var istanbul = require("gulp-istanbul"); - -var _ = require("lodash"); - -/****************/ -/* FILE PATHS */ -/****************/ -var paths = { - js: ["index.js", "lib/**/*.js", "commands/**/*.js"], - - tests: ["test/**/*.spec.js"], - - scripts: ["scripts/*.js"], -}; - -/***********/ -/* TASKS */ -/***********/ -// Lints the JavaScript files -gulp.task("lint", function() { - var filesToLint = _.union(paths.js, paths.tests, paths.scripts); - return gulp - .src(filesToLint) - .pipe(eslint()) - .pipe(eslint.format()) - .pipe(eslint.failAfterError()); -}); - -// Runs the Mocha test suite -gulp.task("test", function() { - return gulp - .src(paths.js) - .pipe(istanbul()) - .pipe(istanbul.hookRequire()) - .on("finish", function() { - gulp - .src(paths.tests) - .pipe( - mocha({ - reporter: "spec", - timeout: 5000, - }) - ) - .pipe(istanbul.writeReports()) - .pipe(exit()); - }); -}); - -// Reruns the linter every time a JavaScript file changes -gulp.task("watch", function() { - gulp.watch(paths.js, gulp.series("lint")); -}); - -// Default task -gulp.task("default", gulp.series("lint", "test")); diff --git a/mocha.opts b/mocha.opts new file mode 100644 index 00000000..c70db2fd --- /dev/null +++ b/mocha.opts @@ -0,0 +1,4 @@ +--require ts-node/register +--recursive +--timeout=1000 +src/test/**/*.{ts,js} diff --git a/package.json b/package.json index 80a64753..0be9f040 100644 --- a/package.json +++ b/package.json @@ -2,16 +2,27 @@ "name": "firebase-tools", "version": "5.1.1", "description": "Command-Line Interface for Firebase", - "main": "index.js", + "main": "./lib/index.js", "bin": { - "firebase": "./bin/firebase" + "firebase": "./lib/bin/firebase.js" }, "scripts": { - "format": "prettier --write '**/*.js' 'bin/*'", - "lint": "eslint '**/*.js'", - "mocha": "nyc mocha test/**/*.spec.js --timeout=1000", + "build": "tsc", + "build:watch": "tsc --watch", + "clean": "rm -rf lib", + "format": "prettier --write 'src/**/*.{js,ts}'", + "lint": "npm run lint:js && npm run lint:ts", + "lint:js": "eslint 'src/**/*.js'", + "lint:ts": "tslint --project tsconfig.json --config tslint.json", + "mocha": "nyc mocha --opts mocha.opts", + "prepublish": "npm run clean && npm run build", + "prepare": "npm run clean && npm run build", "test": "npm run lint && npm run mocha" }, + "files": [ + "lib", + "templates" + ], "repository": { "type": "git", "url": "https://github.com/firebase/firebase-tools.git" @@ -29,7 +40,7 @@ ], "preferGlobal": true, "engines": { - "node": "^4.5 || >=5.10" + "node": ">= 6.0.0" }, "engineStrict": true, "author": "Firebase (https://firebase.google.com/)", @@ -37,13 +48,6 @@ "bugs": { "url": "https://github.com/firebase/firebase-tools/issues" }, - "files": [ - "bin/**", - "lib/**", - "commands/**", - "templates/**", - "index.js" - ], "homepage": "https://github.com/firebase/firebase-tools", "dependencies": { "JSONStream": "^1.2.1", @@ -86,11 +90,15 @@ "winston": "^1.0.1" }, "devDependencies": { + "@types/chai": "^4.1.6", + "@types/glob": "^7.1.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.12.0", "chai": "^4.2.0", "chai-as-promised": "^7.1.1", "coveralls": "^3.0.1", - "eslint": "^4.19.1", - "eslint-plugin-prettier": "^2.6.0", + "eslint": "^5.7.0", + "eslint-plugin-prettier": "^3.0.0", "gulp": "^4.0.0", "gulp-eslint": "^4.0.2", "gulp-exit": "0.0.2", @@ -99,9 +107,13 @@ "mocha": "^5.0.5", "nock": "^9.3.3", "nyc": "^11.9.0", - "prettier": "1.11.1", + "prettier": "1.14.3", "sinon": "^6.3.4", - "sinon-chai": "^3.2.0" + "sinon-chai": "^3.2.0", + "ts-node": "^7.0.1", + "tslint": "^5.11.0", + "tslint-plugin-prettier": "^2.0.0", + "typescript": "^3.1.3" }, "optionalDependencies": { "@google-cloud/functions-emulator": "^1.0.0-beta.5" diff --git a/lib/RulesDeploy.js b/src/RulesDeploy.js similarity index 100% rename from lib/RulesDeploy.js rename to src/RulesDeploy.js diff --git a/lib/accountExporter.js b/src/accountExporter.js similarity index 98% rename from lib/accountExporter.js rename to src/accountExporter.js index bda89212..fabcd168 100644 --- a/lib/accountExporter.js +++ b/src/accountExporter.js @@ -4,8 +4,8 @@ var os = require("os"); var path = require("path"); var _ = require("lodash"); -var api = require("../lib/api"); -var utils = require("../lib/utils"); +var api = require("./api"); +var utils = require("./utils"); var EXPORTED_JSON_KEYS = [ "localId", diff --git a/lib/accountImporter.js b/src/accountImporter.js similarity index 98% rename from lib/accountImporter.js rename to src/accountImporter.js index 3c89f54d..b78d1567 100644 --- a/lib/accountImporter.js +++ b/src/accountImporter.js @@ -3,9 +3,9 @@ var clc = require("cli-color"); var _ = require("lodash"); -var api = require("../lib/api"); -var logger = require("../lib/logger"); -var utils = require("../lib/utils"); +var api = require("./api"); +var logger = require("./logger"); +var utils = require("./utils"); var ALLOWED_JSON_KEYS = [ "localId", diff --git a/lib/api.js b/src/api.js similarity index 100% rename from lib/api.js rename to src/api.js diff --git a/lib/auth.js b/src/auth.js similarity index 100% rename from lib/auth.js rename to src/auth.js diff --git a/bin/firebase b/src/bin/firebase.js similarity index 88% rename from bin/firebase rename to src/bin/firebase.js index cea1649c..eeb99801 100755 --- a/bin/firebase +++ b/src/bin/firebase.js @@ -1,24 +1,24 @@ #!/usr/bin/env node "use strict"; -var pkg = require("../package.json"); +var pkg = require("../../package.json"); var updateNotifier = require("update-notifier")({ pkg: pkg }); updateNotifier.notify({ defer: true }); var client = require(".."); -var errorOut = require("../lib/errorOut"); +var errorOut = require("../errorOut"); var winston = require("winston"); -var logger = require("../lib/logger"); +var logger = require("../logger"); var fs = require("fs"); -var fsutils = require("../lib/fsutils"); +var fsutils = require("../fsutils"); var path = require("path"); var clc = require("cli-color"); var ansiStrip = require("cli-color/strip"); -var configstore = require("../lib/configstore"); +var configstore = require("../configstore"); var _ = require("lodash"); var args = process.argv.slice(2); -var handlePreviewToggles = require("../lib/handlePreviewToggles"); -var utils = require("../lib/utils"); +var handlePreviewToggles = require("../handlePreviewToggles"); +var utils = require("../utils"); var cmd; var logFilename = path.join(process.cwd(), "/firebase-debug.log"); @@ -56,7 +56,7 @@ if (utils.envOverrides.length) { logger.debug(_.repeat("-", 70)); logger.debug(); -require("../lib/fetchMOTD")(); +require("../fetchMOTD")(); process.on("exit", function(code) { code = process.exitCode || code; diff --git a/lib/checkDupHostingKeys.js b/src/checkDupHostingKeys.js similarity index 100% rename from lib/checkDupHostingKeys.js rename to src/checkDupHostingKeys.js diff --git a/lib/checkFirebaseSDKVersion.js b/src/checkFirebaseSDKVersion.js similarity index 100% rename from lib/checkFirebaseSDKVersion.js rename to src/checkFirebaseSDKVersion.js diff --git a/lib/checkValidTargetFilters.js b/src/checkValidTargetFilters.js similarity index 100% rename from lib/checkValidTargetFilters.js rename to src/checkValidTargetFilters.js diff --git a/lib/command.js b/src/command.js similarity index 99% rename from lib/command.js rename to src/command.js index 0de3c2fa..1db1dda2 100644 --- a/lib/command.js +++ b/src/command.js @@ -11,7 +11,7 @@ var getProjectId = require("./getProjectId"); var RC = require("./rc"); var Config = require("./config"); var detectProjectRoot = require("./detectProjectRoot"); -var configstore = require("../lib/configstore"); +var configstore = require("./configstore"); var Command = function(cmd) { this._cmd = cmd; diff --git a/commands/auth-export.js b/src/commands/auth-export.js similarity index 83% rename from commands/auth-export.js rename to src/commands/auth-export.js index ea264f1b..4b16dce9 100644 --- a/commands/auth-export.js +++ b/src/commands/auth-export.js @@ -4,11 +4,11 @@ var clc = require("cli-color"); var fs = require("fs"); var os = require("os"); -var Command = require("../lib/command"); -var accountExporter = require("../lib/accountExporter"); -var getProjectId = require("../lib/getProjectId"); -var logger = require("../lib/logger"); -var requirePermissions = require("../lib/requirePermissions"); +var Command = require("../command"); +var accountExporter = require("../accountExporter"); +var getProjectId = require("../getProjectId"); +var logger = require("../logger"); +var requirePermissions = require("../requirePermissions"); var MAX_BATCH_SIZE = 1000; diff --git a/commands/auth-import.js b/src/commands/auth-import.js similarity index 94% rename from commands/auth-import.js rename to src/commands/auth-import.js index fc2de4e0..c6448277 100644 --- a/commands/auth-import.js +++ b/src/commands/auth-import.js @@ -6,12 +6,12 @@ var fs = require("fs"); var jsonStream = require("JSONStream"); var _ = require("lodash"); -var Command = require("../lib/command"); -var accountImporter = require("../lib/accountImporter"); -var getProjectId = require("../lib/getProjectId"); -var logger = require("../lib/logger"); -var requirePermissions = require("../lib/requirePermissions"); -var utils = require("../lib/utils"); +var Command = require("../command"); +var accountImporter = require("../accountImporter"); +var getProjectId = require("../getProjectId"); +var logger = require("../logger"); +var requirePermissions = require("../requirePermissions"); +var utils = require("../utils"); var MAX_BATCH_SIZE = 1000; var validateOptions = accountImporter.validateOptions; diff --git a/commands/database-get.js b/src/commands/database-get.js similarity index 92% rename from commands/database-get.js rename to src/commands/database-get.js index a6055f97..ca69de96 100644 --- a/commands/database-get.js +++ b/src/commands/database-get.js @@ -1,14 +1,14 @@ "use strict"; -var Command = require("../lib/command"); -var requireInstance = require("../lib/requireInstance"); -var requirePermissions = require("../lib/requirePermissions"); +var Command = require("../command"); +var requireInstance = require("../requireInstance"); +var requirePermissions = require("../requirePermissions"); var request = require("request"); -var api = require("../lib/api"); -var responseToError = require("../lib/responseToError"); -var FirebaseError = require("../lib/error"); +var api = require("../api"); +var responseToError = require("../responseToError"); +var FirebaseError = require("../error"); -var utils = require("../lib/utils"); +var utils = require("../utils"); var querystring = require("querystring"); var _ = require("lodash"); var fs = require("fs"); diff --git a/commands/database-profile.js b/src/commands/database-profile.js similarity index 87% rename from commands/database-profile.js rename to src/commands/database-profile.js index c53bbf90..407da977 100644 --- a/commands/database-profile.js +++ b/src/commands/database-profile.js @@ -2,11 +2,11 @@ var _ = require("lodash"); -var Command = require("../lib/command"); -var requireInstance = require("../lib/requireInstance"); -var requirePermissions = require("../lib/requirePermissions"); -var utils = require("../lib/utils"); -var profiler = require("../lib/profiler"); +var Command = require("../command"); +var requireInstance = require("../requireInstance"); +var requirePermissions = require("../requirePermissions"); +var utils = require("../utils"); +var profiler = require("../profiler"); var description = "profile the Realtime Database and generate a usage report"; diff --git a/commands/database-push.js b/src/commands/database-push.js similarity index 84% rename from commands/database-push.js rename to src/commands/database-push.js index 9bbf1891..30107dd4 100644 --- a/commands/database-push.js +++ b/src/commands/database-push.js @@ -1,16 +1,16 @@ "use strict"; -var Command = require("../lib/command"); -var requireInstance = require("../lib/requireInstance"); -var requirePermissions = require("../lib/requirePermissions"); +var Command = require("../command"); +var requireInstance = require("../requireInstance"); +var requirePermissions = require("../requirePermissions"); var request = require("request"); -var api = require("../lib/api"); -var responseToError = require("../lib/responseToError"); -var FirebaseError = require("../lib/error"); +var api = require("../api"); +var responseToError = require("../responseToError"); +var FirebaseError = require("../error"); -var utils = require("../lib/utils"); +var utils = require("../utils"); var clc = require("cli-color"); -var logger = require("../lib/logger"); +var logger = require("../logger"); var fs = require("fs"); var _ = require("lodash"); diff --git a/commands/database-remove.js b/src/commands/database-remove.js similarity index 83% rename from commands/database-remove.js rename to src/commands/database-remove.js index 43b45853..dd788e99 100644 --- a/commands/database-remove.js +++ b/src/commands/database-remove.js @@ -1,15 +1,15 @@ "use strict"; -var Command = require("../lib/command"); -var requireInstance = require("../lib/requireInstance"); -var requirePermissions = require("../lib/requirePermissions"); +var Command = require("../command"); +var requireInstance = require("../requireInstance"); +var requirePermissions = require("../requirePermissions"); var request = require("request"); -var api = require("../lib/api"); -var responseToError = require("../lib/responseToError"); -var FirebaseError = require("../lib/error"); +var api = require("../api"); +var responseToError = require("../responseToError"); +var FirebaseError = require("../error"); -var utils = require("../lib/utils"); -var prompt = require("../lib/prompt"); +var utils = require("../utils"); +var prompt = require("../prompt"); var clc = require("cli-color"); var _ = require("lodash"); diff --git a/commands/database-set.js b/src/commands/database-set.js similarity index 86% rename from commands/database-set.js rename to src/commands/database-set.js index 39a2cdf5..62326926 100644 --- a/commands/database-set.js +++ b/src/commands/database-set.js @@ -1,18 +1,18 @@ "use strict"; -var Command = require("../lib/command"); -var requireInstance = require("../lib/requireInstance"); -var requirePermissions = require("../lib/requirePermissions"); +var Command = require("../command"); +var requireInstance = require("../requireInstance"); +var requirePermissions = require("../requirePermissions"); var request = require("request"); -var api = require("../lib/api"); -var responseToError = require("../lib/responseToError"); -var FirebaseError = require("../lib/error"); +var api = require("../api"); +var responseToError = require("../responseToError"); +var FirebaseError = require("../error"); -var utils = require("../lib/utils"); +var utils = require("../utils"); var clc = require("cli-color"); -var logger = require("../lib/logger"); +var logger = require("../logger"); var fs = require("fs"); -var prompt = require("../lib/prompt"); +var prompt = require("../prompt"); var _ = require("lodash"); module.exports = new Command("database:set [infile]") diff --git a/commands/database-update.js b/src/commands/database-update.js similarity index 86% rename from commands/database-update.js rename to src/commands/database-update.js index d72bfb59..de3724b0 100644 --- a/commands/database-update.js +++ b/src/commands/database-update.js @@ -1,18 +1,18 @@ "use strict"; -var Command = require("../lib/command"); -var requireInstance = require("../lib/requireInstance"); -var requirePermissions = require("../lib/requirePermissions"); +var Command = require("../command"); +var requireInstance = require("../requireInstance"); +var requirePermissions = require("../requirePermissions"); var request = require("request"); -var api = require("../lib/api"); -var responseToError = require("../lib/responseToError"); -var FirebaseError = require("../lib/error"); +var api = require("../api"); +var responseToError = require("../responseToError"); +var FirebaseError = require("../error"); -var utils = require("../lib/utils"); +var utils = require("../utils"); var clc = require("cli-color"); -var logger = require("../lib/logger"); +var logger = require("../logger"); var fs = require("fs"); -var prompt = require("../lib/prompt"); +var prompt = require("../prompt"); var _ = require("lodash"); module.exports = new Command("database:update [infile]") diff --git a/commands/deploy.js b/src/commands/deploy.js similarity index 83% rename from commands/deploy.js rename to src/commands/deploy.js index 11989604..e807f343 100644 --- a/commands/deploy.js +++ b/src/commands/deploy.js @@ -2,15 +2,15 @@ var _ = require("lodash"); -var requireInstance = require("../lib/requireInstance"); -var requirePermissions = require("../lib/requirePermissions"); -var checkDupHostingKeys = require("../lib/checkDupHostingKeys"); -var checkValidTargetFilters = require("../lib/checkValidTargetFilters"); -var checkFirebaseSDKVersion = require("../lib/checkFirebaseSDKVersion"); -var Command = require("../lib/command"); -var deploy = require("../lib/deploy"); -var requireConfig = require("../lib/requireConfig"); -var filterTargets = require("../lib/filterTargets"); +var requireInstance = require("../requireInstance"); +var requirePermissions = require("../requirePermissions"); +var checkDupHostingKeys = require("../checkDupHostingKeys"); +var checkValidTargetFilters = require("../checkValidTargetFilters"); +var checkFirebaseSDKVersion = require("../checkFirebaseSDKVersion"); +var Command = require("../command"); +var deploy = require("../deploy"); +var requireConfig = require("../requireConfig"); +var filterTargets = require("../filterTargets"); // in order of least time-consuming to most time-consuming var VALID_TARGETS = ["database", "storage", "firestore", "functions", "hosting"]; diff --git a/commands/experimental-functions-shell.js b/src/commands/experimental-functions-shell.js similarity index 62% rename from commands/experimental-functions-shell.js rename to src/commands/experimental-functions-shell.js index 3ffca02f..149083b8 100644 --- a/commands/experimental-functions-shell.js +++ b/src/commands/experimental-functions-shell.js @@ -1,9 +1,9 @@ "use strict"; -var Command = require("../lib/command"); -var requirePermissions = require("../lib/requirePermissions"); -var requireConfig = require("../lib/requireConfig"); -var action = require("../lib/functionsShellCommandAction"); +var Command = require("../command"); +var requirePermissions = require("../requirePermissions"); +var requireConfig = require("../requireConfig"); +var action = require("../functionsShellCommandAction"); module.exports = new Command("experimental:functions:shell") .description( diff --git a/commands/firestore-delete.js b/src/commands/firestore-delete.js similarity index 92% rename from commands/firestore-delete.js rename to src/commands/firestore-delete.js index 675e538c..0edb9a17 100644 --- a/commands/firestore-delete.js +++ b/src/commands/firestore-delete.js @@ -1,11 +1,11 @@ "use strict"; var clc = require("cli-color"); -var Command = require("../lib/command"); -var FirestoreDelete = require("../lib/firestore/delete"); -var prompt = require("../lib/prompt"); -var requirePermissions = require("../lib/requirePermissions"); -var utils = require("../lib/utils"); +var Command = require("../command"); +var FirestoreDelete = require("../firestore/delete"); +var prompt = require("../prompt"); +var requirePermissions = require("../requirePermissions"); +var utils = require("../utils"); var _getConfirmationMessage = function(deleteOp, options) { if (options.allCollections) { diff --git a/commands/firestore-indexes-list.js b/src/commands/firestore-indexes-list.js similarity index 83% rename from commands/firestore-indexes-list.js rename to src/commands/firestore-indexes-list.js index 63ab3c88..798d46d4 100644 --- a/commands/firestore-indexes-list.js +++ b/src/commands/firestore-indexes-list.js @@ -1,9 +1,9 @@ "use strict"; -var Command = require("../lib/command"); -var firestoreIndexes = require("../lib/firestore/indexes.js"); -var requirePermissions = require("../lib/requirePermissions"); -var logger = require("../lib/logger"); +var Command = require("../command"); +var firestoreIndexes = require("../firestore/indexes.js"); +var requirePermissions = require("../requirePermissions"); +var logger = require("../logger"); var _ = require("lodash"); var _prettyPrint = function(indexes) { diff --git a/commands/functions-config-clone.js b/src/commands/functions-config-clone.js similarity index 84% rename from commands/functions-config-clone.js rename to src/commands/functions-config-clone.js index 3b966e28..cd9b7463 100644 --- a/commands/functions-config-clone.js +++ b/src/commands/functions-config-clone.js @@ -1,13 +1,13 @@ "use strict"; var clc = require("cli-color"); -var Command = require("../lib/command"); -var functionsConfig = require("../lib/functionsConfig"); -var functionsConfigClone = require("../lib/functionsConfigClone"); -var getProjectId = require("../lib/getProjectId"); -var requirePermissions = require("../lib/requirePermissions"); -var utils = require("../lib/utils"); -var logger = require("../lib/logger"); +var Command = require("../command"); +var functionsConfig = require("../functionsConfig"); +var functionsConfigClone = require("../functionsConfigClone"); +var getProjectId = require("../getProjectId"); +var requirePermissions = require("../requirePermissions"); +var utils = require("../utils"); +var logger = require("../logger"); module.exports = new Command("functions:config:clone") .description("clone environment config from another project") diff --git a/commands/functions-config-get.js b/src/commands/functions-config-get.js similarity index 80% rename from commands/functions-config-get.js rename to src/commands/functions-config-get.js index 8d6a7fab..c843e625 100644 --- a/commands/functions-config-get.js +++ b/src/commands/functions-config-get.js @@ -1,11 +1,11 @@ "use strict"; var _ = require("lodash"); -var Command = require("../lib/command"); -var getProjectId = require("../lib/getProjectId"); -var logger = require("../lib/logger"); -var requirePermissions = require("../lib/requirePermissions"); -var functionsConfig = require("../lib/functionsConfig"); +var Command = require("../command"); +var getProjectId = require("../getProjectId"); +var logger = require("../logger"); +var requirePermissions = require("../requirePermissions"); +var functionsConfig = require("../functionsConfig"); function _materialize(projectId, path) { if (_.isUndefined(path)) { diff --git a/commands/functions-config-legacy.js b/src/commands/functions-config-legacy.js similarity index 81% rename from commands/functions-config-legacy.js rename to src/commands/functions-config-legacy.js index d8fe2951..15b7cdd4 100644 --- a/commands/functions-config-legacy.js +++ b/src/commands/functions-config-legacy.js @@ -2,12 +2,12 @@ var _ = require("lodash"); -var Command = require("../lib/command"); -var getProjectId = require("../lib/getProjectId"); -var requirePermissions = require("../lib/requirePermissions"); -var runtimeconfig = require("../lib/gcp/runtimeconfig"); -var functionsConfig = require("../lib/functionsConfig"); -var logger = require("../lib/logger"); +var Command = require("../command"); +var getProjectId = require("../getProjectId"); +var requirePermissions = require("../requirePermissions"); +var runtimeconfig = require("../gcp/runtimeconfig"); +var functionsConfig = require("../functionsConfig"); +var logger = require("../logger"); module.exports = new Command("functions:config:legacy") .description("get legacy functions config variables") diff --git a/commands/functions-config-set.js b/src/commands/functions-config-set.js similarity index 82% rename from commands/functions-config-set.js rename to src/commands/functions-config-set.js index 529f1c47..9ebdfa84 100644 --- a/commands/functions-config-set.js +++ b/src/commands/functions-config-set.js @@ -2,12 +2,12 @@ var clc = require("cli-color"); -var Command = require("../lib/command"); -var getProjectId = require("../lib/getProjectId"); -var requirePermissions = require("../lib/requirePermissions"); -var logger = require("../lib/logger"); -var utils = require("../lib/utils"); -var functionsConfig = require("../lib/functionsConfig"); +var Command = require("../command"); +var getProjectId = require("../getProjectId"); +var requirePermissions = require("../requirePermissions"); +var logger = require("../logger"); +var utils = require("../utils"); +var functionsConfig = require("../functionsConfig"); module.exports = new Command("functions:config:set [values...]") .description("set environment config with key=value syntax") diff --git a/commands/functions-config-unset.js b/src/commands/functions-config-unset.js similarity index 80% rename from commands/functions-config-unset.js rename to src/commands/functions-config-unset.js index 5ca64f82..f8cfadc1 100644 --- a/commands/functions-config-unset.js +++ b/src/commands/functions-config-unset.js @@ -3,13 +3,13 @@ var _ = require("lodash"); var clc = require("cli-color"); -var Command = require("../lib/command"); -var functionsConfig = require("../lib/functionsConfig"); -var getProjectId = require("../lib/getProjectId"); -var logger = require("../lib/logger"); -var requirePermissions = require("../lib/requirePermissions"); -var utils = require("../lib/utils"); -var runtimeconfig = require("../lib/gcp/runtimeconfig"); +var Command = require("../command"); +var functionsConfig = require("../functionsConfig"); +var getProjectId = require("../getProjectId"); +var logger = require("../logger"); +var requirePermissions = require("../requirePermissions"); +var utils = require("../utils"); +var runtimeconfig = require("../gcp/runtimeconfig"); module.exports = new Command("functions:config:unset [keys...]") .description("unset environment config at the specified path(s)") diff --git a/commands/functions-delete.js b/src/commands/functions-delete.js similarity index 86% rename from commands/functions-delete.js rename to src/commands/functions-delete.js index 760d751e..7cb3acdd 100644 --- a/commands/functions-delete.js +++ b/src/commands/functions-delete.js @@ -2,15 +2,15 @@ var _ = require("lodash"); -var Command = require("../lib/command"); +var Command = require("../command"); var clc = require("cli-color"); -var cloudfunctions = require("../lib/gcp/cloudfunctions"); -var functionsDelete = require("../lib/functionsDelete"); -var getProjectId = require("../lib/getProjectId"); -var helper = require("../lib/functionsDeployHelper"); -var prompt = require("../lib/prompt"); -var requirePermissions = require("../lib/requirePermissions"); -var utils = require("../lib/utils"); +var cloudfunctions = require("../gcp/cloudfunctions"); +var functionsDelete = require("../functionsDelete"); +var getProjectId = require("../getProjectId"); +var helper = require("../functionsDeployHelper"); +var prompt = require("../prompt"); +var requirePermissions = require("../requirePermissions"); +var utils = require("../utils"); module.exports = new Command("functions:delete [filters...]") .description("delete one or more Cloud Functions by name or group name.") diff --git a/commands/functions-log.js b/src/commands/functions-log.js similarity index 89% rename from commands/functions-log.js rename to src/commands/functions-log.js index 37dd6b14..bc00e371 100644 --- a/commands/functions-log.js +++ b/src/commands/functions-log.js @@ -2,12 +2,12 @@ var _ = require("lodash"); -var Command = require("../lib/command"); -var FirebaseError = require("../lib/error"); -var gcp = require("../lib/gcp"); -var getProjectId = require("../lib/getProjectId"); -var logger = require("../lib/logger"); -var requirePermissions = require("../lib/requirePermissions"); +var Command = require("../command"); +var FirebaseError = require("../error"); +var gcp = require("../gcp"); +var getProjectId = require("../getProjectId"); +var logger = require("../logger"); +var requirePermissions = require("../requirePermissions"); var open = require("opn"); module.exports = new Command("functions:log") diff --git a/commands/functions-shell.js b/src/commands/functions-shell.js similarity index 57% rename from commands/functions-shell.js rename to src/commands/functions-shell.js index 6ea233d9..a3cf28ff 100644 --- a/commands/functions-shell.js +++ b/src/commands/functions-shell.js @@ -1,9 +1,9 @@ "use strict"; -var Command = require("../lib/command"); -var requirePermissions = require("../lib/requirePermissions"); -var requireConfig = require("../lib/requireConfig"); -var action = require("../lib/functionsShellCommandAction"); +var Command = require("../command"); +var requirePermissions = require("../requirePermissions"); +var requireConfig = require("../requireConfig"); +var action = require("../functionsShellCommandAction"); module.exports = new Command("functions:shell") .description("launch full Node shell with emulated functions") diff --git a/commands/help.js b/src/commands/help.js similarity index 86% rename from commands/help.js rename to src/commands/help.js index 4aee2557..56db1afe 100644 --- a/commands/help.js +++ b/src/commands/help.js @@ -1,10 +1,10 @@ "use strict"; -var Command = require("../lib/command"); +var Command = require("../command"); var clc = require("cli-color"); -var logger = require("../lib/logger"); -var utils = require("../lib/utils"); +var logger = require("../logger"); +var utils = require("../utils"); module.exports = new Command("help [command]") .description("display help information") diff --git a/commands/hosting-disable.js b/src/commands/hosting-disable.js similarity index 81% rename from commands/hosting-disable.js rename to src/commands/hosting-disable.js index 028a3ae0..8d2f7814 100644 --- a/commands/hosting-disable.js +++ b/src/commands/hosting-disable.js @@ -1,11 +1,11 @@ "use strict"; -var Command = require("../lib/command"); -var requireInstance = require("../lib/requireInstance"); -var requirePermissions = require("../lib/requirePermissions"); -var api = require("../lib/api"); -var utils = require("../lib/utils"); -var prompt = require("../lib/prompt"); +var Command = require("../command"); +var requireInstance = require("../requireInstance"); +var requirePermissions = require("../requirePermissions"); +var api = require("../api"); +var utils = require("../utils"); +var prompt = require("../prompt"); var clc = require("cli-color"); module.exports = new Command("hosting:disable") diff --git a/commands/index.js b/src/commands/index.js similarity index 90% rename from commands/index.js rename to src/commands/index.js index 1f60d8e3..b4e8bbf1 100644 --- a/commands/index.js +++ b/src/commands/index.js @@ -1,6 +1,6 @@ "use strict"; -var previews = require("../lib/previews"); +var previews = require("../previews"); module.exports = function(client) { var loadCommand = function(name) { var cmd = require("./" + name); @@ -74,6 +74,13 @@ module.exports = function(client) { web: loadCommand("setup-web"), }; + if (previews.emulators) { + client.setup.emulators = { + database: loadCommand("setup-emulators-database"), + firestore: loadCommand("setup-emulators-firestore"), + }; + } + client.target = loadCommand("target"); client.target.apply = loadCommand("target-apply"); client.target.clear = loadCommand("target-clear"); diff --git a/commands/init.js b/src/commands/init.js similarity index 93% rename from commands/init.js rename to src/commands/init.js index 52017972..c3af5f85 100644 --- a/commands/init.js +++ b/src/commands/init.js @@ -5,16 +5,16 @@ var fs = require("fs"); var homeDir = require("user-home"); var path = require("path"); -var Command = require("../lib/command"); -var Config = require("../lib/config"); -var fsutils = require("../lib/fsutils"); -var init = require("../lib/init"); -var logger = require("../lib/logger"); -var prompt = require("../lib/prompt"); -var requireAuth = require("../lib/requireAuth"); -var utils = require("../lib/utils"); +var Command = require("../command"); +var Config = require("../config"); +var fsutils = require("../fsutils"); +var init = require("../init"); +var logger = require("../logger"); +var prompt = require("../prompt"); +var requireAuth = require("../requireAuth"); +var utils = require("../utils"); -var TEMPLATE_ROOT = path.resolve(__dirname, "../templates/"); +var TEMPLATE_ROOT = path.resolve(__dirname, "../../templates/"); var BANNER_TEXT = fs.readFileSync(path.join(TEMPLATE_ROOT, "banner.txt"), "utf8"); var GITIGNORE_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "_gitignore"), "utf8"); diff --git a/commands/kits-install.js b/src/commands/kits-install.js similarity index 89% rename from commands/kits-install.js rename to src/commands/kits-install.js index c8cbb0da..a687e286 100644 --- a/commands/kits-install.js +++ b/src/commands/kits-install.js @@ -2,12 +2,12 @@ var clc = require("cli-color"); -var Command = require("../lib/command"); -var getProjectId = require("../lib/getProjectId"); -var logger = require("../lib/logger"); -var requirePermissions = require("../lib/requirePermissions"); -var utils = require("../lib/utils"); -var kits = require("../lib/kits"); +var Command = require("../command"); +var getProjectId = require("../getProjectId"); +var logger = require("../logger"); +var requirePermissions = require("../requirePermissions"); +var utils = require("../utils"); +var kits = require("../kits"); // TODO: add option for urlPath to be inserted or parse urlPath for name if needed module.exports = new Command("kits:install ") diff --git a/commands/kits-uninstall.js b/src/commands/kits-uninstall.js similarity index 92% rename from commands/kits-uninstall.js rename to src/commands/kits-uninstall.js index becd8120..7b64d740 100644 --- a/commands/kits-uninstall.js +++ b/src/commands/kits-uninstall.js @@ -2,13 +2,13 @@ var clc = require("cli-color"); var _ = require("lodash"); -var Command = require("../lib/command"); -var gcp = require("../lib/gcp"); -var pollKits = require("../lib/kits/pollKits"); -var getProjectId = require("../lib/getProjectId"); -var prompt = require("../lib/prompt"); -var requirePermissions = require("../lib/requirePermissions"); -var utils = require("../lib/utils"); +var Command = require("../command"); +var gcp = require("../gcp"); +var pollKits = require("../kits/pollKits"); +var getProjectId = require("../getProjectId"); +var prompt = require("../prompt"); +var requirePermissions = require("../requirePermissions"); +var utils = require("../utils"); var DEFAULT_REGION = gcp.cloudfunctions.DEFAULT_REGION; diff --git a/commands/list.js b/src/commands/list.js similarity index 92% rename from commands/list.js rename to src/commands/list.js index f0a0096c..8f2a70a0 100644 --- a/commands/list.js +++ b/src/commands/list.js @@ -1,12 +1,12 @@ "use strict"; -var Command = require("../lib/command"); -var api = require("../lib/api"); -var requireAuth = require("../lib/requireAuth"); +var Command = require("../command"); +var api = require("../api"); +var requireAuth = require("../requireAuth"); var clc = require("cli-color"); var Table = require("cli-table"); var _ = require("lodash"); -var logger = require("../lib/logger"); +var logger = require("../logger"); module.exports = new Command("list") .description("list the Firebase projects you have access to") diff --git a/commands/login-ci.js b/src/commands/login-ci.js similarity index 84% rename from commands/login-ci.js rename to src/commands/login-ci.js index 3ff7875d..a3f4fc5c 100644 --- a/commands/login-ci.js +++ b/src/commands/login-ci.js @@ -1,10 +1,10 @@ "use strict"; -var Command = require("../lib/command"); +var Command = require("../command"); var clc = require("cli-color"); -var utils = require("../lib/utils"); -var logger = require("../lib/logger"); -var auth = require("../lib/auth"); +var utils = require("../utils"); +var logger = require("../logger"); +var auth = require("../auth"); module.exports = new Command("login:ci") .description("generate an access token for use in non-interactive environments") diff --git a/commands/login.js b/src/commands/login.js similarity index 87% rename from commands/login.js rename to src/commands/login.js index 236f34de..e811f2af 100644 --- a/commands/login.js +++ b/src/commands/login.js @@ -1,13 +1,13 @@ "use strict"; -var Command = require("../lib/command"); -var logger = require("../lib/logger"); -var configstore = require("../lib/configstore"); +var Command = require("../command"); +var logger = require("../logger"); +var configstore = require("../configstore"); var clc = require("cli-color"); -var utils = require("../lib/utils"); -var prompt = require("../lib/prompt"); +var utils = require("../utils"); +var prompt = require("../prompt"); -var auth = require("../lib/auth"); +var auth = require("../auth"); module.exports = new Command("login") .description("log the CLI into Firebase") diff --git a/commands/logout.js b/src/commands/logout.js similarity index 82% rename from commands/logout.js rename to src/commands/logout.js index 4ebd326f..1991fa30 100644 --- a/commands/logout.js +++ b/src/commands/logout.js @@ -1,13 +1,13 @@ "use strict"; -var Command = require("../lib/command"); -var configstore = require("../lib/configstore"); -var logger = require("../lib/logger"); +var Command = require("../command"); +var configstore = require("../configstore"); +var logger = require("../logger"); var clc = require("cli-color"); -var utils = require("../lib/utils"); -var api = require("../lib/api"); -var auth = require("../lib/auth"); +var utils = require("../utils"); +var api = require("../api"); +var auth = require("../auth"); var _ = require("lodash"); module.exports = new Command("logout") diff --git a/commands/open.js b/src/commands/open.js similarity index 93% rename from commands/open.js rename to src/commands/open.js index 36ae200a..0bc3181a 100644 --- a/commands/open.js +++ b/src/commands/open.js @@ -4,12 +4,12 @@ var _ = require("lodash"); var clc = require("cli-color"); var open = require("opn"); -var api = require("../lib/api"); -var Command = require("../lib/command"); -var logger = require("../lib/logger"); -var prompt = require("../lib/prompt"); -var requirePermissions = require("../lib/requirePermissions"); -var utils = require("../lib/utils"); +var api = require("../api"); +var Command = require("../command"); +var logger = require("../logger"); +var prompt = require("../prompt"); +var requirePermissions = require("../requirePermissions"); +var utils = require("../utils"); var LINKS = [ { name: "Project Dashboard", arg: "dashboard", consoleUrl: "/overview" }, diff --git a/commands/serve.js b/src/commands/serve.js similarity index 59% rename from commands/serve.js rename to src/commands/serve.js index b44b5fb7..a2472d36 100644 --- a/commands/serve.js +++ b/src/commands/serve.js @@ -2,29 +2,34 @@ var clc = require("cli-color"); -var Command = require("../lib/command"); -var logger = require("../lib/logger"); -var utils = require("../lib/utils"); -var requirePermissions = require("../lib/requirePermissions"); -var requireConfig = require("../lib/requireConfig"); -var checkDupHostingKeys = require("../lib/checkDupHostingKeys"); -var serve = require("../lib/serve/index"); -var filterTargets = require("../lib/filterTargets"); -var getProjectNumber = require("../lib/getProjectNumber"); +var Command = require("../command"); +var logger = require("../logger"); +var utils = require("../utils"); +var requirePermissions = require("../requirePermissions"); +var requireConfig = require("../requireConfig"); +var checkDupHostingKeys = require("../checkDupHostingKeys"); +var serve = require("../serve/index"); +var filterTargets = require("../filterTargets"); +var getProjectNumber = require("../getProjectNumber"); +var previews = require("../previews"); var VALID_TARGETS = ["functions", "hosting"]; +if (previews.emulators) { + VALID_TARGETS = ["functions", "hosting", "database", "firestore"]; +} + module.exports = new Command("serve") .description("start a local server for your static assets") .option("-p, --port ", "the port on which to listen (default: 5000)", 5000) .option("-o, --host ", "the host on which to listen (default: localhost)", "localhost") .option( "--only ", - "only serve specified targets (valid targets are: functions, hosting)" + "only serve specified targets (valid targets are: " + VALID_TARGETS.join(", ") + ")" ) .option( "--except ", - "serve all except specified targets (valid targets are: functions, hosting)" + "serve all except specified targets (valid targets are: " + VALID_TARGETS.join(", ") + ")" ) .before(requireConfig) .before(requirePermissions) diff --git a/src/commands/setup-emulators-database.js b/src/commands/setup-emulators-database.js new file mode 100644 index 00000000..73b76c3e --- /dev/null +++ b/src/commands/setup-emulators-database.js @@ -0,0 +1,10 @@ +"use strict"; + +const Command = require("../command"); +const downloadEmulator = require("../emulator/download"); + +const name = "database"; + +module.exports = new Command("setup:emulators:" + name) + .description("downloads the " + name + " emulator") + .action(downloadEmulator.bind(this, name)); diff --git a/src/commands/setup-emulators-firestore.js b/src/commands/setup-emulators-firestore.js new file mode 100644 index 00000000..1a25195b --- /dev/null +++ b/src/commands/setup-emulators-firestore.js @@ -0,0 +1,10 @@ +"use strict"; + +const Command = require("../command"); +const downloadEmulator = require("../emulator/download"); + +const name = "firestore"; + +module.exports = new Command("setup:emulators:" + name) + .description("downloads the " + name + " emulator") + .action(downloadEmulator.bind(this, name)); diff --git a/commands/setup-web.js b/src/commands/setup-web.js similarity index 60% rename from commands/setup-web.js rename to src/commands/setup-web.js index 47da9b6d..43c31389 100644 --- a/commands/setup-web.js +++ b/src/commands/setup-web.js @@ -2,12 +2,12 @@ var fs = require("fs"); -var Command = require("../lib/command"); -var fetchWebSetup = require("../lib/fetchWebSetup"); -var logger = require("../lib/logger"); -var requirePermissions = require("../lib/requirePermissions"); +var Command = require("../command"); +var fetchWebSetup = require("../fetchWebSetup"); +var logger = require("../logger"); +var requirePermissions = require("../requirePermissions"); -var JS_TEMPLATE = fs.readFileSync(__dirname + "/../templates/setup/web.js", "utf8"); +var JS_TEMPLATE = fs.readFileSync(__dirname + "/../../templates/setup/web.js", "utf8"); module.exports = new Command("setup:web") .description("display this project's setup information for the Firebase JS SDK") diff --git a/commands/target-apply.js b/src/commands/target-apply.js similarity index 85% rename from commands/target-apply.js rename to src/commands/target-apply.js index 4b67f135..d4695642 100644 --- a/commands/target-apply.js +++ b/src/commands/target-apply.js @@ -3,10 +3,10 @@ var _ = require("lodash"); var clc = require("cli-color"); -var Command = require("../lib/command"); -var logger = require("../lib/logger"); -var requireConfig = require("../lib/requireConfig"); -var utils = require("../lib/utils"); +var Command = require("../command"); +var logger = require("../logger"); +var requireConfig = require("../requireConfig"); +var utils = require("../utils"); module.exports = new Command("target:apply ") .description("apply a deploy target to a resource") diff --git a/commands/target-clear.js b/src/commands/target-clear.js similarity index 81% rename from commands/target-clear.js rename to src/commands/target-clear.js index 74e207ef..bbf76bb7 100644 --- a/commands/target-clear.js +++ b/src/commands/target-clear.js @@ -2,9 +2,9 @@ var clc = require("cli-color"); -var Command = require("../lib/command"); -var requireConfig = require("../lib/requireConfig"); -var utils = require("../lib/utils"); +var Command = require("../command"); +var requireConfig = require("../requireConfig"); +var utils = require("../utils"); module.exports = new Command("target:clear ") .description("clear all resources from a named resource target") diff --git a/commands/target-remove.js b/src/commands/target-remove.js similarity index 82% rename from commands/target-remove.js rename to src/commands/target-remove.js index 3403a436..6dad67f7 100644 --- a/commands/target-remove.js +++ b/src/commands/target-remove.js @@ -2,9 +2,9 @@ var clc = require("cli-color"); -var Command = require("../lib/command"); -var requireConfig = require("../lib/requireConfig"); -var utils = require("../lib/utils"); +var Command = require("../command"); +var requireConfig = require("../requireConfig"); +var utils = require("../utils"); module.exports = new Command("target:remove ") .description("remove a resource target") diff --git a/commands/target.js b/src/commands/target.js similarity index 85% rename from commands/target.js rename to src/commands/target.js index bef7a4f3..e93cad69 100644 --- a/commands/target.js +++ b/src/commands/target.js @@ -3,10 +3,10 @@ var _ = require("lodash"); var clc = require("cli-color"); -var Command = require("../lib/command"); -var logger = require("../lib/logger"); -var requireConfig = require("../lib/requireConfig"); -var utils = require("../lib/utils"); +var Command = require("../command"); +var logger = require("../logger"); +var requireConfig = require("../requireConfig"); +var utils = require("../utils"); function _logTargets(type, targets) { logger.info(clc.cyan("[ " + type + " ]")); diff --git a/commands/tools-migrate.js b/src/commands/tools-migrate.js similarity index 90% rename from commands/tools-migrate.js rename to src/commands/tools-migrate.js index 1cd51894..7256ed88 100644 --- a/commands/tools-migrate.js +++ b/src/commands/tools-migrate.js @@ -3,13 +3,13 @@ var _ = require("lodash"); var clc = require("cli-color"); -var Command = require("../lib/command"); -var Config = require("../lib/config"); -var identifierToProjectId = require("../lib/identifierToProjectId"); -var logger = require("../lib/logger"); -var prompt = require("../lib/prompt"); -var requireAuth = require("../lib/requireAuth"); -var utils = require("../lib/utils"); +var Command = require("../command"); +var Config = require("../config"); +var identifierToProjectId = require("../identifierToProjectId"); +var logger = require("../logger"); +var prompt = require("../prompt"); +var requireAuth = require("../requireAuth"); +var utils = require("../utils"); var MOVE_KEYS = { rules: "database.rules", diff --git a/commands/use.js b/src/commands/use.js similarity index 96% rename from commands/use.js rename to src/commands/use.js index ab2087f3..9a53fc6a 100644 --- a/commands/use.js +++ b/src/commands/use.js @@ -1,13 +1,13 @@ "use strict"; -var Command = require("../lib/command"); -var logger = require("../lib/logger"); -var requireAuth = require("../lib/requireAuth"); -var api = require("../lib/api"); +var Command = require("../command"); +var logger = require("../logger"); +var requireAuth = require("../requireAuth"); +var api = require("../api"); var clc = require("cli-color"); -var utils = require("../lib/utils"); +var utils = require("../utils"); var _ = require("lodash"); -var prompt = require("../lib/prompt"); +var prompt = require("../prompt"); var listAliases = function(options) { if (options.rc.hasProjects) { diff --git a/lib/config.js b/src/config.js similarity index 100% rename from lib/config.js rename to src/config.js diff --git a/lib/configstore.js b/src/configstore.js similarity index 100% rename from lib/configstore.js rename to src/configstore.js diff --git a/lib/deploy/database/index.js b/src/deploy/database/index.js similarity index 100% rename from lib/deploy/database/index.js rename to src/deploy/database/index.js diff --git a/lib/deploy/database/prepare.js b/src/deploy/database/prepare.js similarity index 100% rename from lib/deploy/database/prepare.js rename to src/deploy/database/prepare.js diff --git a/lib/deploy/database/release.js b/src/deploy/database/release.js similarity index 100% rename from lib/deploy/database/release.js rename to src/deploy/database/release.js diff --git a/lib/deploy/firestore/deploy.js b/src/deploy/firestore/deploy.js similarity index 100% rename from lib/deploy/firestore/deploy.js rename to src/deploy/firestore/deploy.js diff --git a/lib/deploy/firestore/index.js b/src/deploy/firestore/index.js similarity index 100% rename from lib/deploy/firestore/index.js rename to src/deploy/firestore/index.js diff --git a/lib/deploy/firestore/prepare.js b/src/deploy/firestore/prepare.js similarity index 100% rename from lib/deploy/firestore/prepare.js rename to src/deploy/firestore/prepare.js diff --git a/lib/deploy/firestore/release.js b/src/deploy/firestore/release.js similarity index 100% rename from lib/deploy/firestore/release.js rename to src/deploy/firestore/release.js diff --git a/lib/deploy/functions/deploy.js b/src/deploy/functions/deploy.js similarity index 100% rename from lib/deploy/functions/deploy.js rename to src/deploy/functions/deploy.js diff --git a/lib/deploy/functions/index.js b/src/deploy/functions/index.js similarity index 100% rename from lib/deploy/functions/index.js rename to src/deploy/functions/index.js diff --git a/lib/deploy/functions/prepare.js b/src/deploy/functions/prepare.js similarity index 100% rename from lib/deploy/functions/prepare.js rename to src/deploy/functions/prepare.js diff --git a/lib/deploy/functions/release.js b/src/deploy/functions/release.js similarity index 100% rename from lib/deploy/functions/release.js rename to src/deploy/functions/release.js diff --git a/lib/deploy/hosting/convertConfig.js b/src/deploy/hosting/convertConfig.js similarity index 100% rename from lib/deploy/hosting/convertConfig.js rename to src/deploy/hosting/convertConfig.js diff --git a/lib/deploy/hosting/deploy.js b/src/deploy/hosting/deploy.js similarity index 98% rename from lib/deploy/hosting/deploy.js rename to src/deploy/hosting/deploy.js index c577dc2c..4cf34d65 100644 --- a/lib/deploy/hosting/deploy.js +++ b/src/deploy/hosting/deploy.js @@ -1,10 +1,10 @@ "use strict"; -var logger = require("../../logger"); -var utils = require("../../utils"); -var track = require("../../track"); -var listFiles = require("../../listFiles"); const Uploader = require("./uploader"); +var { listFiles } = require("../../listFiles"); +var logger = require("../../logger"); +var track = require("../../track"); +var utils = require("../../utils"); var clc = require("cli-color"); var SPINNER = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]; diff --git a/lib/deploy/hosting/hashcache.js b/src/deploy/hosting/hashcache.js similarity index 100% rename from lib/deploy/hosting/hashcache.js rename to src/deploy/hosting/hashcache.js diff --git a/lib/deploy/hosting/index.js b/src/deploy/hosting/index.js similarity index 100% rename from lib/deploy/hosting/index.js rename to src/deploy/hosting/index.js diff --git a/lib/deploy/hosting/prepare.js b/src/deploy/hosting/prepare.js similarity index 100% rename from lib/deploy/hosting/prepare.js rename to src/deploy/hosting/prepare.js diff --git a/lib/deploy/hosting/release.js b/src/deploy/hosting/release.js similarity index 100% rename from lib/deploy/hosting/release.js rename to src/deploy/hosting/release.js diff --git a/lib/deploy/hosting/uploader.js b/src/deploy/hosting/uploader.js similarity index 98% rename from lib/deploy/hosting/uploader.js rename to src/deploy/hosting/uploader.js index a12d86e6..8aa2d9a5 100644 --- a/lib/deploy/hosting/uploader.js +++ b/src/deploy/hosting/uploader.js @@ -26,7 +26,7 @@ function _progressMessage(message, current, total) { "/" + total + "] (" + - clc.bold.green(Math.floor(current * 1.0 / total * 100).toString() + "%") + + clc.bold.green(Math.floor(((current * 1.0) / total) * 100).toString() + "%") + ")" ); } diff --git a/lib/deploy/index.js b/src/deploy/index.js similarity index 100% rename from lib/deploy/index.js rename to src/deploy/index.js diff --git a/lib/deploy/lifecycleHooks.js b/src/deploy/lifecycleHooks.js similarity index 100% rename from lib/deploy/lifecycleHooks.js rename to src/deploy/lifecycleHooks.js diff --git a/lib/deploy/storage/deploy.js b/src/deploy/storage/deploy.js similarity index 100% rename from lib/deploy/storage/deploy.js rename to src/deploy/storage/deploy.js diff --git a/lib/deploy/storage/index.js b/src/deploy/storage/index.js similarity index 100% rename from lib/deploy/storage/index.js rename to src/deploy/storage/index.js diff --git a/lib/deploy/storage/prepare.js b/src/deploy/storage/prepare.js similarity index 100% rename from lib/deploy/storage/prepare.js rename to src/deploy/storage/prepare.js diff --git a/lib/deploy/storage/release.js b/src/deploy/storage/release.js similarity index 100% rename from lib/deploy/storage/release.js rename to src/deploy/storage/release.js diff --git a/lib/deploymentTool.js b/src/deploymentTool.js similarity index 100% rename from lib/deploymentTool.js rename to src/deploymentTool.js diff --git a/lib/detectProjectRoot.js b/src/detectProjectRoot.js similarity index 100% rename from lib/detectProjectRoot.js rename to src/detectProjectRoot.js diff --git a/src/emulator/constants.js b/src/emulator/constants.js new file mode 100644 index 00000000..611cda58 --- /dev/null +++ b/src/emulator/constants.js @@ -0,0 +1,46 @@ +"use strict"; + +var userHome = require("user-home"); +var path = require("path"); + +const CACHE_DIR = + process.env.FIREBASE_EMULATORS_PATH || path.join(userHome, ".cache", "firebase", "emulators"); + +const _emulators = { + database: { + name: "database", + instance: null, + port: 9000, + stdout: null, + cacheDir: CACHE_DIR, + remoteUrl: + "https://storage.googleapis.com/firebase-preview-drop/emulator/firebase-database-emulator-v3.5.0.jar", + localPath: path.join(CACHE_DIR, "firebase-database-emulator-v3.5.0.jar"), + }, + firestore: { + name: "firestore", + instance: null, + port: 8080, + stdout: null, + cacheDir: CACHE_DIR, + remoteUrl: + "https://storage.googleapis.com/firebase-preview-drop/emulator/cloud-firestore-emulator-v1.2.0.jar", + localPath: path.join(CACHE_DIR, "cloud-firestore-emulator-v1.2.0.jar"), + }, +}; + +const _commands = { + database: { + binary: "java", + args: ["-jar", _emulators.database.localPath, "--port", _emulators.database.port], + }, + firestore: { + binary: "java", + args: ["-jar", _emulators.firestore.localPath, "--port", _emulators.firestore.port], + }, +}; + +module.exports = { + emulators: _emulators, + commands: _commands, +}; diff --git a/src/emulator/download.js b/src/emulator/download.js new file mode 100644 index 00000000..2fa59a38 --- /dev/null +++ b/src/emulator/download.js @@ -0,0 +1,23 @@ +"use strict"; + +const fs = require("fs-extra"); +const request = require("request"); +const emulatorConstants = require("./constants"); +const utils = require("../utils"); + +module.exports = name => { + return new Promise((resolve, reject) => { + utils.logLabeledBullet(name, "downloading emulator..."); + let emulator = emulatorConstants.emulators[name]; + fs.ensureDirSync(emulator.cacheDir); + let req = request.get(emulator.remoteUrl); + let writeStream = fs.createWriteStream(emulator.localPath); + req.on("error", err => reject(err)); + req.on("end", () => { + writeStream.close(); + fs.chmodSync(emulator.localPath, 0o755); + resolve(); + }); + req.pipe(writeStream); + }); +}; diff --git a/lib/ensureApiEnabled.js b/src/ensureApiEnabled.js similarity index 100% rename from lib/ensureApiEnabled.js rename to src/ensureApiEnabled.js diff --git a/lib/ensureDefaultCredentials.js b/src/ensureDefaultCredentials.js similarity index 100% rename from lib/ensureDefaultCredentials.js rename to src/ensureDefaultCredentials.js diff --git a/lib/error.js b/src/error.js similarity index 100% rename from lib/error.js rename to src/error.js diff --git a/lib/errorOut.js b/src/errorOut.js similarity index 100% rename from lib/errorOut.js rename to src/errorOut.js diff --git a/lib/extractTriggers.js b/src/extractTriggers.js similarity index 100% rename from lib/extractTriggers.js rename to src/extractTriggers.js diff --git a/lib/fetchMOTD.js b/src/fetchMOTD.js similarity index 100% rename from lib/fetchMOTD.js rename to src/fetchMOTD.js diff --git a/lib/fetchWebSetup.js b/src/fetchWebSetup.js similarity index 100% rename from lib/fetchWebSetup.js rename to src/fetchWebSetup.js diff --git a/lib/filterTargets.js b/src/filterTargets.js similarity index 94% rename from lib/filterTargets.js rename to src/filterTargets.js index 35dad524..cd519e7d 100644 --- a/lib/filterTargets.js +++ b/src/filterTargets.js @@ -1,7 +1,7 @@ "use strict"; var _ = require("lodash"); -var FirebaseError = require("../lib/error"); +var FirebaseError = require("./error"); module.exports = function(options, validTargets) { var targets = validTargets.filter(function(t) { diff --git a/lib/firebaseApi.js b/src/firebaseApi.js similarity index 100% rename from lib/firebaseApi.js rename to src/firebaseApi.js diff --git a/lib/firestore/delete.js b/src/firestore/delete.js similarity index 98% rename from lib/firestore/delete.js rename to src/firestore/delete.js index 7c0c6b19..78385929 100644 --- a/lib/firestore/delete.js +++ b/src/firestore/delete.js @@ -3,11 +3,11 @@ var clc = require("cli-color"); var ProgressBar = require("progress"); -var api = require("../../lib/api"); -var firestore = require("../../lib/gcp/firestore"); -var FirebaseError = require("../../lib/error"); -var logger = require("../../lib/logger"); -var utils = require("../../lib/utils"); +var api = require("../api"); +var firestore = require("../gcp/firestore"); +var FirebaseError = require("../error"); +var logger = require("../logger"); +var utils = require("../utils"); /** * Construct a new Firestore delete operation. diff --git a/lib/firestore/encodeFirestoreValue.js b/src/firestore/encodeFirestoreValue.js similarity index 100% rename from lib/firestore/encodeFirestoreValue.js rename to src/firestore/encodeFirestoreValue.js diff --git a/lib/firestore/indexes.js b/src/firestore/indexes.js similarity index 97% rename from lib/firestore/indexes.js rename to src/firestore/indexes.js index d215f1d3..f47f1e9b 100644 --- a/lib/firestore/indexes.js +++ b/src/firestore/indexes.js @@ -1,9 +1,9 @@ "use strict"; -var api = require("../../lib/api"); +var api = require("../api"); var clc = require("cli-color"); -var FirebaseError = require("../../lib/error"); -var loadCJSON = require("../../lib/loadCJSON"); +var FirebaseError = require("../error"); +var loadCJSON = require("../loadCJSON"); var VALID_INDEX_MODES = ["ASCENDING", "DESCENDING", "ARRAY_CONTAINS"]; diff --git a/lib/fsAsync.js b/src/fsAsync.js similarity index 100% rename from lib/fsAsync.js rename to src/fsAsync.js diff --git a/lib/fsutils.js b/src/fsutils.js similarity index 100% rename from lib/fsutils.js rename to src/fsutils.js diff --git a/lib/functionsConfig.js b/src/functionsConfig.js similarity index 100% rename from lib/functionsConfig.js rename to src/functionsConfig.js diff --git a/lib/functionsConfigClone.js b/src/functionsConfigClone.js similarity index 100% rename from lib/functionsConfigClone.js rename to src/functionsConfigClone.js diff --git a/lib/functionsDelete.js b/src/functionsDelete.js similarity index 100% rename from lib/functionsDelete.js rename to src/functionsDelete.js diff --git a/lib/functionsDeployHelper.js b/src/functionsDeployHelper.js similarity index 100% rename from lib/functionsDeployHelper.js rename to src/functionsDeployHelper.js diff --git a/lib/functionsEmulator.js b/src/functionsEmulator.js similarity index 100% rename from lib/functionsEmulator.js rename to src/functionsEmulator.js diff --git a/lib/functionsShellCommandAction.js b/src/functionsShellCommandAction.js similarity index 91% rename from lib/functionsShellCommandAction.js rename to src/functionsShellCommandAction.js index 93189b7c..6803a00b 100644 --- a/lib/functionsShellCommandAction.js +++ b/src/functionsShellCommandAction.js @@ -6,9 +6,9 @@ var _ = require("lodash"); var request = require("request"); var util = require("util"); -var FunctionsEmulator = require("../lib/functionsEmulator"); -var LocalFunction = require("../lib/localFunction"); -var logger = require("../lib/logger"); +var FunctionsEmulator = require("./functionsEmulator"); +var LocalFunction = require("./localFunction"); +var logger = require("./logger"); module.exports = function(options) { options.port = parseInt(options.port, 10); diff --git a/lib/gcp/cloudfunctions.js b/src/gcp/cloudfunctions.js similarity index 100% rename from lib/gcp/cloudfunctions.js rename to src/gcp/cloudfunctions.js diff --git a/lib/gcp/cloudlogging.js b/src/gcp/cloudlogging.js similarity index 100% rename from lib/gcp/cloudlogging.js rename to src/gcp/cloudlogging.js diff --git a/lib/gcp/firestore.js b/src/gcp/firestore.js similarity index 98% rename from lib/gcp/firestore.js rename to src/gcp/firestore.js index df57ae98..5f31a799 100644 --- a/lib/gcp/firestore.js +++ b/src/gcp/firestore.js @@ -1,6 +1,6 @@ "use strict"; -var api = require("../../lib/api"); +var api = require("../api"); var _API_ROOT = "/v1beta1/"; diff --git a/lib/gcp/index.js b/src/gcp/index.js similarity index 100% rename from lib/gcp/index.js rename to src/gcp/index.js diff --git a/lib/gcp/rules.js b/src/gcp/rules.js similarity index 100% rename from lib/gcp/rules.js rename to src/gcp/rules.js diff --git a/lib/gcp/runtimeconfig.js b/src/gcp/runtimeconfig.js similarity index 100% rename from lib/gcp/runtimeconfig.js rename to src/gcp/runtimeconfig.js diff --git a/lib/gcp/storage.js b/src/gcp/storage.js similarity index 100% rename from lib/gcp/storage.js rename to src/gcp/storage.js diff --git a/lib/getInstanceId.js b/src/getInstanceId.js similarity index 100% rename from lib/getInstanceId.js rename to src/getInstanceId.js diff --git a/lib/getProjectId.js b/src/getProjectId.js similarity index 100% rename from lib/getProjectId.js rename to src/getProjectId.js diff --git a/lib/getProjectNumber.js b/src/getProjectNumber.js similarity index 100% rename from lib/getProjectNumber.js rename to src/getProjectNumber.js diff --git a/lib/handlePreviewToggles.js b/src/handlePreviewToggles.js similarity index 100% rename from lib/handlePreviewToggles.js rename to src/handlePreviewToggles.js diff --git a/lib/hosting/functionsProxy.js b/src/hosting/functionsProxy.js similarity index 100% rename from lib/hosting/functionsProxy.js rename to src/hosting/functionsProxy.js diff --git a/lib/hosting/implicitInit.js b/src/hosting/implicitInit.js similarity index 100% rename from lib/hosting/implicitInit.js rename to src/hosting/implicitInit.js diff --git a/lib/hosting/initMiddleware.js b/src/hosting/initMiddleware.js similarity index 100% rename from lib/hosting/initMiddleware.js rename to src/hosting/initMiddleware.js diff --git a/lib/hosting/normalizedHostingConfigs.js b/src/hosting/normalizedHostingConfigs.js similarity index 100% rename from lib/hosting/normalizedHostingConfigs.js rename to src/hosting/normalizedHostingConfigs.js diff --git a/lib/identifierToProjectId.js b/src/identifierToProjectId.js similarity index 100% rename from lib/identifierToProjectId.js rename to src/identifierToProjectId.js diff --git a/index.js b/src/index.js similarity index 92% rename from index.js rename to src/index.js index 8b33aa44..d02a3b43 100644 --- a/index.js +++ b/src/index.js @@ -1,9 +1,9 @@ "use strict"; var program = require("commander"); -var pkg = require("./package.json"); +var pkg = require("../package.json"); var clc = require("cli-color"); -var logger = require("./lib/logger"); +var logger = require("./logger"); var didYouMean = require("didyoumean"); program.version(pkg.version); @@ -20,9 +20,9 @@ program.option("--debug", "print verbose debug output and keep a debug log file" var client = {}; client.cli = program; -client.logger = require("./lib/logger"); +client.logger = require("./logger"); client.errorOut = function(error, status) { - require("./lib/errorOut")(client, error, status); + require("./errorOut")(client, error, status); }; client.getCommand = function(name) { for (var i = 0; i < client.cli.commands.length; i++) { diff --git a/lib/init/features/database.js b/src/init/features/database.js similarity index 100% rename from lib/init/features/database.js rename to src/init/features/database.js diff --git a/lib/init/features/firestore.js b/src/init/features/firestore.js similarity index 100% rename from lib/init/features/firestore.js rename to src/init/features/firestore.js diff --git a/lib/init/features/functions/index.js b/src/init/features/functions/index.js similarity index 100% rename from lib/init/features/functions/index.js rename to src/init/features/functions/index.js diff --git a/lib/init/features/functions/javascript.js b/src/init/features/functions/javascript.js similarity index 100% rename from lib/init/features/functions/javascript.js rename to src/init/features/functions/javascript.js diff --git a/lib/init/features/functions/npm-dependencies.js b/src/init/features/functions/npm-dependencies.js similarity index 100% rename from lib/init/features/functions/npm-dependencies.js rename to src/init/features/functions/npm-dependencies.js diff --git a/lib/init/features/functions/typescript.js b/src/init/features/functions/typescript.js similarity index 100% rename from lib/init/features/functions/typescript.js rename to src/init/features/functions/typescript.js diff --git a/lib/init/features/hosting.js b/src/init/features/hosting.js similarity index 100% rename from lib/init/features/hosting.js rename to src/init/features/hosting.js diff --git a/lib/init/features/index.js b/src/init/features/index.js similarity index 100% rename from lib/init/features/index.js rename to src/init/features/index.js diff --git a/lib/init/features/project.js b/src/init/features/project.js similarity index 100% rename from lib/init/features/project.js rename to src/init/features/project.js diff --git a/lib/init/features/storage.js b/src/init/features/storage.js similarity index 100% rename from lib/init/features/storage.js rename to src/init/features/storage.js diff --git a/lib/init/index.js b/src/init/index.js similarity index 100% rename from lib/init/index.js rename to src/init/index.js diff --git a/lib/kits/deploy.js b/src/kits/deploy.js similarity index 100% rename from lib/kits/deploy.js rename to src/kits/deploy.js diff --git a/lib/kits/index.js b/src/kits/index.js similarity index 100% rename from lib/kits/index.js rename to src/kits/index.js diff --git a/lib/kits/pollKits.js b/src/kits/pollKits.js similarity index 100% rename from lib/kits/pollKits.js rename to src/kits/pollKits.js diff --git a/lib/kits/prepareKitsConfig.js b/src/kits/prepareKitsConfig.js similarity index 100% rename from lib/kits/prepareKitsConfig.js rename to src/kits/prepareKitsConfig.js diff --git a/lib/kits/prepareKitsUpload.js b/src/kits/prepareKitsUpload.js similarity index 100% rename from lib/kits/prepareKitsUpload.js rename to src/kits/prepareKitsUpload.js diff --git a/lib/listFiles.js b/src/listFiles.ts similarity index 53% rename from lib/listFiles.js rename to src/listFiles.ts index 71804d1f..2c6fd57b 100644 --- a/lib/listFiles.js +++ b/src/listFiles.ts @@ -1,14 +1,12 @@ -"use strict"; +import * as glob from "glob"; -var glob = require("glob").sync; - -module.exports = function(cwd, ignore) { - return glob("**/*", { - cwd: cwd, +export function listFiles(cwd: string, ignore: string[]) { + return glob.sync("**/*", { + cwd, + dot: true, + follow: true, ignore: ["**/firebase-debug.log", ".firebase/*"].concat(ignore || []), nodir: true, nosort: true, - follow: true, - dot: true, }); -}; +} diff --git a/lib/loadCJSON.js b/src/loadCJSON.js similarity index 100% rename from lib/loadCJSON.js rename to src/loadCJSON.js diff --git a/lib/localFunction.js b/src/localFunction.js similarity index 100% rename from lib/localFunction.js rename to src/localFunction.js diff --git a/lib/logError.js b/src/logError.js similarity index 100% rename from lib/logError.js rename to src/logError.js diff --git a/lib/logger.js b/src/logger.js similarity index 100% rename from lib/logger.js rename to src/logger.js diff --git a/lib/parseBoltRules.js b/src/parseBoltRules.js similarity index 100% rename from lib/parseBoltRules.js rename to src/parseBoltRules.js diff --git a/lib/parseTriggers.js b/src/parseTriggers.js similarity index 100% rename from lib/parseTriggers.js rename to src/parseTriggers.js diff --git a/lib/pollOperations.js b/src/pollOperations.js similarity index 100% rename from lib/pollOperations.js rename to src/pollOperations.js diff --git a/lib/prepareFirebaseRules.js b/src/prepareFirebaseRules.js similarity index 100% rename from lib/prepareFirebaseRules.js rename to src/prepareFirebaseRules.js diff --git a/lib/prepareFunctionsUpload.js b/src/prepareFunctionsUpload.js similarity index 100% rename from lib/prepareFunctionsUpload.js rename to src/prepareFunctionsUpload.js diff --git a/lib/prepareUpload.js b/src/prepareUpload.js similarity index 96% rename from lib/prepareUpload.js rename to src/prepareUpload.js index 7c61c4e1..85301921 100644 --- a/lib/prepareUpload.js +++ b/src/prepareUpload.js @@ -6,9 +6,9 @@ var path = require("path"); var tar = require("tar"); var tmp = require("tmp"); +var { listFiles } = require("./listFiles"); var FirebaseError = require("./error"); var fsutils = require("./fsutils"); -var listFiles = require("./listFiles"); module.exports = function(options) { var hostingConfig = options.config.get("hosting"); diff --git a/lib/previews.js b/src/previews.js similarity index 95% rename from lib/previews.js rename to src/previews.js index 6d3795ea..f1751f00 100644 --- a/lib/previews.js +++ b/src/previews.js @@ -7,6 +7,7 @@ var previews = _.assign( { // insert previews here... kits: false, + emulators: false, }, configstore.get("previews") ); diff --git a/lib/profileReport.js b/src/profileReport.js similarity index 98% rename from lib/profileReport.js rename to src/profileReport.js index dc26baf1..1978fd1a 100644 --- a/lib/profileReport.js +++ b/src/profileReport.js @@ -495,7 +495,13 @@ ProfileReport.prototype.outputText = function() { writeTitle(title); write(table.toString() + "\n"); }; - writeTitle("Report operations collected over " + totalTime + " ms."); + writeTitle( + "Report operations collected from " + + new Date(this.state.startTime).toISOString() + + " over " + + totalTime + + " ms." + ); writeTitle("Speed Report\n"); write(SPEED_NOTE + "\n\n"); writeTable("Read Speed", this.renderReadSpeed()); diff --git a/lib/profiler.js b/src/profiler.js similarity index 100% rename from lib/profiler.js rename to src/profiler.js diff --git a/lib/prompt.js b/src/prompt.js similarity index 100% rename from lib/prompt.js rename to src/prompt.js diff --git a/lib/queue.js b/src/queue.js similarity index 100% rename from lib/queue.js rename to src/queue.js diff --git a/lib/rc.js b/src/rc.js similarity index 100% rename from lib/rc.js rename to src/rc.js diff --git a/lib/requireAccess.js b/src/requireAccess.js similarity index 100% rename from lib/requireAccess.js rename to src/requireAccess.js diff --git a/lib/requireAuth.js b/src/requireAuth.js similarity index 100% rename from lib/requireAuth.js rename to src/requireAuth.js diff --git a/lib/requireConfig.js b/src/requireConfig.js similarity index 100% rename from lib/requireConfig.js rename to src/requireConfig.js diff --git a/lib/requireInstance.js b/src/requireInstance.js similarity index 100% rename from lib/requireInstance.js rename to src/requireInstance.js diff --git a/lib/requirePermissions.js b/src/requirePermissions.js similarity index 100% rename from lib/requirePermissions.js rename to src/requirePermissions.js diff --git a/lib/resolveProjectPath.js b/src/resolveProjectPath.js similarity index 100% rename from lib/resolveProjectPath.js rename to src/resolveProjectPath.js diff --git a/lib/responseToError.js b/src/responseToError.js similarity index 100% rename from lib/responseToError.js rename to src/responseToError.js diff --git a/lib/rtdb.js b/src/rtdb.js similarity index 100% rename from lib/rtdb.js rename to src/rtdb.js diff --git a/lib/scopes.js b/src/scopes.js similarity index 100% rename from lib/scopes.js rename to src/scopes.js diff --git a/src/serve/database.js b/src/serve/database.js new file mode 100644 index 00000000..ced2111e --- /dev/null +++ b/src/serve/database.js @@ -0,0 +1,18 @@ +"use strict"; + +var javaEmulators = require("./javaEmulators"); + +const name = "database"; + +function _stop() { + return javaEmulators.stop(name); +} + +function _start() { + return javaEmulators.start(name); +} + +module.exports = { + start: _start, + stop: _stop, +}; diff --git a/src/serve/firestore.js b/src/serve/firestore.js new file mode 100644 index 00000000..4ce95622 --- /dev/null +++ b/src/serve/firestore.js @@ -0,0 +1,18 @@ +"use strict"; + +var javaEmulators = require("./javaEmulators"); + +const name = "firestore"; + +function _stop() { + return javaEmulators.stop(name); +} + +function _start() { + return javaEmulators.start(name); +} + +module.exports = { + start: _start, + stop: _stop, +}; diff --git a/lib/serve/functions.js b/src/serve/functions.js similarity index 100% rename from lib/serve/functions.js rename to src/serve/functions.js diff --git a/lib/serve/hosting.js b/src/serve/hosting.js similarity index 100% rename from lib/serve/hosting.js rename to src/serve/hosting.js diff --git a/lib/serve/index.js b/src/serve/index.js similarity index 84% rename from lib/serve/index.js rename to src/serve/index.js index 42776bae..b8029a82 100644 --- a/lib/serve/index.js +++ b/src/serve/index.js @@ -3,11 +3,18 @@ var _ = require("lodash"); var logger = require("../logger"); +var previews = require("../previews"); + var TARGETS = { hosting: require("./hosting"), functions: require("./functions"), }; +if (previews.emulators) { + TARGETS["database"] = require("./database"); + TARGETS["firestore"] = require("./firestore"); +} + var _serve = function(options) { var targetNames = options.targets; options.port = parseInt(options.port, 10); diff --git a/src/serve/javaEmulators.js b/src/serve/javaEmulators.js new file mode 100644 index 00000000..b34ef78b --- /dev/null +++ b/src/serve/javaEmulators.js @@ -0,0 +1,80 @@ +"use strict"; + +var FirebaseError = require("../error"); +var fs = require("fs-extra"); +var childProcess = require("child_process"); +var utils = require("../utils"); +var emulatorConstants = require("../emulator/constants"); + +function _fatal(emulator, errorMsg) { + if (emulator.instance) { + emulator.instance.kill(1); + } + throw new FirebaseError(emulator.name + ": " + errorMsg, { exit: 1 }); +} + +function _runBinary(emulator, command) { + return new Promise(resolve => { + emulator.stdout = fs.createWriteStream(emulator.name + "-debug.log"); + emulator.instance = childProcess.spawn(command.binary, command.args, { + stdio: ["inherit", "pipe", "pipe"], + }); + emulator.instance.stdout.on("data", data => { + console.log(data.toString()); + emulator.stdout.write(data.toString()); + }); + emulator.instance.stderr.on("data", data => { + utils.logWarning(emulator.name + ": " + data.toString()); + }); + emulator.instance.on("error", err => { + if (err.path == "java" && err.code == "ENOENT") { + _fatal( + emulator, + "emulator has exited because java is not installed, you can install it from https://openjdk.java.net/install/" + ); + } else { + _fatal(emulator, "emulator has exited: " + err); + } + }); + emulator.instance.once("exit", (code, signal) => { + if (signal) { + utils.logLabeledBullet( + emulator.name, + "emulator has exited upon receiving signal: " + signal + ); + } else if (code && code !== 0 && code !== /* SIGINT */ 130) { + _fatal(emulator, "emulator has exited with code: " + code); + } else { + utils.logLabeledBullet(emulator.name, "emulator has exited"); + } + }); + utils.logLabeledSuccess(emulator.name, "started on http://localhost:" + emulator.port); + resolve(); + }); +} + +function _stop(targetName) { + var emulator = emulatorConstants.emulators[targetName]; + return new Promise(function(resolve) { + utils.logLabeledSuccess(emulator.name, "shutting down"); + if (emulator.instance) { + return emulator.instance.kill(0); + } + return resolve(); + }); +} + +function _start(targetName) { + var emulator = emulatorConstants.emulators[targetName]; + var command = emulatorConstants.commands[targetName]; + if (!fs.existsSync(emulator.localPath)) { + utils.logWarning("Setup required, please run: firebase setup:emulators:" + emulator.name); + return Promise.reject("emulator not found"); + } + return _runBinary(emulator, command); +} + +module.exports = { + start: _start, + stop: _stop, +}; diff --git a/test/lib/accountExporter.spec.js b/src/test/accountExporter.spec.js similarity index 97% rename from test/lib/accountExporter.spec.js rename to src/test/accountExporter.spec.js index f886142b..befdd0a8 100644 --- a/test/lib/accountExporter.spec.js +++ b/src/test/accountExporter.spec.js @@ -5,8 +5,8 @@ var nock = require("nock"); var os = require("os"); var sinon = require("sinon"); -var accountExporter = require("../../lib/accountExporter"); -var helpers = require("../helpers"); +var accountExporter = require("../accountExporter"); +var helpers = require("./helpers"); var expect = chai.expect; describe("accountExporter", function() { diff --git a/test/lib/accountImporter.spec.js b/src/test/accountImporter.spec.js similarity index 97% rename from test/lib/accountImporter.spec.js rename to src/test/accountImporter.spec.js index 1e5e735d..2e525a37 100644 --- a/test/lib/accountImporter.spec.js +++ b/src/test/accountImporter.spec.js @@ -2,9 +2,9 @@ var chai = require("chai"); var sinon = require("sinon"); -var api = require("../../lib/api"); -var accountImporter = require("../../lib/accountImporter"); -var helpers = require("../helpers"); +var api = require("../api"); +var accountImporter = require("../accountImporter"); +var helpers = require("./helpers"); var expect = chai.expect; describe("accountImporter", function() { diff --git a/test/lib/command.spec.js b/src/test/command.spec.js similarity index 98% rename from test/lib/command.spec.js rename to src/test/command.spec.js index dec39f34..aed12295 100644 --- a/test/lib/command.spec.js +++ b/src/test/command.spec.js @@ -4,7 +4,7 @@ var chai = require("chai"); var expect = chai.expect; chai.use(require("chai-as-promised")); -var Command = require("../../lib/command"); +var Command = require("../command"); describe("Command", function() { var command; diff --git a/test/lib/config.spec.js b/src/test/config.spec.js similarity index 96% rename from test/lib/config.spec.js rename to src/test/config.spec.js index c637cd2b..03fa1432 100644 --- a/test/lib/config.spec.js +++ b/src/test/config.spec.js @@ -3,11 +3,11 @@ var chai = require("chai"); var expect = chai.expect; -var Config = require("../../lib/config"); +var Config = require("../config"); var path = require("path"); var _fixtureDir = function(name) { - return path.resolve(__dirname, "../fixtures/" + name); + return path.resolve(__dirname, "./fixtures/" + name); }; describe("Config", function() { diff --git a/test/lib/extractTriggers.spec.js b/src/test/extractTriggers.spec.js similarity index 95% rename from test/lib/extractTriggers.spec.js rename to src/test/extractTriggers.spec.js index 4589391c..1f674385 100644 --- a/test/lib/extractTriggers.spec.js +++ b/src/test/extractTriggers.spec.js @@ -3,7 +3,7 @@ var chai = require("chai"); var expect = chai.expect; -var extractTriggers = require("../../lib/extractTriggers"); +var extractTriggers = require("../extractTriggers"); describe("extractTriggers", function() { var fnWithTrigger = function() {}; diff --git a/test/fixtures/config-imports/firebase.json b/src/test/fixtures/config-imports/firebase.json similarity index 100% rename from test/fixtures/config-imports/firebase.json rename to src/test/fixtures/config-imports/firebase.json diff --git a/test/fixtures/config-imports/hosting.json b/src/test/fixtures/config-imports/hosting.json similarity index 100% rename from test/fixtures/config-imports/hosting.json rename to src/test/fixtures/config-imports/hosting.json diff --git a/test/fixtures/config-imports/rules.json b/src/test/fixtures/config-imports/rules.json similarity index 100% rename from test/fixtures/config-imports/rules.json rename to src/test/fixtures/config-imports/rules.json diff --git a/test/fixtures/config-imports/unsupported.txt b/src/test/fixtures/config-imports/unsupported.txt similarity index 100% rename from test/fixtures/config-imports/unsupported.txt rename to src/test/fixtures/config-imports/unsupported.txt diff --git a/test/fixtures/dup-top-level/firebase.json b/src/test/fixtures/dup-top-level/firebase.json similarity index 100% rename from test/fixtures/dup-top-level/firebase.json rename to src/test/fixtures/dup-top-level/firebase.json diff --git a/test/fixtures/dup-top-level/rules.json b/src/test/fixtures/dup-top-level/rules.json similarity index 100% rename from test/fixtures/dup-top-level/rules.json rename to src/test/fixtures/dup-top-level/rules.json diff --git a/test/fixtures/fbrc/.firebaserc b/src/test/fixtures/fbrc/.firebaserc similarity index 100% rename from test/fixtures/fbrc/.firebaserc rename to src/test/fixtures/fbrc/.firebaserc diff --git a/test/fixtures/fbrc/conflict/.firebaserc b/src/test/fixtures/fbrc/conflict/.firebaserc similarity index 100% rename from test/fixtures/fbrc/conflict/.firebaserc rename to src/test/fixtures/fbrc/conflict/.firebaserc diff --git a/test/fixtures/fbrc/firebase.json b/src/test/fixtures/fbrc/firebase.json similarity index 100% rename from test/fixtures/fbrc/firebase.json rename to src/test/fixtures/fbrc/firebase.json diff --git a/test/fixtures/fbrc/invalid/.firebaserc b/src/test/fixtures/fbrc/invalid/.firebaserc similarity index 100% rename from test/fixtures/fbrc/invalid/.firebaserc rename to src/test/fixtures/fbrc/invalid/.firebaserc diff --git a/test/fixtures/fbrc/invalid/firebase.json b/src/test/fixtures/fbrc/invalid/firebase.json similarity index 100% rename from test/fixtures/fbrc/invalid/firebase.json rename to src/test/fixtures/fbrc/invalid/firebase.json diff --git a/test/fixtures/ignores/.hiddenfile b/src/test/fixtures/ignores/.hiddenfile similarity index 100% rename from test/fixtures/ignores/.hiddenfile rename to src/test/fixtures/ignores/.hiddenfile diff --git a/test/fixtures/ignores/firebase.json b/src/test/fixtures/ignores/firebase.json similarity index 100% rename from test/fixtures/ignores/firebase.json rename to src/test/fixtures/ignores/firebase.json diff --git a/test/fixtures/ignores/ignored.txt b/src/test/fixtures/ignores/ignored.txt similarity index 100% rename from test/fixtures/ignores/ignored.txt rename to src/test/fixtures/ignores/ignored.txt diff --git a/test/fixtures/ignores/ignored/deeper/index.txt b/src/test/fixtures/ignores/ignored/deeper/index.txt similarity index 100% rename from test/fixtures/ignores/ignored/deeper/index.txt rename to src/test/fixtures/ignores/ignored/deeper/index.txt diff --git a/test/fixtures/ignores/ignored/ignore.txt b/src/test/fixtures/ignores/ignored/ignore.txt similarity index 100% rename from test/fixtures/ignores/ignored/ignore.txt rename to src/test/fixtures/ignores/ignored/ignore.txt diff --git a/test/fixtures/ignores/ignored/index.html b/src/test/fixtures/ignores/ignored/index.html similarity index 100% rename from test/fixtures/ignores/ignored/index.html rename to src/test/fixtures/ignores/ignored/index.html diff --git a/test/fixtures/ignores/index.html b/src/test/fixtures/ignores/index.html similarity index 100% rename from test/fixtures/ignores/index.html rename to src/test/fixtures/ignores/index.html diff --git a/test/fixtures/ignores/present/index.html b/src/test/fixtures/ignores/present/index.html similarity index 100% rename from test/fixtures/ignores/present/index.html rename to src/test/fixtures/ignores/present/index.html diff --git a/test/fixtures/invalid-config/firebase.json b/src/test/fixtures/invalid-config/firebase.json similarity index 100% rename from test/fixtures/invalid-config/firebase.json rename to src/test/fixtures/invalid-config/firebase.json diff --git a/test/fixtures/profiler-data/sample-output.json b/src/test/fixtures/profiler-data/sample-output.json similarity index 100% rename from test/fixtures/profiler-data/sample-output.json rename to src/test/fixtures/profiler-data/sample-output.json diff --git a/test/fixtures/profiler-data/sample.json b/src/test/fixtures/profiler-data/sample.json similarity index 100% rename from test/fixtures/profiler-data/sample.json rename to src/test/fixtures/profiler-data/sample.json diff --git a/test/fixtures/valid-config/firebase.json b/src/test/fixtures/valid-config/firebase.json similarity index 100% rename from test/fixtures/valid-config/firebase.json rename to src/test/fixtures/valid-config/firebase.json diff --git a/test/lib/fsAsync.spec.js b/src/test/fsAsync.spec.js similarity index 98% rename from test/lib/fsAsync.spec.js rename to src/test/fsAsync.spec.js index f7c6d2de..0acea062 100644 --- a/test/lib/fsAsync.spec.js +++ b/src/test/fsAsync.spec.js @@ -5,7 +5,7 @@ var fs = require("fs"); var os = require("os"); var path = require("path"); -var fsAsync = require("../../lib/fsAsync"); +var fsAsync = require("../fsAsync"); var chai = require("chai"); var chaiAsPromised = require("chai-as-promised"); diff --git a/test/lib/functionsConfig.spec.js b/src/test/functionsConfig.spec.js similarity index 95% rename from test/lib/functionsConfig.spec.js rename to src/test/functionsConfig.spec.js index 3c5aabff..2d655b6d 100644 --- a/test/lib/functionsConfig.spec.js +++ b/src/test/functionsConfig.spec.js @@ -3,7 +3,7 @@ var chai = require("chai"); var expect = chai.expect; -var functionsConfig = require("../../lib/functionsConfig"); +var functionsConfig = require("../functionsConfig"); describe("config.parseSetArgs", function() { it("should throw if a reserved namespace is used", function() { diff --git a/test/lib/functionsDeployHelper.spec.js b/src/test/functionsDeployHelper.spec.js similarity index 98% rename from test/lib/functionsDeployHelper.spec.js rename to src/test/functionsDeployHelper.spec.js index 742d3e01..3360df92 100644 --- a/test/lib/functionsDeployHelper.spec.js +++ b/src/test/functionsDeployHelper.spec.js @@ -3,7 +3,7 @@ var chai = require("chai"); var expect = chai.expect; -var helper = require("../../lib/functionsDeployHelper"); +var helper = require("../functionsDeployHelper"); describe("functionsDeployHelper", function() { describe("getFilterGroups", function() { diff --git a/test/helpers/index.js b/src/test/helpers/index.js similarity index 84% rename from test/helpers/index.js rename to src/test/helpers/index.js index 4bb36214..b59d243b 100644 --- a/test/helpers/index.js +++ b/src/test/helpers/index.js @@ -1,6 +1,6 @@ "use strict"; -var auth = require("../../lib/auth"); +var auth = require("../../auth"); exports.mockAuth = function(sandbox) { var authMock = sandbox.mock(auth); diff --git a/test/lib/identifierToProjectId.spec.js b/src/test/identifierToProjectId.spec.js similarity index 88% rename from test/lib/identifierToProjectId.spec.js rename to src/test/identifierToProjectId.spec.js index 7f94de92..ada90cbf 100644 --- a/test/lib/identifierToProjectId.spec.js +++ b/src/test/identifierToProjectId.spec.js @@ -5,9 +5,9 @@ chai.use(require("chai-as-promised")); var expect = chai.expect; var sinon = require("sinon"); -var helpers = require("../helpers"); -var identifierToProjectId = require("../../lib/identifierToProjectId"); -var api = require("../../lib/api"); +var helpers = require("./helpers"); +var identifierToProjectId = require("../identifierToProjectId"); +var api = require("../api"); describe("identifierToProjectId", function() { var sandbox; diff --git a/src/test/listFiles.spec.ts b/src/test/listFiles.spec.ts new file mode 100644 index 00000000..950b3bb3 --- /dev/null +++ b/src/test/listFiles.spec.ts @@ -0,0 +1,18 @@ +import { expect } from "chai"; + +import * as path from "path"; + +import { listFiles } from "../listFiles"; + +describe("listFiles", () => { + // for details, see the file structure and firebase.json in test/fixtures/ignores + it("should ignore firebase-debug.log, specified ignores, and nothing else", () => { + const fileNames = listFiles(path.resolve(__dirname, "./fixtures/ignores"), [ + "**/.*", + "firebase.json", + "ignored.txt", + "ignored/**/*.txt", + ]); + expect(fileNames).to.deep.equal(["index.html", "ignored/index.html", "present/index.html"]); + }); +}); diff --git a/test/lib/localFunction.spec.js b/src/test/localFunction.spec.js similarity index 97% rename from test/lib/localFunction.spec.js rename to src/test/localFunction.spec.js index 9f0281bc..3dc6eb6a 100644 --- a/test/lib/localFunction.spec.js +++ b/src/test/localFunction.spec.js @@ -3,7 +3,7 @@ var chai = require("chai"); var expect = chai.expect; -var LocalFunction = require("../../lib/localFunction"); +var LocalFunction = require("../localFunction"); describe("localFunction._constructAuth", function() { var lf = new LocalFunction({}); diff --git a/test/lib/profilerReport.spec.js b/src/test/profilerReport.spec.js similarity index 96% rename from test/lib/profilerReport.spec.js rename to src/test/profilerReport.spec.js index cb2f20dc..3b4a4305 100644 --- a/test/lib/profilerReport.spec.js +++ b/src/test/profilerReport.spec.js @@ -4,7 +4,7 @@ var chai = require("chai"); var path = require("path"); var stream = require("stream"); -var ProfileReport = require("../../lib/profileReport"); +var ProfileReport = require("../profileReport"); chai.use(require("chai-as-promised")); var expect = chai.expect; @@ -13,7 +13,7 @@ var combinerFunc = function(obj1, obj2) { return { count: obj1.count + obj2.count }; }; -var fixturesDir = path.resolve(__dirname, "../fixtures"); +var fixturesDir = path.resolve(__dirname, "./fixtures"); var newReport = function() { var input = path.resolve(fixturesDir, "profiler-data/sample.json"); diff --git a/test/lib/rc.spec.js b/src/test/rc.spec.js similarity index 98% rename from test/lib/rc.spec.js rename to src/test/rc.spec.js index 56490d80..8aa6cb18 100644 --- a/test/lib/rc.spec.js +++ b/src/test/rc.spec.js @@ -4,9 +4,9 @@ var chai = require("chai"); var expect = chai.expect; var path = require("path"); -var RC = require("../../lib/rc"); +var RC = require("../rc"); -var fixturesDir = path.resolve(__dirname, "../fixtures"); +var fixturesDir = path.resolve(__dirname, "./fixtures"); describe("RC", function() { describe(".load", function() { diff --git a/lib/track.js b/src/track.js similarity index 100% rename from lib/track.js rename to src/track.js diff --git a/lib/triggerParser.js b/src/triggerParser.js similarity index 100% rename from lib/triggerParser.js rename to src/triggerParser.js diff --git a/lib/utils.js b/src/utils.js similarity index 100% rename from lib/utils.js rename to src/utils.js diff --git a/lib/validateJsonRules.js b/src/validateJsonRules.js similarity index 100% rename from lib/validateJsonRules.js rename to src/validateJsonRules.js diff --git a/lib/validator.js b/src/validator.js similarity index 100% rename from lib/validator.js rename to src/validator.js diff --git a/test/lib/listFiles.spec.js b/test/lib/listFiles.spec.js deleted file mode 100644 index 0cf4c3ae..00000000 --- a/test/lib/listFiles.spec.js +++ /dev/null @@ -1,22 +0,0 @@ -"use strict"; - -var chai = require("chai"); -var expect = chai.expect; - -var path = require("path"); - -var listFiles = require("../../lib/listFiles"); - -describe("listFiles", function() { - // for details, see the file structure and firebase.json in test/fixtures/ignores - it("should ignore firebase-debug.log, specified ignores, and nothing else", function() { - expect( - listFiles(path.resolve(__dirname, "../fixtures/ignores"), [ - "**/.*", - "firebase.json", - "ignored.txt", - "ignored/**/*.txt", - ]) - ).to.deep.equal(["index.html", "ignored/index.html", "present/index.html"]); - }); -}); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..48f5813a --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "allowJs": true, + "checkJs": false, + "module": "commonjs", + "strict": true, + "outDir": "lib", + "removeComments": true, + "sourceMap": true, + "target": "ES5" + }, + "include": [ + "src/**/*" + ], + "exclude": [ + "src/test/**/*" + ] +} diff --git a/tslint.json b/tslint.json new file mode 100644 index 00000000..fe1a8d80 --- /dev/null +++ b/tslint.json @@ -0,0 +1,19 @@ +{ + "defaultSeverity": "error", + "extends": [ + "tslint:recommended" + ], + "jsRules": {}, + "rules": { + "prettier": true + }, + "rulesDirectory": [ + "tslint-plugin-prettier" + ], + "linterOptions": { + "exclude": [ + "**/node_modules/**", + "**/*.js" + ] + } +}