@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,13 @@
1
+ // src/constants.ts
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ var __filename = fileURLToPath(import.meta.url);
5
+ var __dirname = dirname(__filename);
6
+ var STATIC_PATH = join(__dirname, "../assets");
7
+ var DEFAULT_DEV_HOST = "0.0.0.0";
8
+ export {
9
+ DEFAULT_DEV_HOST,
10
+ STATIC_PATH,
11
+ __dirname,
12
+ __filename
13
+ };
package/lib/index.mjs ADDED
@@ -0,0 +1,8 @@
1
+ // src/index.ts
2
+ export * from "./plugin-generator.mjs";
3
+ import { initEnv } from "./util.mjs";
4
+ export * from "./builder/build/index.mjs";
5
+ export * from "./package-map-generator.mjs";
6
+ export {
7
+ initEnv
8
+ };
@@ -0,0 +1,5 @@
1
+ // src/notify-updates.ts
2
+ import { createRequire } from "node:module";
3
+ import updateNotifier from "update-notifier";
4
+ var require2 = createRequire(import.meta.url);
5
+ updateNotifier({ pkg: require2("../package.json") }).notify({ defer: true });
package/lib/open.mjs ADDED
@@ -0,0 +1,92 @@
1
+ // src/open.ts
2
+ import { logger } from "@rsbuild/core";
3
+ import chalk from "chalk";
4
+ import open, { apps } from "open";
5
+ import { STATIC_PATH } from "./constants.mjs";
6
+ var supportedChromiumBrowsers = [
7
+ "Google Chrome Canary",
8
+ "Google Chrome Dev",
9
+ "Google Chrome Beta",
10
+ "Google Chrome",
11
+ "Microsoft Edge",
12
+ "Brave Browser",
13
+ "Vivaldi",
14
+ "Chromium"
15
+ ];
16
+ var mapChromiumBrowserName = (browser) => {
17
+ if (browser === "chrome" || browser === "google chrome") {
18
+ return "Google Chrome";
19
+ }
20
+ return browser;
21
+ };
22
+ var shouldTryAppleScript = (browser, browserArgs) => {
23
+ if (process.platform !== "darwin") {
24
+ return false;
25
+ }
26
+ if (browser && browserArgs) {
27
+ return false;
28
+ }
29
+ if (!browser) {
30
+ return true;
31
+ }
32
+ return supportedChromiumBrowsers.includes(mapChromiumBrowserName(browser));
33
+ };
34
+ async function openBrowser(url) {
35
+ const browser = process.env.BROWSER;
36
+ const browserArgs = process.env.BROWSER_ARGS;
37
+ if (shouldTryAppleScript(browser, browserArgs)) {
38
+ const { exec } = await import("node:child_process");
39
+ const { promisify } = await import("node:util");
40
+ const execAsync = promisify(exec);
41
+ const getDefaultBrowserForAppleScript = async () => {
42
+ const { stdout: ps } = await execAsync("ps cax");
43
+ return supportedChromiumBrowsers.find((b) => ps.includes(b));
44
+ };
45
+ try {
46
+ const chromiumBrowser = browser ? mapChromiumBrowserName(browser) : await getDefaultBrowserForAppleScript();
47
+ if (chromiumBrowser) {
48
+ await execAsync(`osascript openChrome.applescript "${encodeURI(url)}" "${chromiumBrowser}"`, {
49
+ cwd: STATIC_PATH
50
+ });
51
+ return true;
52
+ }
53
+ logger.debug("failed to find the target browser.");
54
+ } catch (err) {
55
+ logger.debug("failed to open start URL with apple script.");
56
+ logger.debug(err);
57
+ }
58
+ }
59
+ try {
60
+ const options = browser ? {
61
+ app: {
62
+ name: apps[browser] ?? browser,
63
+ arguments: browserArgs?.split(" ")
64
+ }
65
+ } : {};
66
+ await open(url, options);
67
+ return true;
68
+ } catch (err) {
69
+ logger.error("Failed to open start URL.");
70
+ logger.error(err);
71
+ return false;
72
+ }
73
+ }
74
+ var replacePortPlaceholder = (url, port) => url.replace(/<port>/g, String(port));
75
+ function resolveUrl(str, base) {
76
+ if (URL.canParse(str)) {
77
+ return str;
78
+ }
79
+ try {
80
+ const url = new URL(str, base);
81
+ return url.href;
82
+ } catch {
83
+ throw new Error(
84
+ `${chalk.dim("[rsbuild:open]")} Invalid input: ${chalk.yellow(str)} is not a valid URL or pathname`
85
+ );
86
+ }
87
+ }
88
+ export {
89
+ openBrowser,
90
+ replacePortPlaceholder,
91
+ resolveUrl
92
+ };
@@ -0,0 +1,219 @@
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/package-map-generator.ts
9
+ import { existsSync as _existsSync, existsSync, mkdirSync, readFileSync, rmSync, watch, writeFileSync } from "node:fs";
10
+ import { dirname as _dirname, sep as _sep, join, relative, resolve, sep } from "node:path";
11
+ import { sync } from "fast-glob";
12
+ import { version } from "../package.json";
13
+ var ProjectRoot = process.cwd();
14
+ function getUmiConfig() {
15
+ const { APP_PORT, API_BASE_URL, APP_PUBLIC_PATH } = process.env;
16
+ const API_BASE_PATH = process.env.API_BASE_PATH || "/api/";
17
+ const EXTENSION_UI_BASE_PATH = process.env.EXTENSION_UI_BASE_PATH || "/adapters/";
18
+ const PROXY_TARGET_URL = process.env.PROXY_TARGET_URL || `http://127.0.0.1:${APP_PORT}`;
19
+ const LOCAL_STORAGE_BASE_URL = "storage/uploads/";
20
+ const STATIC_PATH = "static/";
21
+ function getLocalStorageProxy() {
22
+ if (LOCAL_STORAGE_BASE_URL.startsWith("http")) {
23
+ return {};
24
+ }
25
+ return {
26
+ [APP_PUBLIC_PATH + LOCAL_STORAGE_BASE_URL]: {
27
+ target: PROXY_TARGET_URL,
28
+ changeOrigin: true
29
+ },
30
+ [APP_PUBLIC_PATH + STATIC_PATH]: {
31
+ target: PROXY_TARGET_URL,
32
+ changeOrigin: true
33
+ }
34
+ };
35
+ }
36
+ return {
37
+ alias: getPackagePaths().reduce((memo, item) => {
38
+ memo[item[0]] = item[1];
39
+ return memo;
40
+ }, {}),
41
+ define: {
42
+ "process.env.APP_PUBLIC_PATH": process.env.APP_PUBLIC_PATH,
43
+ "process.env.WS_PATH": process.env.WS_PATH,
44
+ "process.env.API_BASE_URL": API_BASE_URL || API_BASE_PATH,
45
+ "process.env.APP_ENV": process.env.APP_ENV,
46
+ "process.env.VERSION": version,
47
+ "process.env.WEBSOCKET_URL": process.env.WEBSOCKET_URL,
48
+ "process.env.__E2E__": process.env.__E2E__
49
+ },
50
+ // only proxy when using `umi dev`
51
+ // if the assets are built, will not proxy
52
+ proxy: {
53
+ [API_BASE_PATH]: {
54
+ target: PROXY_TARGET_URL,
55
+ changeOrigin: true,
56
+ pathRewrite: { [`^${API_BASE_PATH}`]: API_BASE_PATH }
57
+ },
58
+ [EXTENSION_UI_BASE_PATH]: {
59
+ target: PROXY_TARGET_URL,
60
+ changeOrigin: true,
61
+ pathRewrite: { [`^${EXTENSION_UI_BASE_PATH}`]: EXTENSION_UI_BASE_PATH }
62
+ },
63
+ // for local storage
64
+ ...getLocalStorageProxy()
65
+ }
66
+ };
67
+ }
68
+ function getTsconfigPaths() {
69
+ const content = readFileSync(resolve(ProjectRoot, "tsconfig.paths.json"), "utf-8");
70
+ const json = JSON.parse(content);
71
+ return json.compilerOptions.paths;
72
+ }
73
+ function getPackagePaths() {
74
+ const paths = getTsconfigPaths();
75
+ const pkgs = [];
76
+ for (const key in paths) {
77
+ if (Object.hasOwnProperty.call(paths, key)) {
78
+ for (let dir of paths[key]) {
79
+ if (dir.includes("*")) {
80
+ const files = sync(dir, { cwd: ProjectRoot, onlyDirectories: true });
81
+ for (const file of files) {
82
+ const dirname = resolve(ProjectRoot, file);
83
+ if (existsSync(dirname)) {
84
+ const re = new RegExp(dir.replace("*", "(.+)"));
85
+ const p = dirname.substring(ProjectRoot.length + 1).split(sep).join("/");
86
+ const match = re.exec(p);
87
+ pkgs.push([key.replace("*", match?.[1]), dirname]);
88
+ }
89
+ }
90
+ } else {
91
+ const dirname = resolve(ProjectRoot, dir);
92
+ pkgs.push([key, dirname]);
93
+ }
94
+ }
95
+ }
96
+ }
97
+ return pkgs;
98
+ }
99
+ function resolveTachybasePackagesAlias(config) {
100
+ const pkgs = getPackagePaths();
101
+ for (const [pkg, dir] of pkgs) {
102
+ config.module.rules.get("ts-in-node_modules").include.add(dir);
103
+ config.resolve.alias.set(pkg, dir);
104
+ }
105
+ }
106
+ function getNodeModulesPath(packageDir) {
107
+ const node_modules_dir = join(ProjectRoot, "node_modules");
108
+ return join(node_modules_dir, packageDir);
109
+ }
110
+ var IndexGenerator = class {
111
+ tachybaseDir = getNodeModulesPath("@tachybase");
112
+ constructor(outputPath, pluginsPath) {
113
+ this.outputPath = outputPath;
114
+ this.pluginsPath = pluginsPath;
115
+ }
116
+ get indexPath() {
117
+ return join(this.outputPath, "index.ts");
118
+ }
119
+ get packageMapPath() {
120
+ return join(this.outputPath, "packageMap.json");
121
+ }
122
+ get packagesPath() {
123
+ return join(this.outputPath, "packages");
124
+ }
125
+ generate() {
126
+ this.generatePluginContent();
127
+ if (process.env.NODE_ENV === "production") return;
128
+ this.pluginsPath.forEach((pluginPath) => {
129
+ if (!_existsSync(pluginPath)) {
130
+ return;
131
+ }
132
+ watch(pluginPath, { recursive: false }, () => {
133
+ this.generatePluginContent();
134
+ });
135
+ });
136
+ }
137
+ get indexContent() {
138
+ return `// @ts-nocheck
139
+ import packageMap from './packageMap.json';
140
+
141
+ function devDynamicImport(packageName: string): Promise<any> {
142
+ const fileName = packageMap[packageName];
143
+ if (!fileName) {
144
+ return Promise.resolve(null);
145
+ }
146
+ return import(\`./packages/\${fileName}\`)
147
+ }
148
+ export default devDynamicImport;`;
149
+ }
150
+ get emptyIndexContent() {
151
+ return `
152
+ export default function devDynamicImport(packageName: string): Promise<any> {
153
+ return Promise.resolve(null);
154
+ }`;
155
+ }
156
+ generatePluginContent() {
157
+ if (_existsSync(this.outputPath)) {
158
+ rmSync(this.outputPath, { recursive: true, force: true });
159
+ }
160
+ mkdirSync(this.outputPath);
161
+ const validPluginPaths = this.pluginsPath.filter((pluginsPath) => {
162
+ return _existsSync(pluginsPath);
163
+ });
164
+ if (process.env.NODE_ENV === "production") {
165
+ writeFileSync(this.indexPath, this.emptyIndexContent);
166
+ return;
167
+ }
168
+ const pluginInfos = validPluginPaths.map((pluginsPath) => this.getContent(pluginsPath)).flat();
169
+ writeFileSync(this.indexPath, this.indexContent);
170
+ const packageMapContent = pluginInfos.reduce((memo, item) => {
171
+ memo[item.packageJsonName] = item.pluginFileName + ".ts";
172
+ return memo;
173
+ }, {});
174
+ writeFileSync(this.packageMapPath, JSON.stringify(packageMapContent, null, 2));
175
+ mkdirSync(this.packagesPath, { recursive: true });
176
+ pluginInfos.forEach((item) => {
177
+ const pluginPackagePath = join(this.packagesPath, item.pluginFileName + ".ts");
178
+ writeFileSync(pluginPackagePath, item.exportStatement);
179
+ });
180
+ }
181
+ getContent(pluginsPath) {
182
+ const pluginFolders = sync(["plugin-*/package.json", "module-*/package.json"], {
183
+ cwd: pluginsPath,
184
+ onlyFiles: true,
185
+ absolute: true
186
+ });
187
+ const pluginInfos = Array.from(new Set(pluginFolders)).filter((item) => {
188
+ const dirname = _dirname(item);
189
+ const clientJs = join(dirname, "client.js");
190
+ return _existsSync(clientJs);
191
+ }).map((pluginPackageJsonPath) => {
192
+ const pluginPackageJson = __require(pluginPackageJsonPath);
193
+ const pluginPathArr = pluginPackageJsonPath.replaceAll(_sep, "/").split("/");
194
+ const hasNamespace = pluginPathArr[pluginPathArr.length - 3].startsWith("@");
195
+ const pluginFileName = (hasNamespace ? `${pluginPathArr[pluginPathArr.length - 3].replace("@", "")}_${pluginPathArr[pluginPathArr.length - 2]}` : pluginPathArr[pluginPathArr.length - 2]).replaceAll("-", "_");
196
+ let exportStatement = "";
197
+ if (pluginPackageJsonPath.includes("packages")) {
198
+ const pluginSrcClientPath = relative(
199
+ this.packagesPath,
200
+ join(_dirname(pluginPackageJsonPath), "src", "client")
201
+ ).replaceAll(_sep, "/");
202
+ exportStatement = `export { default } from '${pluginSrcClientPath}';`;
203
+ exportStatement += "\n";
204
+ exportStatement += `export * from '${pluginSrcClientPath}';`;
205
+ } else {
206
+ exportStatement = `export { default } from '${pluginPackageJson.name}/client';`;
207
+ exportStatement += "\n";
208
+ exportStatement += `export * from '${pluginPackageJson.name}/client';`;
209
+ }
210
+ return { exportStatement, pluginFileName, packageJsonName: pluginPackageJson.name };
211
+ });
212
+ return pluginInfos;
213
+ }
214
+ };
215
+ export {
216
+ IndexGenerator,
217
+ getUmiConfig,
218
+ resolveTachybasePackagesAlias
219
+ };
@@ -0,0 +1,63 @@
1
+ // src/plugin-generator.ts
2
+ import { existsSync } from "node:fs";
3
+ import { readFile } from "node:fs/promises";
4
+ import { join, resolve } from "node:path";
5
+ import { URL } from "node:url";
6
+ import { Generator } from "@umijs/utils";
7
+ import chalk from "chalk";
8
+ import { execa } from "execa";
9
+ import { genTsConfigPaths } from "./util.mjs";
10
+ var __dirname = new URL(".", import.meta.url).pathname;
11
+ function camelize(str) {
12
+ return str.trim().replace(/[-_\s]+(.)?/g, (match, c) => c.toUpperCase());
13
+ }
14
+ function capitalize(string) {
15
+ return string.charAt(0).toUpperCase() + string.slice(1);
16
+ }
17
+ async function getProjectVersion() {
18
+ const content = await readFile(resolve(process.cwd(), "package.json"), "utf-8");
19
+ const json = JSON.parse(content);
20
+ return json.version || "0.1.0";
21
+ }
22
+ var PluginGenerator = class extends Generator {
23
+ context;
24
+ log;
25
+ constructor(options) {
26
+ const { log, context = {}, ...opts } = options;
27
+ super(opts);
28
+ this.context = context;
29
+ this.log = log || console.log;
30
+ }
31
+ async getContext() {
32
+ const { name } = this.context;
33
+ const packageVersion = await getProjectVersion();
34
+ return {
35
+ ...this.context,
36
+ packageName: name,
37
+ packageVersion,
38
+ tachybaseVersion: "0.0.1",
39
+ pascalCaseName: capitalize(camelize(name.split("/").pop()))
40
+ };
41
+ }
42
+ async writing() {
43
+ const name = this.context.name.split("/").pop();
44
+ const target = resolve(process.cwd(), "packages/", name);
45
+ if (existsSync(target)) {
46
+ this.log(chalk.red(`[${name}] plugin already exists.`));
47
+ return;
48
+ }
49
+ this.log("Creating plugin");
50
+ this.copyDirectory({
51
+ target,
52
+ context: await this.getContext(),
53
+ path: join(__dirname, "../templates/plugin")
54
+ });
55
+ this.log("");
56
+ genTsConfigPaths();
57
+ execa("pnpm", ["postinstall"], { shell: true, stdio: "inherit" });
58
+ this.log(`The plugin folder is in ${chalk.green(`packages/${name}`)}`);
59
+ }
60
+ };
61
+ export {
62
+ PluginGenerator
63
+ };