MCPcopy Create free account
hub / github.com/zenstackhq/zenstack / run

Function run

packages/cli/src/actions/init.ts:13–62  ·  view source on GitHub ↗
(projectPath: string)

Source from the content-addressed store, hash-verified

11 * CLI action for getting information about installed ZenStack packages
12 */
13export async function run(projectPath: string) {
14 const packages = [
15 { name: '@zenstackhq/cli@latest', dev: true },
16 { name: '@zenstackhq/schema@latest', dev: false },
17 { name: '@zenstackhq/orm@latest', dev: false },
18 ];
19 let pm = await detect();
20 if (!pm) {
21 pm = { agent: 'npm', name: 'npm' };
22 }
23
24 console.log(colors.gray(`Using package manager: ${pm.agent}`));
25
26 for (const pkg of packages) {
27 const resolved = resolveCommand(pm.agent, 'add', [
28 pkg.name,
29 ...(pkg.dev ? [pm.agent.startsWith('yarn') || pm.agent === 'bun' ? '--dev' : '--save-dev'] : []),
30 ]);
31 if (!resolved) {
32 throw new CliError(`Unable to determine how to install package "${pkg.name}". Please install it manually.`);
33 }
34
35 const spinner = ora(`Installing "${pkg.name}"`).start();
36 try {
37 execSync(`${resolved.command} ${resolved.args.join(' ')}`, {
38 cwd: projectPath,
39 });
40 spinner.succeed();
41 } catch (e) {
42 spinner.fail();
43 throw e;
44 }
45 }
46
47 const generationFolder = 'zenstack';
48
49 if (!fs.existsSync(path.join(projectPath, generationFolder))) {
50 fs.mkdirSync(path.join(projectPath, generationFolder));
51 }
52
53 if (!fs.existsSync(path.join(projectPath, generationFolder, 'schema.zmodel'))) {
54 fs.writeFileSync(path.join(projectPath, generationFolder, 'schema.zmodel'), STARTER_ZMODEL);
55 } else {
56 console.log(colors.yellow('Schema file already exists. Skipping generation of sample.'));
57 }
58
59 console.log(colors.green('ZenStack project initialized successfully!'));
60 console.log(colors.gray(`See "${generationFolder}/schema.zmodel" for your database schema.`));
61 console.log(colors.gray('Run `zenstack generate` to compile the the schema into a TypeScript file.'));
62}

Callers

nothing calls this directly

Calls 2

execSyncFunction · 0.90
logMethod · 0.65

Tested by

no test coverage detected