Skip to content
Closed

Beta #500

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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## [26.0.2-beta.2](https://github.com/bettyblocks/cli/compare/v26.0.2-beta.1...v26.0.2-beta.2) (2025-10-23)


### Bug Fixes

* use camelcase from new package to match lodash behaviour ([161f7f2](https://github.com/bettyblocks/cli/commit/161f7f25a2e36cc43ef72721b8c1b08d18096a7a))

## [26.0.2-beta.1](https://github.com/bettyblocks/cli/compare/v26.0.1...v26.0.2-beta.1) (2025-10-23)


### Bug Fixes

* use camelcase from new package to match lodash behaviour ([d4a0cdd](https://github.com/bettyblocks/cli/commit/d4a0cddddc079318398efce82ecda473b769e4c3))

## [26.0.1](https://github.com/bettyblocks/cli/compare/v26.0.0...v26.0.1) (2025-10-09)


Expand Down
22 changes: 18 additions & 4 deletions __tests__/functions/functionDefinition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ test('functionDefinition', async (): Promise<void> => {
});
});

test('functionDefinition name with correct camelCase', async (): Promise<void> => {
const functionPath = path.join(functionsPath, 'jsonToXML', '1.0');
expect(functionDefinition(functionPath, functionsPath)).toMatchObject({
name: 'jsonToXml',
path: path.join(functionPath, 'function.json'),
schema: {
description: 'Convert JSON to XML',
label: 'json to xml',
},
version: '1.0',
});
});

test('creating a new functionDefinition', async (): Promise<void> => {
const tmpFunctionsDir = `tmpFunctions${Math.random().toString()}`;
const tmpFunctionsPath = path.join(supportDir, tmpFunctionsDir);
Expand All @@ -64,7 +77,7 @@ test('creating a new functionDefinition', async (): Promise<void> => {
});

test('functionDefinitions for a directory with functions', async (): Promise<void> => {
const [{ schema }] = await functionDefinitions(functionsPath);
const [, { schema }] = await functionDefinitions(functionsPath);
expect(schema).toMatchObject({
label: 'Say Hello',
});
Expand All @@ -76,16 +89,17 @@ test('functionDefinitions for a directory without functions', async (): Promise<
});

test('stringifying function definitions', async (): Promise<void> => {
const expected =
'[{"name":"sayHello","version":"1.0","description":"Say Hello to the world","label":"Say Hello","category":"Misc","icon":{"name":"ChatIcon","color":"Teal"},"options":"[{\\"meta\\":{\\"type\\":\\"Text\\"},\\"name\\":\\"name\\",\\"label\\":\\"Name\\",\\"info\\":\\"The name that\'s going to be used to say hello to the world!\\",\\"advanced\\":false,\\"configuration\\":{\\"placeholder\\":\\"Betty Blocks\\"}}]","yields":"NONE","paths":"{}"}]';
const expected = `[{"name":"jsonToXml","version":"1.0","description":"Convert JSON to XML","label":"json to xml","category":"Misc","icon":{"name":"ChatIcon","color":"Teal"},"options":"[{\\"meta\\":{\\"type\\":\\"Text\\"},\\"name\\":\\"name\\",\\"label\\":\\"Name\\",\\"info\\":\\"The name of the XML root element.\\",\\"advanced\\":false,\\"configuration\\":{\\"placeholder\\":\\"Betty Blocks\\"}}]","yields":"NONE","paths":"{}"},{"name":"sayHello","version":"1.0","description":"Say Hello to the world","label":"Say Hello","category":"Misc","icon":{"name":"ChatIcon","color":"Teal"},"options":"[{\\"meta\\":{\\"type\\":\\"Text\\"},\\"name\\":\\"name\\",\\"label\\":\\"Name\\",\\"info\\":\\"The name that's going to be used to say hello to the world!\\",\\"advanced\\":false,\\"configuration\\":{\\"placeholder\\":\\"Betty Blocks\\"}}]","yields":"NONE","paths":"{}"}]`;
const definitions = await functionDefinitions(functionsPath);
expect(stringifyDefinitions(definitions)).toEqual(expected);
});

test('generating the package index.js', async (): Promise<void> => {
const expected = `import { default as sayHello_1_0 } from './functions/say-hello/1.0';
const expected = `import { default as jsonToXml_1_0 } from './functions/jsonToXML/1.0';
import { default as sayHello_1_0 } from './functions/say-hello/1.0';

const fn = {
"jsonToXml 1.0": jsonToXml_1_0,
"sayHello 1.0": sayHello_1_0,
};

Expand Down
24 changes: 24 additions & 0 deletions __tests__/support/functions/jsonToXML/1.0/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"description": "Convert JSON to XML",
"label": "json to xml",
"category": "Misc",
"icon": {
"name": "ChatIcon",
"color": "Teal"
},
"options": [
{
"meta": {
"type": "Text"
},
"name": "name",
"label": "Name",
"info": "The name of the XML root element.",
"advanced": false,
"configuration": {
"placeholder": "Betty Blocks"
}
}
],
"yields": "NONE"
}
5 changes: 5 additions & 0 deletions __tests__/support/functions/jsonToXML/1.0/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const jsonToXML = async ({ name }) => {
return `<root>${name}</root>`;
};

export default jsonToXML;
3 changes: 3 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@betty-blocks/cli",
"version": "26.0.1",
"version": "26.0.2-beta.2",
"description": "A Betty Blocks CLI",
"module": "./build/bb.js",
"type": "module",
Expand Down Expand Up @@ -59,6 +59,7 @@
"adm-zip": "0.5.16",
"case": "^1.6.3",
"chalk": "^5.6.2",
"change-case": "^5.4.4",
"commander": "^14.0.1",
"fs-extra": "11.3.2",
"joi": "18.0.1",
Expand All @@ -70,8 +71,8 @@
"prismjs": "1.30.0",
"prompts": "^2.4.2",
"semver": "^7.7.2",
"serve-handler": "6.1.6",
"serve": "^11.1.0",
"serve-handler": "6.1.6",
"ts-node": "10.9.2",
"tsconfig-paths": "^3.15.0",
"typescript": "^5.9.2",
Expand Down
4 changes: 2 additions & 2 deletions src/bb-blocks-new.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { kebab } from 'case';
import { kebabCase } from 'change-case';
import { Command } from 'commander';
import fs from 'fs-extra';
import path from 'path';
Expand All @@ -13,7 +13,7 @@ program
.parse(process.argv);

const { args } = program;
const inputBlockName = kebab(args.join());
const inputBlockName = kebabCase(args.join());

const workingDir = process.cwd();
if (fs.existsSync(path.join(workingDir, '.app-functions'))) {
Expand Down
6 changes: 3 additions & 3 deletions src/functions/createWasmDefinitionFiles.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { snake } from 'case';
import { snakeCase } from 'change-case';
import fs from 'fs-extra';
import path from 'path';

const createlibRsFile = (functionDir: string, functionName: string): void => {
const functionDefName = snake(functionName);
const functionDefName = snakeCase(functionName);
fs.mkdirpSync(path.join(functionDir, 'src'));
fs.writeFileSync(
path.join(functionDir, 'src', 'lib.rs'),
Expand Down Expand Up @@ -59,7 +59,7 @@ const createCargoTomlFile = (
functionDir: string,
functionName: string,
): void => {
const functionDefName = snake(functionName);
const functionDefName = snakeCase(functionName);
fs.writeFileSync(
path.join(functionDir, 'Cargo.toml'),
`[package]
Expand Down
10 changes: 5 additions & 5 deletions src/functions/functionDefinitions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AdmZip from 'adm-zip';
import { Glob } from 'bun';
import { camel, title } from 'case';
import { camelCase, capitalCase } from 'change-case';
import fs from 'fs-extra';
import path from 'path';

Expand Down Expand Up @@ -113,10 +113,10 @@ const functionDefinition = (
let version = '';

if (isFunctionVersion(functionPath, functionsDir)) {
name = camel(path.basename(path.dirname(functionPath)));
name = camelCase(path.basename(path.dirname(functionPath)));
version = path.basename(functionPath);
} else {
name = camel(path.basename(functionPath));
name = camelCase(path.basename(functionPath));
}

const filePath = functionDefinitionPath(functionPath);
Expand Down Expand Up @@ -184,7 +184,7 @@ const newFunctionDefinition = (
category: 'Misc',
description: 'Description',
icon: { color: 'Orange', name: 'ActionsIcon' },
label: title(functionName),
label: capitalCase(functionName),
options: [],
yields: 'NONE',
},
Expand Down Expand Up @@ -238,7 +238,7 @@ const createNewWasmFunction = (
};

const toVariableName = ({ name, version }: FunctionDefinition): string =>
`${camel(name)}_${version.replace('.', '_')}`;
`${camelCase(name)}_${version.replace('.', '_')}`;

/* @doc importFunctions
Returns an array of strings, each item being an imported function:
Expand Down
4 changes: 2 additions & 2 deletions src/functions/publishWasmBlockStoreFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { camel } from 'case';
import chalk from 'chalk';
import { camelCase } from 'change-case';
import fs from 'fs-extra';
import fetch, { fileFromSync, FormData } from 'node-fetch';
import path from 'path';
Expand Down Expand Up @@ -68,7 +68,7 @@ const getFunctionJsonFromDir = (functionDir: string): string | null => {
const functionJsonPath = path.join(functionDir, 'function.json');
if (fs.existsSync(functionJsonPath)) {
const version = path.basename(functionDir);
const name = camel(path.basename(path.dirname(functionDir)));
const name = camelCase(path.basename(path.dirname(functionDir)));
const json = {
...fs.readJsonSync(functionJsonPath),
name,
Expand Down