zenstack 0.3.11 → 0.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/post-install.js +20 -0
- package/bundle/cli/index.js +81 -80
- package/package.json +5 -4
- package/src/cli/cli-util.ts +17 -7
- package/src/cli/index.ts +13 -7
- package/src/utils/pkg-utils.ts +4 -4
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publisher": "zenstack",
|
|
4
4
|
"displayName": "ZenStack Language Tools",
|
|
5
5
|
"description": "A toolkit for modeling data and access policies in full-stack development with Next.js and Typescript",
|
|
6
|
-
"version": "0.3.
|
|
6
|
+
"version": "0.3.13",
|
|
7
7
|
"author": {
|
|
8
8
|
"name": "ZenStack Team"
|
|
9
9
|
},
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
},
|
|
66
66
|
"main": "./bundle/extension.js",
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@zenstackhq/runtime": "0.3.
|
|
68
|
+
"@zenstackhq/runtime": "0.3.13",
|
|
69
69
|
"async-exit-hook": "^2.0.1",
|
|
70
70
|
"change-case": "^4.1.2",
|
|
71
71
|
"chevrotain": "^9.1.0",
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
"vscode:prepublish": "cp ../../README.md ./ && pnpm lint && pnpm build",
|
|
119
119
|
"vscode:package": "vsce package --no-dependencies",
|
|
120
120
|
"clean": "rimraf bundle",
|
|
121
|
-
"build": "pnpm langium:generate && tsc --noEmit && pnpm bundle && cp -r src/res/* bundle/res/",
|
|
121
|
+
"build": "pnpm -C ../runtime build && pnpm langium:generate && tsc --noEmit && pnpm bundle && cp -r src/res/* bundle/res/",
|
|
122
122
|
"bundle": "npm run clean && node build/bundle.js --minify",
|
|
123
123
|
"bundle-watch": "node build/bundle.js --watch",
|
|
124
124
|
"ts:watch": "tsc --watch --noEmit",
|
|
@@ -127,6 +127,7 @@
|
|
|
127
127
|
"langium:generate": "langium generate",
|
|
128
128
|
"langium:watch": "langium generate --watch",
|
|
129
129
|
"watch": "concurrently --kill-others \"npm:langium:watch\" \"npm:bundle-watch\"",
|
|
130
|
-
"test": "jest"
|
|
130
|
+
"test": "jest",
|
|
131
|
+
"postinstall": "bin/post-install.js"
|
|
131
132
|
}
|
|
132
133
|
}
|
package/src/cli/cli-util.ts
CHANGED
|
@@ -6,7 +6,7 @@ import fs from 'fs';
|
|
|
6
6
|
import { LangiumServices } from 'langium';
|
|
7
7
|
import { NodeFileSystem } from 'langium/node';
|
|
8
8
|
import path from 'path';
|
|
9
|
-
import { installPackage } from '
|
|
9
|
+
import { installPackage, PackageManagers } from '../utils/pkg-utils';
|
|
10
10
|
import { URI } from 'vscode-uri';
|
|
11
11
|
import { ZenStackGenerator } from '../generator';
|
|
12
12
|
import { GENERATED_CODE_PATH } from '../generator/constants';
|
|
@@ -16,7 +16,15 @@ import { CliError } from './cli-error';
|
|
|
16
16
|
/**
|
|
17
17
|
* Initializes an existing project for ZenStack
|
|
18
18
|
*/
|
|
19
|
-
export async function initProject(
|
|
19
|
+
export async function initProject(
|
|
20
|
+
projectPath: string,
|
|
21
|
+
packageManager: PackageManagers | undefined
|
|
22
|
+
) {
|
|
23
|
+
if (!fs.existsSync(projectPath)) {
|
|
24
|
+
console.error(`Path does not exist: ${projectPath}`);
|
|
25
|
+
throw new CliError('project path does not exist');
|
|
26
|
+
}
|
|
27
|
+
|
|
20
28
|
const schema = path.join(projectPath, 'zenstack', 'schema.zmodel');
|
|
21
29
|
let schemaGenerated = false;
|
|
22
30
|
|
|
@@ -96,16 +104,18 @@ model Post {
|
|
|
96
104
|
schemaGenerated = true;
|
|
97
105
|
}
|
|
98
106
|
|
|
99
|
-
installPackage('zenstack', true,
|
|
100
|
-
installPackage('@zenstackhq/runtime', false,
|
|
107
|
+
installPackage('zenstack', true, packageManager, projectPath);
|
|
108
|
+
installPackage('@zenstackhq/runtime', false, packageManager, projectPath);
|
|
101
109
|
|
|
102
110
|
if (schemaGenerated) {
|
|
103
|
-
console.log(`Sample model generated at: ${colors.
|
|
111
|
+
console.log(`Sample model generated at: ${colors.blue(schema)}
|
|
104
112
|
|
|
105
113
|
Please check the following guide on how to model your app:
|
|
106
114
|
https://zenstack.dev/#/modeling-your-app.
|
|
107
|
-
|
|
115
|
+
`);
|
|
108
116
|
}
|
|
117
|
+
|
|
118
|
+
console.log(colors.green('\nProject initialized successfully!'));
|
|
109
119
|
}
|
|
110
120
|
|
|
111
121
|
/**
|
|
@@ -173,7 +183,7 @@ export async function loadDocument(
|
|
|
173
183
|
}
|
|
174
184
|
|
|
175
185
|
export async function runGenerator(
|
|
176
|
-
options: { schema: string; packageManager:
|
|
186
|
+
options: { schema: string; packageManager: PackageManagers | undefined },
|
|
177
187
|
includedGenerators?: string[],
|
|
178
188
|
clearOutput = true
|
|
179
189
|
) {
|
package/src/cli/index.ts
CHANGED
|
@@ -3,25 +3,31 @@ import { paramCase } from 'change-case';
|
|
|
3
3
|
import colors from 'colors';
|
|
4
4
|
import { Command, Option } from 'commander';
|
|
5
5
|
import path from 'path';
|
|
6
|
+
import { PackageManagers } from '../utils/pkg-utils';
|
|
6
7
|
import { ZModelLanguageMetaData } from '../language-server/generated/module';
|
|
7
8
|
import telemetry from '../telemetry';
|
|
8
9
|
import { execSync } from '../utils/exec-utils';
|
|
9
10
|
import { CliError } from './cli-error';
|
|
10
11
|
import { initProject, runGenerator } from './cli-util';
|
|
11
12
|
|
|
12
|
-
export const initAction = async (
|
|
13
|
+
export const initAction = async (
|
|
14
|
+
projectPath: string,
|
|
15
|
+
options: {
|
|
16
|
+
packageManager: PackageManagers | undefined;
|
|
17
|
+
}
|
|
18
|
+
): Promise<void> => {
|
|
13
19
|
await telemetry.trackSpan(
|
|
14
20
|
'cli:command:start',
|
|
15
21
|
'cli:command:complete',
|
|
16
22
|
'cli:command:error',
|
|
17
23
|
{ command: 'init' },
|
|
18
|
-
() => initProject(projectPath)
|
|
24
|
+
() => initProject(projectPath, options.packageManager)
|
|
19
25
|
);
|
|
20
26
|
};
|
|
21
27
|
|
|
22
28
|
export const generateAction = async (options: {
|
|
23
29
|
schema: string;
|
|
24
|
-
packageManager:
|
|
30
|
+
packageManager: PackageManagers | undefined;
|
|
25
31
|
}): Promise<void> => {
|
|
26
32
|
await telemetry.trackSpan(
|
|
27
33
|
'cli:command:start',
|
|
@@ -118,9 +124,9 @@ export default async function (): Promise<void> {
|
|
|
118
124
|
).default('./zenstack/schema.zmodel');
|
|
119
125
|
|
|
120
126
|
const pmOption = new Option(
|
|
121
|
-
'--package-manager
|
|
122
|
-
'package manager to use
|
|
123
|
-
).
|
|
127
|
+
'-p, --package-manager <pm>',
|
|
128
|
+
'package manager to use'
|
|
129
|
+
).choices(['npm', 'yarn', 'pnpm']);
|
|
124
130
|
|
|
125
131
|
//#region wraps Prisma commands
|
|
126
132
|
|
|
@@ -128,7 +134,7 @@ export default async function (): Promise<void> {
|
|
|
128
134
|
.command('init')
|
|
129
135
|
.description('Set up a new ZenStack project.')
|
|
130
136
|
.addOption(pmOption)
|
|
131
|
-
.argument('
|
|
137
|
+
.argument('[path]', 'project path', '.')
|
|
132
138
|
.action(initAction);
|
|
133
139
|
|
|
134
140
|
program
|
package/src/utils/pkg-utils.ts
CHANGED
|
@@ -2,7 +2,7 @@ import fs from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { execSync } from './exec-utils';
|
|
4
4
|
|
|
5
|
-
type PackageManagers = 'npm' | 'yarn' | 'pnpm';
|
|
5
|
+
export type PackageManagers = 'npm' | 'yarn' | 'pnpm';
|
|
6
6
|
|
|
7
7
|
function getPackageManager(projectPath = '.'): PackageManagers {
|
|
8
8
|
if (fs.existsSync(path.join(projectPath, 'yarn.lock'))) {
|
|
@@ -25,9 +25,9 @@ export function installPackage(
|
|
|
25
25
|
switch (manager) {
|
|
26
26
|
case 'yarn':
|
|
27
27
|
execSync(
|
|
28
|
-
`yarn
|
|
29
|
-
dev ? ' --
|
|
30
|
-
}
|
|
28
|
+
`yarn --cwd "${projectPath}" add ${pkg} ${
|
|
29
|
+
dev ? ' --dev' : ''
|
|
30
|
+
} --ignore-engines`
|
|
31
31
|
);
|
|
32
32
|
break;
|
|
33
33
|
|