diff --git a/.changeset/vast-ravens-invent.md b/.changeset/vast-ravens-invent.md new file mode 100644 index 0000000..a92722a --- /dev/null +++ b/.changeset/vast-ravens-invent.md @@ -0,0 +1,16 @@ +--- +'@offckb/cli': patch +--- + +fix(create): ensure CKB binary and devnet config before generating scripts + +Fix issue #396 where `offckb create` failed if user hasn't run `offckb node` first. + +**Changes:** + +- Add imports for `installCKBBinary`, `initChainIfNeeded`, and `readSettings` +- Call `installCKBBinary` to download CKB binary if not exists +- Call `initChainIfNeeded` to initialize devnet config if not exists +- Both calls happen before `genSystemScriptsJsonFile` to ensure dependencies are ready + +This makes `offckb create` self-sufficient and doesn't require prior `offckb node` execution. diff --git a/src/cmd/create.ts b/src/cmd/create.ts index b9832b0..88dcf89 100644 --- a/src/cmd/create.ts +++ b/src/cmd/create.ts @@ -6,6 +6,9 @@ import { InteractivePrompts } from '../templates/prompts'; import { genSystemScriptsJsonFile } from '../scripts/gen'; import { CKBDebugger } from '../tools/ckb-debugger'; import { logger } from '../util/logger'; +import { installCKBBinary as _installCKBBinary } from '../node/install'; +import { initChainIfNeeded as _initChainIfNeeded } from '../node/init-chain'; +import { readSettings } from '../cfg/setting'; export interface CreateScriptProjectOptions { manager?: 'pnpm' | 'yarn' | 'npm'; @@ -100,6 +103,11 @@ export async function createScriptProject(name?: string, options: CreateScriptPr await processor.generateProject(fullProjectPath, contextWithPath); + const _settings = readSettings(); + + await _installCKBBinary(_settings.bins.defaultCKBVersion); + await _initChainIfNeeded(); + // Generate system-scripts.json logger.info('🔧 Generating system scripts configuration...'); try {