cwm-assistant 0.1.0 → 0.2.0
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/LICENSE +21 -0
- package/README.md +85 -12
- package/dist/cli-G7JDNOMO.js +6461 -0
- package/dist/cli-G7JDNOMO.js.map +1 -0
- package/dist/main.js +5 -6340
- package/dist/main.js.map +1 -1
- package/package.json +30 -5
- package/scripts/postinstall.mjs +76 -0
package/package.json
CHANGED
|
@@ -1,22 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cwm-assistant",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Local Git and workspace assistant for the CWM browser workbench",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cwm",
|
|
7
|
+
"workspace",
|
|
8
|
+
"git",
|
|
9
|
+
"worktree",
|
|
10
|
+
"local"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "tangzhijie <16620151962@163.com>",
|
|
14
|
+
"homepage": "https://github.com/TooLife/code-workspace/tree/main/apps/assistant#readme",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/TooLife/code-workspace.git",
|
|
18
|
+
"directory": "apps/assistant"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/TooLife/code-workspace/issues"
|
|
22
|
+
},
|
|
5
23
|
"type": "module",
|
|
6
24
|
"engines": {
|
|
7
|
-
"node": ">=22"
|
|
25
|
+
"node": ">=22.13"
|
|
8
26
|
},
|
|
9
27
|
"bin": {
|
|
10
28
|
"cwm-assistant": "dist/main.js"
|
|
11
29
|
},
|
|
12
30
|
"files": [
|
|
13
31
|
"dist",
|
|
14
|
-
"
|
|
32
|
+
"scripts/postinstall.mjs",
|
|
33
|
+
"README.md",
|
|
34
|
+
"LICENSE"
|
|
15
35
|
],
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public",
|
|
38
|
+
"registry": "https://registry.npmjs.org/"
|
|
39
|
+
},
|
|
16
40
|
"scripts": {
|
|
17
41
|
"dev": "tsx src/main.ts",
|
|
18
42
|
"build": "tsup --config tsup.config.ts",
|
|
19
|
-
"prepack": "npm run build"
|
|
43
|
+
"prepack": "npm run build",
|
|
44
|
+
"postinstall": "node scripts/postinstall.mjs"
|
|
20
45
|
},
|
|
21
46
|
"dependencies": {
|
|
22
47
|
"fastify": "^5.6.0"
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Runs after `npm install -g cwm-assistant`. Starts the daemon and registers the login item so the
|
|
3
|
+
// package is usable straight from the install command, with no `cwm-assistant setup` follow-up.
|
|
4
|
+
//
|
|
5
|
+
// An install hook must never fail the install: every path here ends with exit code 0 and a line of
|
|
6
|
+
// advice instead of an error.
|
|
7
|
+
|
|
8
|
+
import { spawn } from "node:child_process";
|
|
9
|
+
import fs from "node:fs";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
12
|
+
|
|
13
|
+
const packageRoot = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
14
|
+
const quiet = (message) => process.stderr.write("cwm-assistant: " + message + "\n");
|
|
15
|
+
|
|
16
|
+
/** /tmp is a symlink to /private/tmp on macOS, so comparing raw paths would miss the prefix. */
|
|
17
|
+
function real(value) {
|
|
18
|
+
try {
|
|
19
|
+
return fs.realpathSync(value);
|
|
20
|
+
} catch {
|
|
21
|
+
return path.resolve(value);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Only a real global install should start anything.
|
|
27
|
+
*
|
|
28
|
+
* `npm ci` in this repository, a `--workspace` install, and `npm pack` all run this script too, and
|
|
29
|
+
* a hook that spawns a daemon there would be a surprise. npm also runs hooks as root under
|
|
30
|
+
* `sudo npm i -g`; that HOME has no LaunchAgents domain, so it would only produce a broken service.
|
|
31
|
+
*/
|
|
32
|
+
export function shouldAutoStart(
|
|
33
|
+
env = process.env,
|
|
34
|
+
platform = process.platform,
|
|
35
|
+
root = packageRoot,
|
|
36
|
+
) {
|
|
37
|
+
if (platform !== "darwin" && platform !== "win32") return false;
|
|
38
|
+
if (env.npm_config_global !== "true") return false;
|
|
39
|
+
const prefix = env.npm_config_prefix;
|
|
40
|
+
if (!prefix) return false;
|
|
41
|
+
// The package must be installed under the global prefix, not merely have a global flag set.
|
|
42
|
+
const relative = path.relative(real(prefix), real(root));
|
|
43
|
+
if (!relative || relative.startsWith("..") || path.isAbsolute(relative)) return false;
|
|
44
|
+
if (process.getuid && process.getuid() === 0) return false;
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function main() {
|
|
49
|
+
if (!shouldAutoStart()) return;
|
|
50
|
+
try {
|
|
51
|
+
await import("node:sqlite");
|
|
52
|
+
} catch {
|
|
53
|
+
quiet("当前 Node.js 不支持 node:sqlite,请升级到 22.13 或更高版本后重新安装。");
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const entry = path.join(packageRoot, "dist", "main.js");
|
|
57
|
+
if (!fs.existsSync(entry)) {
|
|
58
|
+
quiet("安装包缺少构建产物,请运行 cwm-assistant start 手动启动。");
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const child = spawn(process.execPath, [entry, "install"], {
|
|
62
|
+
detached: true,
|
|
63
|
+
windowsHide: true,
|
|
64
|
+
stdio: "ignore",
|
|
65
|
+
});
|
|
66
|
+
child.unref();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Run only when executed, not when a test imports shouldAutoStart.
|
|
70
|
+
const self = fileURLToPath(import.meta.url);
|
|
71
|
+
const invoked = process.argv[1];
|
|
72
|
+
if (invoked && real(invoked) === real(self)) {
|
|
73
|
+
main()
|
|
74
|
+
.catch(() => {})
|
|
75
|
+
.finally(() => process.exit(0));
|
|
76
|
+
}
|