npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dekard

v1.2.1

Published

A simple file concatenation tool to provide project context for AI.

Downloads

35

Readme

Dekard

Dekard is a simple file concatenation tool. It allows you to process entire project directories, concatenating the contents of specified files into a single output file, with the ability to watch for changes and update the output automatically. Dekard is perfect for compiling your project into context to provide for AI.

✨Features

  • 🔗Concatenate multiple files into a single output file
  • 💬Add file path comments to the concatenated output
  • 🔍Flexible file inclusion and exclusion with glob patterns
  • 👀Watch mode for automatic updates on file changes
  • 🖥️Easy to use CLI and programmatic API
  • 🧠 Intelligent file ordering based on dependencies
  • 🌐 Support for multiple languages (JavaScript, TypeScript, Python, Java)
  • 🗣️ Verbose logging option for detailed output

🚀Installation

Install dekard globally:

npm install -g dekard

Or as a dependency in your project:

npm install dekard

🔧Usage

Command Line Interface

  1. Initialize a dekard configuration file in your project root:
dekard init

This will create a dekard.json file with default settings. 2. Run dekard

dekard

For verbose output:

dekard --verbose

Or specify a custom config file:

dekard path/to/custom-config.json

Programmic Usage

const { loadConfig, resolveConfig, processDirectory, watchDirectory } = require("dekard");

async function run() {
	const config = resolveConfig(await loadConfig("path/to/dekard.json"));

	if (config.watch) {
		watchDirectory(config);
	} else {
		await processDirectory(config);
	}
}

run().catch(console.error);

⚙️Configuration

The dekard.json file supports the following options:

  • inputDir (string): The root directory to process.
  • outputFile (string): The path to the output file.
  • include (string[]): Glob patterns for files to include.
  • ignore (string[]): Glob patterns for files to ignore.
  • watch (boolean): Whether to watch for file changes and update the output automatically.
  • verbose (boolean): Whether to output detailed logging information.

Example Config dekard.json:

{
	"inputDir": "./src",
	"outputFile": "./concatenated-output.txt",
	"include": ["**/*.ts", "**/*.tsx"],
	"ignore": ["**/*.test.ts", "node_modules/**"],
	"watch": false,
	"verbose": false
}

📝Example

Let's say you have the following directory structure:

src/
├── main.ts
├── utils.ts
└── test.ts

With the following content in each file:

src/main.ts:

import { helper } from "./utils";
import { CONSTANT } from "./utils";

console.log(helper(CONSTANT));

src/utils.ts:

export function helper(value: string): string {
	return `Helper: ${value}`;
}

export const CONSTANT = "Some constant value";

src/test.ts:

import { helper } from "./utils";

describe("helper function", () => {
	it("should return correct string", () => {
		expect(helper("test")).toBe("Helper: test");
	});
});

Using the following dekard.json:

{
	"inputDir": "./src",
	"outputFile": "./output.txt",
	"include": ["**/*.ts"],
	"ignore": ["**/*.test.ts"],
	"watch": false,
	"verbose": false
}

The resulting output.txt would look like this:

// File: src/utils.ts
export function helper(value: string): string {
  return `Helper: ${value}`;
}

export const CONSTANT = 'Some constant value';

// File: src/main.ts
import { helper } from './utils';
import { CONSTANT } from './utils';

console.log(helper(CONSTANT));

You can just provide this file to any LLM and they will understand your project structure to work based off of it.

🧠 Intelligent File Ordering

Dekard now includes intelligent file ordering based on dependencies. This feature:

  • Analyzes imports and dependencies in your files
  • Orders files so that dependencies come before the files that use them
  • Supports JavaScript, TypeScript, Python, and Java
  • Falls back to original order if circular dependencies are detected

This ordering helps maintain a logical flow in the concatenated output, making it easier for humans or AI to understand the project structure and dependencies at a glance.

🤝Contributing

Contributions are welcome! Here are some ways you can contribute to this project:

  1. Report bugs and issues
  2. Suggest new features or enhancements
  3. Submit pull requests to improve the codebase
  4. Improve or add documentation

Development Setup

  1. Fork the repository
  2. Clone your forked repository
  3. Install dependencies with npm install
  4. Make your changes
  5. Run tests with npm test
  6. Submit a pull request

Please ensure that your code adheres to the existing style and that all tests pass before submitting a pull request.

Testing

To run the test suite, execute:

npm test

This will run all unit and integration tests for the project.

📄License

This project is licensed under the ISC License. See the LICENSE file for details.