@tertium/hlpr 0.1.4 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/hlpr.js CHANGED
@@ -38,6 +38,17 @@ const node_child_process_1 = require("node:child_process");
38
38
  const path = __importStar(require("node:path"));
39
39
  const fs = __importStar(require("node:fs"));
40
40
  const readline = __importStar(require("node:readline"));
41
+ const os = __importStar(require("node:os"));
42
+ // Package version from package.json
43
+ const VERSION = "0.1.6";
44
+ // Detect shell type
45
+ function detectShell() {
46
+ const isWindows = os.platform() === "win32";
47
+ if (isWindows) {
48
+ return "powershell";
49
+ }
50
+ return "bash"; // Default to bash for Unix-like systems
51
+ }
41
52
  // Parse command line arguments
42
53
  const args = process.argv.slice(2);
43
54
  let forceFlag = false;
@@ -95,6 +106,11 @@ async function executeCommand(command, variables) {
95
106
  });
96
107
  }
97
108
  async function main() {
109
+ // Check for version flag
110
+ if (commandArgs[0] === "--version" || commandArgs[0] === "-v") {
111
+ console.log(`hlpr version ${VERSION}`);
112
+ process.exit(0);
113
+ }
98
114
  if (commandArgs.length === 0) {
99
115
  console.error("Please provide a command. Example: hlpr ssh init-dir");
100
116
  process.exit(1);
@@ -115,32 +131,38 @@ async function main() {
115
131
  }
116
132
  // Read the script content
117
133
  const scriptContent = await (0, promises_1.readFile)(scriptPath, "utf-8");
118
- const lines = scriptContent.split("\n");
119
134
  // Extract variables from the script (anything in {{variable}})
120
135
  const variableRegex = /{{([^}]+)}}/g;
121
136
  const variables = {};
122
137
  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
- });
138
+ let match;
139
+ while ((match = variableRegex.exec(scriptContent)) !== null) {
140
+ uniqueVars.add(match[1]);
141
+ }
129
142
  // Prompt for each variable
130
143
  for (const varName of uniqueVars) {
131
144
  const value = await prompt(`Enter ${varName}: `);
132
145
  variables[varName] = value;
133
146
  }
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
- }
147
+ // Create a temporary script with variables substituted
148
+ let processedScript = scriptContent;
149
+ for (const [key, value] of Object.entries(variables)) {
150
+ processedScript = processedScript.replace(new RegExp(`{{${key}}}`, 'g'), value);
151
+ }
152
+ const tempScriptPath = path.join(path.dirname(scriptPath), `_temp_${path.basename(scriptPath)}`);
153
+ fs.writeFileSync(tempScriptPath, processedScript);
154
+ // Execute the temporary script with appropriate shell
155
+ const shell = detectShell();
156
+ const command = shell === "powershell"
157
+ ? `powershell -File "${tempScriptPath}"`
158
+ : `bash "${tempScriptPath}"`;
159
+ const success = await executeCommand(command, {});
160
+ // Clean up the temporary script
161
+ fs.unlinkSync(tempScriptPath);
162
+ // If command failed and force flag is not set, exit
163
+ if (!success && !forceFlag) {
164
+ console.error("Command failed, stopping execution.");
165
+ process.exit(1);
144
166
  }
145
167
  console.log("Command completed successfully!");
146
168
  }
@@ -0,0 +1,3 @@
1
+ echo "Running build before commit..."
2
+ bun run build
3
+ git add bin/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tertium/hlpr",
3
- "version": "0.1.4",
3
+ "version": "0.1.7",
4
4
  "description": "Windows and *Nix utility for typical programming activity",
5
5
  "author": "Vitalii Balabanov",
6
6
  "email": "tertiumnon@gmail.com",