symlx 0.1.4 → 0.1.7
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/README.md +49 -36
- package/dist/cli.js +16 -9
- package/dist/commands/link.js +66 -0
- package/dist/commands/serve copy.js +169 -0
- package/dist/commands/serve.js +32 -110
- package/dist/commands/serve_stash.js +169 -0
- package/dist/lib/bin-targets.js +23 -5
- package/dist/lib/constants.js +4 -0
- package/dist/lib/link-manager.js +37 -18
- package/dist/lib/link-result.js +22 -0
- package/dist/lib/options.js +55 -7
- package/dist/lib/schema.js +2 -4
- package/dist/lib/serve-runtime.js +81 -0
- package/dist/lib/session-store.js +50 -11
- package/dist/lib/utils.js +2 -1
- package/dist/lib/validator.js +2 -0
- package/dist/options.js +37 -0
- package/dist/ui/prompts.js +2 -2
- package/dist/ui/serve-output.js +55 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,39 @@
|
|
|
1
|
+
## Quick Start
|
|
2
|
+
|
|
3
|
+
In a CLI project with:
|
|
4
|
+
|
|
5
|
+
```json
|
|
6
|
+
{
|
|
7
|
+
"name": "awesome-cli",
|
|
8
|
+
"bin": {
|
|
9
|
+
"awesome-cli": "./dist/cli.js"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
run:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
symlx link
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Then use your CLI normally:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
awesome-cli --help
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Use `symlx serve` when you want temporary session-scoped links with auto-cleanup on exit.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
1
30
|
# symlx
|
|
2
31
|
|
|
3
32
|
Temporary command linker for local CLI development.
|
|
4
33
|
|
|
5
34
|
`symlx serve` links command names from your project into a runnable bin directory for the lifetime of the process.
|
|
6
35
|
When `symlx` stops, those links are cleaned up.
|
|
36
|
+
`symlx link` creates the same links once and exits immediately.
|
|
7
37
|
|
|
8
38
|
## Why symlx
|
|
9
39
|
|
|
@@ -26,33 +56,6 @@ npx symlx serve
|
|
|
26
56
|
npm i -g symlx
|
|
27
57
|
```
|
|
28
58
|
|
|
29
|
-
## Quick Start
|
|
30
|
-
|
|
31
|
-
In a CLI project with:
|
|
32
|
-
|
|
33
|
-
```json
|
|
34
|
-
{
|
|
35
|
-
"name": "my-cli",
|
|
36
|
-
"bin": {
|
|
37
|
-
"my-cli": "./dist/cli.js"
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
run:
|
|
43
|
-
|
|
44
|
-
```bash
|
|
45
|
-
symlx serve
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
Then use your CLI normally:
|
|
49
|
-
|
|
50
|
-
```bash
|
|
51
|
-
my-cli --help
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
Stop `symlx` with `Ctrl+C` to clean links.
|
|
55
|
-
|
|
56
59
|
## Alias
|
|
57
60
|
|
|
58
61
|
`symlx` can be clackful for power users, hence its alias: `cx`.
|
|
@@ -61,7 +64,9 @@ Equivalent commands:
|
|
|
61
64
|
|
|
62
65
|
```bash
|
|
63
66
|
symlx serve
|
|
67
|
+
symlx link
|
|
64
68
|
cx serve
|
|
69
|
+
cx link
|
|
65
70
|
```
|
|
66
71
|
|
|
67
72
|
## Command Reference
|
|
@@ -88,6 +93,20 @@ symlx serve --bin admin=dist/admin.js --bin worker=dist/worker.js
|
|
|
88
93
|
symlx serve --bin-resolution-strategy merge
|
|
89
94
|
```
|
|
90
95
|
|
|
96
|
+
## `symlx link`
|
|
97
|
+
|
|
98
|
+
Links commands from resolved bin mappings and exits immediately.
|
|
99
|
+
|
|
100
|
+
It uses the exact same options and resolution behavior as `symlx serve`, but it does not keep a live session.
|
|
101
|
+
|
|
102
|
+
Examples:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
symlx link
|
|
106
|
+
symlx link --collision overwrite
|
|
107
|
+
symlx link --bin admin=dist/admin.js
|
|
108
|
+
```
|
|
109
|
+
|
|
91
110
|
## Bin Resolution Model
|
|
92
111
|
|
|
93
112
|
`symlx` resolves options from three user sources plus defaults:
|
|
@@ -203,13 +222,13 @@ symlx serve --bin-dir ~/.symlx/bin
|
|
|
203
222
|
|
|
204
223
|
## Runtime Safety Checks
|
|
205
224
|
|
|
206
|
-
Before linking, symlx
|
|
225
|
+
Before linking, symlx prepares each resolved bin target:
|
|
207
226
|
|
|
208
227
|
- file exists
|
|
209
228
|
- target is not a directory
|
|
210
|
-
- target is executable on unix-like systems
|
|
229
|
+
- target is made executable automatically on unix-like systems when possible
|
|
211
230
|
|
|
212
|
-
|
|
231
|
+
Missing targets, directories, and permission-update failures still fail early with actionable messages.
|
|
213
232
|
|
|
214
233
|
## Exit Behavior
|
|
215
234
|
|
|
@@ -227,12 +246,6 @@ Add a bin mapping in at least one place:
|
|
|
227
246
|
- `symlx.config.json -> bin`
|
|
228
247
|
- `--bin name=path`
|
|
229
248
|
|
|
230
|
-
## "target is not executable"
|
|
231
|
-
|
|
232
|
-
```bash
|
|
233
|
-
chmod +x dist/cli.js # or your target executable
|
|
234
|
-
```
|
|
235
|
-
|
|
236
249
|
## "command conflicts at ..."
|
|
237
250
|
|
|
238
251
|
Use a collision mode:
|
package/dist/cli.js
CHANGED
|
@@ -36,11 +36,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
37
|
const commander_1 = require("commander");
|
|
38
38
|
const log = __importStar(require("./ui/logger"));
|
|
39
|
+
const link_1 = require("./commands/link");
|
|
39
40
|
const serve_1 = require("./commands/serve");
|
|
40
|
-
|
|
41
|
-
previous.push(value);
|
|
42
|
-
return previous;
|
|
43
|
-
}
|
|
41
|
+
const options_1 = require("./options");
|
|
44
42
|
async function main() {
|
|
45
43
|
// Commander orchestrates top-level commands/options and help output.
|
|
46
44
|
const program = new commander_1.Command();
|
|
@@ -51,12 +49,21 @@ async function main() {
|
|
|
51
49
|
program
|
|
52
50
|
.command('serve')
|
|
53
51
|
.description("Link this project's bin commands until symlx exits")
|
|
54
|
-
.option(
|
|
55
|
-
.option(
|
|
56
|
-
.option(
|
|
57
|
-
.option(
|
|
58
|
-
.option(
|
|
52
|
+
.option(...options_1.binDirOption)
|
|
53
|
+
.option(...options_1.collisionOption)
|
|
54
|
+
.option(...options_1.binResolutionStrategyOption)
|
|
55
|
+
.option(...options_1.nonInteractiveOption)
|
|
56
|
+
.option(...options_1.binOption)
|
|
59
57
|
.action(serve_1.serveCommand);
|
|
58
|
+
program
|
|
59
|
+
.command('link')
|
|
60
|
+
.description("Link this project's bin commands once and exit")
|
|
61
|
+
.option(...options_1.binDirOption)
|
|
62
|
+
.option(...options_1.collisionOption)
|
|
63
|
+
.option(...options_1.binResolutionStrategyOption)
|
|
64
|
+
.option(...options_1.nonInteractiveOption)
|
|
65
|
+
.option(...options_1.binOption)
|
|
66
|
+
.action(link_1.linkCommand);
|
|
60
67
|
await program.parseAsync(process.argv);
|
|
61
68
|
}
|
|
62
69
|
// Centralized fatal error boundary for command execution.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.linkCommand = linkCommand;
|
|
40
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
41
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
42
|
+
const log = __importStar(require("../ui/logger"));
|
|
43
|
+
const serve_output_1 = require("../ui/serve-output");
|
|
44
|
+
const options_1 = require("../lib/options");
|
|
45
|
+
const schema_1 = require("../lib/schema");
|
|
46
|
+
const bin_targets_1 = require("../lib/bin-targets");
|
|
47
|
+
const link_manager_1 = require("../lib/link-manager");
|
|
48
|
+
const session_store_1 = require("../lib/session-store");
|
|
49
|
+
const constants_1 = require("../lib/constants");
|
|
50
|
+
async function linkCommand(inlineOptions) {
|
|
51
|
+
const cwd = process.cwd();
|
|
52
|
+
const homeDirectory = node_os_1.default.homedir();
|
|
53
|
+
const sessionDir = node_path_1.default.join(homeDirectory, '.symlx', 'sessions');
|
|
54
|
+
const options = (0, options_1.resolveOptions)(cwd, schema_1.serveInlineOptionsSchema, inlineOptions);
|
|
55
|
+
const internalCollisionOption = (0, options_1.resolveInternalCollisionOption)(options.collision, options.nonInteractive);
|
|
56
|
+
(0, session_store_1.cleanupStaleSessions)(sessionDir);
|
|
57
|
+
(0, session_store_1.ensureSymlxDirectories)(options.binDir, sessionDir);
|
|
58
|
+
(0, bin_targets_1.prepareBinTargets)(options.bin);
|
|
59
|
+
const linkResult = await (0, link_manager_1.createLinks)(options.bin, options.binDir, internalCollisionOption);
|
|
60
|
+
(0, link_manager_1.assertLinksCreated)(linkResult);
|
|
61
|
+
if (options.collision === 'prompt' && internalCollisionOption !== 'prompt') {
|
|
62
|
+
log.warn(constants_1.PROMPT_FALLBACK_WARNING);
|
|
63
|
+
}
|
|
64
|
+
(0, serve_output_1.printLinkOutcome)(options.binDir, linkResult);
|
|
65
|
+
(0, serve_output_1.printPathHintIfNeeded)(options.binDir, process.env.PATH);
|
|
66
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.serveCommand = serveCommand;
|
|
40
|
+
const path_1 = __importDefault(require("path"));
|
|
41
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
42
|
+
const log = __importStar(require("../ui/logger"));
|
|
43
|
+
const utils_1 = require("../lib/utils");
|
|
44
|
+
const link_manager_1 = require("../lib/link-manager");
|
|
45
|
+
const bin_targets_1 = require("../lib/bin-targets");
|
|
46
|
+
const lifecycle_1 = require("../lib/lifecycle");
|
|
47
|
+
const session_store_1 = require("../lib/session-store");
|
|
48
|
+
const prompts_1 = require("../ui/prompts");
|
|
49
|
+
const options_1 = require("../lib/options");
|
|
50
|
+
const schema_1 = require("../lib/schema");
|
|
51
|
+
// Prompts require an interactive terminal; scripts/CI should avoid prompt mode.
|
|
52
|
+
function isInteractiveSession() {
|
|
53
|
+
return Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
54
|
+
}
|
|
55
|
+
function prepareRuntimeDirectories(binDirectory, sessionDirectory) {
|
|
56
|
+
(0, session_store_1.ensureSymlxDirectories)(binDirectory, sessionDirectory);
|
|
57
|
+
(0, session_store_1.cleanupStaleSessions)(sessionDirectory);
|
|
58
|
+
}
|
|
59
|
+
function resolveRuntimeCollisionMode(options) {
|
|
60
|
+
if (options.collision !== 'prompt') {
|
|
61
|
+
return { policy: options.collision };
|
|
62
|
+
}
|
|
63
|
+
const canPromptForCollision = !options.nonInteractive && isInteractiveSession();
|
|
64
|
+
if (canPromptForCollision) {
|
|
65
|
+
return {
|
|
66
|
+
policy: 'prompt',
|
|
67
|
+
resolver: prompts_1.promptCollisionDecision,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
log.warn('prompt collision mode requested but session is non-interactive; falling back to skip (use --collision overwrite|fail to avoid skips)');
|
|
71
|
+
return { policy: 'skip' };
|
|
72
|
+
}
|
|
73
|
+
function buildServeRuntime(options) {
|
|
74
|
+
const currentWorkingDirectory = process.cwd();
|
|
75
|
+
const sessionDirectory = path_1.default.join(node_os_1.default.homedir(), '.symlx', 'sessions');
|
|
76
|
+
prepareRuntimeDirectories(options.binDir, sessionDirectory);
|
|
77
|
+
(0, bin_targets_1.assertValidBinTargets)(options.bin);
|
|
78
|
+
return {
|
|
79
|
+
cwd: currentWorkingDirectory,
|
|
80
|
+
options,
|
|
81
|
+
sessionDirectory,
|
|
82
|
+
bins: new Map(Object.entries(options.bin)),
|
|
83
|
+
collisionMode: resolveRuntimeCollisionMode(options),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
async function createRuntimeLinks(runtime) {
|
|
87
|
+
return (0, link_manager_1.createLinks)({
|
|
88
|
+
bins: runtime.bins,
|
|
89
|
+
binDir: runtime.options.binDir,
|
|
90
|
+
policy: runtime.collisionMode.policy,
|
|
91
|
+
collisionResolver: runtime.collisionMode.resolver,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function formatSkippedLinks(skippedLinks) {
|
|
95
|
+
const maxVisibleSkips = 5;
|
|
96
|
+
const visibleSkips = skippedLinks.slice(0, maxVisibleSkips);
|
|
97
|
+
const visibleSkipLines = visibleSkips
|
|
98
|
+
.map((skip) => `- ${skip.name}: ${skip.reason}`)
|
|
99
|
+
.join('\n');
|
|
100
|
+
const hiddenSkipsCount = skippedLinks.length - maxVisibleSkips;
|
|
101
|
+
const hiddenSkipsLine = hiddenSkipsCount > 0 ? `\n- ...and ${hiddenSkipsCount} more` : '';
|
|
102
|
+
return `${visibleSkipLines}${hiddenSkipsLine}`;
|
|
103
|
+
}
|
|
104
|
+
function assertLinkCreationSucceeded(linkResult) {
|
|
105
|
+
if (linkResult.created.length > 0) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (linkResult.skipped.length === 0) {
|
|
109
|
+
throw new Error('no links were created');
|
|
110
|
+
}
|
|
111
|
+
throw new Error([
|
|
112
|
+
'no links were created because all candidate commands were skipped.',
|
|
113
|
+
formatSkippedLinks(linkResult.skipped),
|
|
114
|
+
'use --collision overwrite or --collision fail for stricter behavior.',
|
|
115
|
+
].join('\n'));
|
|
116
|
+
}
|
|
117
|
+
function persistServeSession(runtime, links) {
|
|
118
|
+
const sessionPath = (0, session_store_1.createSessionFilePath)(runtime.sessionDirectory);
|
|
119
|
+
const record = {
|
|
120
|
+
pid: process.pid,
|
|
121
|
+
cwd: runtime.cwd,
|
|
122
|
+
createdAt: new Date().toISOString(),
|
|
123
|
+
links,
|
|
124
|
+
};
|
|
125
|
+
(0, session_store_1.persistSession)(sessionPath, record);
|
|
126
|
+
return { sessionPath, record };
|
|
127
|
+
}
|
|
128
|
+
function registerServeSessionCleanup(session) {
|
|
129
|
+
(0, lifecycle_1.registerLifecycleCleanup)(() => {
|
|
130
|
+
(0, session_store_1.cleanupSession)(session.sessionPath, session.record.links);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function reportLinkCreation(runtime, linkResult) {
|
|
134
|
+
const createdLinks = linkResult.created;
|
|
135
|
+
log.info(`linked ${createdLinks.length} command${createdLinks.length > 1 ? 's' : ''} into ${runtime.options.binDir}`);
|
|
136
|
+
for (const link of createdLinks) {
|
|
137
|
+
log.info(`${link.name} -> ${link.target}`);
|
|
138
|
+
}
|
|
139
|
+
for (const skippedLink of linkResult.skipped) {
|
|
140
|
+
log.warn(`skip "${skippedLink.name}": ${skippedLink.reason} (${skippedLink.linkPath})`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function reportPathHint(binDirectory) {
|
|
144
|
+
if ((0, utils_1.pathContainsDir)(process.env.PATH, binDirectory)) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
log.info(`add this to your shell config if needed:\nexport PATH="${binDirectory}:$PATH"`);
|
|
148
|
+
}
|
|
149
|
+
function waitUntilProcessExit() {
|
|
150
|
+
return new Promise(() => {
|
|
151
|
+
setInterval(() => undefined, 60_000);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
async function run(options) {
|
|
155
|
+
const runtime = buildServeRuntime(options);
|
|
156
|
+
const linkResult = await createRuntimeLinks(runtime);
|
|
157
|
+
assertLinkCreationSucceeded(linkResult);
|
|
158
|
+
const session = persistServeSession(runtime, linkResult.created);
|
|
159
|
+
registerServeSessionCleanup(session);
|
|
160
|
+
reportLinkCreation(runtime, linkResult);
|
|
161
|
+
reportPathHint(runtime.options.binDir);
|
|
162
|
+
log.info('running. press Ctrl+C to cleanup links.');
|
|
163
|
+
await waitUntilProcessExit();
|
|
164
|
+
}
|
|
165
|
+
function serveCommand(inlineOptions) {
|
|
166
|
+
const currentWorkingDirectory = process.cwd();
|
|
167
|
+
const options = (0, options_1.resolveOptions)(currentWorkingDirectory, schema_1.serveInlineOptionsSchema, inlineOptions);
|
|
168
|
+
return run(options);
|
|
169
|
+
}
|
package/dist/commands/serve.js
CHANGED
|
@@ -37,124 +37,46 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.serveCommand = serveCommand;
|
|
40
|
-
const path_1 = __importDefault(require("path"));
|
|
41
40
|
const node_os_1 = __importDefault(require("node:os"));
|
|
41
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
42
42
|
const log = __importStar(require("../ui/logger"));
|
|
43
|
-
const
|
|
44
|
-
const link_manager_1 = require("../lib/link-manager");
|
|
45
|
-
const bin_targets_1 = require("../lib/bin-targets");
|
|
46
|
-
const lifecycle_1 = require("../lib/lifecycle");
|
|
47
|
-
const session_store_1 = require("../lib/session-store");
|
|
48
|
-
const prompts_1 = require("../ui/prompts");
|
|
43
|
+
const serve_output_1 = require("../ui/serve-output");
|
|
49
44
|
const options_1 = require("../lib/options");
|
|
50
45
|
const schema_1 = require("../lib/schema");
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
function
|
|
56
|
-
(0, session_store_1.cleanupStaleSessions)(sessionDir);
|
|
57
|
-
(0, session_store_1.ensureSymlxDirectories)(binDir, sessionDir);
|
|
58
|
-
}
|
|
59
|
-
function resolveCollisionHandling(options) {
|
|
60
|
-
if (options.collision !== 'prompt') {
|
|
61
|
-
return { policy: options.collision };
|
|
62
|
-
}
|
|
63
|
-
const canPrompt = !options.nonInteractive && isInteractiveSession();
|
|
64
|
-
if (!canPrompt) {
|
|
65
|
-
log.warn('prompt collision mode requested but session is non-interactive; falling back to skip (use --collision overwrite|fail to avoid skips)');
|
|
66
|
-
return { policy: 'skip' };
|
|
67
|
-
}
|
|
68
|
-
return {
|
|
69
|
-
policy: 'prompt',
|
|
70
|
-
collisionResolver: prompts_1.promptCollisionDecision,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
async function linkCommands(options, collisionHandling) {
|
|
74
|
-
return (0, link_manager_1.createLinks)({
|
|
75
|
-
bins: new Map(Object.entries(options.bin)),
|
|
76
|
-
binDir: options.binDir,
|
|
77
|
-
policy: collisionHandling.policy,
|
|
78
|
-
collisionResolver: collisionHandling.collisionResolver,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
function ensureLinksWereCreated(linkResult) {
|
|
82
|
-
if (linkResult.created.length === 0) {
|
|
83
|
-
if (linkResult.skipped.length === 0) {
|
|
84
|
-
throw new Error('no links were created');
|
|
85
|
-
}
|
|
86
|
-
const details = linkResult.skipped
|
|
87
|
-
.slice(0, 5)
|
|
88
|
-
.map((skip) => `- ${skip.name}: ${skip.reason}`)
|
|
89
|
-
.join('\n');
|
|
90
|
-
const remainingCount = linkResult.skipped.length - 5;
|
|
91
|
-
const remaining = remainingCount > 0 ? `\n- ...and ${remainingCount} more` : '';
|
|
92
|
-
throw new Error([
|
|
93
|
-
'no links were created because all candidate commands were skipped.',
|
|
94
|
-
details,
|
|
95
|
-
`${remaining}\nuse --collision overwrite or --collision fail for stricter behavior.`,
|
|
96
|
-
].join('\n'));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
function persistActiveSession(params) {
|
|
100
|
-
const { sessionDir, cwd, links } = params;
|
|
101
|
-
const sessionPath = (0, session_store_1.createSessionFilePath)(sessionDir);
|
|
102
|
-
const sessionRecord = {
|
|
103
|
-
pid: process.pid,
|
|
104
|
-
cwd,
|
|
105
|
-
createdAt: new Date().toISOString(),
|
|
106
|
-
links,
|
|
107
|
-
};
|
|
108
|
-
(0, session_store_1.persistSession)(sessionPath, sessionRecord);
|
|
109
|
-
return { sessionPath, sessionRecord };
|
|
110
|
-
}
|
|
111
|
-
function registerSessionCleanup(sessionPath, links) {
|
|
112
|
-
(0, lifecycle_1.registerLifecycleCleanup)(() => {
|
|
113
|
-
(0, session_store_1.cleanupSession)(sessionPath, links);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
function printLinkOutcome(binDir, linkResult) {
|
|
117
|
-
const createdLinks = linkResult.created;
|
|
118
|
-
log.info(`linked ${createdLinks.length} command${createdLinks.length > 1 ? 's' : ''} into ${binDir}`);
|
|
119
|
-
for (const link of createdLinks) {
|
|
120
|
-
log.info(`${link.name} -> ${link.target}`);
|
|
121
|
-
}
|
|
122
|
-
for (const skip of linkResult.skipped) {
|
|
123
|
-
log.warn(`skip "${skip.name}": ${skip.reason} (${skip.linkPath})`);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
function printPathHintIfNeeded(binDir) {
|
|
127
|
-
if ((0, utils_1.pathContainsDir)(process.env.PATH, binDir)) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
log.info(`add this to your shell config if needed:\nexport PATH="${binDir}:$PATH"`);
|
|
131
|
-
}
|
|
132
|
-
function waitIndefinitely() {
|
|
46
|
+
const bin_targets_1 = require("../lib/bin-targets");
|
|
47
|
+
const link_manager_1 = require("../lib/link-manager");
|
|
48
|
+
const session_store_1 = require("../lib/session-store");
|
|
49
|
+
const constants_1 = require("../lib/constants");
|
|
50
|
+
function waitUntilStopped() {
|
|
133
51
|
return new Promise(() => {
|
|
134
52
|
setInterval(() => undefined, 60_000);
|
|
135
53
|
});
|
|
136
54
|
}
|
|
137
|
-
async function
|
|
138
|
-
const cwd = process.cwd();
|
|
139
|
-
const sessionDir = path_1.default.join(node_os_1.default.homedir(), '.symlx', 'sessions');
|
|
140
|
-
prepareRuntimeDirectories(options.binDir, sessionDir);
|
|
141
|
-
(0, bin_targets_1.assertValidBinTargets)(options.bin);
|
|
142
|
-
const collisionHandling = resolveCollisionHandling(options);
|
|
143
|
-
const linkResult = await linkCommands(options, collisionHandling);
|
|
144
|
-
ensureLinksWereCreated(linkResult);
|
|
145
|
-
const { sessionPath, sessionRecord } = persistActiveSession({
|
|
146
|
-
sessionDir,
|
|
147
|
-
cwd,
|
|
148
|
-
links: linkResult.created,
|
|
149
|
-
});
|
|
150
|
-
registerSessionCleanup(sessionPath, sessionRecord.links);
|
|
151
|
-
printLinkOutcome(options.binDir, linkResult);
|
|
152
|
-
printPathHintIfNeeded(options.binDir);
|
|
153
|
-
log.info('running. press Ctrl+C to cleanup links.');
|
|
154
|
-
await waitIndefinitely();
|
|
155
|
-
}
|
|
156
|
-
function serveCommand(inlineOptions) {
|
|
55
|
+
async function serveCommand(inlineOptions) {
|
|
157
56
|
const cwd = process.cwd();
|
|
57
|
+
const homeDirectory = node_os_1.default.homedir();
|
|
58
|
+
const sessionDir = node_path_1.default.join(homeDirectory, '.symlx', 'sessions');
|
|
59
|
+
// resolve options by merge or otherwise and resolve collision based on interactiveness
|
|
158
60
|
const options = (0, options_1.resolveOptions)(cwd, schema_1.serveInlineOptionsSchema, inlineOptions);
|
|
159
|
-
|
|
61
|
+
const internalCollisionOption = (0, options_1.resolveInternalCollisionOption)(options.collision, options.nonInteractive);
|
|
62
|
+
// prepare
|
|
63
|
+
(0, session_store_1.cleanupStaleSessions)(sessionDir);
|
|
64
|
+
(0, session_store_1.ensureSymlxDirectories)(options.binDir, sessionDir);
|
|
65
|
+
(0, bin_targets_1.prepareBinTargets)(options.bin);
|
|
66
|
+
// link creation
|
|
67
|
+
const linkResult = await (0, link_manager_1.createLinks)(options.bin, options.binDir, internalCollisionOption);
|
|
68
|
+
(0, link_manager_1.assertLinksCreated)(linkResult);
|
|
69
|
+
// session management
|
|
70
|
+
const sessionPath = (0, session_store_1.generateSessionFilePath)(sessionDir);
|
|
71
|
+
const sessionRecord = (0, session_store_1.generateSessionRecord)(cwd, linkResult.created);
|
|
72
|
+
(0, session_store_1.persistSession)(sessionPath, sessionRecord);
|
|
73
|
+
(0, session_store_1.registerLifecycleSessionCleanup)(sessionPath, sessionRecord.links);
|
|
74
|
+
// logs
|
|
75
|
+
if (options.collision === 'prompt' && internalCollisionOption !== 'prompt') {
|
|
76
|
+
log.warn(constants_1.PROMPT_FALLBACK_WARNING);
|
|
77
|
+
}
|
|
78
|
+
(0, serve_output_1.printLinkOutcome)(options.binDir, linkResult);
|
|
79
|
+
(0, serve_output_1.printPathHintIfNeeded)(options.binDir, process.env.PATH);
|
|
80
|
+
log.info('running. press Ctrl+C to cleanup links.');
|
|
81
|
+
await waitUntilStopped();
|
|
160
82
|
}
|