@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
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [2023-2025] [Tego team]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,95 @@
1
+ (*
2
+ Copyright (c) 2015-present, Facebook, Inc.
3
+
4
+ This source code is licensed under the MIT license found in the
5
+ LICENSE file at
6
+ https://github.com/facebookincubator/create-react-app/blob/master/LICENSE
7
+ *)
8
+
9
+ property targetTab: null
10
+ property targetTabIndex: -1
11
+ property targetWindow: null
12
+ property theProgram: "Google Chrome"
13
+
14
+ on run argv
15
+ set theURL to item 1 of argv
16
+
17
+ -- Allow requested program to be optional,
18
+ -- default to Google Chrome
19
+ if (count of argv) > 1 then
20
+ set theProgram to item 2 of argv
21
+ end if
22
+
23
+ using terms from application "Google Chrome"
24
+ tell application theProgram
25
+
26
+ if (count every window) = 0 then
27
+ make new window
28
+ end if
29
+
30
+ -- 1: Looking for tab running debugger
31
+ -- then, Reload debugging tab if found
32
+ -- then return
33
+ set found to my lookupTabWithUrl(theURL)
34
+ if found then
35
+ set targetWindow's active tab index to targetTabIndex
36
+ tell targetTab to reload
37
+ tell targetWindow to activate
38
+ set index of targetWindow to 1
39
+ return
40
+ end if
41
+
42
+ -- 2: Looking for Empty tab
43
+ -- In case debugging tab was not found
44
+ -- We try to find an empty tab instead
45
+ set found to my lookupTabWithUrl("chrome://newtab/")
46
+ if found then
47
+ set targetWindow's active tab index to targetTabIndex
48
+ set URL of targetTab to theURL
49
+ tell targetWindow to activate
50
+ return
51
+ end if
52
+
53
+ -- 3: Create new tab
54
+ -- both debugging and empty tab were not found
55
+ -- make a new tab with url
56
+ tell window 1
57
+ activate
58
+ make new tab with properties {URL:theURL}
59
+ end tell
60
+ end tell
61
+ end using terms from
62
+ end run
63
+
64
+ -- Function:
65
+ -- Lookup tab with given url
66
+ -- if found, store tab, index, and window in properties
67
+ -- (properties were declared on top of file)
68
+ on lookupTabWithUrl(lookupUrl)
69
+ using terms from application "Google Chrome"
70
+ tell application theProgram
71
+ -- Find a tab with the given url
72
+ set found to false
73
+ set theTabIndex to -1
74
+ repeat with theWindow in every window
75
+ set theTabIndex to 0
76
+ repeat with theTab in every tab of theWindow
77
+ set theTabIndex to theTabIndex + 1
78
+ if (theTab's URL as string) contains lookupUrl then
79
+ -- assign tab, tab index, and window to properties
80
+ set targetTab to theTab
81
+ set targetTabIndex to theTabIndex
82
+ set targetWindow to theWindow
83
+ set found to true
84
+ exit repeat
85
+ end if
86
+ end repeat
87
+
88
+ if found then
89
+ exit repeat
90
+ end if
91
+ end repeat
92
+ end tell
93
+ end using terms from
94
+ return found
95
+ end lookupTabWithUrl
package/bin/cli.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import('../lib/cli.mjs');
@@ -0,0 +1,40 @@
1
+ // src/builder/build/buildCjs.ts
2
+ import path from "node:path";
3
+ import chalk from "chalk";
4
+ import fg from "fast-glob";
5
+ import { build } from "tsup";
6
+ import { EsbuildSupportExts, globExcludeFiles } from "./constant.mjs";
7
+ function buildCjs(cwd, userConfig, sourcemap = false, log) {
8
+ log("build cjs");
9
+ const entry = fg.globSync(["src/**", ...globExcludeFiles], { cwd, absolute: true });
10
+ const outDir = path.join(cwd, "lib");
11
+ const otherExts = Array.from(
12
+ new Set(entry.map((item) => path.extname(item)).filter((item) => !EsbuildSupportExts.includes(item)))
13
+ );
14
+ if (otherExts.length) {
15
+ log("%s will not be processed, only be copied to the lib directory.", chalk.yellow(otherExts.join(",")));
16
+ }
17
+ return build(
18
+ userConfig.modifyTsupConfig({
19
+ entry,
20
+ splitting: false,
21
+ clean: true,
22
+ bundle: false,
23
+ silent: true,
24
+ sourcemap,
25
+ treeshake: false,
26
+ target: "node16",
27
+ keepNames: true,
28
+ outDir,
29
+ loader: {
30
+ ...otherExts.reduce((prev, cur) => ({ ...prev, [cur]: "copy" }), {}),
31
+ ".json": "copy"
32
+ },
33
+ format: "cjs",
34
+ skipNodeModulesBundle: true
35
+ })
36
+ );
37
+ }
38
+ export {
39
+ buildCjs
40
+ };
@@ -0,0 +1,97 @@
1
+ // src/builder/build/buildClient.ts
2
+ import path from "node:path";
3
+ import { pluginLess } from "@rsbuild/plugin-less";
4
+ import { pluginReact } from "@rsbuild/plugin-react";
5
+ import { build } from "@rslib/core";
6
+ import fg from "fast-glob";
7
+ import { build as tsupBuild } from "tsup";
8
+ import { globExcludeFiles } from "./constant.mjs";
9
+ async function buildClient(cwd, userConfig, sourcemap = false, log) {
10
+ log("build client");
11
+ const cwdWin = cwd.replaceAll(/\\/g, "/");
12
+ const cwdUnix = cwd.replaceAll(/\//g, "\\");
13
+ const external = function(id) {
14
+ if (id.startsWith(".") || id.startsWith(cwdUnix) || id.startsWith(cwdWin)) {
15
+ return false;
16
+ }
17
+ return true;
18
+ };
19
+ await buildClientEsm(cwd, userConfig, sourcemap, external, log);
20
+ await buildLocale(cwd, userConfig, log);
21
+ }
22
+ async function buildClientEsm(cwd, userConfig, sourcemap, external, log) {
23
+ const entry = fg.globSync(["src/**", ...globExcludeFiles, "!src/**/*.json"], { cwd, absolute: true });
24
+ await build({
25
+ source: {
26
+ entry: {
27
+ index: entry
28
+ },
29
+ define: {
30
+ "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || "production"),
31
+ "process.env.__TEST__": false,
32
+ "process.env.__E2E__": process.env.__E2E__ ? true : false
33
+ }
34
+ },
35
+ lib: [
36
+ {
37
+ bundle: false,
38
+ dts: false,
39
+ format: "esm",
40
+ output: {
41
+ distPath: {
42
+ root: path.join(cwd, "es")
43
+ }
44
+ }
45
+ },
46
+ {
47
+ output: {
48
+ distPath: {
49
+ root: path.join(cwd, "lib")
50
+ }
51
+ },
52
+ bundle: false,
53
+ dts: false,
54
+ format: "cjs"
55
+ }
56
+ ],
57
+ output: {
58
+ sourceMap: {
59
+ css: sourcemap,
60
+ js: sourcemap ? "source-map" : false
61
+ },
62
+ target: "web",
63
+ overrideBrowserslist: ["chrome >= 69", "edge >= 79", "safari >= 12"],
64
+ externals({ request }, callback) {
65
+ if (external(request)) {
66
+ return callback(null, request);
67
+ }
68
+ callback();
69
+ }
70
+ },
71
+ plugins: [pluginReact(), pluginLess()]
72
+ });
73
+ }
74
+ function buildLocale(cwd, userConfig, log) {
75
+ log("build client locale");
76
+ const entry = fg.globSync(["src/locale/**", ...globExcludeFiles], { cwd, absolute: true });
77
+ const outDir = path.resolve(cwd, "lib", "locale");
78
+ return tsupBuild(
79
+ userConfig.modifyTsupConfig({
80
+ entry,
81
+ splitting: false,
82
+ clean: false,
83
+ bundle: false,
84
+ silent: true,
85
+ treeshake: false,
86
+ target: "node16",
87
+ keepNames: true,
88
+ outDir,
89
+ format: "cjs",
90
+ skipNodeModulesBundle: true
91
+ })
92
+ );
93
+ }
94
+ export {
95
+ buildClient,
96
+ buildLocale
97
+ };
@@ -0,0 +1,46 @@
1
+ // src/builder/build/buildDeclaration.ts
2
+ import path from "node:path";
3
+ import fg from "fast-glob";
4
+ import fs from "fs-extra";
5
+ import ts from "typescript";
6
+ import { globExcludeFiles, ROOT_PATH } from "./constant.mjs";
7
+ var buildDeclaration = (cwd, targetDir, log) => {
8
+ return new Promise((resolve, reject) => {
9
+ log("build declaration");
10
+ const localTsConfigPath = path.join(cwd, "tsconfig.json");
11
+ const configPath = fs.existsSync(localTsConfigPath) ? localTsConfigPath : path.join(ROOT_PATH, "tsconfig.json");
12
+ const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
13
+ if (configFile.error) {
14
+ const message = ts.flattenDiagnosticMessageText(configFile.error.messageText, "\n");
15
+ return reject(`Error reading tsconfig.json: ${message}`);
16
+ }
17
+ const parsedCommandLine = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath));
18
+ parsedCommandLine.options.paths = {};
19
+ parsedCommandLine.options.outDir = path.join(cwd, targetDir);
20
+ parsedCommandLine.fileNames = fg.globSync(["src/**/*.{ts,tsx}", ...globExcludeFiles], { cwd, absolute: true });
21
+ parsedCommandLine.options.rootDir = path.join(cwd, "src");
22
+ const program = ts.createProgram(parsedCommandLine.fileNames, parsedCommandLine.options);
23
+ const emitResult = program.emit();
24
+ const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
25
+ const messages = [];
26
+ allDiagnostics.forEach((diagnostic) => {
27
+ if (diagnostic.file) {
28
+ const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
29
+ const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
30
+ messages.push(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
31
+ console.error(`${diagnostic.file.fileName}(${line + 1},${character + 1}): ${message}`);
32
+ } else {
33
+ messages.push(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
34
+ console.error(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
35
+ }
36
+ });
37
+ const exitCode = emitResult.emitSkipped ? 1 : 0;
38
+ if (messages.length > 0) {
39
+ reject(messages.join("\n"));
40
+ }
41
+ resolve({ exitCode, messages });
42
+ });
43
+ };
44
+ export {
45
+ buildDeclaration
46
+ };
@@ -0,0 +1,64 @@
1
+ // src/builder/build/buildEsm.ts
2
+ import { createRequire } from "node:module";
3
+ import path from "node:path";
4
+ import fg from "fast-glob";
5
+ import { build as viteBuild } from "vite";
6
+ var require2 = createRequire(import.meta.url);
7
+ async function buildEsm(cwd, userConfig, sourcemap = false, log) {
8
+ log("build esm");
9
+ const indexEntry = path.join(cwd, "src/index.ts").replaceAll(/\\/g, "/");
10
+ const outDir = path.resolve(cwd, "es");
11
+ await build(cwd, indexEntry, outDir, userConfig, sourcemap, log);
12
+ const clientEntry = fg.sync(["src/client/index.ts", "src/client.ts"], { cwd, absolute: true, onlyFiles: true })?.[0]?.replaceAll(/\\/g, "/");
13
+ const clientOutDir = path.resolve(cwd, "es/client");
14
+ if (clientEntry) {
15
+ await build(cwd, clientEntry, clientOutDir, userConfig, sourcemap, log);
16
+ }
17
+ const pkg = require2(path.join(cwd, "package.json"));
18
+ if (pkg.name === "@tachybase/test") {
19
+ const e2eEntry = path.join(cwd, "src/e2e/index.ts").replaceAll(/\\/g, "/");
20
+ const e2eOutDir = path.resolve(cwd, "es/e2e");
21
+ await build(cwd, e2eEntry, e2eOutDir, userConfig, sourcemap, log);
22
+ }
23
+ }
24
+ function build(cwd, entry, outDir, userConfig, sourcemap = false, log) {
25
+ const cwdWin = cwd.replaceAll(/\\/g, "/");
26
+ const cwdUnix = cwd.replaceAll(/\//g, "\\");
27
+ const external = function(id) {
28
+ if (id.startsWith(".") || id.startsWith(cwdUnix) || id.startsWith(cwdWin)) {
29
+ return false;
30
+ }
31
+ return true;
32
+ };
33
+ return viteBuild(
34
+ userConfig.modifyViteConfig({
35
+ mode: process.env.NODE_ENV || "production",
36
+ define: {
37
+ "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || "production"),
38
+ "process.env.__TEST__": false,
39
+ "process.env.__E2E__": process.env.__E2E__ ? true : false
40
+ },
41
+ build: {
42
+ minify: false,
43
+ outDir,
44
+ cssCodeSplit: true,
45
+ emptyOutDir: true,
46
+ sourcemap,
47
+ lib: {
48
+ entry,
49
+ formats: ["es"],
50
+ fileName: "index"
51
+ },
52
+ target: ["node16"],
53
+ rollupOptions: {
54
+ cache: true,
55
+ treeshake: true,
56
+ external
57
+ }
58
+ }
59
+ })
60
+ );
61
+ }
62
+ export {
63
+ buildEsm
64
+ };
@@ -0,0 +1,58 @@
1
+ // src/builder/build/constant.ts
2
+ import path from "node:path";
3
+ var globExcludeFiles = [
4
+ "!src/**/__tests__",
5
+ "!src/**/__test__",
6
+ "!src/**/__e2e__",
7
+ "!src/**/demos",
8
+ "!src/**/fixtures",
9
+ "!src/**/*.mdx",
10
+ "!src/**/*.md",
11
+ "!src/**/*.+(test|e2e|spec).+(js|jsx|ts|tsx)"
12
+ ];
13
+ var EsbuildSupportExts = [
14
+ ".ts",
15
+ ".tsx",
16
+ ".js",
17
+ ".jsx",
18
+ ".json",
19
+ ".css",
20
+ ".less",
21
+ ".sass",
22
+ ".scss",
23
+ ".styl",
24
+ ".txt",
25
+ ".data"
26
+ ];
27
+ var PATTERN_PLUGIN = "@[^/]+/plugin-";
28
+ var PATTERN_MODULE = "@[^/]+/module-";
29
+ var PLUGIN_PATTRN = /^(@[^/]+\/)?(module|plugin)-/;
30
+ var ROOT_PATH = process.cwd();
31
+ var NODE_MODULES = path.join(ROOT_PATH, "node_modules");
32
+ var PACKAGES_PATH = path.join(ROOT_PATH, "packages");
33
+ var getPluginPackages = (packages) => packages.filter((item) => !!item.manifest.name?.match(PATTERN_PLUGIN) || !!item.manifest.name?.match(PATTERN_MODULE));
34
+ var CORE_APP = path.join(ROOT_PATH, "apps/web");
35
+ var CORE_CLIENT = path.join(PACKAGES_PATH, "client");
36
+ var ESM_PACKAGES = ["@tachybase/test"];
37
+ var CJS_EXCLUDE_PACKAGES = [path.join(ROOT_PATH, "apps/devkit"), CORE_CLIENT, CORE_APP];
38
+ var getCjsPackages = (packages) => packages.filter((item) => !item.manifest.name?.match(PATTERN_PLUGIN)).filter((item) => !item.manifest.name?.match(PATTERN_MODULE)).filter((item) => !CJS_EXCLUDE_PACKAGES.includes(item.dir));
39
+ var tarIncludesFiles = ["package.json", "README.md", "LICENSE", "dist", "!node_modules", "!src"];
40
+ var TAR_OUTPUT_DIR = process.env.TAR_PATH ? process.env.TAR_PATH : path.join(ROOT_PATH, "storage", "tar");
41
+ export {
42
+ CJS_EXCLUDE_PACKAGES,
43
+ CORE_APP,
44
+ CORE_CLIENT,
45
+ ESM_PACKAGES,
46
+ EsbuildSupportExts,
47
+ NODE_MODULES,
48
+ PACKAGES_PATH,
49
+ PATTERN_MODULE,
50
+ PATTERN_PLUGIN,
51
+ PLUGIN_PATTRN,
52
+ ROOT_PATH,
53
+ TAR_OUTPUT_DIR,
54
+ getCjsPackages,
55
+ getPluginPackages,
56
+ globExcludeFiles,
57
+ tarIncludesFiles
58
+ };
@@ -0,0 +1,2 @@
1
+ // src/builder/build/index.ts
2
+ export * from "./utils/index.mjs";
@@ -0,0 +1,28 @@
1
+ // src/builder/build/tarPlugin.ts
2
+ import { mkdir } from "node:fs/promises";
3
+ import path, { dirname } from "node:path";
4
+ import Arborist from "@npmcli/arborist";
5
+ import fs from "fs-extra";
6
+ import packlist from "npm-packlist";
7
+ import * as tar from "tar";
8
+ import { TAR_OUTPUT_DIR } from "./constant.mjs";
9
+ async function tarPlugin(cwd, log) {
10
+ log("tar package", cwd);
11
+ const arborist = new Arborist({ path: cwd });
12
+ const node = await arborist.loadActual();
13
+ const files = await packlist(node);
14
+ const pkg = fs.readJsonSync(path.join(cwd, "package.json"));
15
+ const tarball = path.join(TAR_OUTPUT_DIR, `${pkg.name}-${pkg.version}.tgz`);
16
+ await mkdir(dirname(tarball), { recursive: true });
17
+ await tar.c(
18
+ {
19
+ gzip: true,
20
+ file: tarball,
21
+ cwd
22
+ },
23
+ files
24
+ );
25
+ }
26
+ export {
27
+ tarPlugin
28
+ };