zenstack
Version:
FullStack enhancement for Prisma ORM: seamless integration from database to UI
160 lines • 8.87 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
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.checkAction = exports.formatAction = exports.replAction = exports.generateAction = exports.infoAction = exports.initAction = void 0;
exports.createProgram = createProgram;
exports.default = default_1;
/* eslint-disable @typescript-eslint/no-explicit-any */
const module_1 = require("@zenstackhq/language/module");
const colors_1 = __importDefault(require("colors"));
const commander_1 = require("commander");
const fs_1 = __importDefault(require("fs"));
const telemetry_1 = __importDefault(require("../telemetry"));
const version_utils_1 = require("../utils/version-utils");
const actions = __importStar(require("./actions"));
const config_1 = require("./config");
const DEFAULT_CONFIG_FILE = 'zenstack.config.json';
const initAction = (projectPath, options) => __awaiter(void 0, void 0, void 0, function* () {
yield telemetry_1.default.trackSpan('cli:command:start', 'cli:command:complete', 'cli:command:error', { command: 'init' }, () => actions.init(projectPath, options));
});
exports.initAction = initAction;
const infoAction = (projectPath) => __awaiter(void 0, void 0, void 0, function* () {
yield telemetry_1.default.trackSpan('cli:command:start', 'cli:command:complete', 'cli:command:error', { command: 'info' }, () => actions.info(projectPath));
});
exports.infoAction = infoAction;
const generateAction = (options) => __awaiter(void 0, void 0, void 0, function* () {
yield telemetry_1.default.trackSpan('cli:command:start', 'cli:command:complete', 'cli:command:error', { command: 'generate' }, () => actions.generate(process.cwd(), options));
});
exports.generateAction = generateAction;
const replAction = (options) => __awaiter(void 0, void 0, void 0, function* () {
yield telemetry_1.default.trackSpan('cli:command:start', 'cli:command:complete', 'cli:command:error', { command: 'repl' }, () => actions.repl(process.cwd(), options));
});
exports.replAction = replAction;
const formatAction = (options) => __awaiter(void 0, void 0, void 0, function* () {
yield telemetry_1.default.trackSpan('cli:command:start', 'cli:command:complete', 'cli:command:error', { command: 'format' }, () => actions.format(process.cwd(), options));
});
exports.formatAction = formatAction;
const checkAction = (options) => __awaiter(void 0, void 0, void 0, function* () {
yield telemetry_1.default.trackSpan('cli:command:start', 'cli:command:complete', 'cli:command:error', { command: 'check' }, () => actions.check(process.cwd(), options));
});
exports.checkAction = checkAction;
function createProgram() {
const program = new commander_1.Command('zenstack');
program.version((0, version_utils_1.getVersion)(), '-v --version', 'display CLI version');
const schemaExtensions = module_1.ZModelLanguageMetaData.fileExtensions.join(', ');
program
.description(`${colors_1.default.bold.blue('ζ')} ZenStack is a Prisma power pack for building full-stack apps.\n\nDocumentation: https://zenstack.dev.`)
.showHelpAfterError()
.showSuggestionAfterError();
const schemaOption = new commander_1.Option('--schema <file>', `schema file (with extension ${schemaExtensions}). Defaults to "schema.zmodel" unless specified in package.json.`);
const pmOption = new commander_1.Option('-p, --package-manager <pm>', 'package manager to use').choices([
'npm',
'yarn',
'pnpm',
]);
const noVersionCheckOption = new commander_1.Option('--no-version-check', 'do not check for new version');
const noDependencyCheckOption = new commander_1.Option('--no-dependency-check', 'do not check if dependencies are installed');
const offlineOption = new commander_1.Option('--offline', 'run in offline mode');
program
.command('info')
.description('Get information of installed ZenStack and related packages.')
.argument('[path]', 'project path', '.')
.action(exports.infoAction);
program
.command('init')
.description('Initialize an existing project for ZenStack.')
.addOption(pmOption)
.addOption(new commander_1.Option('--prisma <file>', 'location of Prisma schema file to bootstrap from'))
.addOption(new commander_1.Option('--tag <tag>', 'the NPM package tag to use when installing dependencies'))
.addOption(noVersionCheckOption)
.argument('[path]', 'project path', '.')
.action(exports.initAction);
program
.command('generate')
.description('Run code generation.')
.addOption(schemaOption)
.addOption(new commander_1.Option('-o, --output <path>', 'default output directory for core plugins'))
.addOption(new commander_1.Option('--with-plugins <plugins...>', 'only run specific plugins'))
.addOption(new commander_1.Option('--without-plugins <plugins...>', 'exclude specific plugins'))
.addOption(new commander_1.Option('--no-default-plugins', 'do not run default plugins'))
.addOption(new commander_1.Option('--no-compile', 'do not compile the output of core plugins'))
.addOption(noVersionCheckOption)
.addOption(noDependencyCheckOption)
.addOption(offlineOption)
.action(exports.generateAction);
program
.command('repl')
.description('Start a REPL session.')
.option('--load-path <path>', 'path to load modules generated by ZenStack')
.option('--prisma-client <path>', 'path to Prisma client module')
.option('--debug', 'enable debug output')
.option('--table', 'enable table format output')
.action(exports.replAction);
program
.command('format')
.description('Format a ZenStack schema file.')
.addOption(schemaOption)
.option('--no-prisma-style', 'do not use prisma style')
.action(exports.formatAction);
program
.command('check')
.description('Check a ZenStack schema file for syntax or semantic errors.')
.addOption(schemaOption)
.action(exports.checkAction);
// make sure config is loaded before actions run
program.hook('preAction', (_, actionCommand) => __awaiter(this, void 0, void 0, function* () {
let configFile = actionCommand.opts().config;
if (!configFile && fs_1.default.existsSync(DEFAULT_CONFIG_FILE)) {
configFile = DEFAULT_CONFIG_FILE;
}
if (configFile) {
(0, config_1.loadConfig)(configFile);
}
}));
return program;
}
function default_1() {
return __awaiter(this, void 0, void 0, function* () {
yield telemetry_1.default.trackSpan('cli:start', 'cli:complete', 'cli:error', { args: process.argv }, () => __awaiter(this, void 0, void 0, function* () {
const program = createProgram();
// handle errors explicitly to ensure telemetry
program.exitOverride();
yield program.parseAsync(process.argv);
}));
});
}
//# sourceMappingURL=index.js.map
;