@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,357 @@
1
+ // src/builder/buildable-packages/plugin-package.ts
2
+ import { createRequire } from "node:module";
3
+ import path from "node:path";
4
+ import ncc from "@vercel/ncc";
5
+ import react from "@vitejs/plugin-react";
6
+ import chalk from "chalk";
7
+ import fg from "fast-glob";
8
+ import fs from "fs-extra";
9
+ import { build as tsupBuild } from "tsup";
10
+ import { build as viteBuild } from "vite";
11
+ import cssInjectedByJsPlugin from "vite-plugin-css-injected-by-js";
12
+ import { buildDeclaration } from "../build/buildDeclaration.mjs";
13
+ import { EsbuildSupportExts, globExcludeFiles } from "../build/constant.mjs";
14
+ import { tarPlugin } from "../build/tarPlugin.mjs";
15
+ import { getPackageJson, getPkgLog, getUserConfig } from "../build/utils/index.mjs";
16
+ import {
17
+ buildCheck,
18
+ checkFileSize,
19
+ checkRequire,
20
+ getExcludePackages,
21
+ getIncludePackages,
22
+ getPackagesFromFiles,
23
+ getSourcePackages
24
+ } from "../build/utils/buildPluginUtils.mjs";
25
+ import { getDepPkgPath, getDepsConfig } from "../build/utils/getDepsConfig.mjs";
26
+ var require2 = createRequire(import.meta.url);
27
+ var validExts = [".ts", ".tsx", ".js", ".jsx", ".mjs"];
28
+ var serverGlobalFiles = ["src/**", "!src/client/**", ...globExcludeFiles];
29
+ var clientGlobalFiles = ["src/**", "!src/server/**", ...globExcludeFiles];
30
+ var sourceGlobalFiles = ["src/**/*.{ts,js,tsx,jsx,mjs}", "!src/**/__tests__"];
31
+ var external = [
32
+ // tachybase
33
+ "@tachybase/acl",
34
+ "@tachybase/actions",
35
+ "@tachybase/auth",
36
+ "@tachybase/cache",
37
+ "@tachybase/client",
38
+ "@tachybase/database",
39
+ "@tachybase/data-source",
40
+ "@tachybase/evaluators",
41
+ "@tachybase/logger",
42
+ "@tachybase/resourcer",
43
+ "@tachybase/sdk",
44
+ "@tachybase/schema",
45
+ "@tachybase/components",
46
+ "@tachybase/requirejs",
47
+ "@tachybase/server",
48
+ "@tachybase/test",
49
+ "@tachybase/utils",
50
+ "@tachybase/globals",
51
+ "@tachybase/loader",
52
+ // @tachybase/auth
53
+ "jsonwebtoken",
54
+ // @tachybase/cache
55
+ "cache-manager",
56
+ // @tachybase/database
57
+ "sequelize",
58
+ "umzug",
59
+ "async-mutex",
60
+ // @tachybase/evaluators
61
+ "@formulajs/formulajs",
62
+ "mathjs",
63
+ // @tachybase/logger
64
+ "winston",
65
+ "winston-daily-rotate-file",
66
+ // koa
67
+ "koa",
68
+ "@koa/cors",
69
+ "multer",
70
+ "koa-bodyparser",
71
+ // react
72
+ "react",
73
+ "react-dom",
74
+ "react/jsx-runtime",
75
+ // react-router
76
+ "react-router",
77
+ "react-router-dom",
78
+ // antd
79
+ "antd",
80
+ "antd-style",
81
+ "@ant-design/icons",
82
+ "@ant-design/cssinjs",
83
+ // i18next
84
+ "i18next",
85
+ "react-i18next",
86
+ // dnd-kit 相关
87
+ "@dnd-kit/accessibility",
88
+ "@dnd-kit/core",
89
+ "@dnd-kit/modifiers",
90
+ "@dnd-kit/sortable",
91
+ "@dnd-kit/utilities",
92
+ // utils
93
+ "dayjs",
94
+ "mysql2",
95
+ "pg",
96
+ "pg-hstore",
97
+ "sqlite3",
98
+ "supertest",
99
+ "axios",
100
+ "@emotion/css",
101
+ "ahooks",
102
+ "lodash",
103
+ "china-division"
104
+ ];
105
+ var pluginPrefix = (process.env.PLUGIN_PACKAGE_PREFIX || "@tachybase/plugin-,@tachybase/module-").split(",");
106
+ var target_dir = "dist";
107
+ function deleteServerFiles(cwd, log) {
108
+ log("delete server files");
109
+ const files = fg.globSync(["*"], {
110
+ cwd: path.join(cwd, target_dir),
111
+ absolute: true,
112
+ deep: 1,
113
+ onlyFiles: true
114
+ });
115
+ const dirs = fg.globSync(["*", "!client", "!node_modules"], {
116
+ cwd: path.join(cwd, target_dir),
117
+ absolute: true,
118
+ deep: 1,
119
+ onlyDirectories: true
120
+ });
121
+ [...files, ...dirs].forEach((item) => {
122
+ fs.removeSync(item);
123
+ });
124
+ }
125
+ function writeExternalPackageVersion(cwd, log) {
126
+ log("write external version");
127
+ const sourceFiles = fg.globSync(sourceGlobalFiles, { cwd, absolute: true }).map((item) => fs.readFileSync(item, "utf-8"));
128
+ const sourcePackages = getSourcePackages(sourceFiles);
129
+ const excludePackages = getExcludePackages(sourcePackages, external, pluginPrefix);
130
+ const data = excludePackages.reduce((prev, packageName) => {
131
+ try {
132
+ const depPkgPath = getDepPkgPath(packageName, cwd);
133
+ const depPkg = require2(depPkgPath);
134
+ prev[packageName] = depPkg.version;
135
+ } catch (error) {
136
+ console.error(error);
137
+ }
138
+ return prev;
139
+ }, {});
140
+ const externalVersionPath = path.join(cwd, target_dir, "externalVersion.js");
141
+ fs.writeFileSync(externalVersionPath, `module.exports = ${JSON.stringify(data, null, 2)};`);
142
+ }
143
+ async function buildServerDeps(cwd, serverFiles, log) {
144
+ log("build plugin server dependencies");
145
+ const outDir = path.join(cwd, target_dir, "node_modules");
146
+ const serverFileSource = serverFiles.filter((item) => validExts.includes(path.extname(item))).map((item) => fs.readFileSync(item, "utf-8"));
147
+ const sourcePackages = getSourcePackages(serverFileSource);
148
+ const includePackages = getIncludePackages(sourcePackages, external, pluginPrefix);
149
+ const excludePackages = getExcludePackages(sourcePackages, external, pluginPrefix);
150
+ let tips = [];
151
+ if (includePackages.length) {
152
+ tips.push(
153
+ `These packages ${chalk.yellow(includePackages.join(", "))} will be ${chalk.italic(
154
+ "bundled"
155
+ )} to dist/node_modules.`
156
+ );
157
+ }
158
+ if (excludePackages.length) {
159
+ tips.push(`These packages ${chalk.yellow(excludePackages.join(", "))} will be ${chalk.italic("exclude")}.`);
160
+ }
161
+ log(tips.join(" "));
162
+ if (!includePackages.length) return;
163
+ const deps = getDepsConfig(cwd, outDir, includePackages, external);
164
+ for (const dep of Object.keys(deps)) {
165
+ const { outputDir, mainFile, pkg, nccConfig, depDir } = deps[dep];
166
+ const outputPackageJson = path.join(outputDir, "package.json");
167
+ if (fs.existsSync(outputPackageJson)) {
168
+ const outputPackage = require2(outputPackageJson);
169
+ if (outputPackage.version === pkg.version) {
170
+ continue;
171
+ }
172
+ }
173
+ await fs.copy(depDir, outputDir, { errorOnExist: false });
174
+ const deleteFiles = fg.sync(
175
+ [
176
+ "./**/*.map",
177
+ "./**/*.js.map",
178
+ "./**/*.md",
179
+ "./**/*.mjs",
180
+ "./**/*.png",
181
+ "./**/*.jpg",
182
+ "./**/*.jpeg",
183
+ "./**/*.gif",
184
+ "./**/*/.bin",
185
+ "./**/*/bin",
186
+ "./**/*/LICENSE",
187
+ "./**/*/tsconfig.json"
188
+ ],
189
+ { cwd: outputDir, absolute: true }
190
+ );
191
+ deleteFiles.forEach((file) => {
192
+ fs.unlinkSync(file);
193
+ });
194
+ await ncc(dep, nccConfig).then(
195
+ ({ code, assets }) => {
196
+ fs.writeFileSync(mainFile, code, "utf-8");
197
+ Object.entries(assets).forEach(([name, item]) => {
198
+ const fileurl = path.join(outputDir, name);
199
+ if (!fs.existsSync(path.dirname(fileurl))) {
200
+ fs.mkdirSync(path.dirname(fileurl), { recursive: true });
201
+ }
202
+ fs.writeFileSync(path.join(outputDir, name), item.source, {
203
+ encoding: "utf-8",
204
+ mode: item.permissions
205
+ });
206
+ });
207
+ fs.writeFileSync(
208
+ outputPackageJson,
209
+ JSON.stringify({
210
+ ...pkg,
211
+ _lastModified: (/* @__PURE__ */ new Date()).toISOString()
212
+ }),
213
+ "utf-8"
214
+ );
215
+ }
216
+ );
217
+ }
218
+ }
219
+ async function buildPluginServer(cwd, userConfig, sourcemap, log) {
220
+ log("build plugin server source");
221
+ const packageJson = getPackageJson(cwd);
222
+ const serverFiles = fg.globSync(serverGlobalFiles, { cwd, absolute: true });
223
+ buildCheck({ cwd, packageJson, entry: "server", files: serverFiles, log });
224
+ const otherExts = Array.from(
225
+ new Set(serverFiles.map((item) => path.extname(item)).filter((item) => !EsbuildSupportExts.includes(item)))
226
+ );
227
+ if (otherExts.length) {
228
+ log("%s will not be processed, only be copied to the dist directory.", chalk.yellow(otherExts.join(",")));
229
+ }
230
+ deleteServerFiles(cwd, log);
231
+ await tsupBuild(
232
+ userConfig.modifyTsupConfig({
233
+ entry: serverFiles,
234
+ splitting: false,
235
+ clean: false,
236
+ bundle: false,
237
+ silent: true,
238
+ treeshake: false,
239
+ target: "node16",
240
+ sourcemap,
241
+ outDir: path.join(cwd, target_dir),
242
+ format: "cjs",
243
+ skipNodeModulesBundle: true,
244
+ loader: {
245
+ ...otherExts.reduce((prev, cur) => ({ ...prev, [cur]: "copy" }), {}),
246
+ ".json": "copy"
247
+ }
248
+ })
249
+ );
250
+ await buildServerDeps(cwd, serverFiles, log);
251
+ }
252
+ async function buildPluginClient(cwd, userConfig, sourcemap, log) {
253
+ log("build plugin client");
254
+ const packageJson = getPackageJson(cwd);
255
+ const clientFiles = fg.globSync(clientGlobalFiles, { cwd, absolute: true });
256
+ const clientFileSource = clientFiles.map((item) => fs.readFileSync(item, "utf-8"));
257
+ const sourcePackages = getPackagesFromFiles(clientFileSource);
258
+ const excludePackages = getExcludePackages(sourcePackages, external, pluginPrefix);
259
+ checkRequire(clientFiles, log);
260
+ buildCheck({ cwd, packageJson, entry: "client", files: clientFiles, log });
261
+ const outDir = path.join(cwd, target_dir, "client");
262
+ const globals = excludePackages.reduce((prev, curr) => {
263
+ if (curr.startsWith("@tachybase")) {
264
+ prev[`${curr}/client`] = curr;
265
+ }
266
+ prev[curr] = curr;
267
+ return prev;
268
+ }, {});
269
+ const entry = fg.globSync("src/client/index.{ts,tsx,js,jsx}", { absolute: true, cwd });
270
+ const outputFileName = "index.js";
271
+ await viteBuild(
272
+ userConfig.modifyViteConfig({
273
+ mode: process.env.NODE_ENV || "production",
274
+ define: {
275
+ "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || "production"),
276
+ "process.env.__TEST__": false,
277
+ "process.env.__E2E__": process.env.__E2E__ ? true : false
278
+ },
279
+ logLevel: "warn",
280
+ build: {
281
+ minify: process.env.NODE_ENV === "production",
282
+ outDir,
283
+ cssCodeSplit: false,
284
+ emptyOutDir: true,
285
+ sourcemap,
286
+ lib: {
287
+ entry,
288
+ formats: ["umd"],
289
+ name: packageJson.name,
290
+ fileName: () => outputFileName
291
+ },
292
+ target: ["es2015", "edge88", "firefox78", "chrome87", "safari14"],
293
+ rollupOptions: {
294
+ cache: true,
295
+ external: [...Object.keys(globals), "react", "react/jsx-runtime"],
296
+ output: {
297
+ exports: "named",
298
+ globals: {
299
+ react: "React",
300
+ "react/jsx-runtime": "jsxRuntime",
301
+ ...globals
302
+ }
303
+ }
304
+ }
305
+ },
306
+ plugins: [react(), cssInjectedByJsPlugin({ styleId: packageJson.name })]
307
+ })
308
+ );
309
+ checkFileSize(outDir, log);
310
+ }
311
+ async function buildPlugin(cwd, userConfig, sourcemap, log) {
312
+ }
313
+ var PluginPackage = class {
314
+ static name = "plugin";
315
+ name;
316
+ dir;
317
+ context;
318
+ constructor(name, dir, context) {
319
+ this.name = name;
320
+ this.dir = dir;
321
+ this.context = context;
322
+ }
323
+ async build() {
324
+ const log = getPkgLog(this.name);
325
+ if (this.context.onlyTar) {
326
+ return await tarPlugin(this.dir, log);
327
+ }
328
+ const userConfig = getUserConfig(this.dir);
329
+ if (userConfig.beforeBuild) {
330
+ log("beforeBuild");
331
+ await userConfig.beforeBuild(log);
332
+ }
333
+ await buildPluginClient(this.dir, userConfig, this.context.sourcemap, log);
334
+ await buildPluginServer(this.dir, userConfig, this.context.sourcemap, log);
335
+ writeExternalPackageVersion(this.dir, log);
336
+ if (this.context.dts) {
337
+ await buildDeclaration(this.dir, "dist", log);
338
+ }
339
+ if (userConfig.afterBuild) {
340
+ log("afterBuild");
341
+ await userConfig.afterBuild(log);
342
+ }
343
+ if (this.context.tar) {
344
+ await tarPlugin(this.dir, log);
345
+ }
346
+ log("done");
347
+ }
348
+ };
349
+ export {
350
+ PluginPackage,
351
+ buildPlugin,
352
+ buildPluginClient,
353
+ buildPluginServer,
354
+ buildServerDeps,
355
+ deleteServerFiles,
356
+ writeExternalPackageVersion
357
+ };
@@ -0,0 +1,20 @@
1
+ // src/builder/buildable-packages/skip-package.ts
2
+ import { getPkgLog } from "../build/utils/index.mjs";
3
+ var SkipPackage = class {
4
+ static name = "skip";
5
+ name;
6
+ dir;
7
+ context;
8
+ constructor(name, dir, context) {
9
+ this.name = name;
10
+ this.dir = dir;
11
+ this.context = context;
12
+ }
13
+ async build() {
14
+ const log = getPkgLog(this.name);
15
+ log("skip ", this.name);
16
+ }
17
+ };
18
+ export {
19
+ SkipPackage
20
+ };
@@ -0,0 +1,63 @@
1
+ // src/builder/get-packages.ts
2
+ import path from "node:path";
3
+ import Topo from "@hapi/topo";
4
+ import { findWorkspacePackages } from "@pnpm/workspace.find-packages";
5
+ import fg from "fast-glob";
6
+ import fs from "fs-extra";
7
+ import { ROOT_PATH } from "./build/constant.mjs";
8
+ import { toUnixPath } from "./build/utils/index.mjs";
9
+ function getPackagesPath(pkgs) {
10
+ const allPackageJson = fg.sync(["apps/*/package.json", "packages/*/package.json"], {
11
+ cwd: ROOT_PATH,
12
+ absolute: true,
13
+ onlyFiles: true
14
+ });
15
+ if (pkgs.length === 0) {
16
+ return allPackageJson.map(toUnixPath).map((item) => path.dirname(item));
17
+ }
18
+ const allPackageInfo = allPackageJson.map((packageJsonPath) => ({
19
+ name: fs.readJsonSync(packageJsonPath).name,
20
+ path: path.dirname(toUnixPath(packageJsonPath))
21
+ })).reduce(
22
+ (acc, cur) => {
23
+ acc[cur.name] = cur.path;
24
+ return acc;
25
+ },
26
+ {}
27
+ );
28
+ const allPackagePaths = Object.values(allPackageInfo);
29
+ const pkgNames = pkgs.filter((item) => allPackageInfo[item]);
30
+ const relativePaths = pkgNames.length ? pkgs.filter((item) => !pkgNames.includes(item)) : pkgs;
31
+ const pkgPaths = pkgs.map((item) => allPackageInfo[item]);
32
+ const absPaths = allPackagePaths.filter(
33
+ (absPath) => relativePaths.some((relativePath) => absPath.endsWith(relativePath))
34
+ );
35
+ const dirPaths = fg.sync(pkgs, { onlyDirectories: true, absolute: true, cwd: ROOT_PATH });
36
+ const dirMatchPaths = allPackagePaths.filter((pkgPath) => dirPaths.some((dirPath) => pkgPath.startsWith(dirPath)));
37
+ return [.../* @__PURE__ */ new Set([...pkgPaths, ...absPaths, ...dirMatchPaths])];
38
+ }
39
+ async function getPackages(pkgs) {
40
+ const packagePaths = getPackagesPath(pkgs);
41
+ const allProjects = await findWorkspacePackages(ROOT_PATH, {
42
+ supportedArchitectures: {
43
+ os: ["current"],
44
+ cpu: ["current"],
45
+ libc: ["current"]
46
+ }
47
+ });
48
+ const packages = allProjects.filter((pkg) => packagePaths.includes(toUnixPath(pkg.dir)));
49
+ return sortPackages(packages);
50
+ }
51
+ function sortPackages(packages) {
52
+ const sorter = new Topo.Sorter();
53
+ for (const pkg of packages) {
54
+ const pkgJson = fs.readJsonSync(`${pkg.dir}/package.json`);
55
+ const after = Object.keys({ ...pkgJson.dependencies, ...pkgJson.devDependencies, ...pkgJson.peerDependencies });
56
+ sorter.add(pkg, { after, group: pkg.manifest.name });
57
+ }
58
+ return sorter.nodes;
59
+ }
60
+ export {
61
+ getPackages,
62
+ sortPackages
63
+ };
@@ -0,0 +1,56 @@
1
+ // src/builder/index.ts
2
+ import { PLUGIN_PATTRN } from "./build/constant.mjs";
3
+ import { AppWebPackage } from "./buildable-packages/app-web-package.mjs";
4
+ import { LibPackage } from "./buildable-packages/lib-package.mjs";
5
+ import { PluginPackage } from "./buildable-packages/plugin-package.mjs";
6
+ import { SkipPackage } from "./buildable-packages/skip-package.mjs";
7
+ import { getPackages } from "./get-packages.mjs";
8
+ var TachybaseBuilder = class {
9
+ constructor(ctx) {
10
+ this.ctx = ctx;
11
+ }
12
+ #messages = [];
13
+ async build(pkgs) {
14
+ process.env.NODE_ENV = this.ctx.development ? "development" : "production";
15
+ let packages = await getPackages(pkgs);
16
+ if (packages.length === 0) {
17
+ console.warn("[build] No package matched");
18
+ return;
19
+ }
20
+ const buildable = createBuildablePackages(packages, this.ctx);
21
+ for (const pkg of buildable) {
22
+ try {
23
+ await pkg.build();
24
+ } catch (error) {
25
+ this.#messages.push([pkg.name, error]);
26
+ }
27
+ }
28
+ if (this.#messages.length > 0) {
29
+ this.#messages.forEach((message) => {
30
+ console.log(`\u{1F41B} [${message[0]}]`);
31
+ console.error(message[1]);
32
+ });
33
+ console.log("build failed");
34
+ }
35
+ }
36
+ };
37
+ function createBuildablePackages(projects, context) {
38
+ return projects.map((project) => {
39
+ const name = project.manifest.name;
40
+ const dir = project.dir;
41
+ if (PLUGIN_PATTRN.test(name)) {
42
+ return new PluginPackage(name, dir, context);
43
+ }
44
+ if (name === "@tego/web") {
45
+ return new AppWebPackage(name, dir, context);
46
+ }
47
+ if (name === "@tego/devkit") {
48
+ return new SkipPackage(name, dir, context);
49
+ }
50
+ return new LibPackage(name, dir, context);
51
+ });
52
+ }
53
+ export {
54
+ TachybaseBuilder,
55
+ createBuildablePackages
56
+ };
File without changes
package/lib/cli.mjs ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/cli.ts
4
+ import chalk from "chalk";
5
+ import { Command } from "commander";
6
+ import semver from "semver";
7
+ import commands from "./commands/index.mjs";
8
+ import { genTsConfigPaths, initEnv } from "./util.mjs";
9
+ import "./notify-updates.mjs";
10
+ import { createRequire } from "node:module";
11
+ var require2 = createRequire(import.meta.url);
12
+ var cli = new Command();
13
+ cli.version(require2("../package.json").version);
14
+ initEnv();
15
+ genTsConfigPaths();
16
+ commands(cli).then(() => {
17
+ if (semver.satisfies(process.version, "<20")) {
18
+ console.error(chalk.red("[tachybase cli]: Node.js version must be >= 20"));
19
+ process.exit(1);
20
+ }
21
+ cli.parse(process.argv);
22
+ });
@@ -0,0 +1,20 @@
1
+ // src/commands/build.ts
2
+ import { TachybaseBuilder } from "../builder/index.mjs";
3
+ import { nodeCheck } from "../util.mjs";
4
+ var build_default = (cli) => {
5
+ cli.command("build").allowUnknownOption().argument("[packages...]").option("-r, --retry", "retry the last failed package").option("-s, --sourcemap", "generate server sourcemap").option("--no-dts", "not generate dts").option("--tar", "tar the package").option("--only-tar", "only tar the package").option("--development", "development mode").action(async (pkgs, options) => {
6
+ nodeCheck();
7
+ const tachybaseBuilder = new TachybaseBuilder({
8
+ dts: options.dts,
9
+ sourcemap: options.sourcemap,
10
+ retry: options.retry,
11
+ tar: options.tar,
12
+ onlyTar: options.onlyTar,
13
+ development: options.development
14
+ });
15
+ await tachybaseBuilder.build(pkgs);
16
+ });
17
+ };
18
+ export {
19
+ build_default as default
20
+ };
@@ -0,0 +1,18 @@
1
+ // src/commands/clean.ts
2
+ import { isDev, run } from "../util.mjs";
3
+ var clean_default = (cli) => {
4
+ cli.command("clean").option("--all").allowUnknownOption().action((opts) => {
5
+ if (!isDev()) {
6
+ return;
7
+ }
8
+ run("rimraf", ["-rf", "./storage/app-dev"]);
9
+ if (opts.all) {
10
+ run("rimraf", ["-rf", "{node_modules,.umi,tsconfig.paths.json}"]);
11
+ }
12
+ run("rimraf", ["-rf", "apps/*/{lib,esm,es,dist,node_modules}"]);
13
+ run("rimraf", ["-rf", "packages/*/{lib,esm,es,dist,node_modules}"]);
14
+ });
15
+ };
16
+ export {
17
+ clean_default as default
18
+ };
@@ -0,0 +1,17 @@
1
+ // src/commands/create-nginx-conf.ts
2
+ import { readFileSync, writeFileSync } from "node:fs";
3
+ import { resolve } from "node:path";
4
+ import { URL } from "node:url";
5
+ var __dirname = new URL(".", import.meta.url).pathname;
6
+ var create_nginx_conf_default = (cli) => {
7
+ cli.command("create-nginx-conf").action(async (name, options) => {
8
+ const file = resolve(__dirname, "../../tachybase.conf.tpl");
9
+ const data = readFileSync(file, "utf-8");
10
+ const replaced = data.replace(/\{\{cwd\}\}/g, "/app/tachybase").replace(/\{\{publicPath\}\}/g, process.env.APP_PUBLIC_PATH).replace(/\{\{apiPort\}\}/g, process.env.APP_PORT);
11
+ const targetFile = resolve(process.cwd(), "storage", "tachybase.conf");
12
+ writeFileSync(targetFile, replaced);
13
+ });
14
+ };
15
+ export {
16
+ create_nginx_conf_default as default
17
+ };
@@ -0,0 +1,18 @@
1
+ // src/commands/create-plugin.ts
2
+ import { resolve } from "node:path";
3
+ import { PluginGenerator } from "../plugin-generator.mjs";
4
+ var create_plugin_default = (cli) => {
5
+ cli.command("create-plugin").argument("<name>").allowUnknownOption().action(async (name, options) => {
6
+ const generator = new PluginGenerator({
7
+ cwd: resolve(process.cwd(), name),
8
+ args: options,
9
+ context: {
10
+ name
11
+ }
12
+ });
13
+ await generator.run();
14
+ });
15
+ };
16
+ export {
17
+ create_plugin_default as default
18
+ };