@tego/devkit 1.3.14

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.
Files changed (61) hide show
  1. package/LICENSE +201 -0
  2. package/assets/openChrome.applescript +95 -0
  3. package/bin/cli.js +2 -0
  4. package/lib/builder/build/buildCjs.mjs +40 -0
  5. package/lib/builder/build/buildClient.mjs +97 -0
  6. package/lib/builder/build/buildDeclaration.mjs +46 -0
  7. package/lib/builder/build/buildEsm.mjs +64 -0
  8. package/lib/builder/build/constant.mjs +58 -0
  9. package/lib/builder/build/index.mjs +2 -0
  10. package/lib/builder/build/tarPlugin.mjs +28 -0
  11. package/lib/builder/build/utils/buildPluginUtils.mjs +118 -0
  12. package/lib/builder/build/utils/getDepsConfig.mjs +86 -0
  13. package/lib/builder/build/utils/getPackages.mjs +63 -0
  14. package/lib/builder/build/utils/index.mjs +2 -0
  15. package/lib/builder/build/utils/utils.mjs +60 -0
  16. package/lib/builder/buildable-packages/app-web-package.mjs +38 -0
  17. package/lib/builder/buildable-packages/lib-package.mjs +63 -0
  18. package/lib/builder/buildable-packages/plugin-package.mjs +357 -0
  19. package/lib/builder/buildable-packages/skip-package.mjs +20 -0
  20. package/lib/builder/get-packages.mjs +63 -0
  21. package/lib/builder/index.mjs +56 -0
  22. package/lib/builder/interfaces.mjs +0 -0
  23. package/lib/cli.mjs +22 -0
  24. package/lib/commands/build.mjs +20 -0
  25. package/lib/commands/clean.mjs +18 -0
  26. package/lib/commands/create-nginx-conf.mjs +17 -0
  27. package/lib/commands/create-plugin.mjs +18 -0
  28. package/lib/commands/dev.mjs +131 -0
  29. package/lib/commands/e2e.mjs +204 -0
  30. package/lib/commands/global.mjs +23 -0
  31. package/lib/commands/index.mjs +36 -0
  32. package/lib/commands/init.mjs +13 -0
  33. package/lib/commands/p-test.mjs +79 -0
  34. package/lib/commands/pm2.mjs +16 -0
  35. package/lib/commands/postinstall.mjs +25 -0
  36. package/lib/commands/start.mjs +50 -0
  37. package/lib/commands/tar.mjs +15 -0
  38. package/lib/commands/test.mjs +70 -0
  39. package/lib/commands/upgrade.mjs +13 -0
  40. package/lib/constants.mjs +13 -0
  41. package/lib/index.mjs +8 -0
  42. package/lib/notify-updates.mjs +5 -0
  43. package/lib/open.mjs +92 -0
  44. package/lib/package-map-generator.mjs +219 -0
  45. package/lib/plugin-generator.mjs +63 -0
  46. package/lib/util.mjs +369 -0
  47. package/package.json +77 -0
  48. package/tachybase.conf.tpl +89 -0
  49. package/templates/plugin/.npmignore.tpl +2 -0
  50. package/templates/plugin/README.md.tpl +1 -0
  51. package/templates/plugin/client.d.ts +2 -0
  52. package/templates/plugin/client.js +1 -0
  53. package/templates/plugin/package.json.tpl +11 -0
  54. package/templates/plugin/server.d.ts +2 -0
  55. package/templates/plugin/server.js +1 -0
  56. package/templates/plugin/src/client/index.ts.tpl +1 -0
  57. package/templates/plugin/src/client/plugin.tsx.tpl +11 -0
  58. package/templates/plugin/src/index.ts +2 -0
  59. package/templates/plugin/src/server/collections/.gitkeep +0 -0
  60. package/templates/plugin/src/server/index.ts.tpl +1 -0
  61. package/templates/plugin/src/server/plugin.ts.tpl +19 -0
