offshorly-codebase-kb
v1.0.3
Published
This package provides a tool to manage code snippets
Downloads
16
Maintainers
Readme
Offshorly Codebase KB
Installation and Setup
Install the package:
npm i offshorly-codebase-kb
Create extractor.js in your root directory add this code to it:
import { main_extractor } from 'offshorly-codebase-kb/src/extract_snippet.js'; main_extractor();
Setup Husky:
npm install --save-dev husky npx husky init
Add to package.json scripts section if not present:
"prepare": "husky"
Modify .husky/pre-commit:
#!/bin/bash if ! node extractor.js; then echo "Snippet extraction failed. Commit aborted." exit 1 fi exit 0
Make sure that node_modules is in the .gitignore file
Usage
Use these tags in code comments:
<snippet> and </snippet>: Enclose the entire snippet
<title> and </title>: One-line title
<descr> and </descr>: One-line description
Example in python:
#<snippet>
#<title>My First Snippet</title>
#<descr>This is my first snippet using codebase-kb</descr>
def helloSnippet():
print("Hello World! This is a code snippet")
#</snippet>
After commit, a hash is generated:
#<snippet>a17a246c1d39b345cd6e0a6e54192aa8
#<title>My First Snippet</title>
#<descr>This is my first snippet using codebase-kb</descr>
def helloSnippet():
print("Hello World! This is a code snippet")
#</snippet>
If modified and committed again, a new hash is generated:
#<snippet>cd26bb4950bd8f69feee8000a86fd2da
#<title>My First Snippet</title>
#<descr>This is my first snippet using codebase-kb</descr>
def helloSnippet():
print("Changing this snippet")
#</snippet>
Important
- Use tags in comments
- One-line title and description
- No nested tags
- Close all tags
- Choose meaningful, reusable code
- Don't manually modify the hash