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
10 changes: 5 additions & 5 deletions __tests__/functions/functionDefinition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
});

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 @@ -89,18 +89,18 @@
});

test('stringifying function definitions', async (): Promise<void> => {
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 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":"{}"},{"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":"{}"}]`;

Check warning on line 92 in __tests__/functions/functionDefinition.test.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

`String.raw` should be used to avoid escaping `\`.

See more on https://sonarcloud.io/project/issues?id=bettyblocks_cli&issues=AZ1sHTBO2e01MSbbzvW2&open=AZ1sHTBO2e01MSbbzvW2&pullRequest=502
const definitions = await functionDefinitions(functionsPath);
expect(stringifyDefinitions(definitions)).toEqual(expected);
});

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

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

export default fn;
Expand Down
17 changes: 4 additions & 13 deletions src/functions/publishWasmBlockStoreFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ const publishWasmFunction = async (
}
const functionJson = getFunctionJsonFromDir(functionDir);

if (!functionJson) {
console.log(
chalk.yellow(
`! No function.json file found in ${functionDir}, skipping...`,
),
);
return;
}

const blockName = path.basename(path.dirname(functionPath));

await uploadBlock({
Expand All @@ -64,19 +55,19 @@ const getWasmFileFromDir = (functionDir: string): File | null => {
return null;
};

const getFunctionJsonFromDir = (functionDir: string): string | null => {
const getFunctionJsonFromDir = (functionDir: string): string => {
const functionJsonPath = path.join(functionDir, 'function.json');
const version = path.basename(functionDir);
const name = camelCase(path.basename(path.dirname(functionDir)));
if (fs.existsSync(functionJsonPath)) {
const version = path.basename(functionDir);
const name = camelCase(path.basename(path.dirname(functionDir)));
const json = {
...fs.readJsonSync(functionJsonPath),
name,
version,
};
return stringifyDefinition(json);
}
return null;
return JSON.stringify([{ name, version }]);
};

const stringifyDefinition = (definition: Record<string, unknown>): string => {
Expand Down
Loading