boxlang-modules-and-packages について
BoxLang 開発者向けのモジュールとパッケージのガイドです。インストール、設定、確認方法に加え、互換性や Web、データ処理向けのモジュールを紹介します。
主な機能
- 01CommandBox によるモジュールのインストール
- 02モジュールの有効化、無効化、設定
- 03CFML 互換と Web サポートのモジュール
- 04メール、ORM、各種データ処理モジュール
- 05ロード済みモジュールと詳細の確認
活用シーン
- 01BoxLang アプリに必要な拡張機能の導入
- 02モジュールの接続パラメーター設定や無効化
- 03CFML 互換が必要なアプリの移行
- 04ランタイムのモジュールとバージョンの確認
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ ortus-boxlang/ skills --skill boxlang-modules-and-packagesインストール後、Claude Code で/boxlang-modules-and-packagesを入力して読み込まれたか確認します。
詳細
BoxLang モジュールとパッケージ
BoxLang は、開発者と AI エージェントが協力してアプリケーションを構築、モダナイズ、実行するための、AI ネイティブなソフトウェア生産性プラットフォームです。
概要
BoxLang のモジュールシステムでは、組み込み関数(BIF)、コンポーネント、サービスを追加してランタイムを拡張できます。モジュールは CommandBox の box CLI からインストールし、boxlang.json または Application.bx で設定します。多くのモジュールでは BIF がグローバルに自動登録されるため、インストール後にインポートする必要はありません。
モジュールのインストール
# Install via CommandBox
box install bx-redis
box install bx-pdf
box install bx-csv
box install bx-spreadsheet
# Install a specific version
box install [email protected]
# Install multiple at once
box install bx-redis bx-csv bx-mail
# List installed modules
box list
boxlang.json でのモジュール設定
{
"modules": {
"bx-redis": {
"enabled": true,
"settings": {
"host": "${REDIS_HOST:localhost}",
"port": 6379,
"password": "${REDIS_PASSWORD:}"
}
},
"bx-mail": {
"enabled": true,
"settings": {
"spooling": true,
"serverInterval": 5000,
"smtp": {
"host": "${SMTP_HOST}",
"port": 587,
"tls": true,
"auth": true,
"username": "${SMTP_USER}",
"password": "${SMTP_PASS}"
}
}
},
"compat-cfml": {
"enabled": true,
"settings": {
"engine": "Lucee"
}
}
}
}
モジュールの無効化
{
"modules": {
"bx-orm": {
"enabled": false
}
}
}
無料のコアモジュール
bx-compat-cfml — CFML 互換性
レガシーな ColdFusion または Lucee アプリケーションを移行するために、CFML 構文の解析と CFML 固有の関数・コンポーネントを有効にします。
{
"modules": {
"compat-cfml": {
"enabled": true,
"settings": { "engine": "Lucee" }
}
}
}
有効にすると、BoxLang 構文に加えて、.cfm、.cfc、CFML 構文も認識されます。
bx-web-support — Web サーバー統合
Web リクエストとレスポンスの処理、セッション管理、CGI スコープのサポートを提供します。Web アプリケーションには必須です。通常は CommandBox/MiniServer によって自動的に読み込まれます。
bx-mail — メール
// Send an email
bx:mail
to="[email protected]"
from="[email protected]"
subject="Welcome to MyApp!"
type="html" {
writeOutput( "<h1>Welcome, #name#!</h1>" )
writeOutput( "<p>Your account is ready.</p>" )
}
// Plain text with attachment
bx:mail to="[email protected]" from="[email protected]" subject="Report" {
bx:mailpart type="text" {
writeOutput( "See attached report." )
}
bx:mailparam file=expandPath("./reports/daily.pdf") disposition="attachment"
}
bx-orm — オブジェクトリレーショナルマッピング(Hibernate)
// In Application.bx
class {
this.ormEnabled = true
this.ormSettings = {
datasource : "mainDB",
dbcreate : "update",
flushAtRequestEnd : true,
autoManageSession : true
}
}
// Persistent entity: models/User.bx
class persistent="true" table="users" accessors="true" {
property name="id" column="id" fieldtype="id" generator="native"
property name="name" column="name" type="string"
property name="email" column="email" type="string"
// Relationship
property name="orders" fieldtype="one-to-many" cfc="models.Order"
cascade="all" lazy="true"
}
// ORM operations
var user = entityLoad( "User", userId )
entitySave( new models.User( name="Ada", email="[email protected]" ) )
entityDelete( user )
// HQL queries
var users = ORMExecuteQuery( "FROM User WHERE status = :status", { status: "active" } )
BoxLang+ プレミアムモジュール
BoxLang+ モジュールを利用するには、boxlang.io のサブスクリプションが必要です。
bx-pdf — PDF 生成
// Generate PDF from HTML
bx:pdf action="write" filename=expandPath("./output/report.pdf") overwrite="true" {
bx:pdfparam type="header" {
writeOutput( "<h3>Monthly Report</h3>" )
}
writeOutput( "<h1>Sales Summary</h1>" )
writeOutput( "<p>Total: $#totalSales#</p>" )
include "views/sales-table.bxm"
}
// Merge PDFs
bx:pdf action="merge" destination=expandPath("./merged.pdf") overwrite="true" {
bx:pdfparam source=expandPath("./cover.pdf")
bx:pdfparam source=expandPath("./report.pdf")
}
bx-csv — CSV 処理
// Parse CSV
var data = csvParse( fileRead("data.csv") )
// Parse with options
var data = csvParse(
fileRead( "data.csv" ),
{
hasHeaders : true,
delimiter : ",",
quoteChar : '"',
charset : "UTF-8"
}
)
// Iterate rows
for ( var row in data ) {
processRow( row )
}
// Generate CSV
var output = csvSerialize(
queryExecute( "SELECT id, name, email FROM users" ),
{ hasHeaders: true, delimiter: "," }
)
fileWrite( "export.csv", output )
bx-spreadsheet — Excel(XLSX)
// Read a spreadsheet
var wb = spreadsheetRead( expandPath("./data.xlsx") )
var sheet = spreadsheetGetSheetName( wb, 1 )
var data = spreadsheetRead( expandPath("./data.xlsx"), true, true )
// Create a spreadsheet
var wb = spreadsheetNew( "Report" )
spreadsheetAddRow( wb, ["Name", "Email", "Revenue"] )
for ( var user in users ) {
spreadsheetAddRow( wb, [user.name, user.email, user.revenue] )
}
// Format header row
spreadsheetFormatRow( wb, {
bold : true,
bgcolor : "##336699",
fontcolor : "##FFFFFF"
}, 1 )
spreadsheetWrite( wb, expandPath("./report.xlsx") )
bx-redis — Redis 統合
// After configuring the module, use Redis as a cache provider
// (see caching skill for full details)
// Direct Redis operations via the Redis client
var redis = getBoxService( "RedisService" )
redis.set( "key", "value", 3600 ) // with TTL in seconds
var val = redis.get( "key" )
redis.del( "key" )
redis.incr( "counter" )
redis.lpush( "queue", jsonSerialize(job) )
var job = redis.rpop( "queue" )
bx-ldap — LDAP ディレクトリ
bx:ldap
server="ldap.example.com"
port="389"
username="cn=admin,dc=example,dc=com"
password="#ldapPassword#"
action="query"
name="result"
start="dc=example,dc=com"
attributes="cn,mail,sn"
filter="(objectClass=person)"
for ( var person in result ) {
writeOutput( "#person.cn# — #person.mail#<br>" )
}
bx-audio — 音声
// Make a tone, fade it, save it, inspect it
tone = audioOsc( "sine", 440, 1 )
tone = audioFade( audio=tone, fadeIn=0.01, fadeOut=0.2, curve="smooth" )
audioSave( tone, "tone.wav" )
println( audioInfo( "tone.wav" ) )
// Master a recording to the podcast loudness standard
audioSave( audioMaster( audio=audioLoad( "episode.wav" ), target="podcast" ), "episode-mastered.wav" )
bx-ai がインストールされている場合、bx-audio はエージェントツール(audioTrim@bxaudio など、ほかに 25 個)も登録します。bx-audio スキルを参照してください。
bx-image — 画像操作
// Read and resize
var img = imageRead( expandPath("./upload/photo.jpg") )
imageResize( img, 800, 600 )
imageWrite( img, expandPath("./output/photo-resized.jpg") )
// Crop
imageCrop( img, x=0, y=0, width=400, height=300 )
// Add watermark
var watermark = imageNew( "", 200, 50, "argb", "##00000000" )
imageDrawText( watermark, "© 2024 MyApp", 10, 30, { size: 16, color: "##FFFFFF" } )
imagePaste( img, watermark, 600, 550 )
// Get info
var info = imageInfo( img )
writeOutput( "Width: #info.width#, Height: #info.height#" )
モジュールの詳細確認
// List all loaded modules
var modules = getBoxService( "ModuleService" ).getLoadedModules()
modules.each( (name) -> writeOutput( name & "<br>" ) )
// Get module info
var info = getModuleInfo( "bx-redis" )
writeOutput( "Version: #info.version#" )
writeOutput( "Author: #info.author#" )
// Check if a module is loaded
if ( isModuleLoaded( "bx-redis" ) ) {
// use Redis
}