aliasmate 1.0.0 → 1.2.0
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 +109 -0
- package/README.md +126 -2
- package/dist/cli.js +52 -15
- package/dist/cli.js.map +1 -1
- package/dist/commands/delete.d.ts +12 -0
- package/dist/commands/delete.d.ts.map +1 -1
- package/dist/commands/delete.js +29 -8
- package/dist/commands/delete.js.map +1 -1
- package/dist/commands/edit.d.ts +13 -0
- package/dist/commands/edit.d.ts.map +1 -1
- package/dist/commands/edit.js +50 -23
- package/dist/commands/edit.js.map +1 -1
- package/dist/commands/export.d.ts +17 -0
- package/dist/commands/export.d.ts.map +1 -1
- package/dist/commands/export.js +42 -7
- package/dist/commands/export.js.map +1 -1
- package/dist/commands/import.d.ts +21 -0
- package/dist/commands/import.d.ts.map +1 -1
- package/dist/commands/import.js +93 -48
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/list.d.ts +20 -0
- package/dist/commands/list.d.ts.map +1 -1
- package/dist/commands/list.js +66 -5
- package/dist/commands/list.js.map +1 -1
- package/dist/commands/prev.d.ts +14 -1
- package/dist/commands/prev.d.ts.map +1 -1
- package/dist/commands/prev.js +41 -13
- package/dist/commands/prev.js.map +1 -1
- package/dist/commands/run.d.ts +16 -1
- package/dist/commands/run.d.ts.map +1 -1
- package/dist/commands/run.js +30 -10
- package/dist/commands/run.js.map +1 -1
- package/dist/commands/save.d.ts +15 -1
- package/dist/commands/save.d.ts.map +1 -1
- package/dist/commands/save.js +64 -33
- package/dist/commands/save.js.map +1 -1
- package/dist/commands/search.d.ts +19 -0
- package/dist/commands/search.d.ts.map +1 -0
- package/dist/commands/search.js +113 -0
- package/dist/commands/search.js.map +1 -0
- package/dist/storage/index.d.ts +34 -7
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +55 -11
- package/dist/storage/index.js.map +1 -1
- package/dist/utils/constants.d.ts +48 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +51 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/errors.d.ts +30 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +62 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/executor.d.ts +22 -1
- package/dist/utils/executor.d.ts.map +1 -1
- package/dist/utils/executor.js +36 -11
- package/dist/utils/executor.js.map +1 -1
- package/dist/utils/history.d.ts +21 -3
- package/dist/utils/history.d.ts.map +1 -1
- package/dist/utils/history.js +28 -14
- package/dist/utils/history.js.map +1 -1
- package/dist/utils/llm-generator.d.ts +21 -0
- package/dist/utils/llm-generator.d.ts.map +1 -0
- package/dist/utils/llm-generator.js +337 -0
- package/dist/utils/llm-generator.js.map +1 -0
- package/dist/utils/onboarding.d.ts +10 -0
- package/dist/utils/onboarding.d.ts.map +1 -0
- package/dist/utils/onboarding.js +201 -0
- package/dist/utils/onboarding.js.map +1 -0
- package/dist/utils/paths.d.ts +39 -1
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +56 -1
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/prompts.d.ts +56 -0
- package/dist/utils/prompts.d.ts.map +1 -0
- package/dist/utils/prompts.js +51 -0
- package/dist/utils/prompts.js.map +1 -0
- package/package.json +22 -6
package/dist/commands/run.d.ts
CHANGED
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Run a saved command, optionally overriding its working directory
|
|
3
|
+
*
|
|
4
|
+
* @param name - The name of the saved command to run
|
|
5
|
+
* @param overridePath - Optional path to override the saved working directory
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```
|
|
9
|
+
* // Run command in its saved directory
|
|
10
|
+
* await runCommand('build-prod');
|
|
11
|
+
*
|
|
12
|
+
* // Run command in a different directory
|
|
13
|
+
* await runCommand('build-prod', '/path/to/other/project');
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function runCommand(name: string, overridePath?: string): Promise<void>;
|
|
2
17
|
//# sourceMappingURL=run.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/commands/run.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/commands/run.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqCnF"}
|
package/dist/commands/run.js
CHANGED
|
@@ -8,19 +8,34 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
8
8
|
const storage_1 = require("../storage");
|
|
9
9
|
const executor_1 = require("../utils/executor");
|
|
10
10
|
const paths_1 = require("../utils/paths");
|
|
11
|
-
|
|
11
|
+
const errors_1 = require("../utils/errors");
|
|
12
|
+
const constants_1 = require("../utils/constants");
|
|
13
|
+
/**
|
|
14
|
+
* Run a saved command, optionally overriding its working directory
|
|
15
|
+
*
|
|
16
|
+
* @param name - The name of the saved command to run
|
|
17
|
+
* @param overridePath - Optional path to override the saved working directory
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```
|
|
21
|
+
* // Run command in its saved directory
|
|
22
|
+
* await runCommand('build-prod');
|
|
23
|
+
*
|
|
24
|
+
* // Run command in a different directory
|
|
25
|
+
* await runCommand('build-prod', '/path/to/other/project');
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
async function runCommand(name, overridePath) {
|
|
12
29
|
try {
|
|
13
30
|
// Get the saved alias
|
|
14
31
|
const alias = (0, storage_1.getAlias)(name);
|
|
15
32
|
if (!alias) {
|
|
16
|
-
console.error(chalk_1.default.red(`Error:
|
|
17
|
-
console.log(chalk_1.default.yellow(
|
|
18
|
-
process.exit(
|
|
33
|
+
console.error(chalk_1.default.red(`Error: ${constants_1.ERROR_MESSAGES.commandNotFound(name)}`));
|
|
34
|
+
console.log(chalk_1.default.yellow(constants_1.HELP_MESSAGES.useList));
|
|
35
|
+
process.exit(errors_1.ExitCode.InvalidInput);
|
|
19
36
|
}
|
|
20
37
|
// Determine the directory to run in
|
|
21
|
-
const runDir = overridePath
|
|
22
|
-
? (0, paths_1.resolvePath)(overridePath, process.cwd())
|
|
23
|
-
: alias.directory;
|
|
38
|
+
const runDir = overridePath ? (0, paths_1.resolvePath)(overridePath, process.cwd()) : alias.directory;
|
|
24
39
|
// Show what we're about to run
|
|
25
40
|
console.log(chalk_1.default.blue(`Running: ${alias.command}`));
|
|
26
41
|
console.log(chalk_1.default.gray(`Directory: ${runDir}`));
|
|
@@ -29,15 +44,20 @@ async function runCommand(name, overridePath, _options) {
|
|
|
29
44
|
const result = await (0, executor_1.executeCommand)(alias.command, runDir);
|
|
30
45
|
if (!result.success) {
|
|
31
46
|
console.error(chalk_1.default.red('\n✗ Command failed'));
|
|
47
|
+
if (result.exitCode !== undefined) {
|
|
48
|
+
console.error(chalk_1.default.red(`Exit code: ${result.exitCode}`));
|
|
49
|
+
}
|
|
32
50
|
if (result.stderr) {
|
|
33
51
|
console.error(result.stderr);
|
|
34
52
|
}
|
|
35
|
-
process.exit(
|
|
53
|
+
process.exit(result.exitCode || errors_1.ExitCode.GeneralError);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
console.log(chalk_1.default.green('\n✓ Command completed successfully'));
|
|
36
57
|
}
|
|
37
58
|
}
|
|
38
59
|
catch (error) {
|
|
39
|
-
|
|
40
|
-
process.exit(1);
|
|
60
|
+
(0, errors_1.handleError)(error, 'Failed to run command');
|
|
41
61
|
}
|
|
42
62
|
}
|
|
43
63
|
//# sourceMappingURL=run.js.map
|
package/dist/commands/run.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/commands/run.ts"],"names":[],"mappings":";;;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AAO,EAAE,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC;YAC/C,IAAI,MAAM,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAClC,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,cAAc,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;YAC5D,CAAC;YACD,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;gBAClB,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC/B,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,iBAAQ,CAAC,YAAY,CAAC,CAAC;QACzD,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAA,oBAAW,EAAC,KAAK,EAAE,uBAAuB,CAAC,CAAC;IAC9C,CAAC;AACH,CAAC"}
|
package/dist/commands/save.d.ts
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Interactively save a new command with prompts
|
|
3
|
+
*
|
|
4
|
+
* @param cwd - The default working directory to suggest (defaults to process.cwd())
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```
|
|
8
|
+
* // User is prompted for:
|
|
9
|
+
* // - Command name (e.g., 'deploy-prod')
|
|
10
|
+
* // - Command to save (e.g., 'npm run deploy')
|
|
11
|
+
* // - Working directory (defaults to current directory)
|
|
12
|
+
* await saveCommand();
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function saveCommand(cwd?: string): Promise<void>;
|
|
2
16
|
//# sourceMappingURL=save.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../../src/commands/save.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../../src/commands/save.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;GAaG;AACH,wBAAsB,WAAW,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CA2F5E"}
|
package/dist/commands/save.js
CHANGED
|
@@ -4,26 +4,47 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.saveCommand = saveCommand;
|
|
7
|
-
const inquirer_1 = __importDefault(require("inquirer"));
|
|
8
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
8
|
const storage_1 = require("../storage");
|
|
10
|
-
|
|
9
|
+
const errors_1 = require("../utils/errors");
|
|
10
|
+
const constants_1 = require("../utils/constants");
|
|
11
|
+
const prompts_1 = require("../utils/prompts");
|
|
12
|
+
/**
|
|
13
|
+
* Interactively save a new command with prompts
|
|
14
|
+
*
|
|
15
|
+
* @param cwd - The default working directory to suggest (defaults to process.cwd())
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```
|
|
19
|
+
* // User is prompted for:
|
|
20
|
+
* // - Command name (e.g., 'deploy-prod')
|
|
21
|
+
* // - Command to save (e.g., 'npm run deploy')
|
|
22
|
+
* // - Working directory (defaults to current directory)
|
|
23
|
+
* await saveCommand();
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
async function saveCommand(cwd = process.cwd()) {
|
|
11
27
|
try {
|
|
12
28
|
// Prompt for command details
|
|
13
|
-
const
|
|
29
|
+
const prompts = [
|
|
14
30
|
{
|
|
15
31
|
type: 'input',
|
|
16
32
|
name: 'name',
|
|
17
33
|
message: 'Enter a name for this command:',
|
|
18
34
|
validate: (input) => {
|
|
19
|
-
|
|
20
|
-
|
|
35
|
+
const trimmed = input.trim();
|
|
36
|
+
if (!trimmed) {
|
|
37
|
+
return constants_1.HELP_MESSAGES.emptyValue('Name');
|
|
38
|
+
}
|
|
39
|
+
if (trimmed.includes(' ')) {
|
|
40
|
+
return constants_1.HELP_MESSAGES.invalidName;
|
|
21
41
|
}
|
|
22
|
-
|
|
23
|
-
|
|
42
|
+
// Check for invalid characters
|
|
43
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(trimmed)) {
|
|
44
|
+
return 'Name can only contain letters, numbers, hyphens, and underscores';
|
|
24
45
|
}
|
|
25
46
|
return true;
|
|
26
|
-
}
|
|
47
|
+
},
|
|
27
48
|
},
|
|
28
49
|
{
|
|
29
50
|
type: 'input',
|
|
@@ -31,53 +52,63 @@ async function saveCommand(_options, cwd = process.cwd()) {
|
|
|
31
52
|
message: 'Enter the command to save:',
|
|
32
53
|
validate: (input) => {
|
|
33
54
|
if (!input.trim()) {
|
|
34
|
-
return 'Command
|
|
55
|
+
return constants_1.HELP_MESSAGES.emptyValue('Command');
|
|
35
56
|
}
|
|
36
57
|
return true;
|
|
37
|
-
}
|
|
58
|
+
},
|
|
38
59
|
},
|
|
39
60
|
{
|
|
40
61
|
type: 'input',
|
|
41
62
|
name: 'directory',
|
|
42
63
|
message: 'Enter the working directory:',
|
|
43
|
-
default: cwd
|
|
44
|
-
|
|
45
|
-
|
|
64
|
+
default: cwd,
|
|
65
|
+
validate: (input) => {
|
|
66
|
+
const trimmed = input.trim();
|
|
67
|
+
if (!trimmed) {
|
|
68
|
+
return constants_1.HELP_MESSAGES.emptyValue('Directory');
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
const answers = await (0, prompts_1.promptMultiple)(prompts);
|
|
46
75
|
// Check if alias already exists
|
|
47
76
|
if ((0, storage_1.aliasExists)(answers.name)) {
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
]);
|
|
77
|
+
const confirmPrompt = {
|
|
78
|
+
type: 'confirm',
|
|
79
|
+
name: 'confirm',
|
|
80
|
+
message: `A command named "${answers.name}" already exists. Overwrite?`,
|
|
81
|
+
default: false,
|
|
82
|
+
};
|
|
83
|
+
const confirm = await (0, prompts_1.promptConfirm)(confirmPrompt);
|
|
56
84
|
if (!confirm) {
|
|
57
85
|
console.log(chalk_1.default.yellow('Save cancelled'));
|
|
58
86
|
return;
|
|
59
87
|
}
|
|
60
88
|
}
|
|
61
89
|
// Save the command
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
90
|
+
try {
|
|
91
|
+
const success = (0, storage_1.setAlias)(answers.name.trim(), answers.command, answers.directory);
|
|
92
|
+
if (success) {
|
|
93
|
+
console.log(chalk_1.default.green(`✓ ${constants_1.SUCCESS_MESSAGES.saved(answers.name.trim())}`));
|
|
94
|
+
console.log(chalk_1.default.gray(` Command: ${answers.command}`));
|
|
95
|
+
console.log(chalk_1.default.gray(` Directory: ${answers.directory}`));
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
(0, errors_1.exitWithError)(constants_1.ERROR_MESSAGES.couldNotSave);
|
|
99
|
+
}
|
|
67
100
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
process.exit(1);
|
|
101
|
+
catch (error) {
|
|
102
|
+
(0, errors_1.exitWithError)(`${constants_1.ERROR_MESSAGES.couldNotSave}: ${error.message}`);
|
|
71
103
|
}
|
|
72
104
|
}
|
|
73
105
|
catch (error) {
|
|
74
|
-
if (
|
|
75
|
-
|
|
106
|
+
if ((0, errors_1.isInquirerTTYError)(error)) {
|
|
107
|
+
(0, errors_1.exitWithError)(constants_1.ERROR_MESSAGES.interactiveNotSupported, errors_1.ExitCode.GeneralError);
|
|
76
108
|
}
|
|
77
109
|
else {
|
|
78
|
-
|
|
110
|
+
(0, errors_1.handleError)(error, 'Failed to save command');
|
|
79
111
|
}
|
|
80
|
-
process.exit(1);
|
|
81
112
|
}
|
|
82
113
|
}
|
|
83
114
|
//# sourceMappingURL=save.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save.js","sourceRoot":"","sources":["../../src/commands/save.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"save.js","sourceRoot":"","sources":["../../src/commands/save.ts"],"names":[],"mappings":";;;;;AAoBA,kCA2FC;AA/GD,kDAA0B;AAC1B,wCAAmD;AACnD,4CAA2F;AAC3F,kDAAqF;AACrF,8CAAiG;AAEjG;;;;;;;;;;;;;GAaG;AACI,KAAK,UAAU,WAAW,CAAC,MAAc,OAAO,CAAC,GAAG,EAAE;IAC3D,IAAI,CAAC;QACH,6BAA6B;QAC7B,MAAM,OAAO,GAAsB;YACjC;gBACE,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,gCAAgC;gBACzC,QAAQ,EAAE,CAAC,KAAa,EAAE,EAAE;oBAC1B,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;oBAC7B,IAAI,CAAC,OAAO,EAAE,CAAC;wBACb,OAAO,yBAAa,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;oBAC1C,CAAC;oBACD,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;wBAC1B,OAAO,yBAAa,CAAC,WAAW,CAAC;oBACnC,CAAC;oBACD,+BAA+B;oBAC/B,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;wBACtC,OAAO,kEAAkE,CAAC;oBAC5E,CAAC;oBACD,OAAO,IAAI,CAAC;gBACd,CAAC;aACF;YACD;gBACE,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,4BAA4B;gBACrC,QAAQ,EAAE,CAAC,KAAa,EAAE,EAAE;oBAC1B,IAAI,CAA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I,OAAO,EAAE,CAAC;gBACZ,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,KAAK,4BAAgB,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC7E,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,cAAc,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;gBACzD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,gBAAgB,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;YAC/D,CAAC;iBAAM,CAAC;gBACN,IAAA,sBAAa,EAAC,0BAAc,CAAC,YAAY,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAA,sBAAa,EAAC,GAAG,0BAAc,CAAC,YAAY,KAAM,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,IAAA,2BAAkB,EAAC,KAAK,CAAC,EAAE,CAAC;YAC9B,IAAA,sBAAa,EAAC,0BAAc,CAAC,uBAAuB,EAAE,iBAAQ,CAAC,YAAY,CAAC,CAAC;QAC/E,CAAC;aAAM,CAAC;YACN,IAAA,oBAAW,EAAC,KAAK,EAAE,wBAAwB,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search for commands by name or command text
|
|
3
|
+
*
|
|
4
|
+
* Performs case-insensitive search across command names and command text.
|
|
5
|
+
*
|
|
6
|
+
* @param query - The search query string
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```
|
|
10
|
+
* // Search for commands containing 'build'
|
|
11
|
+
* searchCommand('build');
|
|
12
|
+
* // Output:
|
|
13
|
+
* // build-prod
|
|
14
|
+
* // Command: npm run build --production
|
|
15
|
+
* // Directory: /home/user/project
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function searchCommand(query: string): void;
|
|
19
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/commands/search.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CA0DjD"}
|
|
@@ -0,0 +1,113 @@
|
|
|
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.searchCommand = searchCommand;
|
|
40
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
41
|
+
const fs = __importStar(require("fs"));
|
|
42
|
+
const storage_1 = require("../storage");
|
|
43
|
+
const errors_1 = require("../utils/errors");
|
|
44
|
+
const constants_1 = require("../utils/constants");
|
|
45
|
+
/**
|
|
46
|
+
* Search for commands by name or command text
|
|
47
|
+
*
|
|
48
|
+
* Performs case-insensitive search across command names and command text.
|
|
49
|
+
*
|
|
50
|
+
* @param query - The search query string
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```
|
|
54
|
+
* // Search for commands containing 'build'
|
|
55
|
+
* searchCommand('build');
|
|
56
|
+
* // Output:
|
|
57
|
+
* // build-prod
|
|
58
|
+
* // Command: npm run build --production
|
|
59
|
+
* // Directory: /home/user/project
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
function searchCommand(query) {
|
|
63
|
+
try {
|
|
64
|
+
if (!query || !query.trim()) {
|
|
65
|
+
console.log(chalk_1.default.yellow('Please provide a search query'));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const aliases = (0, storage_1.loadAliases)();
|
|
69
|
+
const names = Object.keys(aliases);
|
|
70
|
+
if (names.length === 0) {
|
|
71
|
+
console.log(chalk_1.default.yellow(constants_1.HELP_MESSAGES.noCommands));
|
|
72
|
+
console.log(chalk_1.default.gray(constants_1.HELP_MESSAGES.useSaveOrPrev));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const searchTerm = query.toLowerCase().trim();
|
|
76
|
+
const results = [];
|
|
77
|
+
// Search in command names and command text
|
|
78
|
+
for (const name of names) {
|
|
79
|
+
const alias = aliases[name];
|
|
80
|
+
const nameMatch = name.toLowerCase().includes(searchTerm);
|
|
81
|
+
const commandMatch = alias.command.toLowerCase().includes(searchTerm);
|
|
82
|
+
const dirMatch = alias.directory.toLowerCase().includes(searchTerm);
|
|
83
|
+
if (nameMatch || commandMatch || dirMatch) {
|
|
84
|
+
let matchType = '';
|
|
85
|
+
if (nameMatch)
|
|
86
|
+
matchType = 'name';
|
|
87
|
+
else if (commandMatch)
|
|
88
|
+
matchType = 'command';
|
|
89
|
+
else if (dirMatch)
|
|
90
|
+
matchType = 'directory';
|
|
91
|
+
results.push({ name, matchType });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (results.length === 0) {
|
|
95
|
+
console.log(chalk_1.default.yellow(`No commands found matching "${query}"`));
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
console.log(chalk_1.default.bold(`\nFound ${results.length} command(s) matching "${query}":\n`));
|
|
99
|
+
for (const { name, matchType } of results) {
|
|
100
|
+
const alias = aliases[name];
|
|
101
|
+
const dirExists = fs.existsSync(alias.directory);
|
|
102
|
+
const dirIndicator = dirExists ? '' : chalk_1.default.red(' [DIR NOT FOUND]');
|
|
103
|
+
console.log(chalk_1.default.cyan(` ${name}${dirIndicator}`) + chalk_1.default.gray(` (matched in ${matchType})`));
|
|
104
|
+
console.log(chalk_1.default.gray(` Command: ${alias.command}`));
|
|
105
|
+
console.log(chalk_1.default.gray(` Directory: ${alias.directory}`));
|
|
106
|
+
console.log();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
(0, errors_1.handleError)(error, 'Failed to search commands');
|
|
111
|
+
}
|
|
112
|
+
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G,eAAK,CAAC,IAAI,CAAC,gBAAgB,SAAS,GAAG,CAAC,CAClF,CAAC;YACF,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,gBAAgB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YACzD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,kBAAkB,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;YAC7D,OAAO,CAAC,GAAG,EAAE,CAAC;QAChB,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAA,oBAAW,EAAC,KAAK,EAAE,2BAA2B,CAAC,CAAC;IAClD,CAAC;AACH,CAAC"}
|
package/dist/storage/index.d.ts
CHANGED
|
@@ -1,42 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a saved command alias with its metadata
|
|
3
|
+
*/
|
|
1
4
|
export interface CommandAlias {
|
|
5
|
+
/** The shell command to execute */
|
|
2
6
|
command: string;
|
|
7
|
+
/** The working directory where the command should be executed */
|
|
3
8
|
directory: string;
|
|
9
|
+
/** ISO 8601 timestamp when the command was created */
|
|
4
10
|
createdAt: string;
|
|
11
|
+
/** ISO 8601 timestamp when the command was last modified */
|
|
5
12
|
updatedAt: string;
|
|
6
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Configuration object containing all saved command aliases
|
|
16
|
+
*/
|
|
7
17
|
export interface AliasConfig {
|
|
8
18
|
[name: string]: CommandAlias;
|
|
9
19
|
}
|
|
10
20
|
/**
|
|
11
|
-
* Get the config directory path
|
|
21
|
+
* Get the config directory path, creating it if it doesn't exist
|
|
22
|
+
* @returns The absolute path to the config directory
|
|
12
23
|
*/
|
|
13
24
|
export declare function getConfigDir(): string;
|
|
14
25
|
/**
|
|
15
26
|
* Get the config file path
|
|
27
|
+
* @returns The absolute path to the config.json file
|
|
16
28
|
*/
|
|
17
29
|
export declare function getConfigPath(): string;
|
|
18
30
|
/**
|
|
19
|
-
* Load all saved aliases
|
|
31
|
+
* Load all saved aliases from the config file
|
|
32
|
+
* @returns The alias configuration object, or an empty object if the file doesn't exist
|
|
20
33
|
*/
|
|
21
34
|
export declare function loadAliases(): AliasConfig;
|
|
22
35
|
/**
|
|
23
|
-
* Save all aliases
|
|
36
|
+
* Save all aliases to the config file
|
|
37
|
+
* Uses atomic write pattern to prevent data corruption
|
|
38
|
+
* @param aliases - The alias configuration to save
|
|
39
|
+
* @returns true if successful, false otherwise
|
|
24
40
|
*/
|
|
25
41
|
export declare function saveAliases(aliases: AliasConfig): boolean;
|
|
26
42
|
/**
|
|
27
|
-
* Get a specific alias
|
|
43
|
+
* Get a specific alias by name
|
|
44
|
+
* @param name - The name of the alias to retrieve
|
|
45
|
+
* @returns The command alias if found, undefined otherwise
|
|
28
46
|
*/
|
|
29
47
|
export declare function getAlias(name: string): CommandAlias | undefined;
|
|
30
48
|
/**
|
|
31
|
-
* Set
|
|
49
|
+
* Set or update an alias
|
|
50
|
+
* @param name - The name of the alias
|
|
51
|
+
* @param command - The shell command to save
|
|
52
|
+
* @param directory - The working directory for the command
|
|
53
|
+
* @returns true if successful, false otherwise
|
|
54
|
+
* @throws {Error} If the directory doesn't exist or isn't accessible
|
|
32
55
|
*/
|
|
33
56
|
export declare function setAlias(name: string, command: string, directory: string): boolean;
|
|
34
57
|
/**
|
|
35
|
-
* Delete an alias
|
|
58
|
+
* Delete an alias by name
|
|
59
|
+
* @param name - The name of the alias to delete
|
|
60
|
+
* @returns true if the alias was deleted, false if it didn't exist
|
|
36
61
|
*/
|
|
37
62
|
export declare function deleteAlias(name: string): boolean;
|
|
38
63
|
/**
|
|
39
|
-
* Check if alias exists
|
|
64
|
+
* Check if an alias exists
|
|
65
|
+
* @param name - The name of the alias to check
|
|
66
|
+
* @returns true if the alias exists, false otherwise
|
|
40
67
|
*/
|
|
41
68
|
export declare function aliasExists(name: string): boolean;
|
|
42
69
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/storage/index.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAC;CAC9B;AAED
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/storage/index.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,iEAAiE;IACjE,SAAS,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;IAClB,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAC;CAC9B;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAUrC;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;;GAGG;AACH,wBAAgB,WAAW,IAAI,WAAW,CAczC;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAsBzD;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAG/D;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAyBlF;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAOjD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGjD"}
|
package/dist/storage/index.js
CHANGED
|
@@ -45,7 +45,8 @@ const fs = __importStar(require("fs"));
|
|
|
45
45
|
const path = __importStar(require("path"));
|
|
46
46
|
const os = __importStar(require("os"));
|
|
47
47
|
/**
|
|
48
|
-
* Get the config directory path
|
|
48
|
+
* Get the config directory path, creating it if it doesn't exist
|
|
49
|
+
* @returns The absolute path to the config directory
|
|
49
50
|
*/
|
|
50
51
|
function getConfigDir() {
|
|
51
52
|
const homeDir = os.homedir();
|
|
@@ -58,12 +59,14 @@ function getConfigDir() {
|
|
|
58
59
|
}
|
|
59
60
|
/**
|
|
60
61
|
* Get the config file path
|
|
62
|
+
* @returns The absolute path to the config.json file
|
|
61
63
|
*/
|
|
62
64
|
function getConfigPath() {
|
|
63
65
|
return path.join(getConfigDir(), 'config.json');
|
|
64
66
|
}
|
|
65
67
|
/**
|
|
66
|
-
* Load all saved aliases
|
|
68
|
+
* Load all saved aliases from the config file
|
|
69
|
+
* @returns The alias configuration object, or an empty object if the file doesn't exist
|
|
67
70
|
*/
|
|
68
71
|
function loadAliases() {
|
|
69
72
|
const configPath = getConfigPath();
|
|
@@ -80,41 +83,80 @@ function loadAliases() {
|
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
/**
|
|
83
|
-
* Save all aliases
|
|
86
|
+
* Save all aliases to the config file
|
|
87
|
+
* Uses atomic write pattern to prevent data corruption
|
|
88
|
+
* @param aliases - The alias configuration to save
|
|
89
|
+
* @returns true if successful, false otherwise
|
|
84
90
|
*/
|
|
85
91
|
function saveAliases(aliases) {
|
|
86
92
|
const configPath = getConfigPath();
|
|
93
|
+
const tempPath = `${configPath}.tmp`;
|
|
87
94
|
try {
|
|
88
|
-
|
|
95
|
+
// Write to temporary file first
|
|
96
|
+
fs.writeFileSync(tempPath, JSON.stringify(aliases, null, 2), 'utf8');
|
|
97
|
+
// Atomic rename
|
|
98
|
+
fs.renameSync(tempPath, configPath);
|
|
89
99
|
return true;
|
|
90
100
|
}
|
|
91
101
|
catch (error) {
|
|
92
102
|
console.error('Error writing config file:', error.message);
|
|
103
|
+
// Clean up temp file if it exists
|
|
104
|
+
try {
|
|
105
|
+
if (fs.existsSync(tempPath)) {
|
|
106
|
+
fs.unlinkSync(tempPath);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
// Ignore cleanup errors
|
|
111
|
+
}
|
|
93
112
|
return false;
|
|
94
113
|
}
|
|
95
114
|
}
|
|
96
115
|
/**
|
|
97
|
-
* Get a specific alias
|
|
116
|
+
* Get a specific alias by name
|
|
117
|
+
* @param name - The name of the alias to retrieve
|
|
118
|
+
* @returns The command alias if found, undefined otherwise
|
|
98
119
|
*/
|
|
99
120
|
function getAlias(name) {
|
|
100
121
|
const aliases = loadAliases();
|
|
101
122
|
return aliases[name];
|
|
102
123
|
}
|
|
103
124
|
/**
|
|
104
|
-
* Set
|
|
125
|
+
* Set or update an alias
|
|
126
|
+
* @param name - The name of the alias
|
|
127
|
+
* @param command - The shell command to save
|
|
128
|
+
* @param directory - The working directory for the command
|
|
129
|
+
* @returns true if successful, false otherwise
|
|
130
|
+
* @throws {Error} If the directory doesn't exist or isn't accessible
|
|
105
131
|
*/
|
|
106
132
|
function setAlias(name, command, directory) {
|
|
133
|
+
// Validate inputs
|
|
134
|
+
if (!name || !name.trim()) {
|
|
135
|
+
throw new Error('Alias name cannot be empty');
|
|
136
|
+
}
|
|
137
|
+
if (!command || !command.trim()) {
|
|
138
|
+
throw new Error('Command cannot be empty');
|
|
139
|
+
}
|
|
140
|
+
if (!directory || !directory.trim()) {
|
|
141
|
+
throw new Error('Directory cannot be empty');
|
|
142
|
+
}
|
|
143
|
+
// Validate directory exists (warning only, don't block)
|
|
144
|
+
if (!fs.existsSync(directory)) {
|
|
145
|
+
console.warn(`Warning: Directory does not exist: ${directory}`);
|
|
146
|
+
}
|
|
107
147
|
const aliases = loadAliases();
|
|
108
148
|
aliases[name] = {
|
|
109
|
-
command,
|
|
110
|
-
directory,
|
|
149
|
+
command: command.trim(),
|
|
150
|
+
directory: path.resolve(directory),
|
|
111
151
|
createdAt: aliases[name]?.createdAt || new Date().toISOString(),
|
|
112
|
-
updatedAt: new Date().toISOString()
|
|
152
|
+
updatedAt: new Date().toISOString(),
|
|
113
153
|
};
|
|
114
154
|
return saveAliases(aliases);
|
|
115
155
|
}
|
|
116
156
|
/**
|
|
117
|
-
* Delete an alias
|
|
157
|
+
* Delete an alias by name
|
|
158
|
+
* @param name - The name of the alias to delete
|
|
159
|
+
* @returns true if the alias was deleted, false if it didn't exist
|
|
118
160
|
*/
|
|
119
161
|
function deleteAlias(name) {
|
|
120
162
|
const aliases = loadAliases();
|
|
@@ -125,7 +167,9 @@ function deleteAlias(name) {
|
|
|
125
167
|
return saveAliases(aliases);
|
|
126
168
|
}
|
|
127
169
|
/**
|
|
128
|
-
* Check if alias exists
|
|
170
|
+
* Check if an alias exists
|
|
171
|
+
* @param name - The name of the alias to check
|
|
172
|
+
* @returns true if the alias exists, false otherwise
|
|
129
173
|
*/
|
|
130
174
|
function aliasExists(name) {
|
|
131
175
|
const aliases = loadAliases();
|