Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 60 additions & 58 deletions scripts/build-single-workflow-js.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,74 @@
import fg from "fast-glob";
import { $ } from "bun";
import { mkdir } from "fs/promises";
import { existsSync } from "fs";
import fg from 'fast-glob'
import { $ } from 'bun'
import { mkdir } from 'fs/promises'
import { existsSync } from 'fs'

export const main = async () => {
const args = process.argv.slice(3);
const args = process.argv.slice(3)

if (args.length === 0) {
console.error("Usage: bun run build-single-workflow-js.ts <workflow-name>");
console.error(" bun run build-single-workflow-js.ts <directory> <workflow-name>");
console.error("Examples:");
console.error(" Single: bun run build-single-workflow-js.ts capability_calls_are_async");
console.error(" Nested: bun run build-single-workflow-js.ts mode_switch don_runtime_in_node_mode");
process.exit(1);
}
if (args.length === 0) {
console.error('Usage: bun run build-single-workflow-js.ts <workflow-name>')
console.error(' bun run build-single-workflow-js.ts <directory> <workflow-name>')
console.error('Examples:')
console.error(' Single: bun run build-single-workflow-js.ts capability_calls_are_async')
console.error(
' Nested: bun run build-single-workflow-js.ts mode_switch don_runtime_in_node_mode',
)
process.exit(1)
}

let workflowPath: string;
let outputPath: string;
let pattern: string;
let workflowPath: string
let outputPath: string
let pattern: string

if (args.length === 1) {
// Single workflow parameter - works as before
const workflowName = args[0];
console.info(`Building workflow: ${workflowName}`);
pattern = `src/workflows/standard_tests/${workflowName}/test.ts`;
outputPath = `dist/workflows/standard_tests/${workflowName}`;
} else if (args.length === 2) {
// Two parameters - first is directory, second is nested workflow
const directory = args[0];
const workflowName = args[1];
console.info(`Building nested workflow: ${directory}/${workflowName}`);
pattern = `src/workflows/standard_tests/${directory}/${workflowName}/test.ts`;
outputPath = `dist/workflows/standard_tests/${directory}/${workflowName}`;
} else {
console.error("❌ Too many arguments provided");
process.exit(1);
}
if (args.length === 1) {
// Single workflow parameter - works as before
const workflowName = args[0]
console.info(`Building workflow: ${workflowName}`)
pattern = `src/workflows/standard_tests/${workflowName}/test.ts`
outputPath = `dist/workflows/standard_tests/${workflowName}`
} else if (args.length === 2) {
// Two parameters - first is directory, second is nested workflow
const directory = args[0]
const workflowName = args[1]
console.info(`Building nested workflow: ${directory}/${workflowName}`)
pattern = `src/workflows/standard_tests/${directory}/${workflowName}/test.ts`
outputPath = `dist/workflows/standard_tests/${directory}/${workflowName}`
} else {
console.error('❌ Too many arguments provided')
process.exit(1)
}

// Find the specific workflow file
const workflowsSourcePaths = await fg(pattern);
// Find the specific workflow file
const workflowsSourcePaths = await fg(pattern)

if (workflowsSourcePaths.length === 0) {
console.error(`❌ No workflow found: ${pattern}`);
process.exit(1);
}
if (workflowsSourcePaths.length === 0) {
console.error(`❌ No workflow found: ${pattern}`)
process.exit(1)
}

workflowPath = workflowsSourcePaths[0];
console.info(`📁 Found: ${workflowPath}`);
workflowPath = workflowsSourcePaths[0]
console.info(`📁 Found: ${workflowPath}`)

// Ensure the output directory exists
await mkdir(outputPath, { recursive: true });
// Ensure the output directory exists
await mkdir(outputPath, { recursive: true })

// Build the single workflow
await Bun.build({
entrypoints: [`./${workflowPath}`],
outdir: outputPath,
target: "node",
format: "esm",
});
// Build the single workflow
await Bun.build({
entrypoints: [`./${workflowPath}`],
outdir: outputPath,
target: 'node',
format: 'esm',
})

const targetJsFile = `${outputPath}/test.js`;
const targetJsFile = `${outputPath}/test.js`

if (!existsSync(targetJsFile)) {
console.error(`❌ Expected file not found: ${targetJsFile}`);
process.exit(1);
}
if (!existsSync(targetJsFile)) {
console.error(`❌ Expected file not found: ${targetJsFile}`)
process.exit(1)
}

await $`bun build ${targetJsFile} --bundle --outfile=${targetJsFile}`;
await $`bun build ${targetJsFile} --bundle --outfile=${targetJsFile}`

console.info(`✅ Built: ${targetJsFile}`);
};
console.info(`✅ Built: ${targetJsFile}`)
}
32 changes: 16 additions & 16 deletions scripts/build-single-workflow.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { $ } from "bun";
import { $ } from 'bun'

