wp-readme-txt-gen 1.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+ - Initial setup of the changelog following Keep a Changelog and Semantic Versioning.
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # wp-readme-txt-gen
2
+
3
+ `wp-readme-txt-gen` is an npm module used to convert your `README.md` and `CHANGELOG.md` files into a WordPress style `README.txt`.
4
+
5
+ ## Installation
6
+
7
+ You can install the module using npm:
8
+
9
+ ```sh
10
+ npm install wp-readme-txt-gen
11
+ ```
12
+
13
+ ## Contributing
14
+
15
+ Contributions are welcome! Please open an issue or submit a pull request.
16
+
17
+ ## License
18
+
19
+ This project is licensed under the MIT License.
20
+
21
+ ## Usage
22
+
23
+ To use the module, simply run:
24
+
25
+ ```sh
26
+ wp-readme-txt-gen
27
+ ```
28
+
29
+ This will generate a `README.txt` file in the same directory as your `README.md` and `CHANGELOG.md` files.
30
+
31
+ ## Support
32
+
33
+ If you encounter any issues or have any questions, feel free to open an issue on the GitHub repository.
34
+
35
+ ## Acknowledgements
36
+
37
+ Thanks to all the contributors who have helped improve this project.
package/index.js ADDED
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const { marked } = require('marked');
6
+
7
+ // Load configuration from config.json
8
+ async function loadConfig() {
9
+ const configPath = path.resolve(process.cwd(), 'config.json');
10
+ const config = JSON.parse(await fs.promises.readFile(configPath, 'utf8'));
11
+ return config;
12
+ }
13
+
14
+ // Functions (reusable and modular)
15
+ async function readFileContent(filePath) {
16
+ return fs.promises.readFile(filePath, 'utf8');
17
+ }
18
+
19
+ function markdownToWordPressFormat(markdown) {
20
+ return markdown
21
+ .replace(/^# (.*$)/gim, '=== $1 ===')
22
+ .replace(/^## (.*$)/gim, '== $1 ==')
23
+ .replace(/^### (.*$)/gim, '= $1 =')
24
+ .replace(/^\* (.*$)/gim, '* $1')
25
+ .replace(/\[([^\[]+)\]\(([^\)]+)\)/gim, '$1 ($2)');
26
+ }
27
+
28
+ function removeFirstH1(content) {
29
+ return content.replace(/^# .*\n/, '');
30
+ }
31
+
32
+ async function updateStyleFiles(version, styleFiles, versionPattern) {
33
+ for (const file of styleFiles) {
34
+ try {
35
+ const content = await readFileContent(file);
36
+ const updatedContent = content.replace(new RegExp(versionPattern, 'm'), `$1${version}`);
37
+ await fs.promises.writeFile(file, updatedContent, 'utf8');
38
+ console.log(`${file} updated with version ${version}`);
39
+ } catch (error) {
40
+ console.error(`Error updating ${file}:`, error);
41
+ }
42
+ }
43
+ }
44
+
45
+ async function generateReadme() {
46
+ try {
47
+ const config = await loadConfig();
48
+
49
+ const [readmeContent, changelogContent] = await Promise.all([
50
+ readFileContent(config.readmeMdPath),
51
+ readFileContent(config.changelogMdPath),
52
+ ]);
53
+
54
+ const version = (readmeContent.match(new RegExp(config.versionPattern, 'm')) || [])[1] || '1.0';
55
+
56
+ const readmeFormatted = markdownToWordPressFormat(readmeContent);
57
+ const changelogFormatted = markdownToWordPressFormat(removeFirstH1(changelogContent));
58
+ const fullContent = `${readmeFormatted}\n\n== Changelog ==\n${changelogFormatted}`;
59
+
60
+ await fs.promises.writeFile(config.readmeTxtPath, fullContent, 'utf8');
61
+ console.log(`Generated ${config.readmeTxtPath}`);
62
+
63
+ await updateStyleFiles(version, config.styleFiles, config.versionReplacementPattern);
64
+ } catch (error) {
65
+ console.error('Error in generating README.txt or updating style files:', error);
66
+ }
67
+ }
68
+
69
+ // Execute when run from the command line
70
+ if (require.main === module) {
71
+ generateReadme();
72
+ }
73
+
74
+ // Export functions for reuse
75
+ module.exports = { generateReadme, updateStyleFiles, markdownToWordPressFormat };
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "dependencies": {
3
+ "marked": "^15.0.0"
4
+ },
5
+ "name": "wp-readme-txt-gen",
6
+ "version": "1.0.0",
7
+ "description": "`wp-readme-txt-gen` is an npm module used to convert your `README.md` and `CHANGELOG.md` files into a WordPress style `README.txt`.",
8
+ "main": "index.js",
9
+ "bin": {
10
+ "generate-readme": "index.js"
11
+ },
12
+ "scripts": {
13
+ "test": "echo \"Error: no test specified\" && exit 1"
14
+ },
15
+ "keywords": [],
16
+ "author": "",
17
+ "license": "ISC"
18
+ }