Skip to content
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ Example result:
Pay attention to the `devnet.configPath` and `devnet.dataPath`.

2. `cd` into the `devnet.configPath` . Modify the config files as needed. See [Custom Devnet Setup](https://docs.nervos.org/docs/node/run-devnet-node#custom-devnet-setup) and [Configure CKB](https://github.com/nervosnetwork/ckb/blob/develop/docs/configure.md) for details.
3. After modifications, run `offckb clean -d` to remove the chain data if needed while keeping the updated config files.
3. After modifications, run `offckb clean` to remove the chain data while keeping the updated config files.
4. Restart local blockchain by running `offckb node`


Expand Down
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ program
program
.command('clean')
.description('Clean the devnet data, need to stop running the chain first')
.option('-d, --data', 'Only remove chain data, keep devnet config files')
.option('-d, --data', 'Deep clean: remove all devnet data including config files (useful when init is corrupted)')
.action((options: { data?: boolean }) => clean(options));
program.command('accounts').description('Print account list info').action(accounts);

Expand Down
28 changes: 14 additions & 14 deletions src/cmd/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,35 @@ export interface CleanOptions {
export function clean(options?: CleanOptions) {
const settings = readSettings();
const allDevnetDataPath = settings.devnet.configPath;
const dataOnly = options?.data || false;
const deepClean = options?.data || false;

if (dataOnly) {
// Only clean the chain data subdirectory
const chainDataPath = settings.devnet.dataPath;
if (isFolderExists(chainDataPath)) {
if (deepClean) {
// Deep clean: Remove everything including config files (useful when init is corrupted)
// this is the root folder of devnet, it contains config, data, debugFullTransactions, transactions, failed-transactions, contracts
if (isFolderExists(allDevnetDataPath)) {
try {
fs.rmSync(chainDataPath, { recursive: true });
logger.info(`Chain data cleaned. Devnet config files preserved.`);
fs.rmSync(allDevnetDataPath, { recursive: true });
logger.info(`Deep clean completed. All devnet data and config files removed.`);
} catch (error: unknown) {
logger.info(`Did you stop running the chain first?`);
logger.error((error as Error).message);
}
} else {
logger.info(`Nothing to clean. Chain data directory ${chainDataPath} not found.`);
logger.info(`Nothing to clean. Devnet directory ${allDevnetDataPath} not found.`);
}
} else {
// Clean everything - the original behavior
// this is the root folder of devnet, it contains config, data, debugFullTransactions, transactions, failed-transactions, contracts
if (isFolderExists(allDevnetDataPath)) {
// Default: Only clean the chain data subdirectory, preserving config files
const chainDataPath = settings.devnet.dataPath;
if (isFolderExists(chainDataPath)) {
try {
fs.rmSync(allDevnetDataPath, { recursive: true });
logger.info(`Chain data cleaned.`);
fs.rmSync(chainDataPath, { recursive: true });
logger.info(`Chain data cleaned. Devnet config files preserved.`);
} catch (error: unknown) {
logger.info(`Did you stop running the chain first?`);
logger.error((error as Error).message);
}
} else {
logger.info(`Nothing to clean. Devnet data directory ${allDevnetDataPath} not found.`);
logger.info(`Nothing to clean. Chain data directory ${chainDataPath} not found.`);
}
}
}
Loading