zenstack
Version:
FullStack enhancement for Prisma ORM: seamless integration from database to UI
45 lines • 2.28 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.format = format;
const runtime_1 = require("@zenstackhq/runtime");
const colors_1 = __importDefault(require("colors"));
const fs_1 = __importDefault(require("fs"));
const promises_1 = require("fs/promises");
const ora_1 = __importDefault(require("ora"));
const cli_error_1 = require("../cli-error");
const cli_util_1 = require("../cli-util");
function format(_projectPath, options) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
const version = (0, runtime_1.getVersion)();
console.log(colors_1.default.bold(`⌛️ ZenStack CLI v${version}`));
const schemaFile = (_a = options.schema) !== null && _a !== void 0 ? _a : (0, cli_util_1.getDefaultSchemaLocation)();
if (!fs_1.default.existsSync(schemaFile)) {
console.error(colors_1.default.red(`File ${schemaFile} does not exist.`));
throw new cli_error_1.CliError('schema file does not exist');
}
const spinner = (0, ora_1.default)(`Formatting ${schemaFile}`).start();
try {
const formattedDoc = yield (0, cli_util_1.formatDocument)(schemaFile, options.prismaStyle);
yield (0, promises_1.writeFile)(schemaFile, formattedDoc);
spinner.succeed();
}
catch (e) {
spinner.fail();
throw e;
}
});
}
//# sourceMappingURL=format.js.map
;