Skip to content

Commit

Permalink
fix: workflow test
Browse files Browse the repository at this point in the history
  • Loading branch information
0xBunzy committed Oct 31, 2024
1 parent 530fb70 commit 7ce0fef
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions src/bin/fix-shebang.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
import { promises as fs } from 'fs';
import { join } from 'path';
/** @format */

import { promises as fs } from "fs";
import { join } from "path";

// Path to the compiled JavaScript file in your dist directory
const scriptPath = join(process.cwd(), 'dist/bin/script.js');
const scriptPath = join(process.cwd(), "dist/bin/script.js");

// The shebang line to add
const shebang = '#!/usr/bin/env node\n';
const shebang = "#!/usr/bin/env node\n";

async function addShebang() {
try {
// Read the contents of the file
let data = await fs.readFile(scriptPath, 'utf8');

// Check if the shebang is already there and replace any existing shebang
const shebangRegex = /^#!.*\n/;
if (shebangRegex.test(data)) {
console.log('Found existing shebang, replacing it.');
data = data.replace(shebangRegex, '');
}

// Prepend the new shebang to the file content
const updatedContent = shebang + data;

// Write the updated content back to the file
await fs.writeFile(scriptPath, updatedContent, 'utf8');
console.log('Shebang added/replaced successfully!');

// Set the correct permissions to make the file executable
await fs.chmod(scriptPath, 0o755);
console.log('Execution permissions added successfully!');
} catch (err) {
console.error('Error:', err);
try {
// Read the contents of the file
let data = await fs.readFile(scriptPath, "utf8");

// Check if the shebang is already there and replace any existing shebang
const shebangRegex = /^#!.*\n/;
if (shebangRegex.test(data)) {
console.log("Found existing shebang, replacing it.");
data = data.replace(shebangRegex, "");
}

const updatedContent = shebang + data;

// Write the updated content back to the file
await fs.writeFile(scriptPath, updatedContent, "utf8");
console.log("Shebang added/replaced successfully!");

// Set the correct permissions to make the file executable
await fs.chmod(scriptPath, 0o755);
console.log("Execution permissions added successfully!");
} catch (err) {
console.error("Error:", err);
}
}

addShebang();

0 comments on commit 7ce0fef

Please sign in to comment.