Comparing version 1.0.0 to 1.1.0
@@ -6,20 +6,10 @@ import * as fs from 'fs'; | ||
const ID_FILE = path.join(__dirname, '..', 'user-id.txt'); | ||
console.log('Saving user ID to:', ID_FILE); | ||
/** | ||
* Generates a unique ID and saves it to a file, or retrieves the existing ID if already generated. | ||
* | ||
* @param {typeof fs} customFs - An optional custom file system module for testing or alternate environments. | ||
* @returns {string} - The unique ID. | ||
* @throws Will throw an error if reading or writing the ID file fails. | ||
*/ | ||
export function generateUniqueId(customFs = fs): string { | ||
try { | ||
// Check if the ID file already exists | ||
if (customFs.existsSync(ID_FILE)) { | ||
// Read and return the existing unique ID | ||
return customFs.readFileSync(ID_FILE, 'utf-8').trim(); | ||
} else { | ||
// Generate a new unique ID using uuidv4 | ||
const uniqueId = uuidv4(); | ||
// Save the generated ID to the file | ||
customFs.writeFileSync(ID_FILE, uniqueId, 'utf-8'); | ||
@@ -30,5 +20,4 @@ return uniqueId; | ||
console.error('Failed to generate or read unique ID:', error); | ||
// Re-throw the error to allow further handling by the caller | ||
throw error; | ||
} | ||
} |
{ | ||
"name": "pm2wick", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Manage your PM2 processes.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39486
846