blytz 1.0.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +68 -20
- package/package.json +49 -49
- package/src/template.js +23 -15
package/bin/cli.js
CHANGED
|
@@ -49,6 +49,18 @@ function collectDependencies(packageJson) {
|
|
|
49
49
|
return Object.keys(packageJson.dependencies || {}).sort();
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
function collectPythonDependencies(requirementsContent) {
|
|
53
|
+
return requirementsContent
|
|
54
|
+
.split(/\r?\n/)
|
|
55
|
+
.map(line => line.trim())
|
|
56
|
+
.filter(line => line && !line.startsWith('#'))
|
|
57
|
+
.filter(line => !line.startsWith('-'))
|
|
58
|
+
.map(line => line.split(';')[0].trim())
|
|
59
|
+
.map(line => line.split(/[=<>!~]/)[0].trim())
|
|
60
|
+
.filter(Boolean)
|
|
61
|
+
.sort((left, right) => left.localeCompare(right));
|
|
62
|
+
}
|
|
63
|
+
|
|
52
64
|
function collectScripts(packageJson) {
|
|
53
65
|
const scripts = new Map();
|
|
54
66
|
|
|
@@ -59,12 +71,26 @@ function collectScripts(packageJson) {
|
|
|
59
71
|
return scripts;
|
|
60
72
|
}
|
|
61
73
|
|
|
74
|
+
function getLicenseName(licenseContent) {
|
|
75
|
+
const firstLine = licenseContent
|
|
76
|
+
.split(/\r?\n/)
|
|
77
|
+
.map(line => line.trim())
|
|
78
|
+
.find(Boolean);
|
|
79
|
+
|
|
80
|
+
return firstLine || '';
|
|
81
|
+
}
|
|
82
|
+
|
|
62
83
|
console.log("Scanning for project files...");
|
|
63
84
|
|
|
64
85
|
const targetDir = process.cwd();
|
|
65
86
|
const readmePath = path.join(targetDir, 'README.md');
|
|
66
87
|
const packageJsonPath = path.join(targetDir, 'package.json');
|
|
88
|
+
const requirementsPath = path.join(targetDir, 'requirements.txt');
|
|
89
|
+
const licensePath = path.join(targetDir, 'LICENSE');
|
|
67
90
|
const readmeExists = fs.existsSync(readmePath);
|
|
91
|
+
const hasPackageJson = fs.existsSync(packageJsonPath);
|
|
92
|
+
const hasRequirements = fs.existsSync(requirementsPath);
|
|
93
|
+
const hasLicense = fs.existsSync(licensePath);
|
|
68
94
|
|
|
69
95
|
if (!readmeExists && !shouldInit && !shouldForce) {
|
|
70
96
|
console.error("Error: No README.md found in this directory. Try --init.");
|
|
@@ -76,8 +102,8 @@ if (readmeExists && shouldInit && !shouldForce) {
|
|
|
76
102
|
process.exit(1);
|
|
77
103
|
}
|
|
78
104
|
|
|
79
|
-
if (!
|
|
80
|
-
console.error("Error: No package.json found in this directory.");
|
|
105
|
+
if (!hasPackageJson && !hasRequirements) {
|
|
106
|
+
console.error("Error: No package.json or requirements.txt found in this directory.");
|
|
81
107
|
process.exit(1);
|
|
82
108
|
}
|
|
83
109
|
|
|
@@ -90,26 +116,48 @@ try {
|
|
|
90
116
|
|
|
91
117
|
// 1. Read the raw text of both files
|
|
92
118
|
const readmeContent = fs.existsSync(readmePath) ? fs.readFileSync(readmePath, 'utf-8') : '';
|
|
93
|
-
const packageJsonData = fs.readFileSync(packageJsonPath, 'utf-8');
|
|
94
|
-
|
|
95
|
-
// 2. Parse package.json to build the context object your engine expects
|
|
96
|
-
const packageJson = JSON.parse(packageJsonData);
|
|
97
119
|
const fileTree = buildFileTree(targetDir);
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
120
|
+
const projectName = path.basename(targetDir);
|
|
121
|
+
const licenseName = hasLicense ? getLicenseName(fs.readFileSync(licensePath, 'utf-8')) : '';
|
|
122
|
+
let context;
|
|
123
|
+
let projectType;
|
|
124
|
+
|
|
125
|
+
if (hasPackageJson) {
|
|
126
|
+
const packageJsonData = fs.readFileSync(packageJsonPath, 'utf-8');
|
|
127
|
+
const packageJson = JSON.parse(packageJsonData);
|
|
128
|
+
|
|
129
|
+
context = {
|
|
130
|
+
packageJson,
|
|
131
|
+
packages: [{ path: 'package.json', content: packageJson }],
|
|
132
|
+
dependencies: collectDependencies(packageJson),
|
|
133
|
+
scripts: collectScripts(packageJson),
|
|
134
|
+
fileTree,
|
|
135
|
+
licenseName,
|
|
136
|
+
username: packageJson.author || process.env.USERNAME || 'Unknown Author',
|
|
137
|
+
projectName: packageJson.name || projectName,
|
|
138
|
+
hasPackageJson: true,
|
|
139
|
+
isMonorepo: false
|
|
140
|
+
};
|
|
141
|
+
projectType = 'node';
|
|
142
|
+
} else {
|
|
143
|
+
const requirementsContent = fs.readFileSync(requirementsPath, 'utf-8');
|
|
144
|
+
|
|
145
|
+
context = {
|
|
146
|
+
packages: [{ path: 'requirements.txt', content: requirementsContent }],
|
|
147
|
+
dependencies: collectPythonDependencies(requirementsContent),
|
|
148
|
+
scripts: new Map(),
|
|
149
|
+
fileTree,
|
|
150
|
+
licenseName,
|
|
151
|
+
username: process.env.USERNAME || 'Unknown Author',
|
|
152
|
+
projectName,
|
|
153
|
+
hasPackageJson: false,
|
|
154
|
+
isMonorepo: false
|
|
155
|
+
};
|
|
156
|
+
projectType = 'python';
|
|
157
|
+
}
|
|
109
158
|
|
|
110
159
|
// 3. Feed everything into your pure engine
|
|
111
|
-
|
|
112
|
-
const updatedReadme = processReadme(readmeContent, 'node', context);
|
|
160
|
+
const updatedReadme = processReadme(readmeContent, projectType, context);
|
|
113
161
|
|
|
114
162
|
// 4. Overwrite the existing README.md with the new content
|
|
115
163
|
fs.writeFileSync(readmePath, updatedReadme, 'utf-8');
|
|
@@ -119,4 +167,4 @@ try {
|
|
|
119
167
|
} catch (error) {
|
|
120
168
|
console.error("An error occurred during processing:", error.message);
|
|
121
169
|
process.exit(1);
|
|
122
|
-
}
|
|
170
|
+
}
|
package/package.json
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "blytz",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"bin": {
|
|
5
|
-
"blytz": "./bin/cli.js"
|
|
6
|
-
},
|
|
7
|
-
"readme": "README-NPM.md",
|
|
8
|
-
"files": [
|
|
9
|
-
"bin/",
|
|
10
|
-
"src/",
|
|
11
|
-
"bin/README-NPM.md"
|
|
12
|
-
],
|
|
13
|
-
"description": "An automated CLI tool to fix and maintain project READMEs",
|
|
14
|
-
"type": "module",
|
|
15
|
-
"scripts": {
|
|
16
|
-
"start": "node src/index.js",
|
|
17
|
-
"prepublishOnly": "node scripts/sync-readme.js prepublish",
|
|
18
|
-
"postpublish": "node scripts/sync-readme.js postpublish"
|
|
19
|
-
},
|
|
20
|
-
"keywords": [
|
|
21
|
-
"blytz",
|
|
22
|
-
"cli",
|
|
23
|
-
"readme",
|
|
24
|
-
"documentation",
|
|
25
|
-
"automation",
|
|
26
|
-
"github",
|
|
27
|
-
"npm",
|
|
28
|
-
"bot",
|
|
29
|
-
"readmefixer",
|
|
30
|
-
"readme-generator",
|
|
31
|
-
"devtools",
|
|
32
|
-
"markdown",
|
|
33
|
-
"workflow",
|
|
34
|
-
"productivity",
|
|
35
|
-
"automated-docs",
|
|
36
|
-
"repository-manager",
|
|
37
|
-
"scaffold",
|
|
38
|
-
"readme-maintainer",
|
|
39
|
-
"readme-updater"
|
|
40
|
-
],
|
|
41
|
-
"author": "Aryan Sharma",
|
|
42
|
-
"license": "MIT",
|
|
43
|
-
"dependencies": {
|
|
44
|
-
"@octokit/app": "^16.1.2",
|
|
45
|
-
"@octokit/rest": "^22.0.1",
|
|
46
|
-
"dotenv": "^17.4.0",
|
|
47
|
-
"express": "^5.2.1"
|
|
48
|
-
}
|
|
49
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "blytz",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"bin": {
|
|
5
|
+
"blytz": "./bin/cli.js"
|
|
6
|
+
},
|
|
7
|
+
"readme": "README-NPM.md",
|
|
8
|
+
"files": [
|
|
9
|
+
"bin/",
|
|
10
|
+
"src/",
|
|
11
|
+
"bin/README-NPM.md"
|
|
12
|
+
],
|
|
13
|
+
"description": "An automated CLI tool to fix and maintain project READMEs",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"start": "node src/index.js",
|
|
17
|
+
"prepublishOnly": "node scripts/sync-readme.js prepublish",
|
|
18
|
+
"postpublish": "node scripts/sync-readme.js postpublish"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"blytz",
|
|
22
|
+
"cli",
|
|
23
|
+
"readme",
|
|
24
|
+
"documentation",
|
|
25
|
+
"automation",
|
|
26
|
+
"github",
|
|
27
|
+
"npm",
|
|
28
|
+
"bot",
|
|
29
|
+
"readmefixer",
|
|
30
|
+
"readme-generator",
|
|
31
|
+
"devtools",
|
|
32
|
+
"markdown",
|
|
33
|
+
"workflow",
|
|
34
|
+
"productivity",
|
|
35
|
+
"automated-docs",
|
|
36
|
+
"repository-manager",
|
|
37
|
+
"scaffold",
|
|
38
|
+
"readme-maintainer",
|
|
39
|
+
"readme-updater"
|
|
40
|
+
],
|
|
41
|
+
"author": "Aryan Sharma",
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@octokit/app": "^16.1.2",
|
|
45
|
+
"@octokit/rest": "^22.0.1",
|
|
46
|
+
"dotenv": "^17.4.0",
|
|
47
|
+
"express": "^5.2.1"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/template.js
CHANGED
|
@@ -5,8 +5,9 @@ export default function getDefaultContent(section, projectType, context = {}) {
|
|
|
5
5
|
packages = [],
|
|
6
6
|
dependencies = [],
|
|
7
7
|
scripts = new Map(),
|
|
8
|
-
fileTree = null,
|
|
9
|
-
|
|
8
|
+
fileTree = null,
|
|
9
|
+
licenseName = "",
|
|
10
|
+
username = "Unknown",
|
|
10
11
|
projectName = "this project",
|
|
11
12
|
isMonorepo = false,
|
|
12
13
|
} = context ?? {};
|
|
@@ -25,8 +26,8 @@ export default function getDefaultContent(section, projectType, context = {}) {
|
|
|
25
26
|
return getDependenciesContent(dependencies, packages);
|
|
26
27
|
case "folder structure":
|
|
27
28
|
return getFolderStructureContent(fileTree);
|
|
28
|
-
case "license":
|
|
29
|
-
return
|
|
29
|
+
case "license":
|
|
30
|
+
return getLicenseContent(licenseName);
|
|
30
31
|
case "built by":
|
|
31
32
|
return `Built with ❤️ by @${(username || "Unknown").trim()}`;
|
|
32
33
|
default:
|
|
@@ -93,21 +94,28 @@ function getUsageContent(projectType, scripts, isMonorepo) {
|
|
|
93
94
|
return "Add usage instructions here.";
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
function getDependenciesContent(dependencies, packages) {
|
|
97
|
-
if (dependencies && dependencies.length > 0) {
|
|
98
|
-
const isMonorepo = packages && packages.length > 1;
|
|
99
|
-
const header = isMonorepo
|
|
100
|
-
? `This project uses the following dependencies (across ${packages.length} packages):\n\n`
|
|
97
|
+
function getDependenciesContent(dependencies, packages) {
|
|
98
|
+
if (dependencies && dependencies.length > 0) {
|
|
99
|
+
const isMonorepo = packages && packages.length > 1;
|
|
100
|
+
const header = isMonorepo
|
|
101
|
+
? `This project uses the following dependencies (across ${packages.length} packages):\n\n`
|
|
101
102
|
: "This project uses the following dependencies:\n\n";
|
|
102
103
|
|
|
103
104
|
return header + dependencies.map(d => `- ${d}`).join("\n");
|
|
104
|
-
}
|
|
105
|
-
return "No dependencies found.";
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function
|
|
105
|
+
}
|
|
106
|
+
return "No dependencies found.";
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function getLicenseContent(licenseName) {
|
|
110
|
+
if (licenseName) {
|
|
111
|
+
return `This project is licensed under the ${licenseName}. See the LICENSE file for details.`;
|
|
112
|
+
}
|
|
113
|
+
return "Add your license information here.";
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function getFolderStructureContent(fileTree) {
|
|
109
117
|
if (!fileTree || typeof fileTree !== "object" || Object.keys(fileTree).length === 0) {
|
|
110
118
|
return "Project structure:\n\n```\n(No file tree provided)\n```";
|
|
111
119
|
}
|
|
112
120
|
return "Project structure:\n\n" + getProjectStructure(fileTree);
|
|
113
|
-
}
|
|
121
|
+
}
|