@@ -0,0 +1,131 @@
1
+ // src/commands/dev.ts
2
+ import { createRsbuild, loadConfig } from "@rsbuild/core";
3
+ import { getPortPromise } from "portfinder";
4
+ import { nodeCheck, postCheck, promptForTs, run } from "../util.mjs";
5
+ var dev_default = (cli) => {
6
+ cli.command("dev").option("-p, --port [port]").option("--proxy-port [port]").option("--client").option("--server").option("--rs").option("-w, --wait-server").option("--no-open").option("--db-sync").option("--inspect [port]").allowUnknownOption().action(async (opts) => {
7
+ promptForTs();
8
+ const { APP_SERVER_ROOT, APP_CLIENT_ROOT, SERVER_TSCONFIG_PATH } = process.env;
9
+ process.env.IS_DEV_CMD = true;
10
+ if (!SERVER_TSCONFIG_PATH) {
11
+ throw new Error("SERVER_TSCONFIG_PATH is not set.");
12
+ }
13
+ if (process.argv.includes("-h") || process.argv.includes("--help")) {
14
+ run("tsx", [
15
+ "--tsconfig",
16
+ SERVER_TSCONFIG_PATH,
17
+ "-r",
18
+ "tsconfig-paths/register",
19
+ `${APP_SERVER_ROOT}/src/index.ts`,
20
+ ...process.argv.slice(2)
21
+ ]);
22
+ return;
23
+ }
24
+ const { port, client, server, inspect, rs } = opts;
25
+ if (port) {
26
+ process.env.APP_PORT = opts.port;
27
+ }
28
+ const { APP_PORT } = process.env;
29
+ let clientPort = 0;
30
+ let serverPort = 0;
31
+ if (APP_PORT) {
32
+ clientPort = Number(APP_PORT);
33
+ }
34
+ nodeCheck();
35
+ await postCheck(opts);
36
+ if (server) {
37
+ serverPort = Number(APP_PORT);
38
+ } else if (!server && !client) {
39
+ serverPort = await getPortPromise({
40
+ port: 1 * clientPort + 10
41
+ });
42
+ }
43
+ if (server || !client) {
44
+ console.log("starting server", serverPort);
45
+ const filteredArgs = process.argv.filter(
46
+ (item, i) => !item.startsWith("--inspect") && !(process.argv[i - 1] === "--inspect" && Number.parseInt(item))
47
+ );
48
+ const argv = [
49
+ "watch",
50
+ ...inspect ? [`--inspect=${inspect === true ? 9229 : inspect}`] : [],
51
+ "--ignore=./storage/plugins/**",
52
+ "--tsconfig",
53
+ SERVER_TSCONFIG_PATH,
54
+ "-r",
55
+ "tsconfig-paths/register",
56
+ `${APP_SERVER_ROOT}/src/index.ts`,
57
+ "start",
58
+ ...filteredArgs.slice(3),
59
+ `--port=${serverPort}`
60
+ ];
61
+ if (opts.dbSync) {
62
+ argv.push("--db-sync");
63
+ }
64
+ const runDevServer = () => {
65
+ run("tsx", argv, {
66
+ env: {
67
+ APP_PORT: serverPort + ""
68
+ }
69
+ }).catch((err) => {
70
+ if (err.exitCode === 100) {
71
+ console.log("Restarting server...");
72
+ runDevServer();
73
+ } else {
74
+ console.error(err);
75
+ }
76
+ });
77
+ };
78
+ runDevServer();
79
+ }
80
+ if (client || !server) {
81
+ const runClient = async () => {
82
+ const getDevEnvironment = (clientPort2, proxyPort2) => ({
83
+ PORT: clientPort2 + "",
84
+ NO_OPEN: opts.open ? void 0 : "1",
85
+ WEBSOCKET_URL: process.env.WEBSOCKET_URL || (proxyPort2 ? `ws://localhost:${proxyPort2}${process.env.WS_PATH}` : void 0),
86
+ PROXY_TARGET_URL: process.env.PROXY_TARGET_URL || (proxyPort2 ? `http://127.0.0.1:${proxyPort2}` : void 0)
87
+ });
88
+ const proxyPort = opts.proxyPort || serverPort || clientPort + 10;
89
+ console.log("starting client", 1 * clientPort, "proxy port", proxyPort);
90
+ const env = getDevEnvironment(clientPort, proxyPort);
91
+ process.env.PORT = env.PORT;
92
+ process.env.NO_OPEN = env.NO_OPEN;
93
+ process.env.WEBSOCKET_URL = env.WEBSOCKET_URL;
94
+ process.env.PROXY_TARGET_URL = env.PROXY_TARGET_URL;
95
+ process.env.NODE_ENV = "development";
96
+ const config = await loadConfig({
97
+ cwd: APP_CLIENT_ROOT
98
+ });
99
+ const rsbuild = await createRsbuild({
100
+ rsbuildConfig: config.content,
101
+ cwd: APP_CLIENT_ROOT
102
+ });
103
+ await rsbuild.startDevServer();
104
+ };
105
+ async function runMqServer() {
106
+ const proxyPort = opts.proxyPort || serverPort || clientPort + 10;
107
+ const targetUrl = process.env.PROXY_TARGET_URL || (proxyPort ? `http://127.0.0.1:${proxyPort}` : void 0);
108
+ try {
109
+ const result = await fetch(`${targetUrl}/api/__health_check`);
110
+ const res = await result.text();
111
+ if (res !== "ok") {
112
+ throw new Error("server not ready");
113
+ }
114
+ await runClient();
115
+ } catch {
116
+ setTimeout(() => {
117
+ runMqServer();
118
+ }, 500);
119
+ }
120
+ }
121
+ if (opts.waitServer) {
122
+ runMqServer();
123
+ } else {
124
+ runClient();
125
+ }
126
+ }
127
+ });
128
+ };
129
+ export {
130
+ dev_default as default
131
+ };
@@ -0,0 +1,204 @@
1
+ // src/commands/e2e.ts
2
+ import { execSync } from "node:child_process";
3
+ import { cpus } from "node:os";
4
+ import chalk from "chalk";
5
+ import treeKill from "tree-kill";
6
+ import { isPortReachable, run } from "../util.mjs";
7
+ import { pTest } from "./p-test.mjs";
8
+ var checkServer = async (duration = 1e3, max = 60 * 10) => {
9
+ return new Promise((resolve, reject) => {
10
+ let count = 0;
11
+ const timer = setInterval(async () => {
12
+ if (count++ > max) {
13
+ clearInterval(timer);
14
+ return reject(new Error("Server start timeout."));
15
+ }
16
+ const url = `${process.env.APP_BASE_URL}/api/__health_check`;
17
+ try {
18
+ const response = await fetch(url);
19
+ if (response.status === 200) {
20
+ clearInterval(timer);
21
+ resolve(true);
22
+ }
23
+ } catch (error) {
24
+ console.error("Request error:", error);
25
+ }
26
+ }, duration);
27
+ });
28
+ };
29
+ var checkUI = async (duration = 1e3, max = 60 * 10) => {
30
+ return new Promise((resolve, reject) => {
31
+ let count = 0;
32
+ const timer = setInterval(async () => {
33
+ if (count++ > max) {
34
+ clearInterval(timer);
35
+ return reject(new Error("UI start timeout."));
36
+ }
37
+ try {
38
+ const response = await fetch(`${process.env.APP_BASE_URL}/__umi/api/bundle-status`);
39
+ const result = await response.json();
40
+ if (result === "ok") {
41
+ clearInterval(timer);
42
+ resolve(true);
43
+ return;
44
+ }
45
+ if (result.bundleStatus.done) {
46
+ clearInterval(timer);
47
+ resolve(true);
48
+ }
49
+ } catch (error) {
50
+ console.error("Request error:", error);
51
+ }
52
+ }, duration);
53
+ });
54
+ };
55
+ async function appReady() {
56
+ console.log("check server...");
57
+ await checkServer();
58
+ console.log("server is ready, check UI...");
59
+ await checkUI();
60
+ console.log("UI is ready.");
61
+ }
62
+ async function runApp(options = {}) {
63
+ console.log("installing...");
64
+ await run("tachybase", ["install", "-f"]);
65
+ if (await isPortReachable(process.env.APP_PORT)) {
66
+ console.log("app started");
67
+ return;
68
+ }
69
+ console.log("starting...");
70
+ run("tachybase", [process.env.APP_ENV === "production" ? "start" : "dev"], options);
71
+ }
72
+ process.on("SIGINT", async () => {
73
+ treeKill(process.pid, (error) => {
74
+ if (error) {
75
+ console.error(error);
76
+ } else {
77
+ console.log(chalk.yellow("Force killing..."));
78
+ }
79
+ process.exit();
80
+ });
81
+ });
82
+ var commonConfig = {
83
+ stdio: "inherit"
84
+ };
85
+ var runCodegenSync = () => {
86
+ try {
87
+ execSync(
88
+ `npx playwright codegen --load-storage=storage/playwright/.auth/codegen.auth.json ${process.env.APP_BASE_URL} --save-storage=storage/playwright/.auth/codegen.auth.json`,
89
+ // @ts-ignore
90
+ commonConfig
91
+ );
92
+ } catch (err) {
93
+ if (err.message.includes("auth.json")) {
94
+ execSync(
95
+ `npx playwright codegen ${process.env.APP_BASE_URL} --save-storage=storage/playwright/.auth/codegen.auth.json`,
96
+ // @ts-ignore
97
+ commonConfig
98
+ );
99
+ } else {
100
+ console.error(err);
101
+ }
102
+ }
103
+ };
104
+ var filterArgv = () => {
105
+ const arr = process.argv.slice(4);
106
+ const argv = [];
107
+ for (let index = 0; index < arr.length; index++) {
108
+ const element = arr[index];
109
+ if (element === "--url") {
110
+ index++;
111
+ continue;
112
+ }
113
+ if (element.startsWith("--url=")) {
114
+ continue;
115
+ }
116
+ if (element === "--skip-reporter") {
117
+ continue;
118
+ }
119
+ if (element === "--build") {
120
+ continue;
121
+ }
122
+ if (element === "--production") {
123
+ continue;
124
+ }
125
+ argv.push(element);
126
+ }
127
+ return argv;
128
+ };
129
+ var e2e_default = (cli) => {
130
+ const e2e = cli.command("e2e").hook("preAction", () => {
131
+ if (process.env.APP_BASE_URL) {
132
+ process.env.APP_BASE_URL = process.env.APP_BASE_URL.replace("localhost", "127.0.0.1");
133
+ console.log("APP_BASE_URL:", process.env.APP_BASE_URL);
134
+ }
135
+ });
136
+ e2e.command("test").allowUnknownOption().option("--url [url]").option("--skip-reporter").option("--build").option("--production").action(async (options) => {
137
+ process.env.__E2E__ = true;
138
+ if (options.production) {
139
+ process.env.APP_ENV = "production";
140
+ }
141
+ if (options.build) {
142
+ process.env.APP_ENV = "production";
143
+ await run("pnpm", ["build"]);
144
+ }
145
+ if (options.skipReporter) {
146
+ process.env.PLAYWRIGHT_SKIP_REPORTER = true;
147
+ }
148
+ if (options.url) {
149
+ process.env.APP_BASE_URL = options.url.replace("localhost", "127.0.0.1");
150
+ } else {
151
+ await runApp({
152
+ stdio: "ignore"
153
+ });
154
+ }
155
+ await appReady();
156
+ await run("npx", ["playwright", "test", ...filterArgv()]);
157
+ process.exit();
158
+ });
159
+ e2e.command("codegen").allowUnknownOption().option("--url [url]").action(async (options) => {
160
+ if (options.url) {
161
+ process.env.APP_BASE_URL = options.url.replace("localhost", "127.0.0.1");
162
+ } else {
163
+ await runApp({
164
+ stdio: "ignore"
165
+ });
166
+ }
167
+ await appReady();
168
+ runCodegenSync();
169
+ });
170
+ e2e.command("start-app").option("--production").option("--build").option("--port [port]").action(async (options) => {
171
+ process.env.__E2E__ = true;
172
+ if (options.build) {
173
+ await run("pnpm", ["build"]);
174
+ }
175
+ if (options.production) {
176
+ process.env.APP_ENV = "production";
177
+ }
178
+ if (options.port) {
179
+ process.env.APP_PORT = options.port;
180
+ }
181
+ runApp();
182
+ });
183
+ e2e.command("reinstall-app").action(async (options) => {
184
+ await run("tachybase", ["install", "-f"], options);
185
+ });
186
+ e2e.command("install-deps").action(async () => {
187
+ await run("npx", ["playwright", "install", "--with-deps"]);
188
+ });
189
+ e2e.command("p-test").option("--stop-on-error").option("--build").option("--concurrency [concurrency]", "", cpus().length + "").option(
190
+ "--match [match]",
191
+ "Only the files matching one of these patterns are executed as test files. Matching is performed against the absolute file path. Strings are treated as glob patterns.",
192
+ "packages/**/__e2e__/**/*.test.ts"
193
+ ).option("--ignore [ignore]", "Skip tests that match the pattern. Strings are treated as glob patterns.", void 0).action(async (options) => {
194
+ process.env.__E2E__ = true;
195
+ if (options.build) {
196
+ process.env.APP_ENV = "production";
197
+ await run("pnpm", ["build"]);
198
+ }
199
+ await pTest({ ...options, concurrency: 1 * options.concurrency });
200
+ });
201
+ };
202
+ export {
203
+ e2e_default as default
204
+ };
@@ -0,0 +1,23 @@
1
+ // src/commands/global.ts
2
+ import { isDev, isProd, promptForTs, run } from "../util.mjs";
3
+ var global_default = (cli) => {
4
+ const { APP_SERVER_ROOT, SERVER_TSCONFIG_PATH } = process.env;
5
+ cli.allowUnknownOption().option("-h, --help").action((options) => {
6
+ if (isDev()) {
7
+ promptForTs();
8
+ run("tsx", [
9
+ "--tsconfig",
10
+ SERVER_TSCONFIG_PATH ?? "",
11
+ "-r",
12
+ "tsconfig-paths/register",
13
+ `${APP_SERVER_ROOT}/src/index.ts`,
14
+ ...process.argv.slice(2)
15
+ ]);
16
+ } else if (isProd()) {
17
+ run("node", [`${APP_SERVER_ROOT}/lib/index.js`, ...process.argv.slice(2)]);
18
+ }
19
+ });
20
+ };
21
+ export {
22
+ global_default as default
23
+ };
@@ -0,0 +1,36 @@
1
+ // src/commands/index.ts
2
+ import { generateAppDir } from "../util.mjs";
3
+ import build from "./build.mjs";
4
+ import clean from "./clean.mjs";
5
+ import createNginxConf from "./create-nginx-conf.mjs";
6
+ import createPlugin from "./create-plugin.mjs";
7
+ import dev from "./dev.mjs";
8
+ import e2e from "./e2e.mjs";
9
+ import global from "./global.mjs";
10
+ import init from "./init.mjs";
11
+ import pm2 from "./pm2.mjs";
12
+ import postinstall from "./postinstall.mjs";
13
+ import start from "./start.mjs";
14
+ import tar from "./tar.mjs";
15
+ import test from "./test.mjs";
16
+ import upgrade from "./upgrade.mjs";
17
+ var commands_default = async (cli) => {
18
+ generateAppDir();
19
+ global(cli);
20
+ createNginxConf(cli);
21
+ build(cli);
22
+ tar(cli);
23
+ dev(cli);
24
+ start(cli);
25
+ e2e(cli);
26
+ clean(cli);
27
+ pm2(cli);
28
+ test(cli);
29
+ upgrade(cli);
30
+ postinstall(cli);
31
+ createPlugin(cli);
32
+ init(cli);
33
+ };
34
+ export {
35
+ commands_default as default
36
+ };
@@ -0,0 +1,13 @@
1
+ // src/commands/init.ts
2
+ var init_default = (cli) => {
3
+ cli.command("init").option("--plugins <list>", "Comma-separated list of plugins to install", (value) => {
4
+ return value.split(",").map((s) => s.trim()).filter(Boolean);
5
+ }).argument("[name]", "project name", "my-app").allowUnknownOption().action(async (name, options) => {
6
+ console.error("\u274C This command has been deprecated.");
7
+ console.log("\u2705 Please use: npx tego init <project-name>");
8
+ process.exit(1);
9
+ });
10
+ };
11
+ export {
12
+ init_default as default
13
+ };
@@ -0,0 +1,79 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
8
+ // src/commands/p-test.ts
9
+ import { existsSync, mkdirSync, readFileSync } from "node:fs";
10
+ import { resolve } from "node:path";
11
+ import { parse } from "dotenv";
12
+ import { execa } from "execa";
13
+ import fastGlob from "fast-glob";
14
+ import lodash from "lodash";
15
+ import pAll from "p-all";
16
+ async function runApp(dir, index = 0) {
17
+ let ENV_FILE = resolve(process.cwd(), ".env.e2e");
18
+ if (!existsSync(ENV_FILE)) {
19
+ ENV_FILE = resolve(process.cwd(), ".env.e2e.example");
20
+ }
21
+ const data = readFileSync(ENV_FILE, "utf-8");
22
+ const config = {
23
+ ...parse(data),
24
+ ...process.env
25
+ };
26
+ index = index * 2;
27
+ const { Client } = __require("pg");
28
+ const database = `tachybase${index}`;
29
+ const client = new Client({
30
+ host: config["DB_HOST"],
31
+ port: Number(config["DB_PORT"]),
32
+ user: config["DB_USER"],
33
+ password: config["DB_PASSWORD"],
34
+ database: "postgres"
35
+ });
36
+ await client.connect();
37
+ await client.query(`DROP DATABASE IF EXISTS "${database}"`);
38
+ await client.query(`CREATE DATABASE "${database}";`);
39
+ await client.end();
40
+ return execa("pnpm", ["tachybase", "e2e", "test", dir, "--skip-reporter"], {
41
+ shell: true,
42
+ stdio: "inherit",
43
+ env: {
44
+ ...config,
45
+ CI: process.env.CI,
46
+ __E2E__: "true",
47
+ APP_BASE_URL: void 0,
48
+ LOGGER_LEVEL: "error",
49
+ APP_ENV: "production",
50
+ APP_PORT: 2e4 + index + "",
51
+ DB_DATABASE: `tachybase${index}`,
52
+ SOCKET_PATH: `storage/e2e/gateway-e2e-${index}.sock`,
53
+ PM2_HOME: resolve(process.cwd(), `storage/e2e/.pm2-${index}`),
54
+ PLAYWRIGHT_AUTH_FILE: resolve(process.cwd(), `storage/playwright/.auth/admin-${index}.json`)
55
+ }
56
+ });
57
+ }
58
+ async function pTest(options) {
59
+ const dir = resolve(process.cwd(), "storage/e2e");
60
+ if (!existsSync(dir)) {
61
+ mkdirSync(dir, { recursive: true });
62
+ }
63
+ const files = fastGlob.sync(options.match, {
64
+ ignore: options.ignore,
65
+ // @ts-ignore
66
+ root: process.cwd()
67
+ });
68
+ const commands = splitArrayIntoParts(lodash.shuffle(files), options.concurrency || 4).map((v, i) => {
69
+ return () => runApp(v.join(" "), i);
70
+ });
71
+ await pAll(commands, { concurrency: 4, stopOnError: false, ...options });
72
+ }
73
+ function splitArrayIntoParts(array, parts) {
74
+ const chunkSize = Math.ceil(array.length / parts);
75
+ return lodash.chunk(array, chunkSize);
76
+ }
77
+ export {
78
+ pTest
79
+ };
@@ -0,0 +1,16 @@
1
+ // src/commands/pm2.ts
2
+ import { run } from "../util.mjs";
3
+ var pm2_default = (cli) => {
4
+ cli.command("pm2").allowUnknownOption().action(() => {
5
+ run("pm2", process.argv.slice(3));
6
+ });
7
+ cli.command("pm2-restart").allowUnknownOption().action(() => {
8
+ run("pm2", ["restart", "all"]);
9
+ });
10
+ cli.command("pm2-stop").allowUnknownOption().action(() => {
11
+ run("pm2", ["stop", "all"]);
12
+ });
13
+ };
14
+ export {
15
+ pm2_default as default
16
+ };
@@ -0,0 +1,25 @@
1
+ // src/commands/postinstall.ts
2
+ import { existsSync } from "node:fs";
3
+ import { readFile, writeFile } from "node:fs/promises";
4
+ import { resolve } from "node:path";
5
+ import { generatePlaywrightPath, isDev } from "../util.mjs";
6
+ var postinstall_default = (cli) => {
7
+ cli.command("postinstall").allowUnknownOption().action(async () => {
8
+ generatePlaywrightPath(true);
9
+ if (!isDev()) {
10
+ return;
11
+ }
12
+ const cwd = process.cwd();
13
+ if (!existsSync(resolve(cwd, ".env")) && existsSync(resolve(cwd, ".env.example"))) {
14
+ const content = await readFile(resolve(cwd, ".env.example"), "utf-8");
15
+ await writeFile(resolve(cwd, ".env"), content, "utf-8");
16
+ }
17
+ if (!existsSync(resolve(cwd, ".env.test")) && existsSync(resolve(cwd, ".env.test.example"))) {
18
+ const content = await readFile(resolve(cwd, ".env.test.example"), "utf-8");
19
+ await writeFile(resolve(cwd, ".env.test"), content, "utf-8");
20
+ }
21
+ });
22
+ };
23
+ export {
24
+ postinstall_default as default
25
+ };
@@ -0,0 +1,50 @@
1
+ // src/commands/start.ts
2
+ import { existsSync } from "node:fs";
3
+ import { resolve } from "node:path";
4
+ import chalk from "chalk";
5
+ import { postCheck, promptForTs, run } from "../util.mjs";
6
+ var start_default = (cli) => {
7
+ const { APP_SERVER_ROOT, NODE_ARGS } = process.env;
8
+ cli.command("start").option("-p, --port [port]").option("-d, --daemon").option("-i, --instances [number]").option("--db-sync").option("--quickstart").allowUnknownOption().action(async (opts) => {
9
+ if (opts.port) {
10
+ process.env.APP_PORT = opts.port;
11
+ }
12
+ if (process.argv.includes("-h") || process.argv.includes("--help")) {
13
+ promptForTs();
14
+ run("tsx", [
15
+ "--tsconfig",
16
+ process.env.SERVER_TSCONFIG_PATH ?? "",
17
+ "-r",
18
+ "tsconfig-paths/register",
19
+ `${APP_SERVER_ROOT}/src/index.ts`,
20
+ ...process.argv.slice(2)
21
+ ]);
22
+ return;
23
+ }
24
+ if (!existsSync(resolve(process.cwd(), `${APP_SERVER_ROOT}/lib/index.js`))) {
25
+ console.log("The code is not compiled, please execute it first");
26
+ console.log(chalk.yellow("$ pnpm build"));
27
+ console.log("If you want to run in development mode, please execute");
28
+ console.log(chalk.yellow("$ pnpm dev"));
29
+ return;
30
+ }
31
+ await postCheck(opts);
32
+ if (opts.daemon) {
33
+ run("pm2", ["start", `${APP_SERVER_ROOT}/lib/index.js`, "--", ...process.argv.slice(2)]);
34
+ } else {
35
+ run(
36
+ "pm2-runtime",
37
+ [
38
+ "start",
39
+ `${APP_SERVER_ROOT}/lib/index.js`,
40
+ NODE_ARGS ? `--node-args="${NODE_ARGS}"` : "",
41
+ "--",
42
+ ...process.argv.slice(2)
43
+ ].filter(Boolean)
44
+ );
45
+ }
46
+ });
47
+ };
48
+ export {
49
+ start_default as default
50
+ };
@@ -0,0 +1,15 @@
1
+ // src/commands/tar.ts
2
+ import { TachybaseBuilder } from "../builder/index.mjs";
3
+ import { nodeCheck } from "../util.mjs";
4
+ var tar_default = (cli) => {
5
+ cli.command("tar").allowUnknownOption().argument("[packages...]").action(async (pkgs) => {
6
+ nodeCheck();
7
+ const tachybaseBuilder = new TachybaseBuilder({
8
+ onlyTar: true
9
+ });
10
+ await tachybaseBuilder.build(pkgs);
11
+ });
12
+ };
13
+ export {
14
+ tar_default as default
15
+ };
@@ -0,0 +1,70 @@
1
+ // src/commands/test.ts
2
+ import { sep } from "node:path";
3
+ import { run } from "../util.mjs";
4
+ function addTestCommand(name, cli) {
5
+ return cli.command(name).option("-w, --watch").option("--run").option("--allowOnly").option("--bail").option("-h, --help").option("--single-thread [singleThread]").arguments("[paths...]").allowUnknownOption().action(async (paths, opts) => {
6
+ process.argv.push("--disable-console-intercept");
7
+ if (name === "test:server") {
8
+ process.env.TEST_ENV = "server-side";
9
+ } else if (name === "test:client") {
10
+ process.env.TEST_ENV = "client-side";
11
+ }
12
+ if (opts.server) {
13
+ process.env.TEST_ENV = "server-side";
14
+ process.argv.splice(process.argv.indexOf("--server"), 1);
15
+ }
16
+ if (opts.client) {
17
+ process.env.TEST_ENV = "client-side";
18
+ process.argv.splice(process.argv.indexOf("--client"), 1);
19
+ }
20
+ process.env.NODE_ENV = "test";
21
+ if (!opts.watch && !opts.run) {
22
+ process.argv.push("--run");
23
+ }
24
+ const first = paths?.[0];
25
+ if (!process.env.TEST_ENV && first) {
26
+ const key = first.split(sep).join("/");
27
+ if (key.includes("/client/")) {
28
+ process.env.TEST_ENV = "client-side";
29
+ } else {
30
+ process.env.TEST_ENV = "server-side";
31
+ }
32
+ }
33
+ if (process.env.TEST_ENV === "server-side" && opts.singleThread !== "false") {
34
+ process.argv.push("--poolOptions.threads.singleThread=true");
35
+ }
36
+ if (opts.singleThread === "false") {
37
+ process.argv.splice(process.argv.indexOf("--single-thread=false"), 1);
38
+ }
39
+ const cliArgs = ["--max_old_space_size=14096", "./node_modules/.bin/vitest", ...process.argv.slice(3)];
40
+ if (process.argv.includes("-h") || process.argv.includes("--help")) {
41
+ await run("node", cliArgs);
42
+ return;
43
+ }
44
+ if (process.env.TEST_ENV) {
45
+ console.log("process.env.TEST_ENV", process.env.TEST_ENV, cliArgs);
46
+ await run("node", cliArgs);
47
+ } else {
48
+ await Promise.all([
49
+ run("node", cliArgs, {
50
+ env: {
51
+ TEST_ENV: "client-side"
52
+ }
53
+ }),
54
+ run("node", cliArgs, {
55
+ env: {
56
+ TEST_ENV: "server-side"
57
+ }
58
+ })
59
+ ]);
60
+ }
61
+ });
62
+ }
63
+ var test_default = (cli) => {
64
+ addTestCommand("test:server", cli);
65
+ addTestCommand("test:client", cli);
66
+ addTestCommand("test", cli).option("--client").option("--server");
67
+ };
68
+ export {
69
+ test_default as default
70
+ };
@@ -0,0 +1,13 @@
1
+ // src/commands/upgrade.ts
2
+ import { hasTsNode, promptForTs, runAppCommand } from "../util.mjs";
3
+ var upgrade_default = (cli) => {
4
+ cli.command("upgrade").allowUnknownOption().option("--raw").option("-S|--skip-code-update").action(async (options) => {
5
+ if (hasTsNode()) {
6
+ promptForTs();
7
+ }
8
+ await runAppCommand("upgrade");
9
+ });
10
+ };
11
+ export {
12
+ upgrade_default as default
13
+ };