Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Config Program",
"program": "${workspaceFolder}\\src\\cli.js",
"request": "launch",
"skipFiles": ["<node_internals>/**"],
"type": "node",
"args": [
".",
"--update-config",
"md.config.js",
"--transform-name",
"fileTreeExtended"
]
},
{
"name": "Launch Programmatic Program",
"program": "${workspaceFolder}\\example\\programmatic-use.js",
Expand Down
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,49 +179,49 @@ Options:

<!-- doc-gen COMMANDS format=list -->

- `describe` — Update repository descriptions in md.config.js transformDefaults for fileTreeExtended. (line [93](./package.json#L93))
- `describe` — Update repository descriptions in md.config.js transformDefaults for fileTreeExtended. (line [92](./package.json#L92))

```bash
node src/cli.js . --update-config md.config.js --transform-name fileTreeExtended
```

- `describe:file` — Generates AI-powered descriptions for repository files and outputs them in various formats. (line [87](./package.json#L87))
- `describe:file` — Generates AI-powered descriptions for repository files and outputs them in various formats. (line [86](./package.json#L86))

```bash
node src/cli.js . --output descriptions.json
node src/cli.js . --output _descriptions.json
```

- `docs` — Generates documentation by processing Markdown files with markdown-magic. (line [92](./package.json#L92))
- `docs` — Generates documentation by processing Markdown files with markdown-magic. (line [91](./package.json#L91))

```bash
npx markdown-magic@3.7.0 **/*.md -c md.config.js
```

- `format` — Formats the codebase using Prettier. (line [90](./package.json#L90))
- `format` — Formats the codebase using Prettier. (line [89](./package.json#L89))

```bash
prettier --write .
```

- `lint` — Lints the codebase for potential errors and style violations. (line [88](./package.json#L88))
- `lint` — Lints the codebase for potential errors and style violations. (line [87](./package.json#L87))

```bash
eslint src/ **/*.js **/*.json
```

- `lint:fix` — Lints the codebase and automatically fixes fixable issues. (line [89](./package.json#L89))
- `lint:fix` — Lints the codebase and automatically fixes fixable issues. (line [88](./package.json#L88))

```bash
eslint --fix src/ **/*.js **/*.json
```

- `prep` — Prepares the codebase by generating documentation, linting, and formatting. (line [91](./package.json#L91))
- `prep` — Prepares the codebase by generating documentation, linting, and formatting. (line [90](./package.json#L90))

```bash
npm run docs && npm run lint:fix && npm run format
npm run describe:file && npm run docs && npm run lint:fix && npm run format
```

- `test` — Runs the test suite using Jest. (line [86](./package.json#L86))
- `test` — Runs the test suite using Jest. (line [85](./package.json#L85))

```bash
jest --passWithNoTests
Expand Down Expand Up @@ -266,7 +266,7 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file

## Project Structure

<!-- doc-gen fileTreeExtended showSize=false showDescriptions=true descriptionsFile=descriptions.json -->
<!-- doc-gen fileTreeExtended showSize=false showDescriptions=true descriptionsFile=_descriptions.json -->

```
repo-description/
Expand All @@ -281,15 +281,16 @@ repo-description/
│ ├── describe.js # Description unavailable.
│ ├── index.js # Description unavailable.
│ └── utils.js # Description unavailable.
├── .env # Configure... the environment by setting the `GROQ_API_KEY` variable to provide authentication for Groq API access.
├── _descriptions.json
├── .env # Defines the GROQ_API_KEY environment variable for authentication.
├── .gitignore
├── .prettierrc.json # Configure Prettier to enforce single quotes, trailing commas (es5), an 80‑character print width, and a specific ordering of fields in package.json via the prettier‑plugin‑packagejson.
├── babel.config.js # [configure] Babel to use @babel/preset‑env with the target set to the current Node version…
├── CHANGELOG.md # Documenting the project's version history by listing each release’s features, bug fixes, and related metadata in a Keep‑a‑Changelog format.
├── CONTRIBUTING.md # Guide contributors on how to report bugs, suggest enhancements, and submit code via pull requests.
├── eslint.config.js # Configure ESLint with global browser, node, and jest globals, recommended core and Prettier rules, and custom JSON/JSONC and YAML parsers and plugins for those file types.
├── LICENSE # Granting permission to use, copy, modify, merge, publish, distribute, sublicense, and sell the software freely under the MIT License.
├── md.config.js # [Exports] a configuration object that defines default settings (like file descriptions and badge style) and registers the markdown‑magic transform modules used to generate and augment the project’s documentation.
├── .prettierrc.json # Description unavailable.
├── babel.config.js # Description unavailable.
├── CHANGELOG.md # Description unavailable.
├── CONTRIBUTING.md # Description unavailable.
├── eslint.config.js # Description unavailable.
├── LICENSE # Description unavailable.
├── md.config.js # Description unavailable.
├── package-lock.json # Description unavailable.
├── package.json # Description unavailable.
├── README.md # Description unavailable.
Expand Down
20 changes: 20 additions & 0 deletions _descriptions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
".env": "Defines the GROQ_API_KEY environment variable for authentication.",
".prettierrc.json": "Description unavailable.",
".vscode/launch.json": "Description unavailable.",
"babel.config.js": "Description unavailable.",
"CHANGELOG.md": "Description unavailable.",
"CONTRIBUTING.md": "Description unavailable.",
"eslint.config.js": "Description unavailable.",
"LICENSE": "Description unavailable.",
"md.config.js": "Description unavailable.",
"package-lock.json": "Description unavailable.",
"package.json": "Description unavailable.",
"README.md": "Description unavailable.",
"RULES_OF_CONDUCT.md": "Description unavailable.",
"src/cli.js": "Description unavailable.",
"src/describe.js": "Description unavailable.",
"src/index.js": "Description unavailable.",
"src/utils.js": "Description unavailable.",
"__tests__/cli.test.js": "Description unavailable."
}
31 changes: 0 additions & 31 deletions md.config.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,5 @@
module.exports = {
transformDefaults: {
fileTreeExtended: {
descriptions: {
'.env':
'Configure... the environment by setting the `GROQ_API_KEY` variable to provide authentication for Groq API access.',
'.prettierrc.json':
'Configure Prettier to enforce single quotes, trailing commas (es5), an 80‑character print width, and a specific ordering of fields in package.json via the prettier‑plugin‑packagejson.',
'.vscode/launch.json':
'Configure launch configurations for debugging Node.js programs in VS Code.',
'babel.config.js':
'[configure] Babel to use @babel/preset‑env with the target set to the current Node version…',
'CHANGELOG.md':
"Documenting the project's version history by listing each release’s features, bug fixes, and related metadata in a Keep‑a‑Changelog format.",
'CONTRIBUTING.md':
'Guide contributors on how to report bugs, suggest enhancements, and submit code via pull requests.',
'eslint.config.js':
'Configure ESLint with global browser, node, and jest globals, recommended core and Prettier rules, and custom JSON/JSONC and YAML parsers and plugins for those file types.',
LICENSE:
'Granting permission to use, copy, modify, merge, publish, distribute, sublicense, and sell the software freely under the MIT License.',
'md.config.js':
'[Exports] a configuration object that defines default settings (like file descriptions and badge style) and registers the markdown‑magic transform modules used to generate and augment the project’s documentation.',
'package-lock.json': 'Description unavailable.',
'package.json': 'Description unavailable.',
'README.md': 'Description unavailable.',
'RULES_OF_CONDUCT.md': 'Description unavailable.',
'src/cli.js': 'Description unavailable.',
'src/describe.js': 'Description unavailable.',
'src/index.js': 'Description unavailable.',
'src/utils.js': 'Description unavailable.',
'__tests__/cli.test.js': 'Description unavailable.',
},
},
BADGES: {
style: 'for-the-badge',
},
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
],
"scripts": {
"describe": "node src/cli.js . --update-config md.config.js --transform-name fileTreeExtended",
"describe:file": "node src/cli.js . --output descriptions.json",
"describe:file": "node src/cli.js . --output _descriptions.json",
"docs": "npx markdown-magic@3.7.0 **/*.md -c md.config.js",
"format": "prettier --write .",
"lint": "eslint src/ **/*.js **/*.json",
"lint:fix": "eslint --fix src/ **/*.js **/*.json",
"prep": "npm run docs && npm run lint:fix && npm run format",
"prep": "npm run describe:file && npm run docs && npm run lint:fix && npm run format",
"test": "jest --passWithNoTests"
},
"jest": {
Expand Down
51 changes: 47 additions & 4 deletions src/describe.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,63 @@ async function updateMarkdownMagicConfig(
throw new Error(`Config file not found: ${absPath}`);
}

const config = require(absPath);
let fileContent = fs.readFileSync(absPath, 'utf8');

// Use require to get the current config object for in-memory manipulation.
// This allows us to easily update the descriptions.
let config = require(absPath);

// Ensure transformDefaults and the specific transformName exist in the in-memory config
if (!config.transformDefaults) {
config.transformDefaults = {};
}
if (!config.transformDefaults[transformName]) {
config.transformDefaults[transformName] = {};
}

// Update the descriptions in the in-memory config object
config.transformDefaults[transformName].descriptions = descriptions;

// Write back to file
const newConfig = `module.exports = ${JSON.stringify(config, null, 2)};\n`;
fs.writeFileSync(absPath, newConfig);
// Now, we need to update the file content string.
// We will find the 'transformDefaults' property and replace its value.
// This regex is designed to find 'transformDefaults:' followed by its object literal.
// It's still somewhat fragile and relies on consistent formatting.
const transformDefaultsRegex = /(transformDefaults:\s*)(\{[\s\S]*?\})/m;
const match = fileContent.match(transformDefaultsRegex);

if (match) {
// The original string for transformDefaults (including the key and colon)
const originalTransformDefaultsString = match[0];
// The object literal part of transformDefaults
// const originalTransformDefaultsObjectString = match[2]; // Not directly used for replacement

// Stringify only the updated transformDefaults from the in-memory config.
// This is safe because 'descriptions' is expected to be a JSON-serializable object.
const updatedTransformDefaultsObjectString = JSON.stringify(
config.transformDefaults,
null,
2
);

// Reconstruct the new transformDefaults string to be inserted back into the file
const newTransformDefaultsString =
match[1] + updatedTransformDefaultsObjectString;

// Replace the old transformDefaults string with the new one in the file content
fileContent = fileContent.replace(
originalTransformDefaultsString,
newTransformDefaultsString
);
} else {
// If the 'transformDefaults' block is not found, we'll throw an error.
// A more complete solution would involve adding the block if it's missing,
// but that significantly increases complexity and fragility with string manipulation.
throw new Error(
'Could not find transformDefaults block in config file. Please ensure it exists and is correctly formatted.'
);
}

fs.writeFileSync(absPath, fileContent);
console.log(`Updated ${transformName}.descriptions in ${configPath}`);
}

Expand Down