Skip to content

Commit 5c49b5f

Browse files
committedAug 1, 2023
πŸ› fix(bundle.js): remove shebang line from bundle.js
πŸ› fix(bundle.js): fix license file name in fs.writeFileSync πŸ› fix(bundle.js): fix package.json file path in fs.readFileSync πŸ› fix(bundle.js): fix README.md file path in fs.writeFileSync πŸ› fix(bundle.js): fix package.json file path in fs.readFileSync πŸ› fix(bundle.js): fix README.md file path in fs.writeFileSync πŸ› fix(index.js): remove shebang line from index.js πŸ› fix(index.js): fix license file name in fs.writeFileSync πŸ› fix(index.js): fix package.json file path in fs.readFileSync πŸ› fix(index.js): fix README.md file path in fs.writeFileSync πŸ› fix(index.js): fix package.json file path in fs.readFileSync πŸ› fix(index.js): fix README.md file path in fs.writeFileSync πŸ› fix(package.json): add missing dependencies πŸ› fix(rollup.config.js): add resolve plugin options to handle CommonJS exports properly The shebang line was removed from both bundle.js and index.js as it is not necessary in the bundled files. The license file name in fs.writeFileSync was fixed to match the selected license. The package.json file path in fs.readFileSync and fs.writeFileSync was fixed to read and write from the project directory. The README.md file path in fs.writeFileSync was fixed to write to the project directory. Missing dependencies were added to the package.json file. The resolve plugin options in rollup.config.js were updated to handle CommonJS exports properly.
1 parent a216628 commit 5c49b5f

File tree

5 files changed

+766
-20
lines changed

5 files changed

+766
-20
lines changed
 

β€Ždist/bundle.js

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env node
2-
31
'use strict';
42

53
var fs = require('fs');
@@ -15,30 +13,45 @@ const rl = readline__default["default"].createInterface({
1513
output: process.stdout
1614
});
1715

16+
const licenses = [
17+
'MIT',
18+
'Apache-2.0',
19+
'GPL-3.0',
20+
'ISC',
21+
'BSD-3-Clause',
22+
'Unlicense'
23+
];
24+
1825
rl.question('What is your project name? ', (name) => {
1926
rl.question('What is your project description? ', (description) => {
20-
rl.question('What is your project license? ', (license) => {
27+
rl.question(`Choose a license for your project (${licenses.join(', ')}): `, (selectedLicense) => {
28+
if (!licenses.includes(selectedLicense)) {
29+
console.error('Invalid license selection. Please choose from the provided options.');
30+
rl.close();
31+
return;
32+
}
33+
2134
rl.question('What is the author name for package.json? ', (authorName) => {
2235
fs__default["default"].mkdirSync(name);
2336

2437
const packageJsonContent = {
2538
name,
2639
description,
27-
license,
40+
license: selectedLicense,
2841
author: authorName
2942
};
3043

3144
fs__default["default"].writeFileSync(`${name}/package.json`, JSON.stringify(packageJsonContent, null, 2));
32-
fs__default["default"].writeFileSync(`${name}/LICENSE`, license);
45+
fs__default["default"].writeFileSync(`${name}/LICENSE`, selectedLicense);
3346

34-
// Read the package.json file
35-
const packageJson = JSON.parse(fs__default["default"].readFileSync('package.json', 'utf8'));
47+
// Read the package.json file from the project directory
48+
const packageJson = JSON.parse(fs__default["default"].readFileSync(`${name}/package.json`, 'utf8'));
3649

3750
// Generate the README.md content
3851
const readmeContent = `# Open Source Project Generator\n\n${packageJson.description}\n\n## Author\n\n${packageJson.author}\n\n## License\n\n${packageJson.license}`;
3952

4053
// Write the README.md file
41-
fs__default["default"].writeFileSync('README.md', readmeContent);
54+
fs__default["default"].writeFileSync(`${name}/README.md`, readmeContent);
4255

4356
fs__default["default"].writeFileSync(`${name}/CONTRIBUTING.md`, `# Contributing to ${name}\n\n`);
4457
fs__default["default"].writeFileSync(`${name}/CODE_OF_CONDUCT.md`, `# Code of Conduct\n\n`);

β€Žindex.js

+21-6
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,45 @@ const rl = readline.createInterface({
66
output: process.stdout
77
});
88

9+
const licenses = [
10+
'MIT',
11+
'Apache-2.0',
12+
'GPL-3.0',
13+
'ISC',
14+
'BSD-3-Clause',
15+
'Unlicense'
16+
];
17+
918
rl.question('What is your project name? ', (name) => {
1019
rl.question('What is your project description? ', (description) => {
11-
rl.question('What is your project license? ', (license) => {
20+
rl.question(`Choose a license for your project (${licenses.join(', ')}): `, (selectedLicense) => {
21+
if (!licenses.includes(selectedLicense)) {
22+
console.error('Invalid license selection. Please choose from the provided options.');
23+
rl.close();
24+
return;
25+
}
26+
1227
rl.question('What is the author name for package.json? ', (authorName) => {
1328
fs.mkdirSync(name);
1429

1530
const packageJsonContent = {
1631
name,
1732
description,
18-
license,
33+
license: selectedLicense,
1934
author: authorName
2035
};
2136

2237
fs.writeFileSync(`${name}/package.json`, JSON.stringify(packageJsonContent, null, 2));
23-
fs.writeFileSync(`${name}/LICENSE`, license);
38+
fs.writeFileSync(`${name}/LICENSE`, selectedLicense);
2439

25-
// Read the package.json file
26-
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
40+
// Read the package.json file from the project directory
41+
const packageJson = JSON.parse(fs.readFileSync(`${name}/package.json`, 'utf8'));
2742

2843
// Generate the README.md content
2944
const readmeContent = `# Open Source Project Generator\n\n${packageJson.description}\n\n## Author\n\n${packageJson.author}\n\n## License\n\n${packageJson.license}`;
3045

3146
// Write the README.md file
32-
fs.writeFileSync('README.md', readmeContent);
47+
fs.writeFileSync(`${name}/README.md`, readmeContent);
3348

3449
fs.writeFileSync(`${name}/CONTRIBUTING.md`, `# Contributing to ${name}\n\n`);
3550
fs.writeFileSync(`${name}/CODE_OF_CONDUCT.md`, `# Code of Conduct\n\n`);

β€Žpackage.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@
2626
"homepage": "https://github.com/OSSPhilippines/opensource#readme",
2727
"devDependencies": {
2828
"jest": "^27.2.0",
29+
"rollup": "^2.56.3",
2930
"rollup-plugin-commonjs": "^10.1.0",
30-
"rollup-plugin-node-resolve": "^5.2.0",
31-
"rollup": "^2.56.3"
31+
"rollup-plugin-node-resolve": "^5.2.0"
32+
},
33+
"dependencies": {
34+
"browserify-fs": "^1.0.0",
35+
"readline-browser": "^0.0.3",
36+
"rollup-plugin-node-builtins": "^2.1.2"
3237
}
33-
}
38+
}

β€Žrollup.config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ module.exports = {
77
output: {
88
file: path.resolve(__dirname, 'dist/bundle.js'),
99
format: 'cjs',
10+
exports: 'auto', // Set output.exports to "auto" to handle CommonJS exports properly
1011
},
1112
plugins: [
12-
resolve(),
13+
resolve({
14+
preferBuiltins: true
15+
}),
1316
commonjs()
1417
]
1518
};

0 commit comments

Comments
 (0)
Please sign in to comment.