An Accord Project template demonstrating contract logic implementation using TypeScript, with flexible CLI tools and extensive testing.
Requirements: Node.js v20 or higher
# Install dependencies
npm install
# Run the demo
npm start
# Generate a contract draft
npm run draft
# Generate a PDF contract
npm run pdf
# Generate a markdown contract file
npm run md
# Generate a JSON business logic response
npm run json
# Test business logic
npm run trigger
# Run tests
npm test├── index.js # Main demo script
├── draft.js # Contract generation CLI
├── trigger.js # Business logic CLI
├── generate-pdf.js # PDF generation CLI
├── generate-md.js # Markdown generation CLI
├── generate-json.js # JSON response generation CLI
├── list-data-files.js # Data file explorer
├── test-different-values.js # Multi-scenario demo
├── data/ # JSON configuration files
│ ├── template-*.json # Template configurations
│ └── request-*.json # Request data files
├── __tests__/ # Comprehensive test suite
└── archives/ # Accord Project template
Generate contract documents from template data:
# Using npm scripts
npm run draft # Basic template
npm run draft:low # Low penalty template
npm run draft:high # High penalty template
# Using Node.js directly
node draft.js data/template-basic.json
node draft.js --help # Show usageExecute contract business logic with request data:
# Using npm scripts
npm run trigger # Basic scenario
npm run trigger:low # Low penalty + low value
npm run trigger:high # High penalty + high value
# Using Node.js directly
node trigger.js data/template-basic.json data/request-basic.json
node trigger.js --help # Show usageGenerate PDF contracts from template data:
# Using npm scripts
npm run pdf # Basic template
npm run pdf:low # Low penalty template
npm run pdf:high # High penalty template
# Using Node.js directly
node generate-pdf.js data/template-basic.json
node generate-pdf.js data/template-basic.json output/contract.pdf
node generate-pdf.js --help # Show usageGenerate markdown contract files from template data:
# Using npm scripts
npm run md # Basic template
npm run md:low # Low penalty template
npm run md:high # High penalty template
# Using Node.js directly
node generate-md.js data/template-basic.json
node generate-md.js data/template-basic.json output/contract.md
node generate-md.js --help # Show usageGenerate JSON business logic response files from template and request data:
# Using npm scripts
npm run json # Basic scenario
npm run json:low # Low penalty + low value
npm run json:high # High penalty + high value
# Using Node.js directly
node generate-json.js data/template-basic.json data/request-basic.json
node generate-json.js data/template-basic.json data/request-basic.json output/response.json
node generate-json.js --help # Show usage# List available data files
node list-data-files.js
# Run multiple test scenarios
npm run test-valuesLocated in data/ directory:
template-basic.json- Default configuration (10.5% penalty, 15-day termination)template-low-penalty.json- Conservative (5% penalty, 30-day termination)template-high-penalty.json- Aggressive (15% penalty, 7-day termination)
request-basic.json- $100 goods valuerequest-low-value.json- $50 goods valuerequest-high-value.json- $1000 goods value
{
"$class": "io.clause.latedeliveryandpenalty@0.1.0.TemplateModel",
"forceMajeure": true,
"penaltyDuration": {
"$class": "org.accordproject.time@0.3.0.Duration",
"amount": 2,
"unit": "days"
},
"penaltyPercentage": 10.5,
"capPercentage": 55,
"termination": {
"$class": "org.accordproject.time@0.3.0.Duration",
"amount": 15,
"unit": "days"
},
"fractionalPart": "days",
"clauseId": "your-clause-id",
"$identifier": "your-clause-id"
}{
"goodsValue": 100
}Comprehensive test suite with CLI integration testing:
# Run all tests
npm test
# Run in watch mode
npm run test:watch
# Run specific test file
npm test __tests__/trigger.test.js- CLI Integration Tests - Tests actual command-line usage
- Error Handling - Invalid files, missing arguments, malformed JSON
- Edge Cases - Boundary conditions, different data formats
- Output Validation - Correct formatting, exit codes, error messages
Note: Coverage metrics are not meaningful for CLI tools tested via process spawning. The integration tests provide comprehensive validation of real-world usage scenarios.
| Template | Request | Expected Penalty | Use Case |
|---|---|---|---|
| Low Penalty | Low Value | $6.25 | Small contracts |
| Basic | Basic | $262.50 | Standard contracts |
| High Penalty | High Value | $3750.00 | High-value contracts |
- Create new JSON files in
data/directory - Test with CLI tools:
node draft.js data/your-template.json node trigger.js data/your-template.json data/your-request.json
# Watch mode for continuous testing
npm run test:watch
# Test specific functionality
npm test -- --testNamePattern="should handle"- Flexible Configuration - JSON-based template and request data
- CLI Tools - Easy-to-use command-line interfaces
- Comprehensive Testing - Full CLI integration test coverage
- Multiple Output Formats - Markdown, HTML, PDF contract generation
- PDF Generation - Direct PDF output from template data
- JSON Response Generation - Business logic responses saved to files
- Business Logic Engine - Penalty calculations and contract logic
- Scenario Testing - Pre-configured test cases and combinations
- Data Exploration - Built-in tools to explore available configurations
npm run test:watch # Continuous testing
node list-data-files.js # Explore available datanpm start # Full demonstration
npm run test-values # Multiple scenarios# Custom scenarios
echo '{"goodsValue": 5000}' > data/custom-request.json
node trigger.js data/template-high-penalty.json data/custom-request.json