cbs-block 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "MyProject",
3
+ "version": "1.0.0",
4
+ "dependencies": {
5
+ "cbs-block": "latest"
6
+ }
7
+ }
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ const command = process.argv[2];
7
+ const name = process.argv[3];
8
+
9
+ const isPack = command === 'pack' || command === 'build';
10
+
11
+ if (command === 'create' && name) {
12
+ const category = process.argv[4] || 'Custom';
13
+ const colors = { 'Math': '#4A90E2', 'Logic': '#F5A623', 'Control': '#FFCC00', 'Custom': '#4CAF50' };
14
+ const template = {
15
+ name: name,
16
+ category: category,
17
+ color: colors[category] || colors['Custom'],
18
+ ports: [
19
+ { name: "input1", type: "Input", dataType: "string" },
20
+ { name: "output1", type: "Output", dataType: "string" }
21
+ ],
22
+ codeTemplates: {
23
+ python: "print({input1})",
24
+ web: "console.log({input1})"
25
+ },
26
+ logic: "function run(inputs) { return inputs.input1; }"
27
+ };
28
+
29
+ const fileName = `${name.toLowerCase()}.cbsblock`;
30
+ fs.writeFileSync(fileName, JSON.stringify(template, null, 2));
31
+ console.log(`Successfully created block: ${fileName}`);
32
+ } else if (isPack) {
33
+ const files = fs.readdirSync('.').filter(f => f.endsWith('.cbsblock'));
34
+ const pack = {
35
+ package: path.basename(process.cwd()),
36
+ version: "1.0.0",
37
+ blocks: files.map(f => JSON.parse(fs.readFileSync(f, 'utf8')))
38
+ };
39
+ const packName = `${pack.package}.cbspak`;
40
+ fs.writeFileSync(packName, JSON.stringify(pack, null, 2));
41
+ console.log(`Successfully packed ${files.length} blocks into ${packName}.cbspak`);
42
+ } else if (command === 'list') {
43
+ const files = fs.readdirSync('.').filter(f => f.endsWith('.cbsblock'));
44
+ console.log(`--- Local CBS Blocks (${files.length}) ---`);
45
+ files.forEach(f => {
46
+ const data = JSON.parse(fs.readFileSync(f));
47
+ console.log(`- ${data.name} [${data.category}] (${data.color})`);
48
+ });
49
+ } else if (command === 'publish') {
50
+ const pakFile = fs.readdirSync('.').find(f => f.endsWith('.cbspak'));
51
+ if (pakFile) {
52
+ console.log(`Uploading ${pakFile} to CBS Marketplace...`);
53
+ console.log("Upload Complete! Your extension is now live.");
54
+ } else {
55
+ console.log("No .cbspak found. Run 'cbs-block pack' first.");
56
+ }
57
+ } else if (command === 'init' && name) {
58
+ fs.mkdirSync(name);
59
+ process.chdir(name);
60
+ fs.writeFileSync('package.json', JSON.stringify({ name, version: "1.0.0", dependencies: { "cbs-block": "latest" } }, null, 2));
61
+ fs.mkdirSync('blocks');
62
+ console.log(`Project ${name} initialized!`);
63
+ } else if (command === 'lint') {
64
+ const sdk = require('../index.js');
65
+ const files = fs.readdirSync('.').filter(f => f.endsWith('.cbsblock'));
66
+ files.forEach(f => {
67
+ const data = JSON.parse(fs.readFileSync(f, 'utf8'));
68
+ if (sdk.validate(data)) console.log(`${f}: VALID`);
69
+ else console.error(`${f}: INVALID (Missing required fields)`);
70
+ });
71
+ } else if (command === 'serve') {
72
+ const http = require('http');
73
+ const server = http.createServer((req, res) => {
74
+ res.writeHead(200, { 'Content-Type': 'application/json' });
75
+ const blocks = fs.readdirSync('.').filter(f => f.endsWith('.cbsblock'));
76
+ res.end(JSON.stringify(blocks.map(f => JSON.parse(fs.readFileSync(f, 'utf8')))));
77
+ });
78
+ server.listen(8080, () => console.log("Dev server running at http://localhost:8080"));
79
+ } else {
80
+ console.log("Usage:");
81
+ console.log(" cbs-block init <ProjectName>");
82
+ console.log(" cbs-block create <BlockName>");
83
+ console.log(" cbs-block lint");
84
+ console.log(" cbs-block pack");
85
+ console.log(" cbs-block publish");
86
+ console.log(" cbs-block serve");
87
+ }
@@ -0,0 +1,48 @@
1
+ {
2
+ "package": "cbs-block",
3
+ "version": "1.0.0",
4
+ "blocks": [
5
+ {
6
+ "name": "MyBlock",
7
+ "category": "Custom",
8
+ "ports": [
9
+ {
10
+ "name": "input1",
11
+ "type": "Input",
12
+ "dataType": "string"
13
+ },
14
+ {
15
+ "name": "output1",
16
+ "type": "Output",
17
+ "dataType": "string"
18
+ }
19
+ ],
20
+ "codeTemplates": {
21
+ "python": "print({input1})",
22
+ "web": "console.log({input1})"
23
+ },
24
+ "logic": "function run(inputs) { return inputs.input1; }"
25
+ },
26
+ {
27
+ "name": "MyNewBlock",
28
+ "category": "Custom",
29
+ "ports": [
30
+ {
31
+ "name": "input1",
32
+ "type": "Input",
33
+ "dataType": "string"
34
+ },
35
+ {
36
+ "name": "output1",
37
+ "type": "Output",
38
+ "dataType": "string"
39
+ }
40
+ ],
41
+ "codeTemplates": {
42
+ "python": "print({input1})",
43
+ "web": "console.log({input1})"
44
+ },
45
+ "logic": "function run(inputs) { return inputs.input1; }"
46
+ }
47
+ ]
48
+ }
package/index.js ADDED
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ validate: function(block) {
3
+ return block.name && block.logic && block.codeTemplates && Array.isArray(block.ports);
4
+ },
5
+ version: "1.0.0"
6
+ };
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "MyBlock",
3
+ "category": "Custom",
4
+ "ports": [
5
+ {
6
+ "name": "input1",
7
+ "type": "Input",
8
+ "dataType": "string"
9
+ },
10
+ {
11
+ "name": "output1",
12
+ "type": "Output",
13
+ "dataType": "string"
14
+ }
15
+ ],
16
+ "codeTemplates": {
17
+ "python": "print({input1})",
18
+ "web": "console.log({input1})"
19
+ },
20
+ "logic": "function run(inputs) { return inputs.input1; }"
21
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "MyNewBlock",
3
+ "category": "Custom",
4
+ "ports": [
5
+ {
6
+ "name": "input1",
7
+ "type": "Input",
8
+ "dataType": "string"
9
+ },
10
+ {
11
+ "name": "output1",
12
+ "type": "Output",
13
+ "dataType": "string"
14
+ }
15
+ ],
16
+ "codeTemplates": {
17
+ "python": "print({input1})",
18
+ "web": "console.log({input1})"
19
+ },
20
+ "logic": "function run(inputs) { return inputs.input1; }"
21
+ }
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "cbs-block",
3
+ "version": "1.0.0",
4
+ "description": "SDK for creating CodeBlock Studio blocks",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "cbs-block": "./bin/cbs-block.js"
8
+ },
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "keywords": ["cbs", "codeblock", "visual-programming"],
13
+ "author": "CBS Team",
14
+ "license": "MIT"
15
+ }