Skip to content

Commit

Permalink
📦feat: custom generate license even if package.json doesn't exist
Browse files Browse the repository at this point in the history
Signed-off-by: phukon <[email protected]>
  • Loading branch information
phukon committed Dec 15, 2023
1 parent 716318d commit e9c5e53
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/generate/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,28 @@ const replacePlaceholders = (text, fullname, year) => {
};

const modifyPackageJson = (newLicense, newAuthor) => {
const packageJsonPath = 'package.json';
try {
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
packageJson.license = newLicense;
if (fs.existsSync(packageJsonPath)) {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
packageJson.license = newLicense;

if (newAuthor) {
packageJson.author = newAuthor;
}
if (newAuthor) {
packageJson.author = newAuthor;
}

fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2));
console.log('package.json updated successfully!');
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
console.log('package.json updated successfully!');
} else {
console.log('package.json does not exist. Skipping modification.');
}
} catch (error) {
console.error('Error modifying package.json:', error);
process.exit(1)
process.exit(1);
}
};


const fetchData = async () => {
try {
const response = await fetch(URL);
Expand Down

0 comments on commit e9c5e53

Please sign in to comment.