export const main = async () => {
const workflowArg = process.argv[3];
const workflowArg = process.argv[3]

if (!workflowArg) {
console.error("Usage: bun run build-single-workflow.ts <workflow-name>");
console.error("Example: bun run build-single-workflow.ts secrets");
process.exit(1);
}
if (!workflowArg) {
console.error('Usage: bun run build-single-workflow.ts <workflow-name>')
console.error('Example: bun run build-single-workflow.ts secrets')
process.exit(1)
}

console.info(`🚀 Building workflow: ${workflowArg}`);
console.info(`🚀 Building workflow: ${workflowArg}`)

// Build JS
console.info("\n📦 Step 1: Building JS...");
await $`bun scripts/run.ts build-single-workflow-js ${workflowArg}`;
// Build JS
console.info('\n📦 Step 1: Building JS...')
await $`bun scripts/run.ts build-single-workflow-js ${workflowArg}`

// Build WASM
console.info("\n🔨 Step 2: Compiling to WASM...");
await $`bun scripts/run.ts compile-single-workflow-to-wasm ${workflowArg}`;
// Build WASM
console.info('\n🔨 Step 2: Compiling to WASM...')
await $`bun scripts/run.ts compile-single-workflow-to-wasm ${workflowArg}`

console.info(`\n✅ Workflow '${workflowArg}' built successfully!`);
};
console.info(`\n✅ Workflow '${workflowArg}' built successfully!`)
}
54 changes: 25 additions & 29 deletions scripts/compile-javy-sdk-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
#!/usr/bin/env bun

import { spawn } from "node:child_process";
import { join } from "node:path";
import { spawn } from 'node:child_process'
import { join } from 'node:path'

export const main = async () => {
const pluginDir = join(process.cwd(), "plugins", "javy_chainlink_sdk");
const pluginDir = join(process.cwd(), 'plugins', 'javy_chainlink_sdk')

console.info("\n\n---> Chainlink SDK Javy plugin (Rust) \n\n");
console.info('\n\n---> Chainlink SDK Javy plugin (Rust) \n\n')

return new Promise<void>((resolve, reject) => {
const buildProcess = spawn(
"cargo",
["build", "--target", "wasm32-wasip1", "--release"],
{
cwd: pluginDir,
stdio: "inherit",
shell: true,
}
);
return new Promise<void>((resolve, reject) => {
const buildProcess = spawn('cargo', ['build', '--target', 'wasm32-wasip1', '--release'], {
cwd: pluginDir,
stdio: 'inherit',
shell: true,
})

buildProcess.on("close", (code) => {
if (code === 0) {
console.info("Done!");
resolve();
} else {
console.error(`❌ Plugin build failed with code ${code}`);
reject(new Error(`Plugin build failed with code ${code}`));
}
});
buildProcess.on('close', (code) => {
if (code === 0) {
console.info('Done!')
resolve()
} else {
console.error(`❌ Plugin build failed with code ${code}`)
reject(new Error(`Plugin build failed with code ${code}`))
}
})

buildProcess.on("error", (error) => {
console.error("❌ Failed to start build process:", error);
reject(error);
});
});
};
buildProcess.on('error', (error) => {
console.error('❌ Failed to start build process:', error)
reject(error)
})
})
}
12 changes: 6 additions & 6 deletions scripts/compile-javy-with-sdk-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { $ } from "bun";
import { $ } from 'bun'

export const main = async () => {
console.info("\n\n---> Compile Javy SDK plugin \n\n");
console.info('\n\n---> Compile Javy SDK plugin \n\n')

await $`mkdir -p dist`;
await $`mkdir -p dist`

await $`bun javy init-plugin plugins/javy_chainlink_sdk/target/wasm32-wasip1/release/javy_chainlink_sdk.wasm -o dist/javy-chainlink-sdk.plugin.wasm`;
await $`bun javy init-plugin plugins/javy_chainlink_sdk/target/wasm32-wasip1/release/javy_chainlink_sdk.wasm -o dist/javy-chainlink-sdk.plugin.wasm`

console.info("Done!");
};
console.info('Done!')
}
124 changes: 58 additions & 66 deletions scripts/compile-single-workflow-to-wasm.ts
Original file line number Diff line number Diff line change
@@ -1,68 +1,60 @@
import { $ } from "bun";
import fg from "fast-glob";
import { $ } from 'bun'
import fg from 'fast-glob'

