-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31f0178
commit bbf28ee
Showing
4 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
You are awesome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["example.txt"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const fs = require('fs'); | ||
const yargs = require('yargs'); | ||
|
||
// Load filenames from `filenames.txt` if it exists | ||
let filenames = []; | ||
const filenamesPath = 'filenames.txt'; | ||
|
||
if (fs.existsSync(filenamesPath)) { | ||
const data = fs.readFileSync(filenamesPath, 'utf-8'); | ||
filenames = data ? JSON.parse(data) : []; | ||
} | ||
|
||
// Configure yargs to take a filename as input | ||
const argv = yargs | ||
.option('filename', { | ||
alias: 'f', | ||
type: 'string', | ||
description: 'Name of the file to create', | ||
demandOption: true, | ||
}) | ||
.help() | ||
.argv; | ||
|
||
const newFilename = argv.filename; | ||
|
||
// Check if the file already exists | ||
if (filenames.includes(newFilename)) { | ||
console.log(`The file "${newFilename}" already exists. Please provide a new filename.`); | ||
} else { | ||
// Write 'You are awesome' to the new file | ||
fs.writeFileSync(newFilename, 'You are awesome', 'utf-8'); | ||
console.log(`File "${newFilename}" created successfully!`); | ||
|
||
// Add the new filename to the array | ||
filenames.push(newFilename); | ||
|
||
// Save updated filenames to `filenames.txt` | ||
fs.writeFileSync(filenamesPath, JSON.stringify(filenames), 'utf-8'); | ||
console.log('Updated filenames list saved to filenames.txt.'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "assignment-1", | ||
"version": "1.0.0", | ||
"description": "assignment 1", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "vikrant", | ||
"license": "ISC", | ||
"dependencies": { | ||
"yargs": "^17.7.2" | ||
} | ||
} |