Skip to content

Commit 168cb10

Browse files
authored
refactor: simplify create js script dApp with existing tools (#246)
* refactor: js script dApp with existing tools * chore: update readme
1 parent 365ba63 commit 168cb10

5 files changed

Lines changed: 25 additions & 181 deletions

File tree

README.md

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,6 @@ CKB local development network for your first try.
1717

1818
There are BREAKING CHANGES between v0.3.x and v0.4.x, make sure to read the [migration guide](/docs/migration.md) before upgrading.
1919

20-
## Table of Contents
21-
22-
- [OffCKB](#offckb)
23-
- [Table of Contents](#table-of-contents)
24-
- [Install](#install)
25-
- [Usage](#usage)
26-
- [Get started](#get-started)
27-
- [Running CKB](#running-ckb)
28-
- [List scripts info](#list-scripts-info)
29-
- [Tweak Devnet Config](#tweak-devnet-config)
30-
- [Create a full-stack Project](#create-a-full-stack-project)
31-
- [Create a script-only Project](#create-a-script-only-project)
32-
- [Create a dApp-only Project](#create-a-dapp-only-project)
33-
- [Build and Deploy a script](#build-and-deploy-a-script)
34-
- [Start the frontend project](#start-the-frontend-project)
35-
- [Debug a transaction](#debug-a-transaction)
36-
- [Config Setting](#config-setting)
37-
- [List All Settings](#list-all-settings)
38-
- [Set CKB version](#set-ckb-version)
39-
- [Set Network Proxy](#set-network-proxy)
40-
- [Built-in scripts](#built-in-scripts)
41-
- [Accounts](#accounts)
42-
- [About CCC](#about-ccc)
43-
- [FAQ](#faq)
44-
- [Contributing](#contributing)
45-
4620
## Install
4721

4822
```sh
@@ -199,7 +173,7 @@ You can create a new script project without a frontend. This is useful when you
199173
offckb create <your-project-name> --script
200174
```
201175

202-
Note: you need to have rust/cargo/cargo-generate/clang 16+ installed in your environment to use this command. offckb doesn't do anything really, it just call [ckb-script-template](https://github.com/cryptape/ckb-script-templates) to do all the magic.
176+
Note: you need to have pnpm installed in your environment to use this command. offckb doesn't do anything really, it just call [create-js-vm-app](https://github.com/nervosnetwork/ckb-js-vm/tree/main/packages/create-app) to do all the magic.
203177

204178
### Create a dApp-only Project
205179

src/cli.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { DeployOptions, deploy } from './cmd/deploy';
1111
import { syncScripts } from './cmd/sync-scripts';
1212
import { TransferOptions, transfer } from './cmd/transfer';
1313
import { BalanceOption, balanceOf } from './cmd/balance';
14-
import { create, selectBareTemplate, CreateOption, createScriptProject, createDappProject } from './cmd/create';
14+
import { create, CreateOption, createScriptProject, createDAppProject } from './cmd/create';
1515
import { printMyScripts, DeployedScriptOption } from './cmd/my-scripts';
1616
import { Config, ConfigItem } from './cmd/config';
1717
import { debugSingleScript, debugTransaction, parseSingleScriptOption } from './cmd/debug';
@@ -40,11 +40,10 @@ program
4040
}
4141

4242
if (option.dapp) {
43-
return await createDappProject(name);
43+
return await createDAppProject(name);
4444
}
4545

46-
const template = await selectBareTemplate();
47-
return create(name, template);
46+
return create(name);
4847
});
4948

5049
program

src/cmd/create.ts

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import path from 'path';
22
import { findFileInFolder } from '../util/fs';
3-
import { gitCloneAndDownloadFolderSync } from '../util/git';
43
import { injectConfig } from './inject-config';
5-
import { select, confirm } from '@inquirer/prompts';
4+
import { confirm } from '@inquirer/prompts';
65
import { execSync } from 'child_process';
76
import { genMyScriptsJsonFile, genSystemScriptsJsonFile } from '../scripts/gen';
8-
import { readSettings } from '../cfg/setting';
9-
import { BareTemplateOption, loadBareTemplateOpts } from '../template/option';
107
import { OffCKBConfigFile } from '../template/offckb-config';
118
const version = require('../../package.json').version;
129

@@ -23,15 +20,15 @@ export type DappOnly = {
2320
export type CreateOption = ScriptOnly | DappOnly;
2421

2522
export function createScriptProject(name: string) {
26-
const cmd = `cargo generate gh:cryptape/ckb-script-templates workspace --name ${name}`;
23+
const cmd = `pnpm create ckb-js-vm-app ${name}`;
2724
try {
2825
execSync(cmd, { encoding: 'utf-8', stdio: 'inherit' });
2926
} catch (error: unknown) {
3027
console.error('create script project failed, ', (error as Error).message);
3128
}
3229
}
3330

34-
export async function createDappProject(name: string) {
31+
export async function createDAppProject(name: string) {
3532
const cmd = `npx create-ccc-app@latest ${name} --ts --}`;
3633
try {
3734
execSync(cmd, { encoding: 'utf-8', stdio: 'inherit' });
@@ -42,20 +39,26 @@ export async function createDappProject(name: string) {
4239
}
4340
}
4441

45-
export async function create(name: string, template: BareTemplateOption) {
46-
const targetPath = path.resolve(process.cwd(), name);
47-
const settings = readSettings();
48-
const dappTemplateFolderPath = `${settings.dappTemplate.gitFolder}/${template.value}`;
49-
gitCloneAndDownloadFolderSync(
50-
settings.dappTemplate.gitRepoUrl,
51-
settings.dappTemplate.gitBranch,
52-
dappTemplateFolderPath,
53-
targetPath,
54-
);
42+
export async function createFullstackProject(name: string) {
43+
createScriptProject(name);
44+
console.log("Now let's create the dapp part..");
45+
const cmd = `pnpm create create-ccc-app@latest ${name}/packages/dapp --ts --}`;
46+
try {
47+
execSync(cmd, { encoding: 'utf-8', stdio: 'inherit' });
48+
const dappFolderPath = path.resolve(process.cwd(), name, 'packages', 'dapp');
49+
await askForInjectOffckbConfig(dappFolderPath);
50+
return dappFolderPath;
51+
} catch (error: unknown) {
52+
console.error('create fullstack appp project failed, ', (error as Error).message);
53+
process.exit(1);
54+
}
55+
}
56+
57+
export async function create(name: string) {
58+
const dappFolderPath = await createFullstackProject(name);
5559

5660
// update the version
57-
const projectFolder = path.resolve(process.cwd(), name);
58-
const targetConfigPath = findFileInFolder(projectFolder, 'offckb.config.ts');
61+
const targetConfigPath = findFileInFolder(dappFolderPath, 'offckb.config.ts');
5962
if (targetConfigPath) {
6063
OffCKBConfigFile.updateVersion(version, targetConfigPath);
6164
const contractInfoFolder = OffCKBConfigFile.readContractInfoFolder(targetConfigPath);
@@ -73,23 +76,6 @@ export async function create(name: string, template: BareTemplateOption) {
7376
}
7477
}
7578

76-
export async function selectBareTemplate() {
77-
const opts = await loadBareTemplateOpts();
78-
79-
const answer = await select({
80-
message: 'Select a bare template',
81-
choices: opts.map((opt) => {
82-
return {
83-
name: opt.name,
84-
value: opt.value,
85-
description: `${opt.description}, \n[${opt.tag.toString()}]`,
86-
};
87-
}),
88-
});
89-
90-
return opts.find((opt) => opt.value === answer)!;
91-
}
92-
9379
export async function askForInjectOffckbConfig(dappFolderPath: string) {
9480
const answer = await confirm({
9581
message: 'Do you want to inject offckb configs in your project so that it can work with local blockchain info?',

src/template/option.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/util/git.ts

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)