cbs-block 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,55 +1,84 @@
1
- # cbs-block SDK 🚀
1
+ # 🚀 CodeBlock Studio SDK (CLI)
2
2
 
3
- The official toolkit for building **CodeBlock Studio** extensions. Create, package, and share powerful visual blocks with ease.
3
+ The professional toolkit for building, testing, and sharing **CodeBlock Studio** extensions.
4
+
5
+ Built for performance. Designed for developers.
6
+
7
+ ---
4
8
 
5
9
  ## ðŸ“Ķ Installation
6
10
 
7
- Install the CLI globally to use the `cbs-block` command anywhere:
11
+ Install globally to use the `cbs-block` command anywhere:
8
12
 
9
13
  ```bash
10
14
  npm install cbs-block -g
11
15
  ```
12
16
 
17
+ ## 🛠ïļ Feature Highlights
18
+
19
+ * **Code-First Workflow**: Build complex blocks with full folder structures, supporting `index.js/ts`, `package.json`, and local `node_modules`.
20
+ * **Integrated Unit Testing**: Run logic tests instantly with `cbs-block test`.
21
+ * **Micro-Benchmarking**: Performance-test your logic with `cbs-block bench` (100k iteration analysis).
22
+ * **Integrated Tutorials**: Every new project includes a beautiful, CSS-rich `tutorial.html`. View it via `cbs-block tutorial`.
23
+ * **VSIX-Style Packaging**: Bundle your workspace into a professional `.cbsext` extension with one command.
24
+
25
+ ---
26
+
13
27
  ## 🚀 Quick Start
14
28
 
15
29
  ### 1. Initialize a Project
16
30
  Create a new workspace for your block library:
17
31
  ```bash
18
- cbs-block init MyAwesomeBlocks
19
- cd MyAwesomeBlocks
32
+ cbs-block init MyAwesomePack
33
+ cd MyAwesomePack
20
34
  ```
21
35
 
22
- ### 2. Create your First Block
23
- Generate a template for a new block. Choose a category like `Math`, `Logic`, or `Control`:
36
+ ### 2. Create a Block
37
+ Generate a professional directory-based block:
24
38
  ```bash
25
- cbs-block create SimpleAdd Math
39
+ cbs-block create MyBlock
26
40
  ```
27
41
 
28
- ### 3. Build & Package
29
- When you're ready to share, bundle your blocks into a `.cbspak` file:
42
+ ### 3. Develop & Test
43
+ Open `index.js`, write your logic, and test it:
30
44
  ```bash
31
45
  cbs-block build
46
+ cbs-block test myblock.cbsblock
32
47
  ```
33
48
 
49
+ ### 4. Pack & Share
50
+ Bundle your workspace into a professional extension:
51
+ ```bash
52
+ cbs-block pack
53
+ ```
54
+
55
+ ---
56
+
34
57
  ## 🛠ïļ Command Reference
35
58
 
36
59
  | Command | Description |
37
60
  | --- | --- |
38
- | `init <Name>` | Creates a new block development workspace. |
39
- | `create <Name> [Category]` | Generates a new `.cbsblock` template. |
40
- | `list` | Lists all blocks in the current directory. |
41
- | `lint` | Validates your blocks against the Studio schema. |
42
- | `build` | Packages your project into a `.cbspak` for the marketplace. |
43
- | `serve` | Starts a local hot-reload server for real-time testing. |
44
- | `publish` | Deploys your package to the CBS Marketplace. |
45
-
46
- ## ðŸ§Đ What is a .cbsblock?
47
- A block is a JSON file that defines its visuals and its logic.
48
- - **Visuals**: Ports (Input/Output/Flow) and interactive fields.
49
- - **Logic**: A sandboxed JavaScript function that executes within the Studio.
50
-
51
- ## 🔒 The CBS Ecosystem
52
- Note: `.cbspak` and `.cbsblock` files are proprietary formats optimized for **CodeBlock Studio**. They cannot be opened in standard text editors or other IDEs without the CBS engine.
61
+ | `init [name]` | Initialize a new block project workspace. |
62
+ | `create [name]` | Scaffold a new block (supports Directory or Single-File mode). |
63
+ | `build [dir]` | Compile a directory block into a production `.cbsblock`. |
64
+ | `pack` | Bundle your workspace into a professional `.cbsext` extension. |
65
+ | `test <file>` | Run logic unit tests with mock data. |
66
+ | `bench <file>` | Benchmark block logic performance (iterations & Ξs). |
67
+ | `tutorial` | Open the integrated developer guide in your browser. |
68
+ | `link` | Link local blocks to your CodeBlock Studio installation. |
69
+ | `publish` | Deploys your package to the global CBS Marketplace. |
70
+ | `site` | Generate a themed documentation website for your project. |
71
+ | `doc <file>` | Generate a markdown README for a specific block. |
72
+ | `lint` | Validate block definitions for schema compliance. |
73
+ | `status` | Check SDK version and environment health. |
74
+
75
+ ---
76
+
77
+ ## ðŸ§Đ The .cbsext Format
78
+ Professional extensions are packaged as ZIP-based `.cbsext` files. This allows for:
79
+ - **Rich Assets**: Bundle icons, helper scripts, and HTML tutorials into one file.
80
+ - **Enterprise Metadata**: Verified publisher IDs and display names.
81
+ - **Dependency Isolation**: Fully bundled logic with optimized execution.
53
82
 
