Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

name: CI

env:
TELEMETRY_TRACKING_TOKEN: ${{ secrets.TELEMETRY_TRACKING_TOKEN }}

on:
push:
branches: ['dev', 'main']
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ export const getServerSideProps: GetServerSideProps = async () => {

### [Setting up logging](/docs/ref/setup-logging.md)

### [Telemetry](/docs/ref/telemetry.md)

## Reach out to us for issues, feedback and ideas!

[Discord](https://go.zenstack.dev/chat) | [Twitter](https://twitter.com/zenstackhq) |
Expand Down
21 changes: 21 additions & 0 deletions docs/ref/telemetry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Telemetry

ZenStack CLI and VSCode extension sends anonymous telemetry for analyzing usage stats and finding bugs.

The information collected includes:

- OS
- Node.js version
- CLI version
- CLI command and arguments
- CLI errors
- Duration of command run
- Region (based on IP)

We don't collect any telemetry at the runtime of apps using ZenStack.

We appreciate that you keep the telemetry ON so we can keep improving the toolkit. We follow the [Console Do Not Track](https://consoledonottrack.com/) convention, and you can turn off the telemetry by setting environment variable `DO_NOT_TRACK` to `1`:

```bash
DO_NOT_TRACK=1 npx zenstack ...
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zenstack-monorepo",
"version": "0.3.4",
"version": "0.3.7",
"description": "",
"scripts": {
"build": "pnpm -r build",
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/internal",
"version": "0.3.4",
"version": "0.3.7",
"displayName": "ZenStack Internal Library",
"description": "ZenStack internal runtime library. This package is for supporting runtime functionality of ZenStack and not supposed to be used directly.",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/runtime",
"displayName": "ZenStack Runtime Library",
"version": "0.3.4",
"version": "0.3.7",
"description": "This package contains runtime library for consuming client and server side code generated by ZenStack.",
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions packages/schema/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TELEMETRY_TRACKING_TOKEN=
2 changes: 2 additions & 0 deletions packages/schema/build/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const watch = process.argv.includes('--watch');
const minify = process.argv.includes('--minify');
const success = watch ? 'Watch build succeeded' : 'Build succeeded';
const fs = require('fs');
const envFilePlugin = require('./env-plugin');

require('esbuild')
.build({
Expand All @@ -24,6 +25,7 @@ require('esbuild')
}
: false,
minify,
plugins: [envFilePlugin],
})
.then(() => {
fs.cpSync('./src/res', 'bundle/res', { force: true, recursive: true });
Expand Down
60 changes: 60 additions & 0 deletions packages/schema/build/env-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// from: https://github.com/rw3iss/esbuild-envfile-plugin

const path = require('path');
const fs = require('fs');

const ENV = process.env.NODE_ENV || 'development';

module.exports = {
name: 'env',

setup(build) {
function _findEnvFile(dir) {
if (!fs.existsSync(dir)) return undefined;

if (fs.existsSync(`${dir}/.env.${ENV}`)) {
return `${dir}/.env.${ENV}`;
} else if (fs.existsSync(`${dir}/.env`)) {
return `${dir}/.env`;
} else {
const next = path.resolve(dir, '../');
if (next === dir) {
// at root now, exit
return undefined;
} else {
return _findEnvFile(next);
}
}
}

build.onResolve({ filter: /^env$/ }, async (args) => {
const envPath = _findEnvFile(args.resolveDir);
return {
path: args.path,
namespace: 'env-ns',
pluginData: {
...args.pluginData,
envPath,
},
};
});

build.onLoad({ filter: /.*/, namespace: 'env-ns' }, async (args) => {
// read in .env file contents and combine with regular .env:
let config = {};
if (args.pluginData && args.pluginData.envPath) {
let data = await fs.promises.readFile(
args.pluginData.envPath,
'utf8'
);
const buf = Buffer.from(data);
config = require('dotenv').parse(buf);
}

return {
contents: JSON.stringify({ ...config, ...process.env }),
loader: 'json',
};
});
},
};
11 changes: 9 additions & 2 deletions packages/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publisher": "zenstack",
"displayName": "ZenStack Language Tools",
"description": "A toolkit for modeling data and access policies in full-stack development with Next.js and Typescript",
"version": "0.3.4",
"version": "0.3.7",
"author": {
"name": "ZenStack Team"
},
Expand Down Expand Up @@ -70,7 +70,7 @@
"vscode:package": "vsce package --no-dependencies",
"clean": "rimraf bundle",
"build": "pnpm langium:generate && tsc --noEmit && pnpm bundle && cp -r src/res/* bundle/res/",
"bundle": "npm run clean && node build/bundle.js",
"bundle": "npm run clean && node build/bundle.js --minify",
"bundle-watch": "node build/bundle.js --watch",
"ts:watch": "tsc --watch --noEmit",
"tsc-alias:watch": "tsc-alias --watch",
Expand All @@ -83,14 +83,19 @@
},
"dependencies": {
"@zenstackhq/internal": "workspace:*",
"async-exit-hook": "^2.0.1",
"change-case": "^4.1.2",
"chevrotain": "^9.1.0",
"colors": "1.4.0",
"commander": "^8.3.0",
"cuid": "^2.1.8",
"langium": "^0.5.0",
"mixpanel": "^0.17.0",
"node-machine-id": "^1.1.12",
"pluralize": "^8.0.0",
"prisma": "^4.5.0",
"promisify": "^0.0.3",
"sleep-promise": "^9.1.0",
"ts-morph": "^16.0.0",
"uuid": "^9.0.0",
"vscode-jsonrpc": "^8.0.2",
Expand All @@ -101,6 +106,7 @@
},
"devDependencies": {
"@prisma/internals": "^4.5.0",
"@types/async-exit-hook": "^2.0.0",
"@types/jest": "^29.2.0",
"@types/node": "^14.18.32",
"@types/pluralize": "^0.0.29",
Expand All @@ -110,6 +116,7 @@
"@typescript-eslint/eslint-plugin": "^5.42.0",
"@typescript-eslint/parser": "^5.42.0",
"concurrently": "^7.4.0",
"dotenv": "^16.0.3",
"esbuild": "^0.15.12",
"eslint": "^8.27.0",
"jest": "^29.2.1",
Expand Down
4 changes: 4 additions & 0 deletions packages/schema/src/cli/cli-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Indicating an error during CLI execution
*/
export class CliError extends Error {}
9 changes: 5 additions & 4 deletions packages/schema/src/cli/cli-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ZenStackGenerator } from '../generator';
import { URI } from 'vscode-uri';
import { GENERATED_CODE_PATH } from '../generator/constants';
import { Context, GeneratorError } from '../generator/types';
import { CliError } from './cli-error';

/**
* Loads a zmodel document from a file.
Expand All @@ -26,12 +27,12 @@ export async function loadDocument(
console.error(
colors.yellow(`Please choose a file with extension: ${extensions}.`)
);
process.exit(1);
throw new CliError('invalid schema file');
}

if (!fs.existsSync(fileName)) {
console.error(colors.red(`File ${fileName} does not exist.`));
process.exit(1);
throw new CliError('schema file does not exist');
}

// load standard library
Expand Down Expand Up @@ -69,7 +70,7 @@ export async function loadDocument(
)
);
}
process.exit(1);
throw new CliError('schema validation errors');
}

return document.parseResult.value as Model;
Expand Down Expand Up @@ -99,7 +100,7 @@ export async function runGenerator(
} catch (err) {
if (err instanceof GeneratorError) {
console.error(colors.red(err.message));
process.exit(1);
throw new CliError(err.message);
}
}
}
Loading