@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,118 @@
1
+ // src/builder/build/utils/buildPluginUtils.ts
2
+ import fs from "node:fs";
3
+ import { builtinModules } from "node:module";
4
+ import path from "node:path";
5
+ import chalk from "chalk";
6
+ var requireRegex = /require\s*\(['"`](.*?)['"`]\)/g;
7
+ var importRegex = /^import(?:['"\s]*([\w*${}\s,]+)from\s*)?['"\s]['"\s](.*[@\w_-]+)['"\s].*/gm;
8
+ function isNotBuiltinModule(packageName) {
9
+ return !builtinModules.includes(packageName);
10
+ }
11
+ var isValidPackageName = (str) => {
12
+ const pattern = /^(?:@[a-zA-Z0-9_-]+\/)?[a-zA-Z0-9_-]+$/;
13
+ return pattern.test(str);
14
+ };
15
+ function getPackageNameFromString(str) {
16
+ if (str.startsWith(".")) return null;
17
+ const arr = str.split("/");
18
+ let packageName;
19
+ if (arr[0].startsWith("@")) {
20
+ packageName = arr.slice(0, 2).join("/");
21
+ } else {
22
+ packageName = arr[0];
23
+ }
24
+ packageName = packageName.trim();
25
+ return isValidPackageName(packageName) ? packageName : null;
26
+ }
27
+ function getPackagesFromFiles(files) {
28
+ const packageNames = files.map((item) => [
29
+ ...[...item.matchAll(importRegex)].map((item2) => item2[2]),
30
+ ...[...item.matchAll(requireRegex)].map((item2) => item2[1])
31
+ ]).flat().map(getPackageNameFromString).filter(Boolean).filter(isNotBuiltinModule);
32
+ return [...new Set(packageNames)];
33
+ }
34
+ function getSourcePackages(fileSources) {
35
+ return getPackagesFromFiles(fileSources);
36
+ }
37
+ function getIncludePackages(sourcePackages, external, pluginPrefix) {
38
+ return sourcePackages.filter((packageName) => !external.includes(packageName)).filter((packageName) => !pluginPrefix.some((prefix) => packageName.startsWith(prefix)));
39
+ }
40
+ function getExcludePackages(sourcePackages, external, pluginPrefix) {
41
+ const includePackages = getIncludePackages(sourcePackages, external, pluginPrefix);
42
+ return sourcePackages.filter((packageName) => !includePackages.includes(packageName));
43
+ }
44
+ function getPackageJsonPackages(packageJson) {
45
+ return [
46
+ .../* @__PURE__ */ new Set([...Object.keys(packageJson.devDependencies || {}), ...Object.keys(packageJson.dependencies || {})])
47
+ ];
48
+ }
49
+ function checkEntryExists(cwd, entry, log) {
50
+ const srcDir = path.join(cwd, "src", entry);
51
+ if (!fs.existsSync(srcDir)) {
52
+ log("Missing %s. Please create it.", chalk.red(`src/${entry}`));
53
+ process.exit(-1);
54
+ }
55
+ return srcDir;
56
+ }
57
+ function checkDependencies(packageJson, log) {
58
+ }
59
+ function getFileSize(filePath) {
60
+ const stat = fs.statSync(filePath);
61
+ return stat.size;
62
+ }
63
+ function formatFileSize(fileSize) {
64
+ const kb = fileSize / 1024;
65
+ return kb.toFixed(2) + " KB";
66
+ }
67
+ function buildCheck(options) {
68
+ const { cwd, log, entry, files, packageJson } = options;
69
+ checkEntryExists(cwd, entry, log);
70
+ checkDependencies(packageJson, log);
71
+ }
72
+ function checkRequire(sourceFiles, log) {
73
+ const requireArr = sourceFiles.map((filePath) => {
74
+ const code = fs.readFileSync(filePath, "utf-8");
75
+ return [...code.matchAll(requireRegex)].map((item) => ({
76
+ filePath,
77
+ code: item[0]
78
+ }));
79
+ }).flat();
80
+ if (requireArr.length) {
81
+ log("%s not allowed. Please use %s instead.", chalk.red("require()"), chalk.red("import"));
82
+ requireArr.forEach((item, index) => {
83
+ console.log("%s. %s in %s;", index + 1, chalk.red(item.code), chalk.red(item.filePath));
84
+ });
85
+ console.log("\n");
86
+ process.exit(-1);
87
+ }
88
+ }
89
+ function checkFileSize(outDir, log) {
90
+ const files = fs.readdirSync(outDir);
91
+ files.forEach((file) => {
92
+ const fileSize = getFileSize(path.join(outDir, file));
93
+ if (fileSize > 1024 * 1024) {
94
+ log(
95
+ `The %s size %s exceeds 1MB. You can use dynamic import \`import()\` for lazy loading content.`,
96
+ chalk.red(file),
97
+ chalk.red(formatFileSize(fileSize))
98
+ );
99
+ }
100
+ });
101
+ }
102
+ export {
103
+ buildCheck,
104
+ checkDependencies,
105
+ checkEntryExists,
106
+ checkFileSize,
107
+ checkRequire,
108
+ formatFileSize,
109
+ getExcludePackages,
110
+ getFileSize,
111
+ getIncludePackages,
112
+ getPackageJsonPackages,
113
+ getPackageNameFromString,
114
+ getPackagesFromFiles,
115
+ getSourcePackages,
116
+ isNotBuiltinModule,
117
+ isValidPackageName
118
+ };
@@ -0,0 +1,86 @@
1
+ // src/builder/build/utils/getDepsConfig.ts
2
+ import { createRequire } from "node:module";
3
+ import path from "node:path";
4
+ import fs from "fs-extra";
5
+ var require2 = createRequire(import.meta.url);
6
+ function winPath(path2) {
7
+ const isExtendedLengthPath = path2.startsWith("\\\\?\\");
8
+ if (isExtendedLengthPath) {
9
+ return path2;
10
+ }
11
+ return path2.replace(/\\/g, "/");
12
+ }
13
+ function getRltExternalsFromDeps(depExternals, current) {
14
+ return Object.entries(depExternals).reduce((r, [dep, target]) => {
15
+ if (dep !== current.name) {
16
+ r[dep] = winPath(path.relative(current.outputDir, path.dirname(target)));
17
+ }
18
+ return r;
19
+ }, {});
20
+ }
21
+ function findPackageJson(filePath) {
22
+ const directory = path.dirname(filePath);
23
+ const packageJsonPath = path.resolve(directory, "package.json");
24
+ if (fs.existsSync(packageJsonPath)) {
25
+ return directory;
26
+ } else if (directory !== "/") {
27
+ return findPackageJson(directory);
28
+ } else {
29
+ throw new Error("package.json not found.");
30
+ }
31
+ }
32
+ function getDepPkgPath(dep, cwd) {
33
+ try {
34
+ return require2.resolve(`${dep}/package.json`, { paths: [cwd] });
35
+ } catch {
36
+ const mainFile = require2.resolve(`${dep}`, { paths: cwd ? [cwd] : void 0 });
37
+ const packageDir = mainFile.slice(0, mainFile.indexOf(dep.replace("/", path.sep)) + dep.length);
38
+ const result = path.join(packageDir, "package.json");
39
+ if (!fs.existsSync(result)) {
40
+ return path.join(findPackageJson(mainFile), "package.json");
41
+ }
42
+ return result;
43
+ }
44
+ }
45
+ function getDepsConfig(cwd, outDir, depsName, external) {
46
+ const pkgExternals = external.reduce((r, dep) => ({ ...r, [dep]: dep }), {});
47
+ const depExternals = {};
48
+ const deps = depsName.reduce((acc, packageName) => {
49
+ const depEntryPath = require2.resolve(packageName, { paths: [cwd] });
50
+ const depPkgPath = getDepPkgPath(packageName, cwd);
51
+ const depPkg = require2(depPkgPath);
52
+ const depDir = path.dirname(depPkgPath);
53
+ const outputDir = path.join(outDir, packageName);
54
+ const mainFile = path.join(outputDir, depEntryPath.replace(depDir, ""));
55
+ acc[depEntryPath] = {
56
+ nccConfig: {
57
+ minify: true,
58
+ target: "es5",
59
+ quiet: true,
60
+ externals: {}
61
+ },
62
+ depDir,
63
+ pkg: depPkg,
64
+ outputDir,
65
+ mainFile
66
+ };
67
+ return acc;
68
+ }, {});
69
+ Object.values(deps).forEach((depConfig) => {
70
+ const rltDepExternals = getRltExternalsFromDeps(depExternals, {
71
+ name: depConfig.pkg.name,
72
+ outputDir: depConfig.outputDir
73
+ });
74
+ depConfig.nccConfig.externals = {
75
+ ...pkgExternals,
76
+ ...rltDepExternals
77
+ };
78
+ });
79
+ return deps;
80
+ }
81
+ export {
82
+ getDepPkgPath,
83
+ getDepsConfig,
84
+ getRltExternalsFromDeps,
85
+ winPath
86
+ };
@@ -0,0 +1,63 @@
1
+ // src/builder/build/utils/getPackages.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 "../constant.mjs";
8
+ import { toUnixPath } from "./utils.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,2 @@
1
+ // src/builder/build/utils/index.ts
2
+ export * from "./utils.mjs";
@@ -0,0 +1,60 @@
1
+ // src/builder/build/utils/utils.ts
2
+ import { createRequire } from "node:module";
3
+ import path from "node:path";
4
+ import chalk from "chalk";
5
+ import fg from "fast-glob";
6
+ import fs from "fs-extra";
7
+ import { require as tsxRequire } from "tsx/cjs/api";
8
+ import { NODE_MODULES } from "../constant.mjs";
9
+ var require2 = createRequire(import.meta.url);
10
+ var getPkgLog = (pkgName) => {
11
+ const pkgStr = chalk.underline.magentaBright(pkgName);
12
+ const pkgLog = (msg, ...optionalParams) => console.log(`${pkgStr}: ${msg}`, ...optionalParams);
13
+ return pkgLog;
14
+ };
15
+ function toUnixPath(filepath) {
16
+ return filepath.replace(/\\/g, "/");
17
+ }
18
+ function getPackageJson(cwd) {
19
+ return require2(path.join(cwd, "package.json"));
20
+ }
21
+ function defineConfig(config) {
22
+ return config;
23
+ }
24
+ function getUserConfig(cwd) {
25
+ const config = defineConfig({
26
+ modifyTsupConfig: (config2) => config2,
27
+ modifyViteConfig: (config2) => config2
28
+ });
29
+ const buildConfigs = fg.sync(["./build.config.js", "./build.config.ts"], { cwd });
30
+ if (buildConfigs.length > 1) {
31
+ throw new Error(`Multiple build configs found: ${buildConfigs.join(", ")}`);
32
+ }
33
+ if (buildConfigs.length === 1) {
34
+ const userConfig = tsxRequire(buildConfigs[0], path.resolve(cwd, "index.js"));
35
+ Object.assign(config, userConfig.default || userConfig);
36
+ }
37
+ return config;
38
+ }
39
+ var CACHE_DIR = path.join(NODE_MODULES, ".cache", "tachybase");
40
+ function writeToCache(key, data) {
41
+ const cachePath = path.join(CACHE_DIR, `${key}.json`);
42
+ fs.ensureDirSync(path.dirname(cachePath));
43
+ fs.writeJsonSync(cachePath, data, { spaces: 2 });
44
+ }
45
+ function readFromCache(key) {
46
+ const cachePath = path.join(CACHE_DIR, `${key}.json`);
47
+ if (fs.existsSync(cachePath)) {
48
+ return fs.readJsonSync(cachePath);
49
+ }
50
+ return {};
51
+ }
52
+ export {
53
+ defineConfig,
54
+ getPackageJson,
55
+ getPkgLog,
56
+ getUserConfig,
57
+ readFromCache,
58
+ toUnixPath,
59
+ writeToCache
60
+ };
@@ -0,0 +1,38 @@
1
+ // src/builder/buildable-packages/app-web-package.ts
2
+ import path from "node:path";
3
+ import { createRsbuild, loadConfig } from "@rsbuild/core";
4
+ import { ROOT_PATH } from "../build/constant.mjs";
5
+ import { tarPlugin } from "../build/tarPlugin.mjs";
6
+ import { getPkgLog } from "../build/utils/index.mjs";
7
+ var AppWebPackage = class {
8
+ static name = "app web";
9
+ name;
10
+ dir;
11
+ context;
12
+ constructor(name, dir, context) {
13
+ this.name = name;
14
+ this.dir = dir;
15
+ this.context = context;
16
+ }
17
+ async build() {
18
+ const log = getPkgLog(this.name);
19
+ if (this.context.onlyTar) {
20
+ return await tarPlugin(this.dir, log);
21
+ }
22
+ const config = await loadConfig({
23
+ cwd: path.join(ROOT_PATH, "apps/web")
24
+ });
25
+ const rsbuild = await createRsbuild({
26
+ rsbuildConfig: config.content,
27
+ cwd: path.join(ROOT_PATH, "apps/web")
28
+ });
29
+ await rsbuild.build();
30
+ if (this.context.tar) {
31
+ await tarPlugin(this.dir, log);
32
+ }
33
+ log("done");
34
+ }
35
+ };
36
+ export {
37
+ AppWebPackage
38
+ };
@@ -0,0 +1,63 @@
1
+ // src/builder/buildable-packages/lib-package.ts
2
+ import { buildCjs } from "../build/buildCjs.mjs";
3
+ import { buildClient } from "../build/buildClient.mjs";
4
+ import { buildDeclaration } from "../build/buildDeclaration.mjs";
5
+ import { buildEsm } from "../build/buildEsm.mjs";
6
+ import { CORE_CLIENT, ESM_PACKAGES } from "../build/constant.mjs";
7
+ import { tarPlugin } from "../build/tarPlugin.mjs";
8
+ import { getPkgLog, getUserConfig } from "../build/utils/index.mjs";
9
+ var LibPackage = class {
10
+ static name = "lib";
11
+ name;
12
+ dir;
13
+ context;
14
+ isEsm = false;
15
+ isClient = false;
16
+ constructor(name, dir, context) {
17
+ this.name = name;
18
+ this.dir = dir;
19
+ this.context = context;
20
+ this.isEsm = ESM_PACKAGES.includes(this.name);
21
+ this.isClient = this.dir === CORE_CLIENT;
22
+ }
23
+ async build() {
24
+ const log = getPkgLog(this.name);
25
+ if (this.context.onlyTar) {
26
+ return await tarPlugin(this.dir, log);
27
+ }
28
+ const userConfig = getUserConfig(this.dir);
29
+ if (userConfig.beforeBuild) {
30
+ log("beforeBuild");
31
+ await userConfig.beforeBuild(log);
32
+ }
33
+ if (!this.isClient) {
34
+ await buildCjs(this.dir, userConfig, this.context.sourcemap, log);
35
+ if (this.context.dts) {
36
+ await buildDeclaration(this.dir, "lib", log);
37
+ }
38
+ }
39
+ if (this.isClient) {
40
+ await buildClient(this.dir, userConfig, this.context.sourcemap, log);
41
+ if (this.context.dts) {
42
+ await buildDeclaration(this.dir, "es", log);
43
+ }
44
+ }
45
+ if (this.isEsm) {
46
+ await buildEsm(this.dir, userConfig, this.context.sourcemap, log);
47
+ if (this.context.dts) {
48
+ await buildDeclaration(this.dir, "es", log);
49
+ }
50
+ }
51
+ if (userConfig.afterBuild) {
52
+ log("afterBuild");
53
+ await userConfig.afterBuild(log);
54
+ }
55
+ if (this.context.tar) {
56
+ await tarPlugin(this.dir, log);
57
+ }
58
+ log("done");
59
+ }
60
+ };
61
+ export {
62
+ LibPackage
63
+ };