@dx-pkg/mksymlink 1.0.10 → 1.0.15
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/CHANGELOG.md +15 -0
- package/README.md +27 -10
- package/examples/index.js +5 -6
- package/examples/index.mjs +5 -0
- package/package.json +22 -22
- package/src/index.d.mts +149 -0
- package/src/index.d.ts +149 -11
- package/src/index.js +4 -27
- package/src/index.mjs +4 -0
- package/examples/advanced-usage.d.ts +0 -1
- package/examples/advanced-usage.js +0 -38
- package/examples/basic-usage.d.ts +0 -1
- package/examples/basic-usage.js +0 -14
- package/examples/config-usage.d.ts +0 -2
- package/examples/config-usage.js +0 -64
- package/examples/cross-platform.d.ts +0 -1
- package/examples/cross-platform.js +0 -40
- package/examples/index.d.ts +0 -1
- package/src/commands/config/config.command-factory.d.ts +0 -4
- package/src/commands/config/config.command-factory.js +0 -17
- package/src/commands/config/config.command.d.ts +0 -22
- package/src/commands/config/config.command.js +0 -93
- package/src/commands/config/config.option-validator.d.ts +0 -8
- package/src/commands/config/config.option-validator.js +0 -40
- package/src/commands/create/mksymlink.command-factory.d.ts +0 -4
- package/src/commands/create/mksymlink.command-factory.js +0 -18
- package/src/commands/create/mksymlink.command.d.ts +0 -23
- package/src/commands/create/mksymlink.command.js +0 -70
- package/src/commands/create/mksymlink.option-validator.d.ts +0 -8
- package/src/commands/create/mksymlink.option-validator.js +0 -34
- package/src/commands/index.d.ts +0 -2
- package/src/commands/index.js +0 -118
- package/src/services/config.service.d.ts +0 -44
- package/src/services/config.service.js +0 -112
- package/src/services/platform-detector.d.ts +0 -10
- package/src/services/platform-detector.js +0 -35
- package/src/services/symlink-error.d.ts +0 -11
- package/src/services/symlink-error.js +0 -32
- package/src/services/symlink-manager.d.ts +0 -12
- package/src/services/symlink-manager.js +0 -114
- package/src/services/symlink.service.d.ts +0 -12
- package/src/services/symlink.service.js +0 -114
- package/src/types/index.d.ts +0 -39
- package/src/types/index.js +0 -2
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConfigService = void 0;
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const os_1 = require("os");
|
|
7
|
-
class ConfigService {
|
|
8
|
-
configPath;
|
|
9
|
-
config = {};
|
|
10
|
-
constructor(configPath) {
|
|
11
|
-
const homeDir = (0, os_1.homedir)();
|
|
12
|
-
this.configPath = configPath || (0, path_1.resolve)(homeDir, '.mksymlinkrc');
|
|
13
|
-
this.loadConfig();
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Get a configuration value by key
|
|
17
|
-
*/
|
|
18
|
-
get(key) {
|
|
19
|
-
return this.config[key];
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Set a configuration value
|
|
23
|
-
*/
|
|
24
|
-
set(key, value) {
|
|
25
|
-
this.config[key] = value;
|
|
26
|
-
this.saveConfig();
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Unset (remove) a configuration value
|
|
30
|
-
*/
|
|
31
|
-
unset(key) {
|
|
32
|
-
delete this.config[key];
|
|
33
|
-
this.saveConfig();
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* List all configuration values
|
|
37
|
-
*/
|
|
38
|
-
list() {
|
|
39
|
-
return { ...this.config };
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Get the default symlink directory from config
|
|
43
|
-
*/
|
|
44
|
-
getDefaultSymlinkDir() {
|
|
45
|
-
return this.get('symlink.defaultDir');
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Set the default symlink directory
|
|
49
|
-
*/
|
|
50
|
-
setDefaultSymlinkDir(dir) {
|
|
51
|
-
this.set('symlink.defaultDir', dir);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Get configuration file information
|
|
55
|
-
*/
|
|
56
|
-
getConfigInfo() {
|
|
57
|
-
const exists = (0, fs_1.existsSync)(this.configPath);
|
|
58
|
-
const entries = Object.keys(this.config).length;
|
|
59
|
-
if (!exists) {
|
|
60
|
-
return {
|
|
61
|
-
path: this.configPath,
|
|
62
|
-
exists: false,
|
|
63
|
-
entries,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
const stats = (0, fs_1.statSync)(this.configPath);
|
|
67
|
-
return {
|
|
68
|
-
path: this.configPath,
|
|
69
|
-
exists: true,
|
|
70
|
-
size: stats.size,
|
|
71
|
-
modified: stats.mtime,
|
|
72
|
-
entries,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
loadConfig() {
|
|
76
|
-
if (!(0, fs_1.existsSync)(this.configPath)) {
|
|
77
|
-
this.config = {};
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
try {
|
|
81
|
-
const content = (0, fs_1.readFileSync)(this.configPath, 'utf-8');
|
|
82
|
-
const lines = content.split('\n').filter((line) => line.trim());
|
|
83
|
-
this.config = {};
|
|
84
|
-
for (const line of lines) {
|
|
85
|
-
const [key, ...valueParts] = line.split('=');
|
|
86
|
-
if (key && valueParts.length > 0) {
|
|
87
|
-
this.config[key.trim()] = valueParts.join('=').trim();
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
throw new Error(`Failed to load config from ${this.configPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
saveConfig() {
|
|
96
|
-
try {
|
|
97
|
-
const configDir = (0, path_1.dirname)(this.configPath);
|
|
98
|
-
if (!(0, fs_1.existsSync)(configDir)) {
|
|
99
|
-
(0, fs_1.mkdirSync)(configDir, { recursive: true });
|
|
100
|
-
}
|
|
101
|
-
const content = Object.entries(this.config)
|
|
102
|
-
.filter(([, value]) => value !== undefined)
|
|
103
|
-
.map(([key, value]) => `${key}=${value}`)
|
|
104
|
-
.join('\n');
|
|
105
|
-
(0, fs_1.writeFileSync)(this.configPath, content + '\n', 'utf-8');
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
throw new Error(`Failed to save config to ${this.configPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
exports.ConfigService = ConfigService;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { PlatformInformation, OSPlatform } from '../types';
|
|
2
|
-
export declare class PlatformDetector implements PlatformInformation {
|
|
3
|
-
private readonly _platform;
|
|
4
|
-
constructor();
|
|
5
|
-
private normalizePlatform;
|
|
6
|
-
getPlatform(): OSPlatform;
|
|
7
|
-
isWindows(): boolean;
|
|
8
|
-
isMacOS(): boolean;
|
|
9
|
-
isLinux(): boolean;
|
|
10
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PlatformDetector = void 0;
|
|
4
|
-
const os_1 = require("os");
|
|
5
|
-
class PlatformDetector {
|
|
6
|
-
_platform;
|
|
7
|
-
constructor() {
|
|
8
|
-
this._platform = this.normalizePlatform((0, os_1.platform)());
|
|
9
|
-
}
|
|
10
|
-
normalizePlatform(osPlatform) {
|
|
11
|
-
switch (osPlatform) {
|
|
12
|
-
case 'darwin':
|
|
13
|
-
return 'darwin';
|
|
14
|
-
case 'win32':
|
|
15
|
-
return 'win32';
|
|
16
|
-
case 'linux':
|
|
17
|
-
return 'linux';
|
|
18
|
-
default:
|
|
19
|
-
return 'unknown';
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
getPlatform() {
|
|
23
|
-
return this._platform;
|
|
24
|
-
}
|
|
25
|
-
isWindows() {
|
|
26
|
-
return this._platform === 'win32';
|
|
27
|
-
}
|
|
28
|
-
isMacOS() {
|
|
29
|
-
return this._platform === 'darwin';
|
|
30
|
-
}
|
|
31
|
-
isLinux() {
|
|
32
|
-
return this._platform === 'linux';
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.PlatformDetector = PlatformDetector;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@dx-pkg/logger';
|
|
2
|
-
import { CommandError } from '../types';
|
|
3
|
-
export declare class SymlinkError extends Error implements CommandError {
|
|
4
|
-
code?: string;
|
|
5
|
-
constructor(message: string, code?: string);
|
|
6
|
-
}
|
|
7
|
-
export declare class SymlinkErrorHandler {
|
|
8
|
-
private readonly logger;
|
|
9
|
-
constructor(logger: Logger);
|
|
10
|
-
handle(error: unknown): never;
|
|
11
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SymlinkErrorHandler = exports.SymlinkError = void 0;
|
|
4
|
-
class SymlinkError extends Error {
|
|
5
|
-
code;
|
|
6
|
-
constructor(message, code) {
|
|
7
|
-
super(message);
|
|
8
|
-
this.name = 'SymlinkError';
|
|
9
|
-
this.code = code;
|
|
10
|
-
Error.captureStackTrace(this, this.constructor);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.SymlinkError = SymlinkError;
|
|
14
|
-
class SymlinkErrorHandler {
|
|
15
|
-
logger;
|
|
16
|
-
constructor(logger) {
|
|
17
|
-
this.logger = logger;
|
|
18
|
-
}
|
|
19
|
-
handle(error) {
|
|
20
|
-
if (error instanceof SymlinkError) {
|
|
21
|
-
this.logger.error(`Symlink Error [${error.code || 'UNKNOWN'}]: ${error.message}`);
|
|
22
|
-
throw error;
|
|
23
|
-
}
|
|
24
|
-
if (error instanceof Error) {
|
|
25
|
-
this.logger.error(`Unexpected Error: ${error.message}`);
|
|
26
|
-
throw new SymlinkError(error.message, 'UNEXPECTED_ERROR');
|
|
27
|
-
}
|
|
28
|
-
this.logger.error(`Unknown Error: ${String(error)}`);
|
|
29
|
-
throw new SymlinkError(String(error), 'UNKNOWN_ERROR');
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.SymlinkErrorHandler = SymlinkErrorHandler;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@dx-pkg/logger';
|
|
2
|
-
import { SymlinkOperations, SymlinkOptions, SymlinkResult, PlatformInformation } from '../types';
|
|
3
|
-
export declare class SymlinkService implements SymlinkOperations {
|
|
4
|
-
private readonly logger;
|
|
5
|
-
private readonly osDetector;
|
|
6
|
-
constructor(logger: Logger, osDetector: PlatformInformation);
|
|
7
|
-
createSymlink(options: SymlinkOptions): Promise<SymlinkResult>;
|
|
8
|
-
private createWindowsSymlink;
|
|
9
|
-
private createUnixSymlink;
|
|
10
|
-
symlinkExists(path: string): Promise<boolean>;
|
|
11
|
-
removeSymlink(path: string): Promise<void>;
|
|
12
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SymlinkService = void 0;
|
|
4
|
-
const child_process_1 = require("child_process");
|
|
5
|
-
const util_1 = require("util");
|
|
6
|
-
const promises_1 = require("fs/promises");
|
|
7
|
-
const symlink_error_1 = require("./symlink-error");
|
|
8
|
-
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
9
|
-
class SymlinkService {
|
|
10
|
-
logger;
|
|
11
|
-
osDetector;
|
|
12
|
-
constructor(logger, osDetector) {
|
|
13
|
-
this.logger = logger;
|
|
14
|
-
this.osDetector = osDetector;
|
|
15
|
-
}
|
|
16
|
-
async createSymlink(options) {
|
|
17
|
-
const { source, target, type = 'dir', force = false } = options;
|
|
18
|
-
try {
|
|
19
|
-
// this.logger.info(`Creating symlink: ${target} -> ${source}`);
|
|
20
|
-
if (await this.symlinkExists(target)) {
|
|
21
|
-
if (!force) {
|
|
22
|
-
return {
|
|
23
|
-
success: false,
|
|
24
|
-
source,
|
|
25
|
-
target,
|
|
26
|
-
message: `Symlink already exists: ${target}`,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
this.logger.info(`Force mode enabled. Removing existing symlink: ${target}`);
|
|
30
|
-
await this.removeSymlink(target);
|
|
31
|
-
}
|
|
32
|
-
if (this.osDetector.isWindows()) {
|
|
33
|
-
await this.createWindowsSymlink(source, target, type);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
await this.createUnixSymlink(source, target);
|
|
37
|
-
}
|
|
38
|
-
// this.logger.success(`Symlink created successfully: ${target} -> ${source}`);
|
|
39
|
-
return {
|
|
40
|
-
success: true,
|
|
41
|
-
source,
|
|
42
|
-
target,
|
|
43
|
-
message: 'Symlink created successfully',
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
this.logger.error(`Failed to create symlink: ${error instanceof Error ? error.message : String(error)}`);
|
|
48
|
-
return {
|
|
49
|
-
success: false,
|
|
50
|
-
source,
|
|
51
|
-
target,
|
|
52
|
-
error: error instanceof Error ? error : new Error(String(error)),
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
async createWindowsSymlink(source, target, type) {
|
|
57
|
-
let flag;
|
|
58
|
-
switch (type) {
|
|
59
|
-
case 'junction':
|
|
60
|
-
flag = '/J';
|
|
61
|
-
break;
|
|
62
|
-
case 'file':
|
|
63
|
-
flag = '';
|
|
64
|
-
break;
|
|
65
|
-
case 'dir':
|
|
66
|
-
default:
|
|
67
|
-
flag = '/D';
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
const command = flag
|
|
71
|
-
? `mklink ${flag} "${target}" "${source}"`
|
|
72
|
-
: `mklink "${target}" "${source}"`;
|
|
73
|
-
this.logger.info(`Executing Windows command: ${command}`);
|
|
74
|
-
try {
|
|
75
|
-
const { stdout, stderr } = await execAsync(command, { shell: 'cmd.exe' });
|
|
76
|
-
if (stderr && !stderr.includes('Junction') && !stderr.includes('symbolic link')) {
|
|
77
|
-
throw new symlink_error_1.SymlinkError(stderr, 'WINDOWS_MKLINK_ERROR');
|
|
78
|
-
}
|
|
79
|
-
this.logger.info(`Windows mklink output: ${stdout}`);
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
throw new symlink_error_1.SymlinkError(`Failed to create Windows symlink: ${error instanceof Error ? error.message : String(error)}`, 'WINDOWS_MKLINK_FAILED');
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
async createUnixSymlink(source, target) {
|
|
86
|
-
try {
|
|
87
|
-
await (0, promises_1.symlink)(source, target);
|
|
88
|
-
this.logger.info(`Unix symlink created: ln -s ${source} ${target}`);
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
throw new symlink_error_1.SymlinkError(`Failed to create Unix symlink: ${error instanceof Error ? error.message : String(error)}`, 'UNIX_SYMLINK_FAILED');
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
async symlinkExists(path) {
|
|
95
|
-
try {
|
|
96
|
-
const stats = await (0, promises_1.lstat)(path);
|
|
97
|
-
return stats.isSymbolicLink();
|
|
98
|
-
}
|
|
99
|
-
catch {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
async removeSymlink(path) {
|
|
104
|
-
try {
|
|
105
|
-
await (0, promises_1.access)(path);
|
|
106
|
-
await (0, promises_1.unlink)(path);
|
|
107
|
-
this.logger.info(`Symlink removed: ${path}`);
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
throw new symlink_error_1.SymlinkError(`Failed to remove symlink: ${error instanceof Error ? error.message : String(error)}`, 'REMOVE_SYMLINK_FAILED');
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
exports.SymlinkService = SymlinkService;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@dx-pkg/logger';
|
|
2
|
-
import { SymlinkOperations, SymlinkOptions, SymlinkResult, PlatformInformation } from '../types';
|
|
3
|
-
export declare class SymlinkService implements SymlinkOperations {
|
|
4
|
-
private readonly logger;
|
|
5
|
-
private readonly osDetector;
|
|
6
|
-
constructor(logger: Logger, osDetector: PlatformInformation);
|
|
7
|
-
createSymlink(options: SymlinkOptions): Promise<SymlinkResult>;
|
|
8
|
-
private createWindowsSymlink;
|
|
9
|
-
private createUnixSymlink;
|
|
10
|
-
symlinkExists(path: string): Promise<boolean>;
|
|
11
|
-
removeSymlink(path: string): Promise<void>;
|
|
12
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SymlinkService = void 0;
|
|
4
|
-
const child_process_1 = require("child_process");
|
|
5
|
-
const util_1 = require("util");
|
|
6
|
-
const promises_1 = require("fs/promises");
|
|
7
|
-
const symlink_error_1 = require("./symlink-error");
|
|
8
|
-
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
9
|
-
class SymlinkService {
|
|
10
|
-
logger;
|
|
11
|
-
osDetector;
|
|
12
|
-
constructor(logger, osDetector) {
|
|
13
|
-
this.logger = logger;
|
|
14
|
-
this.osDetector = osDetector;
|
|
15
|
-
}
|
|
16
|
-
async createSymlink(options) {
|
|
17
|
-
const { source, target, type = 'dir', force = false } = options;
|
|
18
|
-
try {
|
|
19
|
-
// this.logger.info(`Creating symlink: ${target} -> ${source}`);
|
|
20
|
-
if (await this.symlinkExists(target)) {
|
|
21
|
-
if (!force) {
|
|
22
|
-
return {
|
|
23
|
-
success: false,
|
|
24
|
-
source,
|
|
25
|
-
target,
|
|
26
|
-
message: `Symlink already exists: ${target}`,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
this.logger.info(`Force mode enabled. Removing existing symlink: ${target}`);
|
|
30
|
-
await this.removeSymlink(target);
|
|
31
|
-
}
|
|
32
|
-
if (this.osDetector.isWindows()) {
|
|
33
|
-
await this.createWindowsSymlink(source, target, type);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
await this.createUnixSymlink(source, target);
|
|
37
|
-
}
|
|
38
|
-
// this.logger.success(`Symlink created successfully: ${target} -> ${source}`);
|
|
39
|
-
return {
|
|
40
|
-
success: true,
|
|
41
|
-
source,
|
|
42
|
-
target,
|
|
43
|
-
message: 'Symlink created successfully',
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
this.logger.error(`Failed to create symlink: ${error instanceof Error ? error.message : String(error)}`);
|
|
48
|
-
return {
|
|
49
|
-
success: false,
|
|
50
|
-
source,
|
|
51
|
-
target,
|
|
52
|
-
error: error instanceof Error ? error : new Error(String(error)),
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
async createWindowsSymlink(source, target, type) {
|
|
57
|
-
let flag;
|
|
58
|
-
switch (type) {
|
|
59
|
-
case 'junction':
|
|
60
|
-
flag = '/J';
|
|
61
|
-
break;
|
|
62
|
-
case 'file':
|
|
63
|
-
flag = '';
|
|
64
|
-
break;
|
|
65
|
-
case 'dir':
|
|
66
|
-
default:
|
|
67
|
-
flag = '/D';
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
const command = flag
|
|
71
|
-
? `mklink ${flag} "${target}" "${source}"`
|
|
72
|
-
: `mklink "${target}" "${source}"`;
|
|
73
|
-
this.logger.info(`Executing Windows command: ${command}`);
|
|
74
|
-
try {
|
|
75
|
-
const { stdout, stderr } = await execAsync(command, { shell: 'cmd.exe' });
|
|
76
|
-
if (stderr && !stderr.includes('Junction') && !stderr.includes('symbolic link')) {
|
|
77
|
-
throw new symlink_error_1.SymlinkError(stderr, 'WINDOWS_MKLINK_ERROR');
|
|
78
|
-
}
|
|
79
|
-
this.logger.info(`Windows mklink output: ${stdout}`);
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
throw new symlink_error_1.SymlinkError(`Failed to create Windows symlink: ${error instanceof Error ? error.message : String(error)}`, 'WINDOWS_MKLINK_FAILED');
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
async createUnixSymlink(source, target) {
|
|
86
|
-
try {
|
|
87
|
-
await (0, promises_1.symlink)(source, target);
|
|
88
|
-
this.logger.info(`Unix symlink created: ln -s ${source} ${target}`);
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
throw new symlink_error_1.SymlinkError(`Failed to create Unix symlink: ${error instanceof Error ? error.message : String(error)}`, 'UNIX_SYMLINK_FAILED');
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
async symlinkExists(path) {
|
|
95
|
-
try {
|
|
96
|
-
const stats = await (0, promises_1.lstat)(path);
|
|
97
|
-
return stats.isSymbolicLink();
|
|
98
|
-
}
|
|
99
|
-
catch {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
async removeSymlink(path) {
|
|
104
|
-
try {
|
|
105
|
-
await (0, promises_1.access)(path);
|
|
106
|
-
await (0, promises_1.unlink)(path);
|
|
107
|
-
this.logger.info(`Symlink removed: ${path}`);
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
throw new symlink_error_1.SymlinkError(`Failed to remove symlink: ${error instanceof Error ? error.message : String(error)}`, 'REMOVE_SYMLINK_FAILED');
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
exports.SymlinkService = SymlinkService;
|
package/src/types/index.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export type CommandName = string;
|
|
2
|
-
export interface CommandOptions {
|
|
3
|
-
[key: string]: unknown;
|
|
4
|
-
}
|
|
5
|
-
export interface Command<TOptions extends CommandOptions> {
|
|
6
|
-
execute(options: TOptions): Promise<void>;
|
|
7
|
-
}
|
|
8
|
-
export interface CommandError extends Error {
|
|
9
|
-
code?: string;
|
|
10
|
-
}
|
|
11
|
-
export interface CommandOptionsValidator<TOptions extends CommandOptions> {
|
|
12
|
-
validate(options: TOptions): void;
|
|
13
|
-
}
|
|
14
|
-
export type OSPlatform = 'darwin' | 'win32' | 'linux' | 'unknown';
|
|
15
|
-
export type WindowsSymlinkType = 'file' | 'dir' | 'junction';
|
|
16
|
-
export interface SymlinkOptions {
|
|
17
|
-
source: string;
|
|
18
|
-
target: string;
|
|
19
|
-
type?: WindowsSymlinkType;
|
|
20
|
-
force?: boolean;
|
|
21
|
-
}
|
|
22
|
-
export interface SymlinkResult {
|
|
23
|
-
success: boolean;
|
|
24
|
-
source: string;
|
|
25
|
-
target: string;
|
|
26
|
-
message?: string;
|
|
27
|
-
error?: Error;
|
|
28
|
-
}
|
|
29
|
-
export interface PlatformInformation {
|
|
30
|
-
getPlatform(): OSPlatform;
|
|
31
|
-
isWindows(): boolean;
|
|
32
|
-
isMacOS(): boolean;
|
|
33
|
-
isLinux(): boolean;
|
|
34
|
-
}
|
|
35
|
-
export interface SymlinkOperations {
|
|
36
|
-
createSymlink(options: SymlinkOptions): Promise<SymlinkResult>;
|
|
37
|
-
symlinkExists(path: string): Promise<boolean>;
|
|
38
|
-
removeSymlink(path: string): Promise<void>;
|
|
39
|
-
}
|
package/src/types/index.js
DELETED