pi-revit 0.1.4 → 0.1.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/bin/pi-revit.js CHANGED
@@ -1,95 +1,95 @@
1
- #!/usr/bin/env node
2
- const { spawnSync } = require("node:child_process");
3
- const fs = require("node:fs");
4
- const path = require("node:path");
5
-
6
- const root = path.resolve(__dirname, "..");
7
- const scriptsDir = path.join(root, "scripts");
8
-
9
- function usage() {
10
- console.log(`pi-revit installer\n\nUsage:\n npx.cmd -y pi-revit\n\nWhat it does on Windows:\n 1. Runs: pi install npm:pi-revit\n 2. Builds and deploys the Revit bridge add-in\n 3. Creates the Documents\\pi-revit workspace and global pi-revit command\n\nClose Revit before running. Revit 2025, 2026, or 2027 and the matching .NET SDK are required.`);
11
- }
12
-
13
- function fail(message) {
14
- console.error(`\npi-revit install failed: ${message}`);
15
- process.exit(1);
16
- }
17
-
18
- function commandExists(command) {
19
- return spawnSync("where.exe", [command], { stdio: "ignore" }).status === 0;
20
- }
21
-
22
- function run(title, command, args) {
23
- console.log(`\n==> ${title}`);
24
- const result = spawnSync(command, args, { stdio: "inherit", shell: false });
25
- if (result.error) fail(`${command} could not be started: ${result.error.message}`);
26
- if (result.status !== 0) process.exit(result.status ?? 1);
27
- }
28
-
29
- function runCmd(title, commandLine) {
30
- console.log(`\n==> ${title}`);
31
- // On Windows, npm/pi are usually .cmd shims. Run them through cmd.exe so PATHEXT
32
- // resolution works from npx's Node process just like it does in PowerShell/CMD.
33
- const result = spawnSync("cmd.exe", ["/d", "/s", "/c", commandLine], { stdio: "inherit" });
34
- if (result.error) fail(`${commandLine} could not be started: ${result.error.message}`);
35
- if (result.status !== 0) process.exit(result.status ?? 1);
36
- }
37
-
38
- function runPowerShellScript(scriptName) {
39
- const scriptPath = path.join(scriptsDir, scriptName);
40
- if (!fs.existsSync(scriptPath)) fail(`missing script: ${scriptPath}`);
41
- run(scriptName, "powershell.exe", ["-ExecutionPolicy", "Bypass", "-File", scriptPath]);
42
- }
43
-
44
- function revitIsRunning() {
45
- const result = spawnSync(
46
- "powershell.exe",
47
- ["-NoProfile", "-Command", "if (Get-Process Revit -ErrorAction SilentlyContinue) { exit 0 } else { exit 1 }"],
48
- { stdio: "ignore" },
49
- );
50
- return result.status === 0;
51
- }
52
-
53
- function waitForEnter() {
54
- console.log("\nRevit appears to be running. Close Revit now, then press Enter to continue (or Ctrl+C to cancel).");
55
- try {
56
- fs.readSync(0, Buffer.alloc(1), 0, 1);
57
- } catch {
58
- // Non-interactive shell: fall through to the second running check.
59
- }
60
- }
61
-
62
- if (process.argv.includes("--help") || process.argv.includes("-h")) {
63
- usage();
64
- process.exit(0);
65
- }
66
-
67
- if (process.platform !== "win32") {
68
- fail("pi-revit's Revit bridge installer supports Windows only.");
69
- }
70
-
71
- if (!commandExists("pi")) {
72
- fail("the 'pi' command was not found on PATH. Install Pi first: npm install -g --ignore-scripts @earendil-works/pi-coding-agent");
73
- }
74
-
75
- if (!commandExists("dotnet")) {
76
- fail("the 'dotnet' command was not found on PATH. Install the .NET SDK required by your Revit version.");
77
- }
78
-
79
- if (revitIsRunning()) {
80
- waitForEnter();
81
- if (revitIsRunning()) fail("Revit is still running. Close Revit and run 'npx.cmd -y pi-revit' again.");
82
- }
83
-
84
- console.log("pi-revit full installer");
85
- console.log("This installs the Pi package, deploys the Revit add-in, and creates the workspace/global command.");
86
-
87
- runCmd("Install the Pi package from npm", "pi install npm:pi-revit");
88
- runPowerShellScript("deploy.ps1");
89
- runPowerShellScript("setup-workspace.ps1");
90
-
91
- console.log("\npi-revit installed.");
92
- console.log("Next steps:");
93
- console.log(" 1. Start Revit and click Always Load if prompted.");
94
- console.log(" 2. Open a project.");
95
- console.log(" 3. Run: pi-revit");
1
+ #!/usr/bin/env node
2
+ const { spawnSync } = require("node:child_process");
3
+ const fs = require("node:fs");
4
+ const path = require("node:path");
5
+
6
+ const root = path.resolve(__dirname, "..");
7
+ const scriptsDir = path.join(root, "scripts");
8
+
9
+ function usage() {
10
+ console.log(`pi-revit installer\n\nUsage:\n npx.cmd -y pi-revit\n\nWhat it does on Windows:\n 1. Runs: pi install npm:pi-revit\n 2. Builds and deploys the Revit bridge add-in\n 3. Creates the Documents\\pi-revit workspace and global pi-revit command\n\nClose Revit before running. Revit 2025, 2026, or 2027 and the matching .NET SDK are required.`);
11
+ }
12
+
13
+ function fail(message) {
14
+ console.error(`\npi-revit install failed: ${message}`);
15
+ process.exit(1);
16
+ }
17
+
18
+ function commandExists(command) {
19
+ return spawnSync("where.exe", [command], { stdio: "ignore" }).status === 0;
20
+ }
21
+
22
+ function run(title, command, args) {
23
+ console.log(`\n==> ${title}`);
24
+ const result = spawnSync(command, args, { stdio: "inherit", shell: false });
25
+ if (result.error) fail(`${command} could not be started: ${result.error.message}`);
26
+ if (result.status !== 0) process.exit(result.status ?? 1);
27
+ }
28
+
29
+ function runCmd(title, commandLine) {
30
+ console.log(`\n==> ${title}`);
31
+ // On Windows, npm/pi are usually .cmd shims. Run them through cmd.exe so PATHEXT
32
+ // resolution works from npx's Node process just like it does in PowerShell/CMD.
33
+ const result = spawnSync("cmd.exe", ["/d", "/s", "/c", commandLine], { stdio: "inherit" });
34
+ if (result.error) fail(`${commandLine} could not be started: ${result.error.message}`);
35
+ if (result.status !== 0) process.exit(result.status ?? 1);
36
+ }
37
+
38
+ function runPowerShellScript(scriptName) {
39
+ const scriptPath = path.join(scriptsDir, scriptName);
40
+ if (!fs.existsSync(scriptPath)) fail(`missing script: ${scriptPath}`);
41
+ run(scriptName, "powershell.exe", ["-ExecutionPolicy", "Bypass", "-File", scriptPath]);
42
+ }
43
+
44
+ function revitIsRunning() {
45
+ const result = spawnSync(
46
+ "powershell.exe",
47
+ ["-NoProfile", "-Command", "if (Get-Process Revit -ErrorAction SilentlyContinue) { exit 0 } else { exit 1 }"],
48
+ { stdio: "ignore" },
49
+ );
50
+ return result.status === 0;
51
+ }
52
+
53
+ function waitForEnter() {
54
+ console.log("\nRevit appears to be running. Close Revit now, then press Enter to continue (or Ctrl+C to cancel).");
55
+ try {
56
+ fs.readSync(0, Buffer.alloc(1), 0, 1);
57
+ } catch {
58
+ // Non-interactive shell: fall through to the second running check.
59
+ }
60
+ }
61
+
62
+ if (process.argv.includes("--help") || process.argv.includes("-h")) {
63
+ usage();
64
+ process.exit(0);
65
+ }
66
+
67
+ if (process.platform !== "win32") {
68
+ fail("pi-revit's Revit bridge installer supports Windows only.");
69
+ }
70
+
71
+ if (!commandExists("pi")) {
72
+ fail("the 'pi' command was not found on PATH. Install Pi first: npm install -g --ignore-scripts @earendil-works/pi-coding-agent");
73
+ }
74
+
75
+ if (!commandExists("dotnet")) {
76
+ fail("the 'dotnet' command was not found on PATH. Install the .NET SDK required by your Revit version.");
77
+ }
78
+
79
+ if (revitIsRunning()) {
80
+ waitForEnter();
81
+ if (revitIsRunning()) fail("Revit is still running. Close Revit and run 'npx.cmd -y pi-revit' again.");
82
+ }
83
+
84
+ console.log("pi-revit full installer");
85
+ console.log("This installs the Pi package, deploys the Revit add-in, and creates the workspace/global command.");
86
+
87
+ runCmd("Install the Pi package from npm", "pi install npm:pi-revit");
88
+ runPowerShellScript("deploy.ps1");
89
+ runPowerShellScript("setup-workspace.ps1");
90
+
91
+ console.log("\npi-revit installed.");
92
+ console.log("Next steps:");
93
+ console.log(" 1. Start Revit and click Always Load if prompted.");
94
+ console.log(" 2. Open a project.");
95
+ console.log(" 3. Run: pi-revit");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-revit",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Native Pi connector for Autodesk Revit. Run npx.cmd -y pi-revit for the full Windows install.",
5
5
  "author": "Ahmad Altahlawi",
