pier-setup 0.2.0 → 0.2.1
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/install.mjs +65 -16
- package/package.json +1 -1
package/install.mjs
CHANGED
|
@@ -8,17 +8,18 @@
|
|
|
8
8
|
* node install.mjs update [--dev] [--hmr-dev] [--force] # 更新 = 卸载注册 + 重新安装(重探测路径)
|
|
9
9
|
*
|
|
10
10
|
* 模式:
|
|
11
|
-
* 用户模式(默认):pi install
|
|
11
|
+
* 用户模式(默认):pi install npm:pi-pier
|
|
12
12
|
* + herdr plugin install July24/pier/packages/pier-workbench --yes
|
|
13
|
-
* boot-config.json 写 herdr plugin config-dir
|
|
13
|
+
* boot-config.json 写 herdr plugin config-dir;extPath 指向 pi 已安装的
|
|
14
|
+
* pi-pier(~/.pi/agent/npm/...),不是 pier-setup 包内的仓库路径。
|
|
14
15
|
* --dev 开发模式:pi install <repo>/packages/pier-ext + herdr plugin link <repo>/packages/pier-workbench
|
|
15
16
|
* (link 目录是活的,改码即生效;update 只重写 boot-config)。
|
|
16
|
-
*
|
|
17
17
|
* 发行规格可用 --pi-spec= / --herdr-spec= 覆盖(npm 发布或 fork 场景)。
|
|
18
18
|
* 失败语义:每步给出手动等价命令;步骤失败不阻断报告(exitCode=1)。
|
|
19
19
|
*/
|
|
20
20
|
import { execFileSync } from 'node:child_process';
|
|
21
21
|
import { existsSync, mkdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
|
|
22
|
+
import { homedir } from 'node:os';
|
|
22
23
|
import { dirname, join, resolve } from 'node:path';
|
|
23
24
|
import { fileURLToPath } from 'node:url';
|
|
24
25
|
|
|
@@ -121,14 +122,70 @@ function probePiRuntime() {
|
|
|
121
122
|
return null;
|
|
122
123
|
}
|
|
123
124
|
|
|
125
|
+
function piAgentDir() {
|
|
126
|
+
return process.env.PI_CODING_AGENT_DIR || join(homedir(), '.pi', 'agent');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function npmNameFromSpec(spec) {
|
|
130
|
+
if (!spec.startsWith('npm:')) return null;
|
|
131
|
+
const rest = spec.slice(4);
|
|
132
|
+
if (rest.startsWith('@')) {
|
|
133
|
+
const slash = rest.indexOf('/');
|
|
134
|
+
if (slash < 0) return rest;
|
|
135
|
+
return `${rest.slice(0, slash)}/${rest.slice(slash + 1).split('@')[0]}`;
|
|
136
|
+
}
|
|
137
|
+
return rest.split('@')[0];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function extPathFromPiList() {
|
|
141
|
+
let out;
|
|
142
|
+
try { out = run('pi', ['list']); } catch { return null; }
|
|
143
|
+
const lines = out.split(/\r?\n/);
|
|
144
|
+
for (let i = 0; i < lines.length; i++) {
|
|
145
|
+
const spec = lines[i].trim();
|
|
146
|
+
const loc = lines[i + 1]?.trim();
|
|
147
|
+
if (!loc) continue;
|
|
148
|
+
if (!/pi-pier|pier-ext|july24\/pier/i.test(spec)) continue;
|
|
149
|
+
for (const c of [join(loc, 'src', 'index.ts'), join(loc, 'packages', 'pier-ext', 'src', 'index.ts')]) {
|
|
150
|
+
if (existsSync(c)) return c;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** User-mode extPath: pi's installed package, never the pier-setup npx cache. */
|
|
157
|
+
function resolveUserExtPath() {
|
|
158
|
+
const candidates = [];
|
|
159
|
+
const npmName = npmNameFromSpec(PI_SPEC);
|
|
160
|
+
if (npmName) candidates.push(join(piAgentDir(), 'npm', 'node_modules', npmName, 'src', 'index.ts'));
|
|
161
|
+
if (PI_SPEC.startsWith('git:')) {
|
|
162
|
+
const hostPath = PI_SPEC.slice(4).replace(/^git@/, '').replace(/:/g, '/');
|
|
163
|
+
candidates.push(
|
|
164
|
+
join(piAgentDir(), 'git', hostPath, 'packages', 'pier-ext', 'src', 'index.ts'),
|
|
165
|
+
join(piAgentDir(), 'git', hostPath, 'src', 'index.ts'),
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
candidates.push(
|
|
169
|
+
join(piAgentDir(), 'npm', 'node_modules', 'pi-pier', 'src', 'index.ts'),
|
|
170
|
+
join(piAgentDir(), 'git', 'github.com', 'July24', 'pier', 'packages', 'pier-ext', 'src', 'index.ts'),
|
|
171
|
+
);
|
|
172
|
+
for (const p of candidates) {
|
|
173
|
+
if (p && existsSync(p)) return p;
|
|
174
|
+
}
|
|
175
|
+
return extPathFromPiList();
|
|
176
|
+
}
|
|
177
|
+
|
|
124
178
|
function writeBootConfig(hmrDev, force) {
|
|
125
179
|
const probed = probePiRuntime();
|
|
126
180
|
if (!probed) die('cannot locate pi cli.js (tried: pi shim realpath, npm root -g). Fill boot-config.json manually.');
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
181
|
+
let extPath;
|
|
182
|
+
if (dev) {
|
|
183
|
+
if (!existsSync(EXT_PATH)) die(`pier-ext entry missing: ${EXT_PATH} (repo layout broken?)`);
|
|
184
|
+
extPath = EXT_PATH;
|
|
185
|
+
} else {
|
|
186
|
+
extPath = resolveUserExtPath();
|
|
187
|
+
if (!extPath) die(`cannot locate installed pier-ext (npm:pi-pier / git clone). Did \`pi install ${piSource()}\` succeed?`);
|
|
188
|
+
}
|
|
132
189
|
|
|
133
190
|
const config = {
|
|
134
191
|
mainTabLabel: 'main',
|
|
@@ -160,14 +217,6 @@ function writeBootConfig(hmrDev, force) {
|
|
|
160
217
|
log(` extPath = ${config.extPath}`);
|
|
161
218
|
}
|
|
162
219
|
|
|
163
|
-
/** herdr 管理的插件 checkout 根(GitHub 安装布局:…/plugins/<owner>-<repo>/…)。 */
|
|
164
|
-
function herdrManagedRootGuess() {
|
|
165
|
-
const dir = herdrConfigDir();
|
|
166
|
-
if (!dir) return '';
|
|
167
|
-
// config-dir 形如 <plugins-root>/<plugin-id>/config → checkout 在 <plugins-root>/<plugin-id>/
|
|
168
|
-
return resolve(dir, '..');
|
|
169
|
-
}
|
|
170
|
-
|
|
171
220
|
/* ── 三命令 ──────────────────────────────────────────────────────── */
|
|
172
221
|
function install() {
|
|
173
222
|
const hmrDev = flags.has('--hmr-dev');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pier-setup",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "One-shot installer for pier: registers the pi-pier extension with pi and the pier.workbench plugin with herdr (install / uninstall / update)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|