UNPKG

@blitzjs/cli

Version:
44 lines (43 loc) 1.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hook = void 0; const tslib_1 = require("tslib"); const chalk_1 = (0, tslib_1.__importDefault)(require("chalk")); const is_blitz_root_1 = require("./utils/is-blitz-root"); const commandAllowListGlobal = [ "-h", "--help", "help", "new", "autocomplete", "autocomplete:script", ]; const argumentAllowListGlobal = ["-h", "--help", "help"]; const hook = function (options) { return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { const { argv, id } = options; if (argv.length > 0 && argumentAllowListGlobal.some((arg) => argv.includes(arg))) return; if (id && commandAllowListGlobal.includes(id)) return; if (id === "db" && argv.length === 0) return; const { err, message, depth } = yield (0, is_blitz_root_1.isBlitzRoot)(); if (err) { switch (message) { case is_blitz_root_1.IsBlitzRootError.NotBlitz: return this.error(`You are not inside a Blitz project, so this command won't work.\nYou can create a new app with ${chalk_1.default.bold("blitz new myapp")} or see help with ${chalk_1.default.bold("blitz help")}`); case is_blitz_root_1.IsBlitzRootError.NotRoot: const help = depth ? `\nUse ${chalk_1.default.bold("cd " + "../".repeat(depth))} to get to the root of your project` : ""; return this.error(`You are currently in a sub-folder of your Blitz app, but this command must be used from the root of your project.${help}`); case is_blitz_root_1.IsBlitzRootError.BadPackageJson: return this.error(`Reading package.json file`); default: return this.error(`An error occurred`); } } }); }; exports.hook = hook;