✨ Standardize string quotes to single quotes and improve code readability
This commit is contained in:
@@ -14,10 +14,10 @@
|
|||||||
* Example:
|
* Example:
|
||||||
* npm run bookmarklet -- code/bookmarklets/example-bookmarklet.js
|
* npm run bookmarklet -- code/bookmarklets/example-bookmarklet.js
|
||||||
*/
|
*/
|
||||||
import fs from "fs";
|
import fs from 'fs';
|
||||||
import path from "path";
|
import path from 'path';
|
||||||
import clipboardy from "clipboardy";
|
import clipboardy from 'clipboardy';
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
@@ -29,9 +29,9 @@ const __dirname = path.dirname(__filename);
|
|||||||
*/
|
*/
|
||||||
function removeComments(code) {
|
function removeComments(code) {
|
||||||
// Remove multi-line comments /* ... */
|
// Remove multi-line comments /* ... */
|
||||||
code = code.replace(/\/\*[\s\S]*?\*\//g, "");
|
code = code.replace(/\/\*[\s\S]*?\*\//g, '');
|
||||||
// Remove single-line comments //
|
// Remove single-line comments //
|
||||||
code = code.replace(/\/\/.*$/gm, "");
|
code = code.replace(/\/\/.*$/gm, '');
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,12 +42,12 @@ function removeComments(code) {
|
|||||||
*/
|
*/
|
||||||
function minify(code) {
|
function minify(code) {
|
||||||
return code
|
return code
|
||||||
.split("\n")
|
.split('\n')
|
||||||
.map((line) => line.trim())
|
.map(line => line.trim())
|
||||||
.filter((line) => line.length > 0)
|
.filter(line => line.length > 0)
|
||||||
.join(" ")
|
.join(' ')
|
||||||
.replace(/\s+/g, " ")
|
.replace(/\s+/g, ' ')
|
||||||
.replace(/\s*([{}();,])\s*/g, "$1");
|
.replace(/\s*([{}();,])\s*/g, '$1');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,7 +62,7 @@ function generateBookmarklet(filePath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read the JavaScript file
|
// Read the JavaScript file
|
||||||
const jsCode = fs.readFileSync(filePath, "utf8");
|
const jsCode = fs.readFileSync(filePath, 'utf8');
|
||||||
|
|
||||||
// Clean and minify
|
// Clean and minify
|
||||||
let cleanedCode = removeComments(jsCode);
|
let cleanedCode = removeComments(jsCode);
|
||||||
@@ -79,11 +79,11 @@ try {
|
|||||||
const filePath = process.argv[2];
|
const filePath = process.argv[2];
|
||||||
|
|
||||||
if (!filePath) {
|
if (!filePath) {
|
||||||
console.error("❌ Error: Please provide a file path");
|
console.error('❌ Error: Please provide a file path');
|
||||||
console.log("\nUsage:");
|
console.log('\nUsage:');
|
||||||
console.log(" npm run bookmarklet -- <path-to-js-file>");
|
console.log(' npm run bookmarklet -- <path-to-js-file>');
|
||||||
console.log("\nExample:");
|
console.log('\nExample:');
|
||||||
console.log(" npm run bookmarklet -- code/bookmarklets/my-bookmarklet.js");
|
console.log(' npm run bookmarklet -- code/bookmarklets/my-bookmarklet.js');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,14 +93,14 @@ try {
|
|||||||
// Copy to clipboard
|
// Copy to clipboard
|
||||||
clipboardy.writeSync(bookmarklet);
|
clipboardy.writeSync(bookmarklet);
|
||||||
|
|
||||||
console.log("✅ Bookmarklet generated successfully!");
|
console.log('✅ Bookmarklet generated successfully!');
|
||||||
console.log(`📁 Source: ${fileName}`);
|
console.log(`📁 Source: ${fileName}`);
|
||||||
console.log(`📋 Copied to clipboard (${bookmarklet.length} characters)`);
|
console.log(`📋 Copied to clipboard (${bookmarklet.length} characters)`);
|
||||||
console.log("\n📝 Next steps:");
|
console.log('\n📝 Next steps:');
|
||||||
console.log(" 1. Create a new bookmark in your browser");
|
console.log(' 1. Create a new bookmark in your browser');
|
||||||
console.log(" 2. Paste the clipboard content as the URL");
|
console.log(' 2. Paste the clipboard content as the URL');
|
||||||
console.log(" 3. Give it a name and save");
|
console.log(' 3. Give it a name and save');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("❌ Error:", error.message);
|
console.error('❌ Error:', error.message);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user