@tertium/hlpr 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/hlpr.js +155 -3
- package/package.json +7 -5
- package/dist/hlpr.js +0 -153
- /package/{dist → bin}/hlpr.d.ts +0 -0
package/bin/hlpr.js
CHANGED
|
@@ -1,3 +1,155 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const promises_1 = require("node:fs/promises");
|
|
37
|
+
const node_child_process_1 = require("node:child_process");
|
|
38
|
+
const path = __importStar(require("node:path"));
|
|
39
|
+
const fs = __importStar(require("node:fs"));
|
|
40
|
+
const readline = __importStar(require("node:readline"));
|
|
41
|
+
// Parse command line arguments
|
|
42
|
+
const args = process.argv.slice(2);
|
|
43
|
+
let forceFlag = false;
|
|
44
|
+
let commandArgs = [];
|
|
45
|
+
// Check for -f flag
|
|
46
|
+
if (args[0] === "-f") {
|
|
47
|
+
forceFlag = true;
|
|
48
|
+
commandArgs = args.slice(1);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
commandArgs = args;
|
|
52
|
+
}
|
|
53
|
+
// Create readline interface for user input
|
|
54
|
+
const rl = readline.createInterface({
|
|
55
|
+
input: process.stdin,
|
|
56
|
+
output: process.stdout
|
|
57
|
+
});
|
|
58
|
+
// Prompt for user input
|
|
59
|
+
function prompt(question) {
|
|
60
|
+
return new Promise((resolve) => {
|
|
61
|
+
rl.question(question, (answer) => {
|
|
62
|
+
resolve(answer);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
// Execute a command with variable substitution
|
|
67
|
+
async function executeCommand(command, variables) {
|
|
68
|
+
// Replace variables in the command
|
|
69
|
+
let processedCommand = command;
|
|
70
|
+
for (const [key, value] of Object.entries(variables)) {
|
|
71
|
+
processedCommand = processedCommand.replace(new RegExp(`{{${key}}}`, 'g'), value);
|
|
72
|
+
}
|
|
73
|
+
return new Promise((resolve) => {
|
|
74
|
+
console.log(`Executing: ${processedCommand}`);
|
|
75
|
+
const childProcess = (0, node_child_process_1.exec)(processedCommand);
|
|
76
|
+
if (childProcess.stdout) {
|
|
77
|
+
childProcess.stdout.on("data", (data) => {
|
|
78
|
+
console.log(data.toString().trim());
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
if (childProcess.stderr) {
|
|
82
|
+
childProcess.stderr.on("data", (data) => {
|
|
83
|
+
console.error(data.toString().trim());
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
childProcess.on("exit", (code) => {
|
|
87
|
+
if (code === 0) {
|
|
88
|
+
resolve(true);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
console.error(`Command failed with exit code ${code}`);
|
|
92
|
+
resolve(false);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
async function main() {
|
|
98
|
+
if (commandArgs.length === 0) {
|
|
99
|
+
console.error("Please provide a command. Example: hlpr ssh init-dir");
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
// Get the category (first argument) and the rest of the command
|
|
104
|
+
const category = commandArgs[0];
|
|
105
|
+
const restArgs = commandArgs.slice(1);
|
|
106
|
+
// Join the rest of the arguments without hyphens
|
|
107
|
+
const scriptName = restArgs.join("");
|
|
108
|
+
// Get the directory where the hlpr script is installed
|
|
109
|
+
const scriptDir = path.dirname(path.dirname(__dirname));
|
|
110
|
+
const scriptPath = path.join(scriptDir, "commands", category, `${scriptName}.sh`);
|
|
111
|
+
// Check if the script exists
|
|
112
|
+
if (!fs.existsSync(scriptPath)) {
|
|
113
|
+
console.error(`Script not found: ${scriptPath}`);
|
|
114
|
+
process.exit(1);
|
|
115
|
+
}
|
|
116
|
+
// Read the script content
|
|
117
|
+
const scriptContent = await (0, promises_1.readFile)(scriptPath, "utf-8");
|
|
118
|
+
const lines = scriptContent.split("\n");
|
|
119
|
+
// Extract variables from the script (anything in {{variable}})
|
|
120
|
+
const variableRegex = /{{([^}]+)}}/g;
|
|
121
|
+
const variables = {};
|
|
122
|
+
const uniqueVars = new Set();
|
|
123
|
+
lines.forEach(line => {
|
|
124
|
+
let match;
|
|
125
|
+
while ((match = variableRegex.exec(line)) !== null) {
|
|
126
|
+
uniqueVars.add(match[1]);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
// Prompt for each variable
|
|
130
|
+
for (const varName of uniqueVars) {
|
|
131
|
+
const value = await prompt(`Enter ${varName}: `);
|
|
132
|
+
variables[varName] = value;
|
|
133
|
+
}
|
|
134
|
+
// Execute each line of the script
|
|
135
|
+
for (const line of lines) {
|
|
136
|
+
if (!line.trim())
|
|
137
|
+
continue;
|
|
138
|
+
const success = await executeCommand(line, variables);
|
|
139
|
+
// If command failed and force flag is not set, exit
|
|
140
|
+
if (!success && !forceFlag) {
|
|
141
|
+
console.error("Command failed, stopping execution.");
|
|
142
|
+
process.exit(1);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
console.log("Command completed successfully!");
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
console.error("Error:", error);
|
|
149
|
+
process.exit(1);
|
|
150
|
+
}
|
|
151
|
+
finally {
|
|
152
|
+
rl.close();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
main();
|
package/package.json
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tertium/hlpr",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Windows and *Nix utility for typical programming activity",
|
|
5
5
|
"author": "Vitalii Balabanov",
|
|
6
6
|
"email": "tertiumnon@gmail.com",
|
|
7
|
-
"main": "
|
|
7
|
+
"main": "bin/hlpr.js",
|
|
8
8
|
"type": "commonjs",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "tsc --project tsconfig.json",
|
|
11
11
|
"prepublishOnly": "npm run build",
|
|
12
|
-
"release:minor": "node_modules/@tertium/shared-js-configs-and-types/scripts/release.js
|
|
13
|
-
"release:patch": "node_modules/@tertium/shared-js-configs-and-types/scripts/release.js
|
|
14
|
-
"release:major": "node_modules/@tertium/shared-js-configs-and-types/scripts/release.js
|
|
12
|
+
"release:minor": "node node_modules/@tertium/shared-js-configs-and-types/scripts/release.js minor",
|
|
13
|
+
"release:patch": "node node_modules/@tertium/shared-js-configs-and-types/scripts/release.js patch",
|
|
14
|
+
"release:major": "node node_modules/@tertium/shared-js-configs-and-types/scripts/release.js major",
|
|
15
|
+
"prepare": "husky"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|
|
17
18
|
"@tertium/shared-js-configs-and-types": "^0.14.0",
|
|
18
19
|
"@types/node": "^22.13.10",
|
|
20
|
+
"husky": "^9.1.7",
|
|
19
21
|
"typescript": "^5.8.3"
|
|
20
22
|
},
|
|
21
23
|
"bin": {
|
package/dist/hlpr.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
const promises_1 = require("node:fs/promises");
|
|
37
|
-
const node_child_process_1 = require("node:child_process");
|
|
38
|
-
const path = __importStar(require("node:path"));
|
|
39
|
-
const fs = __importStar(require("node:fs"));
|
|
40
|
-
const readline = __importStar(require("node:readline"));
|
|
41
|
-
// Parse command line arguments
|
|
42
|
-
const args = process.argv.slice(2);
|
|
43
|
-
let forceFlag = false;
|
|
44
|
-
let commandArgs = [];
|
|
45
|
-
// Check for -f flag
|
|
46
|
-
if (args[0] === "-f") {
|
|
47
|
-
forceFlag = true;
|
|
48
|
-
commandArgs = args.slice(1);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
commandArgs = args;
|
|
52
|
-
}
|
|
53
|
-
// Create readline interface for user input
|
|
54
|
-
const rl = readline.createInterface({
|
|
55
|
-
input: process.stdin,
|
|
56
|
-
output: process.stdout
|
|
57
|
-
});
|
|
58
|
-
// Prompt for user input
|
|
59
|
-
function prompt(question) {
|
|
60
|
-
return new Promise((resolve) => {
|
|
61
|
-
rl.question(question, (answer) => {
|
|
62
|
-
resolve(answer);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
// Execute a command with variable substitution
|
|
67
|
-
async function executeCommand(command, variables) {
|
|
68
|
-
// Replace variables in the command
|
|
69
|
-
let processedCommand = command;
|
|
70
|
-
for (const [key, value] of Object.entries(variables)) {
|
|
71
|
-
processedCommand = processedCommand.replace(new RegExp(`{{${key}}}`, 'g'), value);
|
|
72
|
-
}
|
|
73
|
-
return new Promise((resolve) => {
|
|
74
|
-
console.log(`Executing: ${processedCommand}`);
|
|
75
|
-
const childProcess = (0, node_child_process_1.exec)(processedCommand);
|
|
76
|
-
if (childProcess.stdout) {
|
|
77
|
-
childProcess.stdout.on("data", (data) => {
|
|
78
|
-
console.log(data.toString().trim());
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
if (childProcess.stderr) {
|
|
82
|
-
childProcess.stderr.on("data", (data) => {
|
|
83
|
-
console.error(data.toString().trim());
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
childProcess.on("exit", (code) => {
|
|
87
|
-
if (code === 0) {
|
|
88
|
-
resolve(true);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
console.error(`Command failed with exit code ${code}`);
|
|
92
|
-
resolve(false);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
async function main() {
|
|
98
|
-
if (commandArgs.length === 0) {
|
|
99
|
-
console.error("Please provide a command. Example: hlpr ssh init-dir");
|
|
100
|
-
process.exit(1);
|
|
101
|
-
}
|
|
102
|
-
try {
|
|
103
|
-
// Get the category (first argument) and the rest of the command
|
|
104
|
-
const category = commandArgs[0];
|
|
105
|
-
const restArgs = commandArgs.slice(1);
|
|
106
|
-
// Join the rest of the arguments without hyphens
|
|
107
|
-
const scriptName = restArgs.join("");
|
|
108
|
-
const scriptPath = path.join(process.cwd(), "commands", category, `${scriptName}.sh`);
|
|
109
|
-
// Check if the script exists
|
|
110
|
-
if (!fs.existsSync(scriptPath)) {
|
|
111
|
-
console.error(`Script not found: ${scriptPath}`);
|
|
112
|
-
process.exit(1);
|
|
113
|
-
}
|
|
114
|
-
// Read the script content
|
|
115
|
-
const scriptContent = await (0, promises_1.readFile)(scriptPath, "utf-8");
|
|
116
|
-
const lines = scriptContent.split("\n");
|
|
117
|
-
// Extract variables from the script (anything in {{variable}})
|
|
118
|
-
const variableRegex = /{{([^}]+)}}/g;
|
|
119
|
-
const variables = {};
|
|
120
|
-
const uniqueVars = new Set();
|
|
121
|
-
lines.forEach(line => {
|
|
122
|
-
let match;
|
|
123
|
-
while ((match = variableRegex.exec(line)) !== null) {
|
|
124
|
-
uniqueVars.add(match[1]);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
// Prompt for each variable
|
|
128
|
-
for (const varName of uniqueVars) {
|
|
129
|
-
const value = await prompt(`Enter ${varName}: `);
|
|
130
|
-
variables[varName] = value;
|
|
131
|
-
}
|
|
132
|
-
// Execute each line of the script
|
|
133
|
-
for (const line of lines) {
|
|
134
|
-
if (!line.trim())
|
|
135
|
-
continue;
|
|
136
|
-
const success = await executeCommand(line, variables);
|
|
137
|
-
// If command failed and force flag is not set, exit
|
|
138
|
-
if (!success && !forceFlag) {
|
|
139
|
-
console.error("Command failed, stopping execution.");
|
|
140
|
-
process.exit(1);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
console.log("Command completed successfully!");
|
|
144
|
-
}
|
|
145
|
-
catch (error) {
|
|
146
|
-
console.error("Error:", error);
|
|
147
|
-
process.exit(1);
|
|
148
|
-
}
|
|
149
|
-
finally {
|
|
150
|
-
rl.close();
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
main();
|
/package/{dist → bin}/hlpr.d.ts
RENAMED
|
File without changes
|