54
83
  ---
55
- **Build the future of visual coding with CodeBlock Studio.**
84
+ **Build the future of visual coding with [CodeBlock Studio](https://codeblockstudio.web.app).**
package/bin/cbs-block.js CHANGED
@@ -3,7 +3,7 @@
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
5
  const chalk = require('chalk');
6
- const { execSync } = require('child_process');
6
+ const { execSync, exec } = require('child_process');
7
7
 
8
8
  async function main() {
9
9
  const { default: inquirer } = await import('inquirer');
@@ -14,13 +14,15 @@ async function main() {
14
14
 
15
15
  if (command === 'create') {
16
16
  const answers = await inquirer.prompt([
17
- { type: 'input', name: 'name', message: 'Block name:', default: target || 'MyBlock' },
17
+ { type: 'input', name: 'name', message: 'Internal ID (no spaces):', default: target || 'my-block' },
18
+ { type: 'input', name: 'displayName', message: 'Display Name:', default: (a) => a.name },
19
+ { type: 'input', name: 'publisher', message: 'Publisher:', default: 'cbs-creator' },
18
20
  { type: 'list', name: 'category', message: 'Category:', choices: ['Math', 'Logic', 'Control', 'Input', 'Output', 'Data', 'Custom'] },
19
21
  { type: 'input', name: 'color', message: 'Hex Color:', default: (a) => {
20
22
  const colors = { 'Math': '#4A90E2', 'Logic': '#F5A623', 'Control': '#FFCC00', 'Custom': '#4CAF50' };
21
23
  return colors[a.category] || '#4CAF50';
22
24
  }},
23
- { type: 'confirm', name: 'useDir', message: 'Create as directory (Recommended for external packages)?', default: true },
25
+ { type: 'confirm', name: 'useDir', message: 'Create as directory (Professional Extension Mode)?', default: true },
24
26
  { type: 'list', name: 'lang', message: 'Primary Language:', choices: ['JavaScript', 'TypeScript'] }
25
27
  ]);
26
28
 
@@ -54,14 +56,28 @@ async function main() {
54
56
  fs.writeFileSync(path.join(dirName, answers.lang === 'TypeScript' ? 'index.ts' : 'index.js'), logicStr);
55
57
  fs.writeFileSync(path.join(dirName, 'package.json'), JSON.stringify({
56
58
  name: dirName,
59
+ displayName: answers.displayName,
60
+ publisher: answers.publisher,
57
61
  version: "1.0.0",
58
62
  main: "index.js",
63
+ engines: { "cbs": ">=1.1.0" },
59
64
  dependencies: {}
60
65
  }, null, 2));
61
66
 
67
+ // NEW: Copy templates
68
+ const templateDir = path.join(__dirname, '../templates');
69
+ if (fs.existsSync(templateDir)) {
70
+ ['tutorial.html', 'README.md'].forEach(file => {
71
+ let content = fs.readFileSync(path.join(templateDir, file), 'utf8');
72
+ content = content.replace(/{BLOCK_NAME}/g, answers.name);
73
+ fs.writeFileSync(path.join(dirName, file), content);
74
+ });
75
+ fs.writeFileSync(path.join(dirName, 'LICENSE'), `MIT License\n\nCopyright (c) 2026 ${answers.name} Author`);
76
+ }
77
+
62
78
  console.log(chalk.green(`\n✔ Created code-first block directory: ${chalk.bold(dirName)}`));
63
79
  console.log(chalk.cyan(` → cd ${dirName}`));
64
- console.log(chalk.cyan(` → npm install <your-package>`));
80
+ console.log(chalk.cyan(` → cbs-block tutorial (View the guide!)`));
65
81
  console.log(chalk.cyan(` → cbs-block build`));
66
82
 
67
83
  } else {
@@ -136,31 +152,29 @@ async function main() {
136
152
  console.log(chalk.green(`\n✔ Project ${chalk.bold(answers.projName)} initialized!`));
137
153
 
138
154
  } else if (command === 'pack') {
139
- const files = fs.readdirSync('.').filter(f => f.endsWith('.cbsblock'));
140
- const dirs = fs.readdirSync('.').filter(d => fs.statSync(d).isDirectory() && fs.existsSync(path.join(d, 'metadata.json')));
141
-
142
- console.log(chalk.yellow(`Packing ${files.length} files and ${dirs.length} directories into a .cbspak...`));
155
+ const pkgPath = path.join(process.cwd(), 'package.json');
156
+ if (!fs.existsSync(pkgPath)) {
157
+ // Legacy/Single-file packing (keeping for compatibility)
158
+ const files = fs.readdirSync('.').filter(f => f.endsWith('.cbsblock'));
159
+ const pack = { package: path.basename(process.cwd()), version: "1.0.4", blocks: files.map(f => JSON.parse(fs.readFileSync(f, 'utf8'))) };
160
+ fs.writeFileSync(`${pack.package}.cbspak`, JSON.stringify(pack, null, 2));
161
+ return console.log(chalk.green(`\n✔ Legacy pack created: ${pack.package}.cbspak`));
162
+ }
163
+
164
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
165
+ const packName = `${pkg.name}-${pkg.version}.cbsext`;
166
+ console.log(chalk.yellow(`Bundling professional extension: ${chalk.bold(packName)}...`));
143
167
 
144
- const packedBlocks = [
145
- ...files.map(f => JSON.parse(fs.readFileSync(f, 'utf8'))),
146
- ...dirs.map(d => {
147
- const meta = JSON.parse(fs.readFileSync(path.join(d, 'metadata.json'), 'utf8'));
148
- const indexPath = fs.existsSync(path.join(d, 'index.ts')) ? path.join(d, 'index.ts') : path.join(d, 'index.js');
149
- let logic = fs.readFileSync(indexPath, 'utf8');
150
- if (logic.includes('export function run')) logic = logic.replace('export function run', 'function run');
151
- meta.logic = logic;
152
- return meta;
153
- })
154
- ];
155
-
156
- const pack = {
157
- package: path.basename(process.cwd()),
158
- version: "1.0.0",
159
- blocks: packedBlocks
160
- };
161
- const packName = `${pack.package}.cbspak`;
162
- fs.writeFileSync(packName, JSON.stringify(pack, null, 2));
163
- console.log(chalk.green(`\n✔ Packed ${packedBlocks.length} blocks into ${chalk.bold(packName)}`));
168
+ try {
169
+ // Use tar to create a ZIP (Cross-platform)
170
+ // -a (auto-compress based on extension), -c (create), -f (file)
171
+ // We include everything except node_modules (build command already bundled what's needed)
172
+ execSync(`tar -a -c -f ${packName} --exclude=node_modules .`);
173
+ console.log(chalk.green(`\n✔ Extension packed successfully: ${chalk.bold(packName)}`));
174
+ console.log(chalk.dim(`This file is ready for Marketplace installation.`));
175
+ } catch (e) {
176
+ console.error(chalk.red(`\n✘ Packing failed: ${e.message}`));
177
+ }
164
178
 
165
179
  } else if (command === 'doc' && target) {
166
180
  if (!fs.existsSync(target)) return console.error(chalk.red(`Error: File ${target} not found.`));
@@ -215,6 +229,17 @@ async function main() {
215
229
  console.error(chalk.red(`\n✘ Test Failed: ${e.message}`));
216
230
  }
217
231
 
232
+ } else if (command === 'tutorial') {
233
+ const tutorialPath = path.join(process.cwd(), 'tutorial.html');
234
+ if (fs.existsSync(tutorialPath)) {
235
+ console.log(chalk.cyan(`Opening Developer Guide...`));
236
+ const start = process.platform === 'win32' ? 'start' : process.platform === 'darwin' ? 'open' : 'xdg-open';
237
+ exec(`${start} ${tutorialPath}`);
238
+ } else {
239
+ console.error(chalk.red(`Error: tutorial.html not found in current directory.`));
240
+ console.log(chalk.dim(`Try running 'cbs-block create' to generate a project with a tutorial.`));
241
+ }
242
+
218
243
  } else if (command === 'publish' && target) {
219
244
  if (!fs.existsSync(target)) return console.error(chalk.red(`Error: File ${target} not found.`));
220
245
  const block = JSON.parse(fs.readFileSync(target, 'utf8'));
@@ -293,13 +318,14 @@ async function main() {
293
318
  console.log(chalk.white(`Available commands:`));
294
319
  console.log(` ${chalk.bold('create [name]')} - Create a new block (file or directory)`);
295
320
  console.log(` ${chalk.bold('build [dir]')} - Build a directory block into a .cbsblock`);
296
- console.log(` ${chalk.bold('pack')} - Bundle all blocks in folder into .cbspak`);
321
+ console.log(` ${chalk.bold('pack')} - Bundle workspace into professional .cbsext`);
297
322
  console.log(` ${chalk.bold('init [name]')} - Initialize a new block project`);
298
323
  console.log(` ${chalk.bold('test <file>')} - Run unit tests on a block`);
299
324
  console.log(` ${chalk.bold('dev <file>')} - Watch for changes and re-test`);
300
325
  console.log(` ${chalk.bold('search <query>')} - Search Marketplace from CLI`);
301
326
  console.log(` ${chalk.bold('bench <file>')} - Benchmark block performance`);
302
327
  console.log(` ${chalk.bold('site')} - Generate documentation website`);
328
+ console.log(` ${chalk.bold('tutorial')} - Open integrated developer guide`);
303
329
  console.log(` ${chalk.bold('publish <file>')} - Publish block to CodeBlock Marketplace`);
304
330
  console.log(` ${chalk.bold('version --bump')} - Bump patch version of package`);
305
331
  console.log(` ${chalk.bold('doc <file>')} - Generate markdown documentation`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cbs-block",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "SDK for creating CodeBlock Studio blocks",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -0,0 +1,18 @@
1
+ # {BLOCK_NAME} Extension
2
+
3
+ This is a professional CodeBlock Studio block extension.
4
+
5
+ ## Usage
6
+ 1. Customize the logic in `index.js`.
7
+ 2. Update block metadata in `metadata.json`.
8
+ 3. Build the block: `cbs-block build`.
9
+ 4. Test the block: `cbs-block test`.
10
+
11
+ ## Components
12
+ - `index.js`: The execution logic for your block.
13
+ - `metadata.json`: Defines the block's UI (color, ports, category).
14
+ - `package.json`: NPM manifest for dependencies.
15
+ - `tutorial.html`: Integrated developer guide.
16
+
17
+ ## Publishing
18
+ When ready, run `cbs-block publish` to share your block on the CodeBlock Marketplace.
@@ -0,0 +1,54 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Developer Guide - {BLOCK_NAME}</title>
7
+ <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;800&family=JetBrains+Mono:wght@400;700&display=swap" rel="stylesheet">
8
+ <style>
9
+ :root { --primary: #4caf50; --accent: #1ed760; --bg: #0a0a0c; }
10
+ body { background: var(--bg); color: #e0e0e0; font-family: 'Outfit', sans-serif; line-height: 1.6; margin: 0; }
11
+ .container { max-width: 800px; margin: 4rem auto; padding: 0 2rem; }
12
+ .glass { background: rgba(255, 255, 255, 0.03); border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 24px; padding: 2rem; box-shadow: 0 20px 40px rgba(0,0,0,0.4); }
13
+ h1 { font-size: 2.5rem; background: linear-gradient(45deg, var(--primary), var(--accent)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; margin-bottom: 0.5rem; }
14
+ .badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 6px; background: var(--primary); color: #000; font-weight: 800; font-size: 0.7rem; text-transform: uppercase; margin-bottom: 2rem; }
15
+ pre { background: #000; padding: 1.2rem; border-radius: 12px; border: 1px solid rgba(255,255,255,0.1); overflow-x: auto; font-family: 'JetBrains Mono', monospace; font-size: 0.9rem; }
16
+ code { color: var(--accent); }
17
+ .step { margin-bottom: 2rem; }
18
+ .tip { padding: 1rem; background: rgba(76, 175, 80, 0.1); border-radius: 12px; border-left: 4px solid var(--primary); margin: 1rem 0; }
19
+ </style>
20
+ </head>
21
+ <body>
22
+ <div class="container">
23
+ <div class="glass">
24
+ <div class="badge">Developer Guide</div>
25
+ <h1>Building {BLOCK_NAME}</h1>
26
+ <p>Welcome to your new CodeBlock Studio extension! This guide will help you build and test your block logic.</p>
27
+
28
+ <div class="step">
29
+ <h2>1. Writing Logic</h2>
30
+ <p>Open <code>index.js</code> and edit the <code>run</code> function. This function receives data from your block's input ports.</p>
31
+ <pre><code>function run(inputs) {
32
+ // Your logic here
33
+ return inputs.input1;
34
+ }</code></pre>
35
+ </div>
36
+
37
+ <div class="step">
38
+ <h2>2. Building & Testing</h2>
39
+ <p>Run these commands in your terminal to see your changes in action:</p>
40
+ <pre><code>cbs-block build
41
+ cbs-block test myblock.cbsblock</code></pre>
42
+ </div>
43
+
44
+ <div class="tip">
45
+ <strong>ðŸ’Ą PRO TIP:</strong> You can run <code>npm install <package></code> in this folder and use external libraries in your block logic!
46
+ </div>
47
+
48
+ <footer style="margin-top: 4rem; opacity: 0.4; font-size: 0.8rem; text-align: center;">
49
+ &copy; 2026 CodeBlock Studio SDK. Created with passion.
50
+ </footer>
51
+ </div>
52
+ </div>
53
+ </body>
54
+ </html>