@dx-pkg/mksymlink 1.0.14 → 1.0.16
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 +14 -0
- package/bin/index.js +5 -0
- package/examples/index.js +5 -6
- package/examples/index.mjs +5 -0
- package/package.json +22 -24
- 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 -24
- package/src/commands/create/mksymlink.command.js +0 -78
- 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 -102
- 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
package/examples/config-usage.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.configExamples = configExamples;
|
|
4
|
-
const config_command_factory_1 = require("../src/commands/config/config.command-factory");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const os_1 = require("os");
|
|
7
|
-
async function configExamples() {
|
|
8
|
-
console.log('=== Config Command Examples ===\n');
|
|
9
|
-
try {
|
|
10
|
-
// Example 1: List all configuration
|
|
11
|
-
console.log('1. List all configuration:');
|
|
12
|
-
const listCommand = config_command_factory_1.ConfigCommandFactory.create({ action: 'list' });
|
|
13
|
-
await listCommand.execute();
|
|
14
|
-
console.log('');
|
|
15
|
-
// Example 2: Set default symlink directory
|
|
16
|
-
console.log('2. Set default symlink directory:');
|
|
17
|
-
const setCommand = config_command_factory_1.ConfigCommandFactory.create({
|
|
18
|
-
action: 'set',
|
|
19
|
-
key: 'symlink.defaultDir',
|
|
20
|
-
value: (0, path_1.join)((0, os_1.homedir)(), 'symlinks'),
|
|
21
|
-
});
|
|
22
|
-
await setCommand.execute();
|
|
23
|
-
console.log('');
|
|
24
|
-
// Example 3: Get a specific config value
|
|
25
|
-
console.log('3. Get default symlink directory:');
|
|
26
|
-
const getCommand = config_command_factory_1.ConfigCommandFactory.create({
|
|
27
|
-
action: 'get',
|
|
28
|
-
key: 'symlink.defaultDir',
|
|
29
|
-
});
|
|
30
|
-
await getCommand.execute();
|
|
31
|
-
console.log('');
|
|
32
|
-
// Example 4: Set a custom config key
|
|
33
|
-
console.log('4. Set a custom config key:');
|
|
34
|
-
const setCustomCommand = config_command_factory_1.ConfigCommandFactory.create({
|
|
35
|
-
action: 'set',
|
|
36
|
-
key: 'user.name',
|
|
37
|
-
value: 'John Doe',
|
|
38
|
-
});
|
|
39
|
-
await setCustomCommand.execute();
|
|
40
|
-
console.log('');
|
|
41
|
-
// Example 5: List all configuration again (to see changes)
|
|
42
|
-
console.log('5. List all configuration (after changes):');
|
|
43
|
-
const listCommand2 = config_command_factory_1.ConfigCommandFactory.create({ action: 'list' });
|
|
44
|
-
await listCommand2.execute();
|
|
45
|
-
console.log('');
|
|
46
|
-
// Example 6: Unset a config value
|
|
47
|
-
console.log('6. Unset user.name:');
|
|
48
|
-
const unsetCommand = config_command_factory_1.ConfigCommandFactory.create({
|
|
49
|
-
action: 'unset',
|
|
50
|
-
key: 'user.name',
|
|
51
|
-
});
|
|
52
|
-
await unsetCommand.execute();
|
|
53
|
-
console.log('');
|
|
54
|
-
// Example 7: List configuration one more time
|
|
55
|
-
console.log('7. List configuration (after unset):');
|
|
56
|
-
const listCommand3 = config_command_factory_1.ConfigCommandFactory.create({ action: 'list' });
|
|
57
|
-
await listCommand3.execute();
|
|
58
|
-
console.log('');
|
|
59
|
-
console.log('=== Config Examples Completed ===\n');
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
console.error('Error running config examples:', error);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const src_1 = require("../src");
|
|
4
|
-
async function crossPlatformExample() {
|
|
5
|
-
console.log('=== Cross-Platform Symlink Example ===\n');
|
|
6
|
-
const osDetector = new src_1.PlatformDetector();
|
|
7
|
-
const platform = osDetector.getPlatform();
|
|
8
|
-
console.log(`Current platform: ${platform}`);
|
|
9
|
-
console.log(`Is Windows: ${osDetector.isWindows()}`);
|
|
10
|
-
console.log(`Is macOS: ${osDetector.isMacOS()}`);
|
|
11
|
-
console.log(`Is Linux: ${osDetector.isLinux()}\n`);
|
|
12
|
-
const source = process.cwd();
|
|
13
|
-
let target;
|
|
14
|
-
let type;
|
|
15
|
-
if (osDetector.isWindows()) {
|
|
16
|
-
target = 'C:\\temp\\my-symlink';
|
|
17
|
-
type = 'junction';
|
|
18
|
-
console.log('Using Windows junction for better compatibility\n');
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
target = '/tmp/my-symlink';
|
|
22
|
-
type = 'dir';
|
|
23
|
-
console.log('Using standard directory symlink\n');
|
|
24
|
-
}
|
|
25
|
-
const command = src_1.MkSymlinkCommandFactory.create({
|
|
26
|
-
source,
|
|
27
|
-
target,
|
|
28
|
-
type,
|
|
29
|
-
force: true,
|
|
30
|
-
});
|
|
31
|
-
try {
|
|
32
|
-
await command.execute();
|
|
33
|
-
console.log('\nCross-platform symlink created successfully!');
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
console.error('\nFailed to create symlink:');
|
|
37
|
-
console.error(error);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
crossPlatformExample().catch(console.error);
|
package/examples/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import './basic-usage';
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConfigCommandFactory = void 0;
|
|
4
|
-
const logger_1 = require("@dx-pkg/logger");
|
|
5
|
-
const config_command_1 = require("./config.command");
|
|
6
|
-
const config_option_validator_1 = require("./config.option-validator");
|
|
7
|
-
const config_service_1 = require("../../services/config.service");
|
|
8
|
-
class ConfigCommandFactory {
|
|
9
|
-
static create(options) {
|
|
10
|
-
const validator = new config_option_validator_1.ConfigOptionValidator();
|
|
11
|
-
validator.validate(options);
|
|
12
|
-
const logger = new logger_1.ConsoleLogger();
|
|
13
|
-
const configService = new config_service_1.ConfigService();
|
|
14
|
-
return new config_command_1.ConfigCommand(logger, configService, options);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.ConfigCommandFactory = ConfigCommandFactory;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@dx-pkg/logger';
|
|
2
|
-
import { Command } from '../../types';
|
|
3
|
-
import { ConfigService } from '../../services/config.service';
|
|
4
|
-
export type ConfigAction = 'get' | 'set' | 'unset' | 'list' | 'info';
|
|
5
|
-
export interface ConfigCommandOptions {
|
|
6
|
-
action: ConfigAction;
|
|
7
|
-
key?: string;
|
|
8
|
-
value?: string;
|
|
9
|
-
[key: string]: unknown;
|
|
10
|
-
}
|
|
11
|
-
export declare class ConfigCommand implements Command<ConfigCommandOptions> {
|
|
12
|
-
private readonly logger;
|
|
13
|
-
private readonly configService;
|
|
14
|
-
private readonly options;
|
|
15
|
-
constructor(logger: Logger, configService: ConfigService, options: ConfigCommandOptions);
|
|
16
|
-
execute(): Promise<void>;
|
|
17
|
-
private handleGet;
|
|
18
|
-
private handleSet;
|
|
19
|
-
private handleUnset;
|
|
20
|
-
private handleList;
|
|
21
|
-
private handleInfo;
|
|
22
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConfigCommand = void 0;
|
|
4
|
-
class ConfigCommand {
|
|
5
|
-
logger;
|
|
6
|
-
configService;
|
|
7
|
-
options;
|
|
8
|
-
constructor(logger, configService, options) {
|
|
9
|
-
this.logger = logger;
|
|
10
|
-
this.configService = configService;
|
|
11
|
-
this.options = options;
|
|
12
|
-
}
|
|
13
|
-
async execute() {
|
|
14
|
-
try {
|
|
15
|
-
const { action, key, value } = this.options;
|
|
16
|
-
switch (action) {
|
|
17
|
-
case 'get':
|
|
18
|
-
await this.handleGet(key);
|
|
19
|
-
break;
|
|
20
|
-
case 'set':
|
|
21
|
-
await this.handleSet(key, value);
|
|
22
|
-
break;
|
|
23
|
-
case 'unset':
|
|
24
|
-
await this.handleUnset(key);
|
|
25
|
-
break;
|
|
26
|
-
case 'list':
|
|
27
|
-
await this.handleList();
|
|
28
|
-
break;
|
|
29
|
-
case 'info':
|
|
30
|
-
await this.handleInfo();
|
|
31
|
-
break;
|
|
32
|
-
default:
|
|
33
|
-
throw new Error(`Unknown config action: ${action}`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
this.logger.error(`Config command failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
38
|
-
throw error;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
async handleGet(key) {
|
|
42
|
-
if (!key) {
|
|
43
|
-
throw new Error('Key is required for get action');
|
|
44
|
-
}
|
|
45
|
-
const value = this.configService.get(key);
|
|
46
|
-
if (value === undefined) {
|
|
47
|
-
this.logger.warning(`Config key '${key}' not found`);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
this.logger.info(value);
|
|
51
|
-
}
|
|
52
|
-
async handleSet(key, value) {
|
|
53
|
-
if (!key) {
|
|
54
|
-
throw new Error('Key is required for set action');
|
|
55
|
-
}
|
|
56
|
-
if (!value) {
|
|
57
|
-
throw new Error('Value is required for set action');
|
|
58
|
-
}
|
|
59
|
-
this.configService.set(key, value);
|
|
60
|
-
this.logger.success(`Config set: ${key} = ${value}`);
|
|
61
|
-
}
|
|
62
|
-
async handleUnset(key) {
|
|
63
|
-
if (!key) {
|
|
64
|
-
throw new Error('Key is required for unset action');
|
|
65
|
-
}
|
|
66
|
-
this.configService.unset(key);
|
|
67
|
-
this.logger.success(`Config unset: ${key}`);
|
|
68
|
-
}
|
|
69
|
-
async handleList() {
|
|
70
|
-
const config = this.configService.list();
|
|
71
|
-
const entries = Object.entries(config);
|
|
72
|
-
if (entries.length === 0) {
|
|
73
|
-
this.logger.info('No configuration found');
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
this.logger.info('Current configuration:');
|
|
77
|
-
for (const [key, value] of entries) {
|
|
78
|
-
this.logger.info(` ${key} = ${value}`);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
async handleInfo() {
|
|
82
|
-
const info = this.configService.getConfigInfo();
|
|
83
|
-
this.logger.info('Configuration file information:');
|
|
84
|
-
this.logger.info(` Path: ${info.path}`);
|
|
85
|
-
this.logger.info(` Exists: ${info.exists ? 'Yes' : 'No'}`);
|
|
86
|
-
if (info.exists) {
|
|
87
|
-
this.logger.info(` Size: ${info.size} bytes`);
|
|
88
|
-
this.logger.info(` Modified: ${info.modified?.toLocaleString()}`);
|
|
89
|
-
}
|
|
90
|
-
this.logger.info(` Entries: ${info.entries}`);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
exports.ConfigCommand = ConfigCommand;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { CommandOptionsValidator } from '../../types';
|
|
2
|
-
import { ConfigCommandOptions } from './config.command';
|
|
3
|
-
export declare class ConfigOptionValidator implements CommandOptionsValidator<ConfigCommandOptions> {
|
|
4
|
-
validate(options: ConfigCommandOptions): void;
|
|
5
|
-
private validateAction;
|
|
6
|
-
private validateKey;
|
|
7
|
-
private validateValue;
|
|
8
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConfigOptionValidator = void 0;
|
|
4
|
-
const symlink_error_1 = require("../../services/symlink-error");
|
|
5
|
-
const VALID_ACTIONS = ['get', 'set', 'unset', 'list', 'info'];
|
|
6
|
-
class ConfigOptionValidator {
|
|
7
|
-
validate(options) {
|
|
8
|
-
this.validateAction(options.action);
|
|
9
|
-
this.validateKey(options.action, options.key);
|
|
10
|
-
this.validateValue(options.action, options.value);
|
|
11
|
-
}
|
|
12
|
-
validateAction(action) {
|
|
13
|
-
if (!VALID_ACTIONS.includes(action)) {
|
|
14
|
-
throw new symlink_error_1.SymlinkError(`Invalid config action: ${action}. Must be one of: ${VALID_ACTIONS.join(', ')}`, 'INVALID_CONFIG_ACTION');
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
validateKey(action, key) {
|
|
18
|
-
if (action === 'list' || action === 'info') {
|
|
19
|
-
return; // list and info don't require a key
|
|
20
|
-
}
|
|
21
|
-
if (!key) {
|
|
22
|
-
throw new symlink_error_1.SymlinkError(`Key is required for '${action}' action`, 'MISSING_CONFIG_KEY');
|
|
23
|
-
}
|
|
24
|
-
if (typeof key !== 'string' || key.trim().length === 0) {
|
|
25
|
-
throw new symlink_error_1.SymlinkError(`Invalid config key: ${key}. Key must be a non-empty string.`, 'INVALID_CONFIG_KEY');
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
validateValue(action, value) {
|
|
29
|
-
if (action !== 'set') {
|
|
30
|
-
return; // only 'set' requires a value
|
|
31
|
-
}
|
|
32
|
-
if (!value) {
|
|
33
|
-
throw new symlink_error_1.SymlinkError(`Value is required for 'set' action`, 'MISSING_CONFIG_VALUE');
|
|
34
|
-
}
|
|
35
|
-
if (typeof value !== 'string') {
|
|
36
|
-
throw new symlink_error_1.SymlinkError(`Invalid config value: ${value}. Value must be a string.`, 'INVALID_CONFIG_VALUE');
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.ConfigOptionValidator = ConfigOptionValidator;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MkSymlinkCommandFactory = void 0;
|
|
4
|
-
const logger_1 = require("@dx-pkg/logger");
|
|
5
|
-
const mksymlink_command_1 = require("./mksymlink.command");
|
|
6
|
-
const symlink_service_1 = require("../../services/symlink.service");
|
|
7
|
-
const platform_detector_1 = require("../../services/platform-detector");
|
|
8
|
-
const mksymlink_option_validator_1 = require("./mksymlink.option-validator");
|
|
9
|
-
class MkSymlinkCommandFactory {
|
|
10
|
-
static create(options) {
|
|
11
|
-
const optionValidator = new mksymlink_option_validator_1.MkSymlinkOptionValidator();
|
|
12
|
-
const logger = new logger_1.ConsoleLogger();
|
|
13
|
-
const osDetector = new platform_detector_1.PlatformDetector();
|
|
14
|
-
const symlinkManager = new symlink_service_1.SymlinkService(logger, osDetector);
|
|
15
|
-
return new mksymlink_command_1.MkSymlinkCommand(optionValidator, logger, symlinkManager, options);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.MkSymlinkCommandFactory = MkSymlinkCommandFactory;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@dx-pkg/logger';
|
|
2
|
-
import { Command, WindowsSymlinkType, SymlinkOperations } from '../../types';
|
|
3
|
-
import { ConfigService } from '../../services/config.service';
|
|
4
|
-
import { MkSymlinkOptionValidator } from './mksymlink.option-validator';
|
|
5
|
-
export interface MkSymlinkCommandOptions {
|
|
6
|
-
target?: string;
|
|
7
|
-
source?: string;
|
|
8
|
-
type?: WindowsSymlinkType;
|
|
9
|
-
force?: boolean;
|
|
10
|
-
[key: string]: unknown;
|
|
11
|
-
}
|
|
12
|
-
export declare const SYMLINK_TYPES: readonly WindowsSymlinkType[];
|
|
13
|
-
export declare class MkSymlinkCommand implements Command<MkSymlinkCommandOptions> {
|
|
14
|
-
private readonly optionValidator;
|
|
15
|
-
private readonly logger;
|
|
16
|
-
private readonly symlinkManager;
|
|
17
|
-
private readonly options;
|
|
18
|
-
private readonly configService;
|
|
19
|
-
constructor(optionValidator: MkSymlinkOptionValidator, logger: Logger, symlinkManager: SymlinkOperations, options: MkSymlinkCommandOptions, configService?: ConfigService);
|
|
20
|
-
execute(): Promise<void>;
|
|
21
|
-
private resolveOptions;
|
|
22
|
-
private resolveTarget;
|
|
23
|
-
private generateDefaultTarget;
|
|
24
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MkSymlinkCommand = exports.SYMLINK_TYPES = void 0;
|
|
4
|
-
const path_1 = require("path");
|
|
5
|
-
const config_service_1 = require("../../services/config.service");
|
|
6
|
-
exports.SYMLINK_TYPES = ['file', 'dir', 'junction'];
|
|
7
|
-
class MkSymlinkCommand {
|
|
8
|
-
optionValidator;
|
|
9
|
-
logger;
|
|
10
|
-
symlinkManager;
|
|
11
|
-
options;
|
|
12
|
-
configService;
|
|
13
|
-
constructor(optionValidator, logger, symlinkManager, options, configService = new config_service_1.ConfigService()) {
|
|
14
|
-
this.optionValidator = optionValidator;
|
|
15
|
-
this.logger = logger;
|
|
16
|
-
this.symlinkManager = symlinkManager;
|
|
17
|
-
this.options = options;
|
|
18
|
-
this.configService = configService;
|
|
19
|
-
}
|
|
20
|
-
async execute() {
|
|
21
|
-
this.optionValidator.validate(this.options);
|
|
22
|
-
try {
|
|
23
|
-
const { source, target, type, force } = this.resolveOptions();
|
|
24
|
-
this.logger.info('Creating symlink with options:');
|
|
25
|
-
this.logger.info(` Source: ${source}`);
|
|
26
|
-
this.logger.info(` Target: ${target}`);
|
|
27
|
-
this.logger.info(` Type: ${type}`);
|
|
28
|
-
this.logger.info(` Force: ${force}`);
|
|
29
|
-
const result = await this.symlinkManager.createSymlink({
|
|
30
|
-
source,
|
|
31
|
-
target,
|
|
32
|
-
type,
|
|
33
|
-
force,
|
|
34
|
-
});
|
|
35
|
-
if (!result.success) {
|
|
36
|
-
if (result.error) {
|
|
37
|
-
throw result.error;
|
|
38
|
-
}
|
|
39
|
-
this.logger.warning(result.message || 'Symlink creation failed');
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
this.logger.success('Symlink created successfully!');
|
|
43
|
-
this.logger.info(` Source: ${result.source}`);
|
|
44
|
-
this.logger.info(` Target: ${result.target}`);
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
this.logger.error(`Failed to create symlink: ${error instanceof Error ? error.message : String(error)}`);
|
|
48
|
-
throw error;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
resolveOptions() {
|
|
52
|
-
const currentDir = process.cwd();
|
|
53
|
-
const source = this.options.source || currentDir;
|
|
54
|
-
const target = this.resolveTarget(this.options) || this.generateDefaultTarget(currentDir);
|
|
55
|
-
const type = this.options.type || 'junction';
|
|
56
|
-
const force = this.options.force || false;
|
|
57
|
-
return { source, target, type, force };
|
|
58
|
-
}
|
|
59
|
-
resolveTarget(options) {
|
|
60
|
-
if (options.target !== '.' && options.target !== './') {
|
|
61
|
-
return options.target;
|
|
62
|
-
}
|
|
63
|
-
const currentDir = process.cwd();
|
|
64
|
-
const sourceBasename = (0, path_1.basename)(options.source || currentDir);
|
|
65
|
-
return (0, path_1.resolve)(currentDir, sourceBasename);
|
|
66
|
-
}
|
|
67
|
-
generateDefaultTarget(currentDir) {
|
|
68
|
-
const currentBasename = (0, path_1.basename)(currentDir);
|
|
69
|
-
const parentDir = (0, path_1.dirname)(currentDir);
|
|
70
|
-
const parentBasename = (0, path_1.basename)(parentDir);
|
|
71
|
-
const symlinkName = `${parentBasename}--${currentBasename}`;
|
|
72
|
-
// Check if there's a configured default directory
|
|
73
|
-
const configuredDir = this.configService.getDefaultSymlinkDir();
|
|
74
|
-
const defaultSymlinkDir = configuredDir || currentDir;
|
|
75
|
-
return (0, path_1.resolve)(defaultSymlinkDir, symlinkName);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.MkSymlinkCommand = MkSymlinkCommand;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { CommandOptionsValidator } from '../../types';
|
|
2
|
-
import { MkSymlinkCommandOptions } from './mksymlink.command';
|
|
3
|
-
export declare class MkSymlinkOptionValidator implements CommandOptionsValidator<MkSymlinkCommandOptions> {
|
|
4
|
-
validate(options: MkSymlinkCommandOptions): void;
|
|
5
|
-
private validateType;
|
|
6
|
-
private validateSource;
|
|
7
|
-
private validateForce;
|
|
8
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MkSymlinkOptionValidator = void 0;
|
|
4
|
-
const symlink_error_1 = require("../../services/symlink-error");
|
|
5
|
-
const mksymlink_command_1 = require("./mksymlink.command");
|
|
6
|
-
const fs_1 = require("fs");
|
|
7
|
-
const path_1 = require("path");
|
|
8
|
-
class MkSymlinkOptionValidator {
|
|
9
|
-
validate(options) {
|
|
10
|
-
this.validateType(options.type);
|
|
11
|
-
this.validateSource(options.source);
|
|
12
|
-
this.validateForce(options.force);
|
|
13
|
-
}
|
|
14
|
-
validateType(type) {
|
|
15
|
-
if (type && !mksymlink_command_1.SYMLINK_TYPES.includes(type)) {
|
|
16
|
-
throw new symlink_error_1.SymlinkError(`Invalid symlink type: ${type}. Must be one of: ${mksymlink_command_1.SYMLINK_TYPES.join(', ')}`, 'INVALID_SYMLINK_TYPE');
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
validateSource(source) {
|
|
20
|
-
if (!source) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const resolvedSource = (0, path_1.resolve)(source);
|
|
24
|
-
if (!(0, fs_1.existsSync)(resolvedSource)) {
|
|
25
|
-
throw new symlink_error_1.SymlinkError(`Source path does not exist: ${resolvedSource}`, 'SOURCE_NOT_FOUND');
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
validateForce(force) {
|
|
29
|
-
if (force !== undefined && typeof force !== 'boolean') {
|
|
30
|
-
throw new symlink_error_1.SymlinkError(`Invalid force option: ${force}. Must be a boolean.`, 'INVALID_FORCE_OPTION');
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.MkSymlinkOptionValidator = MkSymlinkOptionValidator;
|
package/src/commands/index.d.ts
DELETED
package/src/commands/index.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const commander_1 = require("commander");
|
|
5
|
-
const mksymlink_command_factory_1 = require("./create/mksymlink.command-factory");
|
|
6
|
-
const config_command_factory_1 = require("./config/config.command-factory");
|
|
7
|
-
const { version } = require('../../package.json');
|
|
8
|
-
const program = new commander_1.Command();
|
|
9
|
-
program
|
|
10
|
-
.name('mksymlink')
|
|
11
|
-
.description('Create symbolic links across platforms (macOS, Windows, Linux)')
|
|
12
|
-
.version(version);
|
|
13
|
-
program
|
|
14
|
-
.command('create', { isDefault: true })
|
|
15
|
-
.description('Create a symbolic link')
|
|
16
|
-
.option('-s, --source <path>', 'Source path (defaults to current directory)')
|
|
17
|
-
.option('-t, --target <path>', 'Target symlink path (auto-generated if not provided)')
|
|
18
|
-
.option('--type <type>', 'Symlink type for Windows: file, dir, junction (default: junction)', 'junction')
|
|
19
|
-
.option('-f, --force', 'Force overwrite existing symlink', true)
|
|
20
|
-
.action(async (options) => {
|
|
21
|
-
try {
|
|
22
|
-
const command = mksymlink_command_factory_1.MkSymlinkCommandFactory.create(options);
|
|
23
|
-
await command.execute();
|
|
24
|
-
process.exit(0);
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
console.error('Command failed:', error instanceof Error ? error.message : String(error));
|
|
28
|
-
process.exit(1);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
const configCmd = program.command('config').description('Manage mksymlink configuration');
|
|
32
|
-
configCmd
|
|
33
|
-
.command('get <key>')
|
|
34
|
-
.description('Get a configuration value')
|
|
35
|
-
.action(async (key) => {
|
|
36
|
-
try {
|
|
37
|
-
const command = config_command_factory_1.ConfigCommandFactory.create({ action: 'get', key });
|
|
38
|
-
await command.execute();
|
|
39
|
-
process.exit(0);
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
console.error('Config get failed:', error instanceof Error ? error.message : String(error));
|
|
43
|
-
process.exit(1);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
configCmd
|
|
47
|
-
.command('set <key> <value>')
|
|
48
|
-
.description('Set a configuration value')
|
|
49
|
-
.action(async (key, value) => {
|
|
50
|
-
try {
|
|
51
|
-
const command = config_command_factory_1.ConfigCommandFactory.create({ action: 'set', key, value });
|
|
52
|
-
await command.execute();
|
|
53
|
-
process.exit(0);
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
console.error('Config set failed:', error instanceof Error ? error.message : String(error));
|
|
57
|
-
process.exit(1);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
configCmd
|
|
61
|
-
.command('unset <key>')
|
|
62
|
-
.description('Unset a configuration value')
|
|
63
|
-
.action(async (key) => {
|
|
64
|
-
try {
|
|
65
|
-
const command = config_command_factory_1.ConfigCommandFactory.create({ action: 'unset', key });
|
|
66
|
-
await command.execute();
|
|
67
|
-
process.exit(0);
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
console.error('Config unset failed:', error instanceof Error ? error.message : String(error));
|
|
71
|
-
process.exit(1);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
configCmd
|
|
75
|
-
.command('list')
|
|
76
|
-
.description('List all configuration values')
|
|
77
|
-
.action(async () => {
|
|
78
|
-
try {
|
|
79
|
-
const command = config_command_factory_1.ConfigCommandFactory.create({ action: 'list' });
|
|
80
|
-
await command.execute();
|
|
81
|
-
process.exit(0);
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
console.error('Config list failed:', error instanceof Error ? error.message : String(error));
|
|
85
|
-
process.exit(1);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
configCmd
|
|
89
|
-
.command('info')
|
|
90
|
-
.description('Show configuration file information')
|
|
91
|
-
.action(async () => {
|
|
92
|
-
try {
|
|
93
|
-
const command = config_command_factory_1.ConfigCommandFactory.create({ action: 'info' });
|
|
94
|
-
await command.execute();
|
|
95
|
-
process.exit(0);
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
console.error('Config info failed:', error instanceof Error ? error.message : String(error));
|
|
99
|
-
process.exit(1);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
program.parse(process.argv);
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
export interface ConfigData {
|
|
2
|
-
[key: string]: string | undefined;
|
|
3
|
-
}
|
|
4
|
-
export declare class ConfigService {
|
|
5
|
-
private readonly configPath;
|
|
6
|
-
private config;
|
|
7
|
-
constructor(configPath?: string);
|
|
8
|
-
/**
|
|
9
|
-
* Get a configuration value by key
|
|
10
|
-
*/
|
|
11
|
-
get(key: string): string | undefined;
|
|
12
|
-
/**
|
|
13
|
-
* Set a configuration value
|
|
14
|
-
*/
|
|
15
|
-
set(key: string, value: string): void;
|
|
16
|
-
/**
|
|
17
|
-
* Unset (remove) a configuration value
|
|
18
|
-
*/
|
|
19
|
-
unset(key: string): void;
|
|
20
|
-
/**
|
|
21
|
-
* List all configuration values
|
|
22
|
-
*/
|
|
23
|
-
list(): ConfigData;
|
|
24
|
-
/**
|
|
25
|
-
* Get the default symlink directory from config
|
|
26
|
-
*/
|
|
27
|
-
getDefaultSymlinkDir(): string | undefined;
|
|
28
|
-
/**
|
|
29
|
-
* Set the default symlink directory
|
|
30
|
-
*/
|
|
31
|
-
setDefaultSymlinkDir(dir: string): void;
|
|
32
|
-
/**
|
|
33
|
-
* Get configuration file information
|
|
34
|
-
*/
|
|
35
|
-
getConfigInfo(): {
|
|
36
|
-
path: string;
|
|
37
|
-
exists: boolean;
|
|
38
|
-
size?: number;
|
|
39
|
-
modified?: Date;
|
|
40
|
-
entries: number;
|
|
41
|
-
};
|
|
42
|
-
private loadConfig;
|
|
43
|
-
private saveConfig;
|
|
44
|
-
}
|