Registry / serialization / codemaker

codemaker

JSON →
library0.0.2.2jsnpmunverified

`codemaker` is a concise utility designed for programmatic generation of source code. It facilitates the structured creation of text files by supporting features such as automatically indented code blocks, management of multiple output files across subdirectories, and the ability to selectively exclude files from the final output. The package is currently at version 1.128.0 and exhibits an active development and release cadence, primarily delivering bug fixes and minor feature enhancements as part of the larger `jsii` ecosystem. Its core differentiators include a fluent API for building hierarchical code structures and highly customizable block and indentation formatting. Additionally, it bundles widely used string casing utilities like `toCamelCase`, `toPascalCase`, and `toSnakeCase`, providing a complete toolkit for robust and predictable code generation tasks.

npm install codemaker
INSTALL
IMPORT
SIG · CODEMAKER
C
codemaker
serializationjavascriptv0.0.2.2
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CodeMaker
✓ import { CodeMaker } from 'codemaker'
✗ const { CodeMaker } = require('codemaker')
The library primarily uses ES Modules. While Node.js's CommonJS `require` might work with transpilation or specific configurations, native ESM `import` is the recommended and best-supported approach.
CodeMaker (default instance)
✓ const maker = new CodeMaker();
✗ import CodeMaker from 'codemaker'; // Incorrect default import
The `CodeMaker` class is a named export, not a default export. Always use curly braces for importing it.

This quickstart demonstrates how to initialize `CodeMaker`, open and write to multiple files (including nested directories), use customizable block formatting, control indentation, and exclude files before saving the generated code to a specified output path.

import { CodeMaker } from 'codemaker'; import * as path from 'path'; import * as os from 'os'; import * as fs from 'fs/promises'; async function generateCode() { const maker = new CodeMaker(); const outputPath = path.join(os.tmpdir(), 'codemaker-example'); await fs.mkdir(outputPath, { recursive: true }); maker.openFile('myfile.js'); maker.line('console.log("Hello,");'); maker.openBlock('function greet(name) {'); maker.line(' console.log(`Hello, ${name}!`);'); maker.closeBlock('}'); maker.line('greet("World");'); maker.closeFile('myfile.js'); const yourfileRelativePath = 'sub/dir/yourfile.ts'; maker.openFile(yourfileRelativePath); maker.indentation = 4; // Set indentation to 4 spaces maker.openBlockFormatter = s => `/* ${s} */ {`; maker.closeBlockFormatter = s => `} /* ${s} */`; maker.line('export interface MyInterface {'); maker.indent(' '); maker.line('id: string;'); maker.line('name: string;'); maker.unindent(); maker.line('}'); maker.openBlock('export class MyClass {'); maker.line(' constructor(private data: MyInterface) {}'); maker.line(''); maker.openBlock(' public greet(): void {'); maker.line(' console.log(`Hello from ${this.data.name}!`);'); maker.closeBlock(' }'); maker.closeBlock('}'); maker.closeFile(yourfileRelativePath); // Exclude a file before saving maker.openFile('temp/excluded.txt'); maker.line('This file will not be saved.'); maker.closeFile('temp/excluded.txt'); maker.exclude('temp/excluded.txt'); // Save all generated files const files = await maker.save(outputPath); console.log(`Generated files at ${outputPath}:`); files.forEach(file => console.log(`- ${path.relative(outputPath, file)}`)); // Clean up example directory (optional) // await fs.rm(outputPath, { recursive: true, force: true }); } generateCode().catch(console.error);
Debug
Known issues
gotchaCustom block formatters (`openBlockFormatter`, `closeBlockFormatter`, or overriding `openBlock`, `closeBlock` methods) can drastically change the output. Ensure careful testing when implementing custom logic to avoid unintended formatting or syntax errors in the generated code.
fix
Always test generated output with custom formatters. Consider using the built-in `openBlock()` and `closeBlock()` for standard brace-based blocks before customizing.
affects: >=1.0.0
gotchaFailing to call `closeFile()` for an opened file before calling `save()` can result in incomplete or unsaved content for that specific file. `CodeMaker` operates on a per-file buffer that needs to be finalized.
fix
Ensure that every call to `maker.openFile(fileName)` is paired with a corresponding `maker.closeFile(fileName)` when you are done writing to that file. The `closeFile` argument is optional but recommended for clarity.
affects: >=1.0.0
gotchaThe `exclude(filePath)` method must be called *before* `maker.save()` is invoked for the exclusion to take effect. If `exclude()` is called after `save()`, the file will still be written to disk.
fix
Structure your code generation logic such that all calls to `maker.exclude()` are made before the final `await maker.save()` call.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'line')
Attempting to call a `CodeMaker` method like `line()` or `openBlock()` on an uninitialized or incorrectly initialized `CodeMaker` instance.
fix
Ensure you have correctly initialized `CodeMaker` with `const maker = new CodeMaker();` before using its methods.
Generated code has incorrect indentation or unexpected block formatting.
Misconfiguration of `maker.indentation`, `maker.openBlockFormatter`, `maker.closeBlockFormatter`, or custom overrides of `openBlock`/`closeBlock` methods.
fix
Review your indentation settings and custom formatter functions. Use `maker.indentation = 2` (or your preferred value) for basic spacing. Debug custom formatters by logging their input/output.
Error: EEXIST: file already exists, mkdir '...' (during `maker.save()` in existing directory)
The `maker.save()` method might attempt to create directories that already exist if not handled correctly by the underlying filesystem operations, or if the target directory already contains a file with the same name as a generated file and the overwrite logic is not explicit.
fix
Ensure the target directory for `maker.save()` is prepared. If using `fs.mkdir` directly, add `{ recursive: true }`. `CodeMaker.save` itself should handle overwriting files by default, but directory conflicts can arise if not careful.
Upgrade
Version history
0.0.2.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
2
Resources
codemaker — npm install codemaker · libregistry