gomtm-cli 0.6.5

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.
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "gomtm-cli",
3
+ "private": false,
4
+ "version": "0.6.5",
5
+ "type": "module",
6
+ "types": "./dist/index.d.ts",
7
+ "main": "./dist/index.js",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "files": [
12
+ "bin",
13
+ "dist",
14
+ "src"
15
+ ],
16
+ "bin22": {
17
+ "gomtm-cli": "./dist/gomtm-cli.js"
18
+ },
19
+ "os": [
20
+ "darwin",
21
+ "linux",
22
+ "win32"
23
+ ],
24
+ "cpu": [
25
+ "x64",
26
+ "arm64"
27
+ ],
28
+ "sideEffects": false,
29
+ "scripts": {
30
+ "build": "bun build src/cli/main.ts --outdir=dist/gomtm-cli.js"
31
+ },
32
+ "dependencies": {},
33
+ "devDependencies": {
34
+ "esbuild": "^0.24.2",
35
+ "commander": "^12.1.0"
36
+ }
37
+ }
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env node
2
+ import { program } from "commander";
3
+ import dotenv from "dotenv";
4
+ import fs from "node:fs";
5
+ import path from "node:path";
6
+ // import { buildWithTsc } from "./build_tsc";
7
+ // import { buildWithViteBuild } from "./build_vite";
8
+ // import { compileMigrations } from "./compile-migrations";
9
+
10
+ const envFiles = ["../../env/dev.env", "./env/dev.env", ".env"];
11
+ function loadEnv() {
12
+ // biome-ignore lint/complexity/noForEach: <explanation>
13
+ envFiles.forEach((envFile) => {
14
+ if (fs.existsSync(envFile)) {
15
+ const envPath = path.resolve(envFile);
16
+ const dotenvConfig = dotenv.config({
17
+ path: envPath,
18
+ });
19
+ if (dotenvConfig.error) {
20
+ throw new Error("parse env error", dotenvConfig.error);
21
+ }
22
+ }
23
+ });
24
+ }
25
+ (async () => {
26
+ await loadEnv();
27
+ program.command("hello").action(async () => {
28
+ console.log("(gomtmcli hello4)", import.meta.url);
29
+ // await buildWithViteBuild();
30
+ // console.log("(mtxuilib)build tsc");
31
+ // await buildWithTsc();
32
+ });
33
+
34
+ // program.command("gen").action(async () => {
35
+ // try {
36
+ // await exec("drizzle-kit generate");
37
+ // await compileMigrations();
38
+ // } catch (e) {
39
+ // console.error("执行 compile-migrations 失败", e);
40
+ // process.exit(1);
41
+ // }
42
+ // });
43
+ // program.command("dp_workflow").action(async () => {
44
+ // try {
45
+ // const codeRoot = path.resolve(
46
+ // path.dirname(fileURLToPath(import.meta.url)),
47
+ // "../",
48
+ // );
49
+ // const cmd = `cd ${codeRoot} && bun run dp_workflow`;
50
+ // console.log("执行命令:", cmd);
51
+ // await exec(cmd);
52
+ // } catch (e) {
53
+ // console.error("执行 dp_workflow 失败", e);
54
+ // process.exit(1);
55
+ // }
56
+ // });
57
+ program.parse();
58
+ })();
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ console.log("hello gomtm2");
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env node
2
+ import child_process from "node:child_process";
3
+ import { mkdirSync } from "node:fs";
4
+ import { dirname } from "node:path";
5
+
6
+ export const exec = (
7
+ command: string,
8
+ options?: child_process.SpawnSyncOptionsWithBufferEncoding & {
9
+ env?;
10
+ logPath?: string;
11
+ args?: string[];
12
+ },
13
+ ) => {
14
+ const logFile = options?.logPath;
15
+ let logStream = process.stdout;
16
+ if (logFile) {
17
+ const dirName = dirname(logFile);
18
+ mkdirSync(dirName, { recursive: true });
19
+ //@ts-ignore
20
+ logStream = openSync(logFile, "a");
21
+ }
22
+ return new Promise((resolve, reject) => {
23
+ try {
24
+ const childProcess = child_process.spawn(command, {
25
+ shell: true,
26
+ stdio: [process.stdin, logStream, logStream],
27
+ env: { ...process.env, ...(options?.env || {}) },
28
+ ...options,
29
+ });
30
+ childProcess.on("error", (e) => {
31
+ console.log("error", e);
32
+ reject(e);
33
+ });
34
+ // a.stdout!.on("data",(data)=>{
35
+ // console.log("on data:", data.toString())
36
+ // })
37
+ childProcess.once("exit", (num) => {
38
+ if (num !== 0) {
39
+ console.log("exe 命令出错,code=", {
40
+ code: num,
41
+ command,
42
+ });
43
+ reject(num);
44
+ } else {
45
+ resolve(num);
46
+ }
47
+ });
48
+ } catch (e) {
49
+ console.log({ message: "[exec error]", error: e, command });
50
+ reject(e);
51
+ }
52
+ });
53
+ };