6
6
  "license": "MIT",
@@ -43,9 +43,15 @@ Write-Host "Workspace ready: $WorkspaceDir" -ForegroundColor Green
43
43
  $pi = Get-Command pi -ErrorAction SilentlyContinue
44
44
  if ($pi) {
45
45
  $binDir = Split-Path $pi.Source -Parent
46
- $globalCmd = Get-Content (Join-Path $templates 'pi-revit-global.cmd')
47
- $globalCmd = $globalCmd -replace '^set "WORKSPACE=.*$', ('set "WORKSPACE=' + $WorkspaceDir + '"')
48
- Set-Content -Path (Join-Path $binDir 'pi-revit.cmd') -Value $globalCmd -Encoding Ascii
46
+ # Literal line swap (no regex): the workspace path may contain characters
47
+ # like $ that a -replace replacement string would misinterpret.
48
+ $globalCmd = Get-Content (Join-Path $templates 'pi-revit-global.cmd') | ForEach-Object {
49
+ if ($_ -like 'set "WORKSPACE=*') { 'set "WORKSPACE=' + $WorkspaceDir + '"' } else { $_ }
50
+ }
51
+ # cmd.exe parses .cmd files in the console's OEM code page: write the launcher
52
+ # in that encoding so workspace paths with non-ASCII characters (user names,
53
+ # localized folder names) stay intact.
54
+ Set-Content -Path (Join-Path $binDir 'pi-revit.cmd') -Value $globalCmd -Encoding Oem
49
55
  Write-Host "Global command installed: $(Join-Path $binDir 'pi-revit.cmd')" -ForegroundColor Green
50
56
  Write-Host 'Run pi-revit from any terminal (pi-revit <project> for a project folder).'
51
57
  } else {
@@ -66,24 +66,30 @@ if ($pi) {
66
66
  # 3. Bridge runtime folder (connection token; recreated on each Revit start).
67
67
  Remove-IfExists (Join-Path $env:APPDATA 'RevitBridge') 'bridge runtime folder'
68
68
 
69
- # 4. Pi package registration. Mirror the documented install command exactly:
70
- # `pi install ./` stores the package keyed by a path resolved relative to Pi's
71
- # settings file, so removal must use the same `./` form from the repo root.
72
- # An absolute path may not match the original registration. The repo root is
73
- # the parent of this script's folder.
69
+ # 4. Pi package registration. Pi keys a package by its install source: the npm
70
+ # installer (npx.cmd -y pi-revit) registers `npm:pi-revit`, while an install
71
+ # from a clone of this repo (`pi install ./`) registers the repo path resolved
72
+ # from the repo root. Try both forms; each succeeds only for the source that
73
+ # is actually registered, so a machine with both gets both removed.
74
74
  if ($pi) {
75
75
  $repoRoot = Split-Path $PSScriptRoot -Parent
76
76
  Push-Location $repoRoot
77
77
  try {
78
- $global:LASTEXITCODE = 0
79
- & pi remove ./
80
- if ($LASTEXITCODE -eq 0) {
81
- Write-Host 'Removed the pi-revit Pi package.' -ForegroundColor Green
78
+ $removed = @()
79
+ foreach ($source in @('npm:pi-revit', './')) {
80
+ $global:LASTEXITCODE = 0
81
+ & pi remove $source
82
+ if ($LASTEXITCODE -eq 0) {
83
+ $removed += $source
84
+ }
85
+ }
86
+ if ($removed.Count -gt 0) {
87
+ Write-Host "Removed the pi-revit Pi package ($($removed -join ', '))." -ForegroundColor Green
82
88
  } else {
83
- Write-Warning "pi remove exited with code $LASTEXITCODE; run 'pi remove ./' from this repo manually."
89
+ Write-Warning "No pi-revit Pi package registration was found. If pi still lists it, run 'pi remove npm:pi-revit' (npm install) or 'pi remove ./' from this repo (install from source)."
84
90
  }
85
91
  } catch {
86
- Write-Warning "Could not auto-remove the Pi package; run 'pi remove ./' from this repo manually. ($_)"
92
+ Write-Warning "Could not auto-remove the Pi package; run 'pi remove npm:pi-revit' (npm install) or 'pi remove ./' from this repo (install from source). ($_)"
87
93
  } finally {
88
94
  Pop-Location
89
95
  }