export const main = async () => {
const args = process.argv.slice(3);

if (args.length === 0) {
console.error(
"Usage: bun run compile-single-workflow-to-wasm.ts <workflow-name>"
);
console.error(
" bun run compile-single-workflow-to-wasm.ts <directory> <workflow-name>"
);
console.error("Examples:");
console.error(
" Single: bun run compile-single-workflow-to-wasm.ts capability_calls_are_async"
);
console.error(
" Nested: bun run compile-single-workflow-to-wasm.ts mode_switch don_runtime_in_node_mode"
);
process.exit(1);
}

let jsFile: string;
let buildCommand: string;

if (args.length === 1) {
// Single workflow parameter - works as before
const workflowName = args[0];
console.info(`🔨 Compiling workflow to WASM: ${workflowName}`);
jsFile = `dist/workflows/standard_tests/${workflowName}/test.js`;
buildCommand = `bun run build-single-workflow-js.ts ${workflowName}`;
} else if (args.length === 2) {
// Two parameters - first is directory, second is nested workflow
const directory = args[0];
const workflowName = args[1];
console.info(`🔨 Compiling nested workflow to WASM: ${directory}/${workflowName}`);
jsFile = `dist/workflows/standard_tests/${directory}/${workflowName}/test.js`;
buildCommand = `bun run build-single-workflow-js.ts ${directory} ${workflowName}`;
} else {
console.error("❌ Too many arguments provided");
process.exit(1);
}

const wasmFile = jsFile.replace(/\.js$/, ".wasm");

// Check if the JS file exists
const jsFiles = fg.sync(jsFile);
if (jsFiles.length === 0) {
console.error(`❌ No JS file found: ${jsFile}`);
console.error(
`Make sure to build the workflow first with: ${buildCommand}`
);
process.exit(1);
}

console.info(`📁 Found: ${jsFile}`);
console.info(`🎯 Output: ${wasmFile}`);

/**
* -C wit=src/workflows/workflow.wit — points to the WIT file (definition of what will be available for the Host).
* -C wit-world=workflow — specifies the WIT world name (world "workflow" which is defined in the .wit file).
* -C plugin=... — uses your custom runtime (bundled javy chainlink sdk plugin)
*/
await $`bun javy build -C wit=src/workflows/workflow.wit -C wit-world=workflow -C plugin=dist/javy-chainlink-sdk.plugin.wasm ${jsFile} -o ${wasmFile}`;

console.info(`✅ Compiled: ${wasmFile}`);
};
const args = process.argv.slice(3)

if (args.length === 0) {
console.error('Usage: bun run compile-single-workflow-to-wasm.ts <workflow-name>')
console.error(' bun run compile-single-workflow-to-wasm.ts <directory> <workflow-name>')
console.error('Examples:')
console.error(' Single: bun run compile-single-workflow-to-wasm.ts capability_calls_are_async')
console.error(
' Nested: bun run compile-single-workflow-to-wasm.ts mode_switch don_runtime_in_node_mode',
)
process.exit(1)
}

let jsFile: string
let buildCommand: string

if (args.length === 1) {
// Single workflow parameter - works as before
const workflowName = args[0]
console.info(`🔨 Compiling workflow to WASM: ${workflowName}`)
jsFile = `dist/workflows/standard_tests/${workflowName}/test.js`
buildCommand = `bun run build-single-workflow-js.ts ${workflowName}`
} else if (args.length === 2) {
// Two parameters - first is directory, second is nested workflow
const directory = args[0]
const workflowName = args[1]
console.info(`🔨 Compiling nested workflow to WASM: ${directory}/${workflowName}`)
jsFile = `dist/workflows/standard_tests/${directory}/${workflowName}/test.js`
buildCommand = `bun run build-single-workflow-js.ts ${directory} ${workflowName}`
} else {
console.error('❌ Too many arguments provided')
process.exit(1)
}

const wasmFile = jsFile.replace(/\.js$/, '.wasm')

// Check if the JS file exists
const jsFiles = fg.sync(jsFile)
if (jsFiles.length === 0) {
console.error(`❌ No JS file found: ${jsFile}`)
console.error(`Make sure to build the workflow first with: ${buildCommand}`)
process.exit(1)
}

console.info(`📁 Found: ${jsFile}`)
console.info(`🎯 Output: ${wasmFile}`)

/**
* -C wit=src/workflows/workflow.wit — points to the WIT file (definition of what will be available for the Host).
* -C wit-world=workflow — specifies the WIT world name (world "workflow" which is defined in the .wit file).
* -C plugin=... — uses your custom runtime (bundled javy chainlink sdk plugin)
*/
await $`bun javy build -C wit=src/workflows/workflow.wit -C wit-world=workflow -C plugin=dist/javy-chainlink-sdk.plugin.wasm ${jsFile} -o ${wasmFile}`

console.info(`✅ Compiled: ${wasmFile}`)
}
Loading
Loading