fix: Remove block metadata from build.

This commit is contained in:
Sam Tolmay 2021-11-23 15:04:26 +02:00
parent f8fc2cace9
commit 06a4fba06c
No known key found for this signature in database
GPG Key ID: D004126FCD1A6DF0
21 changed files with 20 additions and 2224 deletions

View File

@ -20,14 +20,12 @@ import buildSubBlocks from './buildSubBlocks.js';
import getOperators from './getOperators.js';
import moveSubBlocksToArea from './moveSubBlocksToArea.js';
import setBlockId from './setBlockId.js';
import setBlockMeta from './setBlockMeta.js';
import validateBlock from './validateBlock.js';
async function buildBlock(block, pageContext) {
validateBlock(block, pageContext);
getOperators(block, pageContext);
setBlockId(block, pageContext);
await setBlockMeta(block, pageContext);
buildEvents(block, pageContext);
buildRequests(block, pageContext);
moveSubBlocksToArea(block, pageContext);

View File

@ -25,132 +25,11 @@ const logger = {
log: mockLog,
};
const blockMetas = {
Container: {
category: 'container',
loading: {
type: 'Spinner',
},
moduleFederation: {
scope: 'blocks',
module: 'Container',
url: 'https://example.com/remoteEntry.js',
},
schema: {
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'https://example.com/Container.json',
},
},
List: {
category: 'list',
loading: {
type: 'Spinner',
},
moduleFederation: {
scope: 'blocks',
module: 'List',
url: 'https://example.com/remoteEntry.js',
},
schema: {
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'https://example.com/Container.json',
},
},
Input: {
category: 'input',
valueType: 'string',
loading: {
type: 'SkeletonInput',
},
moduleFederation: {
scope: 'blocks',
module: 'Input',
url: 'https://example.com/remoteEntry.js',
},
schema: {
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'https://example.com/Container.json',
},
},
Display: {
category: 'display',
loading: {
type: 'Spinner',
},
moduleFederation: {
scope: 'blocks',
module: 'Display',
url: 'https://example.com/remoteEntry.js',
},
schema: {
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'https://example.com/Container.json',
},
},
};
const outputMetas = {
Container: {
category: 'container',
moduleFederation: {
scope: 'blocks',
module: 'Container',
url: 'https://example.com/remoteEntry.js',
},
loading: {
type: 'Spinner',
},
},
List: {
category: 'list',
moduleFederation: {
scope: 'blocks',
module: 'List',
url: 'https://example.com/remoteEntry.js',
},
loading: {
type: 'Spinner',
},
valueType: 'array',
},
Input: {
category: 'input',
moduleFederation: {
scope: 'blocks',
module: 'Input',
url: 'https://example.com/remoteEntry.js',
},
valueType: 'string',
loading: {
type: 'SkeletonInput',
},
},
Display: {
category: 'display',
moduleFederation: {
scope: 'blocks',
module: 'Display',
url: 'https://example.com/remoteEntry.js',
},
loading: {
type: 'Spinner',
},
},
};
const auth = {
public: true,
};
const getMeta = (type) => {
const meta = blockMetas[type];
if (!meta) {
return null;
}
return Promise.resolve(meta);
};
const context = testContext({ logger, getMeta });
const context = testContext({ logger });
beforeEach(() => {
mockLogWarn.mockReset();
@ -496,16 +375,6 @@ test("don't throw on Duplicate separate block events action ids", async () => {
},
},
id: 'block:page_1:block_1',
meta: {
category: 'input',
loading: { type: 'SkeletonInput' },
moduleFederation: {
module: 'Input',
scope: 'blocks',
url: 'https://example.com/remoteEntry.js',
},
valueType: 'string',
},
type: 'Input',
});
});

View File

@ -25,83 +25,11 @@ const logger = {
log: mockLog,
};
const blockMetas = {
Container: {
category: 'container',
loading: {
type: 'Spinner',
},
moduleFederation: {
scope: 'blocks',
module: 'Container',
url: 'https://example.com/remoteEntry.js',
},
schema: {
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'https://example.com/Container.json',
},
},
List: {
category: 'list',
loading: {
type: 'Spinner',
},
moduleFederation: {
scope: 'blocks',
module: 'List',
url: 'https://example.com/remoteEntry.js',
},
schema: {
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'https://example.com/Container.json',
},
},
Input: {
category: 'input',
valueType: 'string',
loading: {
type: 'SkeletonInput',
},
moduleFederation: {
scope: 'blocks',
module: 'Input',
url: 'https://example.com/remoteEntry.js',
},
schema: {
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'https://example.com/Container.json',
},
},
Display: {
category: 'display',
loading: {
type: 'Spinner',
},
moduleFederation: {
scope: 'blocks',
module: 'Display',
url: 'https://example.com/remoteEntry.js',
},
schema: {
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'https://example.com/Container.json',
},
},
};
const auth = {
public: true,
};
const getMeta = (type) => {
const meta = blockMetas[type];
if (!meta) {
return null;
}
return Promise.resolve(meta);
};
const context = testContext({ logger, getMeta });
const context = testContext({ logger });
beforeEach(() => {
mockLogWarn.mockReset();

View File

@ -1,42 +0,0 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
async function setBlockMeta(block, { getMeta, pageId }) {
const meta = await getMeta(block.type);
if (!meta) {
throw new Error(
`Invalid block type at "${block.blockId}" on page "${pageId}". Received ${JSON.stringify(
block.type
)}.`
);
}
const { category, loading, moduleFederation, valueType } = meta;
block.meta = { category, loading, moduleFederation };
if (category === 'input') {
block.meta.valueType = valueType;
}
if (category === 'list') {
// include valueType to ensure block has value on init
block.meta.valueType = 'array';
}
// Add user defined loading
if (block.loading) {
block.meta.loading = block.loading;
}
}
export default setBlockMeta;

View File

@ -24,132 +24,11 @@ const logger = {
log: mockLog,
};
const blockMetas = {
Container: {
category: 'container',
loading: {
type: 'Spinner',
},
moduleFederation: {
scope: 'blocks',
module: 'Container',
url: 'https://example.com/remoteEntry.js',
},
schema: {
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'https://example.com/Container.json',
},
},
List: {
category: 'list',
loading: {
type: 'Spinner',
},
moduleFederation: {
scope: 'blocks',
module: 'List',
url: 'https://example.com/remoteEntry.js',
},
schema: {
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'https://example.com/Container.json',
},
},
Input: {
category: 'input',
valueType: 'string',
loading: {
type: 'SkeletonInput',
},
moduleFederation: {
scope: 'blocks',
module: 'Input',
url: 'https://example.com/remoteEntry.js',
},
schema: {
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'https://example.com/Container.json',
},
},
Display: {
category: 'display',
loading: {
type: 'Spinner',
},
moduleFederation: {
scope: 'blocks',
module: 'Display',
url: 'https://example.com/remoteEntry.js',
},
schema: {
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'https://example.com/Container.json',
},
},
};
const outputMetas = {
Container: {
category: 'container',
moduleFederation: {
scope: 'blocks',
module: 'Container',
url: 'https://example.com/remoteEntry.js',
},
loading: {
type: 'Spinner',
},
},
List: {
category: 'list',
moduleFederation: {
scope: 'blocks',
module: 'List',
url: 'https://example.com/remoteEntry.js',
},
loading: {
type: 'Spinner',
},
valueType: 'array',
},
Input: {
category: 'input',
moduleFederation: {
scope: 'blocks',
module: 'Input',
url: 'https://example.com/remoteEntry.js',
},
valueType: 'string',
loading: {
type: 'SkeletonInput',
},
},
Display: {
category: 'display',
moduleFederation: {
scope: 'blocks',
module: 'Display',
url: 'https://example.com/remoteEntry.js',
},
loading: {
type: 'Spinner',
},
},
};
const auth = {
public: true,
};
const getMeta = (type) => {
const meta = blockMetas[type];
if (!meta) {
return null;
}
return Promise.resolve(meta);
};
const context = testContext({ logger, getMeta });
const context = testContext({ logger });
beforeEach(() => {
mockLogWarn.mockReset();
@ -292,42 +171,6 @@ test('block type missing', async () => {
);
});
test('invalid page type', async () => {
const components = {
pages: [
{
id: 'page1',
type: 'NotABlock',
auth,
},
],
};
await expect(buildPages({ components, context })).rejects.toThrow(
'Invalid block type at "page1" on page "page1". Received "NotABlock".'
);
});
test('invalid block type', async () => {
const components = {
pages: [
{
id: 'page1',
type: 'Container',
auth,
blocks: [
{
id: 'blockId',
type: 'NotABlock',
},
],
},
],
};
await expect(buildPages({ components, context })).rejects.toThrow(
'Invalid block type at "blockId" on page "page1". Received "NotABlock".'
);
});
test('page type not a string', async () => {
const components = {
pages: [
@ -384,7 +227,6 @@ test('no blocks on page', async () => {
pageId: '1',
blockId: '1',
type: 'Container',
meta: outputMetas.Container,
requests: [],
},
],
@ -421,71 +263,6 @@ test('block not an object', async () => {
);
});
test('block meta should include all meta fields', async () => {
const components = {
pages: [
{
id: 'page_1',
type: 'Container',
auth,
blocks: [
{
id: 'block_1',
type: 'Input',
},
{
id: 'block_2',
type: 'Display',
},
{
id: 'block_3',
type: 'List',
},
],
},
],
};
const res = await buildPages({ components, context });
expect(res).toEqual({
pages: [
{
id: 'page:page_1',
auth: { public: true },
operators: [],
pageId: 'page_1',
blockId: 'page_1',
type: 'Container',
meta: outputMetas.Container,
requests: [],
areas: {
content: {
blocks: [
{
id: 'block:page_1:block_1',
blockId: 'block_1',
type: 'Input',
meta: outputMetas.Input,
},
{
id: 'block:page_1:block_2',
blockId: 'block_2',
type: 'Display',
meta: outputMetas.Display,
},
{
id: 'block:page_1:block_3',
blockId: 'block_3',
type: 'List',
meta: outputMetas.List,
},
],
},
},
},
],
});
});
test('nested blocks', async () => {
const components = {
pages: [
@ -518,7 +295,6 @@ test('nested blocks', async () => {
pageId: 'page_1',
blockId: 'page_1',
type: 'Container',
meta: outputMetas.Container,
requests: [],
areas: {
content: {
@ -527,7 +303,6 @@ test('nested blocks', async () => {
id: 'block:page_1:block_1',
blockId: 'block_1',
type: 'Container',
meta: outputMetas.Container,
areas: {
content: {
blocks: [
@ -535,7 +310,6 @@ test('nested blocks', async () => {
id: 'block:page_1:block_2',
blockId: 'block_2',
type: 'Input',
meta: outputMetas.Input,
},
],
},
@ -593,7 +367,6 @@ describe('block areas', () => {
operators: [],
pageId: 'page1',
type: 'Container',
meta: outputMetas.Container,
requests: [],
areas: {
content: {
@ -635,7 +408,6 @@ describe('block areas', () => {
operators: [],
pageId: '1',
type: 'Container',
meta: outputMetas.Container,
requests: [],
areas: {
content: {
@ -644,7 +416,6 @@ describe('block areas', () => {
id: 'block:1:block1',
blockId: 'block1',
type: 'Input',
meta: outputMetas.Input,
},
],
},
@ -685,7 +456,6 @@ describe('block areas', () => {
operators: [],
blockId: '1',
type: 'Container',
meta: outputMetas.Container,
requests: [],
areas: {
content: {
@ -695,7 +465,6 @@ describe('block areas', () => {
id: 'block:1:block1',
blockId: 'block1',
type: 'Input',
meta: outputMetas.Input,
},
],
},
@ -743,7 +512,6 @@ describe('block areas', () => {
pageId: '1',
blockId: '1',
type: 'Container',
meta: outputMetas.Container,
requests: [],
areas: {
content: {
@ -752,7 +520,6 @@ describe('block areas', () => {
id: 'block:1:textInput',
blockId: 'textInput',
type: 'Input',
meta: outputMetas.Input,
},
],
},
@ -762,7 +529,6 @@ describe('block areas', () => {
id: 'block:1:avatar',
blockId: 'avatar',
type: 'Display',
meta: outputMetas.Display,
},
],
},
@ -808,7 +574,6 @@ describe('block areas', () => {
pageId: '1',
blockId: '1',
type: 'Container',
meta: outputMetas.Container,
requests: [],
areas: {
content: {
@ -817,7 +582,6 @@ describe('block areas', () => {
id: 'block:1:textInput',
blockId: 'textInput',
type: 'Input',
meta: outputMetas.Input,
},
],
},
@ -827,7 +591,6 @@ describe('block areas', () => {
id: 'block:1:avatar',
blockId: 'avatar',
type: 'Display',
meta: outputMetas.Display,
},
],
},
@ -881,7 +644,6 @@ describe('block areas', () => {
pageId: '1',
blockId: '1',
type: 'Container',
meta: outputMetas.Container,
requests: [],
areas: {
content: {
@ -890,7 +652,6 @@ describe('block areas', () => {
id: 'block:1:textInput',
blockId: 'textInput',
type: 'Input',
meta: outputMetas.Input,
},
],
},
@ -900,7 +661,6 @@ describe('block areas', () => {
id: 'block:1:avatar',
blockId: 'avatar',
type: 'Display',
meta: outputMetas.Display,
},
],
},
@ -970,7 +730,6 @@ describe('block areas', () => {
pageId: '1',
blockId: '1',
type: 'Container',
meta: outputMetas.Container,
requests: [],
areas: {
content: {
@ -979,7 +738,6 @@ describe('block areas', () => {
id: 'block:1:card',
blockId: 'card',
type: 'Container',
meta: outputMetas.Container,
areas: {
content: {
blocks: [
@ -987,7 +745,6 @@ describe('block areas', () => {
id: 'block:1:card2',
blockId: 'card2',
type: 'Container',
meta: outputMetas.Container,
areas: {
title: {
blocks: [
@ -995,7 +752,6 @@ describe('block areas', () => {
id: 'block:1:title',
blockId: 'title',
type: 'Display',
meta: outputMetas.Display,
},
],
},
@ -1005,7 +761,6 @@ describe('block areas', () => {
id: 'block:1:textInput',
blockId: 'textInput',
type: 'Input',
meta: outputMetas.Input,
},
],
},
@ -1019,7 +774,6 @@ describe('block areas', () => {
id: 'block:1:avatar',
blockId: 'avatar',
type: 'Display',
meta: outputMetas.Display,
},
],
},
@ -1034,7 +788,7 @@ describe('block areas', () => {
});
});
test('add user defined loading to meta', async () => {
test('user defined loading', async () => {
const components = {
pages: [
{
@ -1069,17 +823,6 @@ test('add user defined loading to meta', async () => {
loading: {
custom: true,
},
meta: {
category: 'container',
moduleFederation: {
scope: 'blocks',
module: 'Container',
url: 'https://example.com/remoteEntry.js',
},
loading: {
custom: true,
},
},
requests: [],
areas: {
content: {
@ -1091,18 +834,6 @@ test('add user defined loading to meta', async () => {
loading: {
custom: true,
},
meta: {
category: 'input',
moduleFederation: {
scope: 'blocks',
module: 'Input',
url: 'https://example.com/remoteEntry.js',
},
valueType: 'string',
loading: {
custom: true,
},
},
},
],
},

View File

@ -24,132 +24,11 @@ const logger = {
log: mockLog,
};
const blockMetas = {
Container: {
category: 'container',
loading: {
type: 'Spinner',
},
moduleFederation: {
scope: 'blocks',
module: 'Container',
url: 'https://example.com/remoteEntry.js',
},
schema: {
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'https://example.com/Container.json',
},
},
List: {
category: 'list',
loading: {
type: 'Spinner',
},
moduleFederation: {
scope: 'blocks',
module: 'List',
url: 'https://example.com/remoteEntry.js',
},
schema: {
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'https://example.com/Container.json',
},
},
Input: {
category: 'input',
valueType: 'string',
loading: {
type: 'SkeletonInput',
},
moduleFederation: {
scope: 'blocks',
module: 'Input',
url: 'https://example.com/remoteEntry.js',
},
schema: {
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'https://example.com/Container.json',
},
},
Display: {
category: 'display',
loading: {
type: 'Spinner',
},
moduleFederation: {
scope: 'blocks',
module: 'Display',
url: 'https://example.com/remoteEntry.js',
},
schema: {
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'https://example.com/Container.json',
},
},
};
const outputMetas = {
Container: {
category: 'container',
moduleFederation: {
scope: 'blocks',
module: 'Container',
url: 'https://example.com/remoteEntry.js',
},
loading: {
type: 'Spinner',
},
},
List: {
category: 'list',
moduleFederation: {
scope: 'blocks',
module: 'List',
url: 'https://example.com/remoteEntry.js',
},
loading: {
type: 'Spinner',
},
valueType: 'array',
},
Input: {
category: 'input',
moduleFederation: {
scope: 'blocks',
module: 'Input',
url: 'https://example.com/remoteEntry.js',
},
valueType: 'string',
loading: {
type: 'SkeletonInput',
},
},
Display: {
category: 'display',
moduleFederation: {
scope: 'blocks',
module: 'Display',
url: 'https://example.com/remoteEntry.js',
},
loading: {
type: 'Spinner',
},
},
};
const auth = {
public: true,
};
const getMeta = (type) => {
const meta = blockMetas[type];
if (!meta) {
return null;
}
return Promise.resolve(meta);
};
const context = testContext({ logger, getMeta });
const context = testContext({ logger });
beforeEach(() => {
mockLogWarn.mockReset();
@ -309,7 +188,6 @@ test('give request an id', async () => {
pageId: 'page_1',
blockId: 'page_1',
type: 'Container',
meta: outputMetas.Container,
requests: [
{
id: 'request:page_1:request_1',
@ -355,7 +233,6 @@ test('request on a sub-block', async () => {
operators: [],
pageId: 'page_1',
type: 'Container',
meta: outputMetas.Container,
requests: [
{
id: 'request:page_1:request_1',
@ -372,7 +249,6 @@ test('request on a sub-block', async () => {
id: 'block:page_1:box',
blockId: 'box',
type: 'Container',
meta: outputMetas.Container,
},
],
},
@ -410,7 +286,6 @@ test('multiple requests', async () => {
pageId: 'page_1',
blockId: 'page_1',
type: 'Container',
meta: outputMetas.Container,
requests: [
{
id: 'request:page_1:request_1',
@ -467,7 +342,6 @@ test('set auth to request', async () => {
pageId: 'page_1',
blockId: 'page_1',
type: 'Container',
meta: outputMetas.Container,
requests: [
{
id: 'request:page_1:request_1',
@ -485,7 +359,6 @@ test('set auth to request', async () => {
pageId: 'page_2',
blockId: 'page_2',
type: 'Container',
meta: outputMetas.Container,
requests: [
{
id: 'request:page_2:request_2',

View File

@ -14,23 +14,18 @@
limitations under the License.
*/
import { cleanDirectory } from '@lowdefy/node-utils';
import cleanBuildDirectory from './cleanBuildDirectory.js';
jest.mock('@lowdefy/node-utils', () => {
return {
cleanDirectory: jest.fn(),
};
});
beforeEach(() => {
cleanDirectory.mockReset();
});
test('cleanOutputDirectory calls cleanDirectory', async () => {
const nodeUtils = await import('@lowdefy/node-utils');
const cleanBuildDirectory = await import('./cleanBuildDirectory.js');
const context = {
buildDirectory: 'buildDirectory',
};
await cleanBuildDirectory({ context });
expect(cleanDirectory.mock.calls).toEqual([['buildDirectory']]);
await cleanBuildDirectory.default({ context });
expect(nodeUtils.cleanDirectory.mock.calls).toEqual([['buildDirectory']]);
});

View File

@ -1,12 +0,0 @@
{
"moduleFederation": {
"remoteEntryUrl": "https://unpkg.com/@lowdefy/blocks-antd@1.0.0-experimental.1/dist/remoteEntry.js",
"scope": "lowdefy_blocks_antd",
"module": "Button"
},
"category": "display",
"loading": {
"type": "SkeletonButton"
},
"schema": {}
}

View File

@ -15,9 +15,6 @@
*/
import path from 'path';
import { readFile } from '@lowdefy/node-utils';
import createReadConfigFile from './readConfigFile.js';
jest.mock('@lowdefy/node-utils', () => {
return {
@ -27,25 +24,25 @@ jest.mock('@lowdefy/node-utils', () => {
const configDirectory = './config';
beforeEach(() => {
readFile.mockReset();
});
test('readConfigFile reads a file from the correct dir', async () => {
const readConfigFile = createReadConfigFile({ configDirectory });
readFile.mockImplementation(() => 'Text file content');
const nodeUtils = await import('@lowdefy/node-utils');
const createReadConfigFile = await import('./readConfigFile.js');
const readConfigFile = createReadConfigFile.default({ configDirectory });
nodeUtils.readFile.mockImplementation(() => 'Text file content');
const res = await readConfigFile('file.txt');
expect(res).toEqual('Text file content');
expect(readFile.mock.calls).toEqual([[path.resolve(configDirectory, 'file.txt')]]);
expect(nodeUtils.readFile.mock.calls).toEqual([[path.resolve(configDirectory, 'file.txt')]]);
});
test('readConfigFile memoizes results', async () => {
const readConfigFile = createReadConfigFile({ configDirectory });
readFile.mockImplementation(() => 'Text file content');
const nodeUtils = await import('@lowdefy/node-utils');
const createReadConfigFile = await import('./readConfigFile.js');
const readConfigFile = createReadConfigFile.default({ configDirectory });
nodeUtils.readFile.mockImplementation(() => 'Text file content');
const res1 = await readConfigFile('file.txt');
expect(res1).toEqual('Text file content');
expect(readFile.mock.calls).toEqual([[path.resolve(configDirectory, 'file.txt')]]);
expect(nodeUtils.readFile.mock.calls).toEqual([[path.resolve(configDirectory, 'file.txt')]]);
const res2 = await readConfigFile('file.txt');
expect(res2).toEqual('Text file content');
expect(readFile.mock.calls).toEqual([[path.resolve(configDirectory, 'file.txt')]]);
expect(nodeUtils.readFile.mock.calls).toEqual([[path.resolve(configDirectory, 'file.txt')]]);
});

View File

@ -1,39 +0,0 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { type } from '@lowdefy/helpers';
function createCacheKey(location) {
if (type.isNone(location)) {
throw new Error('Failed to create cache key, location is undefined.');
}
if (!type.isString(location.url)) {
throw new Error('Location url definition should be a string.');
}
return (
location.url
// Replace all non alphanumeric characters (or _ - ) with a _
.replace(/~/g, '_tilde_')
.replace(/\^/g, '_caret_')
.replace(/\*/g, '_star_')
.replace(/[^a-zA-Z0-9-_]/g, '_')
.toLowerCase()
// Replace _json at end of the file with .json
.replace(/_json$/, '.json')
);
}
export default createCacheKey;

View File

@ -1,77 +0,0 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import createCacheKey from './createCacheKey.js';
test('createCacheKey converts a url to a file safe string', () => {
const location = {
url: 'https://unpkg.com/@lowdefy/blocks-antd@1.0.0/dist/Button.json',
};
expect(createCacheKey(location)).toEqual(
'https___unpkg_com__lowdefy_blocks-antd_1_0_0_dist_button.json'
);
});
test('createCacheKey replaces semantic versioning special characters', () => {
const location = {
url: '^~*',
};
expect(createCacheKey(location)).toEqual('_caret__tilde__star_');
});
test('createCacheKey semantic versioning special characters do not clash', () => {
const locationCaret = {
url: 'https://unpkg.com/@lowdefy/blocks-antd@^1.0.0/dist/button.json',
};
const locationTilde = {
url: 'https://unpkg.com/@lowdefy/blocks-antd@~1.0.0/dist/button.json',
};
expect(createCacheKey(locationCaret)).toEqual(
'https___unpkg_com__lowdefy_blocks-antd__caret_1_0_0_dist_button.json'
);
expect(createCacheKey(locationTilde)).toEqual(
'https___unpkg_com__lowdefy_blocks-antd__tilde_1_0_0_dist_button.json'
);
});
test('createCacheKey converts to lowercase', () => {
const location = {
url: 'UPPERCASE',
};
expect(createCacheKey(location)).toEqual('uppercase');
});
test('createCacheKey converts all non alphanumerics', () => {
const location = {
url: `!@#$%&()+=±§[]{};:"'\\|\`,.<>/?`,
};
expect(createCacheKey(location)).toEqual('_____________________________');
});
test('createCacheKey only replaces _json at then end of the string', () => {
const location = {
url: 'ABC$jsonDEF.jsonHIJ.json',
};
expect(createCacheKey(location)).toEqual('abc_jsondef_jsonhij.json');
});
test('createCacheKey throws if location is undefined', () => {
expect(() => createCacheKey()).toThrow('Failed to create cache key, location is undefined.');
});
test('createCacheKey throws if location url is not a string', () => {
expect(() => createCacheKey({ url: 1 })).toThrow('Location url definition should be a string.');
});

View File

@ -1,30 +0,0 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import path from 'path';
import { readFile } from '@lowdefy/node-utils';
import createCacheKey from './createCacheKey.js';
function createFetchMetaCache({ cacheDirectory }) {
async function fetchMetaCache(location) {
const cacheKey = createCacheKey(location);
const fileContent = await readFile(path.resolve(cacheDirectory, 'meta/', cacheKey));
return JSON.parse(fileContent);
}
return fetchMetaCache;
}
export default createFetchMetaCache;

View File

@ -1,43 +0,0 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import path from 'path';
import createFetchMetaCache from './fetchMetaCache.js';
const cacheDirectory = path.resolve(process.cwd(), 'src/test/fetchMetaCache');
const fetchMetaCache = createFetchMetaCache({ cacheDirectory });
test('fetchMetaCache fetches from cache', async () => {
const meta = await fetchMetaCache({ url: 'cachekey.json' });
expect(meta).toEqual({
moduleFederation: {
remoteEntryUrl:
'https://unpkg.com/@lowdefy/blocks-antd@1.0.0-experimental.1/dist/remoteEntry.js',
scope: 'lowdefy_blocks_antd',
module: 'Button',
},
category: 'display',
loading: {
type: 'SkeletonButton',
},
schema: {},
});
});
test('fetchMetaCache returns null if not found', async () => {
const meta = await fetchMetaCache({ url: 'doesNotExist.json' });
expect(meta).toEqual(null);
});

View File

@ -1,41 +0,0 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import axios from 'axios';
import { type as typeHelper } from '@lowdefy/helpers';
async function fetchMetaUrl({ location, type } = {}) {
if (typeHelper.isNone(location)) {
throw new Error('Failed to fetch meta, location is undefined.');
}
if (!typeHelper.isString(location.url)) {
throw new Error(`Block type ${JSON.stringify(type)} url definition should be a string.`);
}
let res;
try {
res = await axios.get(location.url);
} catch (error) {
if (error.response && error.response.status === 404) {
throw new Error(
`Meta for type ${JSON.stringify(type)} could not be found at ${JSON.stringify(location)}.`
);
}
throw error;
}
return res.data;
}
export default fetchMetaUrl;

View File

@ -1,91 +0,0 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// eslint-disable-next-line no-unused-vars
import axios from 'axios';
import fetchMetaUrl from './fetchMetaUrl.js';
const type = 'Type';
jest.mock('axios', () => {
return {
get: (url) => {
if (url === 'valid-url') {
return Promise.resolve({ data: { key: 'value' } });
}
if (url === '404') {
const error = new Error('Test 404');
error.response = {};
error.response.status = 404;
throw error;
}
throw new Error('Invalid url');
},
};
});
test('fetchMetaUrl fetches from url', async () => {
const meta = await fetchMetaUrl({
type,
location: {
url: 'valid-url',
},
});
expect(meta).toEqual({ key: 'value' });
});
test('fetchMetaUrl request errors', async () => {
await expect(
fetchMetaUrl({
type,
location: {
url: 'invalid-url',
},
})
).rejects.toThrow('Invalid url');
});
test('fetchMetaUrl throws if args are undefined', async () => {
await expect(fetchMetaUrl()).rejects.toThrow('Failed to fetch meta, location is undefined.');
});
test('fetchMetaUrl throws if location is undefined', async () => {
await expect(fetchMetaUrl({ type })).rejects.toThrow(
'Failed to fetch meta, location is undefined.'
);
});
test('fetchMetaUrl throws if location is not a string', async () => {
await expect(
fetchMetaUrl({
type,
location: {
url: 1,
},
})
).rejects.toThrow('Block type "Type" url definition should be a string.');
});
test('fetchMetaUrl throws if response returns a 404 not found', async () => {
await expect(
fetchMetaUrl({
type,
location: {
url: '404',
},
})
).rejects.toThrow('Meta for type "Type" could not be found at {"url":"404"}.');
});

View File

@ -1,78 +0,0 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Steps to fetch meta
- check in cache
- in cache
- return
- not in cache
- fetch url
- write cache
- return
*/
import { cachedPromises, type as typeHelper } from '@lowdefy/helpers';
import createFetchMetaCache from './fetchMetaCache.js';
import createWriteMetaCache from './writeMetaCache.js';
import metaLocations from './metaLocations.js';
import fetchMetaUrl from './fetchMetaUrl.js';
function createGetMeta({ components, context }) {
const { cacheDirectory } = context;
const { types } = components;
const allMetaLocations = {
...metaLocations(context),
...types,
};
const fetchMetaCache = createFetchMetaCache({ cacheDirectory });
const writeMetaCache = createWriteMetaCache({ cacheDirectory });
async function getMeta(type) {
const location = allMetaLocations[type];
if (!location) {
throw new Error(
`Block type ${JSON.stringify(type)} is not defined. Specify type url in types array.`
);
}
const cacheMeta = !location.url.startsWith('http://localhost:');
let meta;
if (cacheMeta) {
meta = await fetchMetaCache(location);
if (meta) {
return meta;
}
}
meta = await fetchMetaUrl({ location, type });
// TODO: implement Ajv schema check. Use testAjvSchema func from @lowdefy/ajv
if (meta && typeHelper.isString(meta.category) && meta.moduleFederation) {
if (cacheMeta) {
await writeMetaCache({ location, meta });
}
return meta;
}
throw new Error(
`Block type ${JSON.stringify(type)} has invalid block meta at ${JSON.stringify(location)}.`
);
}
return cachedPromises(getMeta);
}
export default createGetMeta;

View File

@ -1,231 +0,0 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import createGetMeta from './getMeta.js';
import createFetchMetaCache from './fetchMetaCache.js';
import createWriteMetaCache from './writeMetaCache.js';
import fetchMetaUrl from './fetchMetaUrl.js';
// eslint-disable-next-line no-unused-vars
import metaLocations from './metaLocations.js';
jest.mock('./fetchMetaCache', () => {
const mockFetchMetaCache = jest.fn();
return () => mockFetchMetaCache;
});
jest.mock('./writeMetaCache', () => {
const mockWriteMetaCache = jest.fn();
return () => mockWriteMetaCache;
});
jest.mock('./fetchMetaUrl', () => {
const mockFetchMetaUrl = jest.fn();
return mockFetchMetaUrl;
});
jest.mock('./metaLocations', () => {
const mockMetaLocations = jest.fn(() => ({
DefaultType: {
url: 'defaultTypeUrl',
},
}));
return mockMetaLocations;
});
const mockFetchMetaCache = createFetchMetaCache();
const mockWriteMetaCache = createWriteMetaCache();
const mockFetchMetaUrl = fetchMetaUrl;
const types = {
Type1: {
url: 'type1Url',
},
Type2: {
url: 'type2Url',
},
Localhost: {
url: 'http://localhost:3003/meta/Block.json',
},
};
const defaultMeta = {
category: 'input',
moduleFederation: {
module: 'Module',
scope: 'scope',
version: '1.0.0',
remoteEntryUrl: `http://localhost:3002/remoteEntry.js`,
},
};
const components = { types };
const context = { cacheDirectory: 'cacheDirectory' };
beforeEach(() => {
mockFetchMetaCache.mockReset();
mockWriteMetaCache.mockReset();
mockFetchMetaUrl.mockReset();
});
test('getMeta cache returns from cache', async () => {
const getMeta = createGetMeta({ components, context });
mockFetchMetaCache.mockImplementation((location) => {
if (location && location.url === 'type1Url') {
return defaultMeta;
}
return null;
});
const res = await getMeta('Type1');
expect(res).toEqual(defaultMeta);
});
test('getMeta fetches from url and writes to cache', async () => {
const getMeta = createGetMeta({ components, context });
mockFetchMetaUrl.mockImplementation(({ location }) => {
if (location && location.url === 'type1Url') {
return defaultMeta;
}
return null;
});
const res = await getMeta('Type1');
expect(res).toEqual(defaultMeta);
expect(mockWriteMetaCache.mock.calls).toEqual([
[
{
location: {
url: 'type1Url',
},
meta: defaultMeta,
},
],
]);
});
test('getMeta uses locations from metaLocations', async () => {
const getMeta = createGetMeta({ components, context });
mockFetchMetaCache.mockImplementation((location) => {
if (location && location.url === 'defaultTypeUrl') {
return defaultMeta;
}
return null;
});
const res = await getMeta('DefaultType');
expect(res).toEqual(defaultMeta);
});
test('getMeta type not in types', async () => {
const getMeta = createGetMeta({ components, context });
await expect(getMeta('Undefined')).rejects.toThrow(
'Block type "Undefined" is not defined. Specify type url in types array.'
);
});
test('getMeta undefined type', async () => {
const getMeta = createGetMeta({ components, context });
await expect(getMeta()).rejects.toThrow(
'Block type undefined is not defined. Specify type url in types array.'
);
});
test('getMeta meta not found in cache or url', async () => {
const getMeta = createGetMeta({ components, context });
await expect(getMeta('Type2')).rejects.toThrow(
'Block type "Type2" has invalid block meta at {"url":"type2Url"}.'
);
});
test('getMeta invalid meta', async () => {
const getMeta = createGetMeta({ components, context });
mockFetchMetaUrl.mockImplementation(() => ({ invalidMeta: true }));
await expect(getMeta('Type2')).rejects.toThrow(
'Block type "Type2" has invalid block meta at {"url":"type2Url"}.'
);
});
test('getMeta fetches from url and does not write to cache if location is localhost', async () => {
const getMeta = createGetMeta({ components, context });
mockFetchMetaUrl.mockImplementation(({ location }) => {
if (location && location.url === 'http://localhost:3003/meta/Block.json') {
return defaultMeta;
}
return null;
});
const res = await getMeta('Localhost');
expect(res).toEqual(defaultMeta);
expect(mockFetchMetaCache.mock.calls).toEqual([]);
expect(mockWriteMetaCache.mock.calls).toEqual([]);
});
test('getMeta meta is memoised when returned from cache', async () => {
const getMeta = createGetMeta({ components, context });
mockFetchMetaCache.mockImplementation((location) => {
if (location && location.url === 'defaultTypeUrl') {
return defaultMeta;
}
return null;
});
await getMeta('DefaultType');
await getMeta('DefaultType');
expect(mockFetchMetaCache.mock.calls).toEqual([
[
{
url: 'defaultTypeUrl',
},
],
]);
});
test('getMeta meta is memoised when returned from cache', async () => {
const getMeta = createGetMeta({ components, context });
mockFetchMetaUrl.mockImplementation(({ location }) => {
if (location && location.url === 'defaultTypeUrl') {
return defaultMeta;
}
return null;
});
await getMeta('DefaultType');
await getMeta('DefaultType');
expect(mockFetchMetaCache.mock.calls).toEqual([
[
{
url: 'defaultTypeUrl',
},
],
]);
expect(mockFetchMetaUrl.mock.calls).toEqual([
[
{
location: {
url: 'defaultTypeUrl',
},
type: 'DefaultType',
},
],
]);
});
test('The correct params are passed to metaLocations', async () => {
createGetMeta({
components,
context: { blocksServerUrl: 'blocksServerUrl', version: 'v1.0.0' },
});
expect(metaLocations.mock.calls).toEqual([
[
{
blocksServerUrl: 'blocksServerUrl',
version: 'v1.0.0',
},
],
]);
});

View File

@ -1,290 +0,0 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { type } from '@lowdefy/helpers';
function metaLocations({ blocksServerUrl, version }) {
let baseUrl = blocksServerUrl;
if (type.isNone(baseUrl)) {
baseUrl = `https://blocks-cdn.lowdefy.com/v${version}`;
}
return {
// @lowdefy/blocks-basic
Context: {
url: `${baseUrl}/blocks-basic/meta/Context.json`,
},
Box: {
url: `${baseUrl}/blocks-basic/meta/Box.json`,
},
DangerousHtml: {
url: `${baseUrl}/blocks-basic/meta/DangerousHtml.json`,
},
Html: {
url: `${baseUrl}/blocks-basic/meta/Html.json`,
},
Img: {
url: `${baseUrl}/blocks-basic/meta/Img.json`,
},
List: {
url: `${baseUrl}/blocks-basic/meta/List.json`,
},
Span: {
url: `${baseUrl}/blocks-basic/meta/Span.json`,
},
// @lowdefy/blocks-antd
Affix: {
url: `${baseUrl}/blocks-antd/meta/Affix.json`,
},
Alert: {
url: `${baseUrl}/blocks-antd/meta/Alert.json`,
},
Anchor: {
url: `${baseUrl}/blocks-antd/meta/Anchor.json`,
},
AutoComplete: {
url: `${baseUrl}/blocks-antd/meta/AutoComplete.json`,
},
Avatar: {
url: `${baseUrl}/blocks-antd/meta/Avatar.json`,
},
Badge: {
url: `${baseUrl}/blocks-antd/meta/Badge.json`,
},
Breadcrumb: {
url: `${baseUrl}/blocks-antd/meta/Breadcrumb.json`,
},
Button: {
url: `${baseUrl}/blocks-antd/meta/Button.json`,
},
ButtonSelector: {
url: `${baseUrl}/blocks-antd/meta/ButtonSelector.json`,
},
Card: {
url: `${baseUrl}/blocks-antd/meta/Card.json`,
},
CheckboxSelector: {
url: `${baseUrl}/blocks-antd/meta/CheckboxSelector.json`,
},
CheckboxSwitch: {
url: `${baseUrl}/blocks-antd/meta/CheckboxSwitch.json`,
},
Collapse: {
url: `${baseUrl}/blocks-antd/meta/Collapse.json`,
},
Comment: {
url: `${baseUrl}/blocks-antd/meta/Comment.json`,
},
ConfirmModal: {
url: `${baseUrl}/blocks-antd/meta/ConfirmModal.json`,
},
Content: {
url: `${baseUrl}/blocks-antd/meta/Content.json`,
},
ControlledList: {
url: `${baseUrl}/blocks-antd/meta/ControlledList.json`,
},
DateRangeSelector: {
url: `${baseUrl}/blocks-antd/meta/DateRangeSelector.json`,
},
DateSelector: {
url: `${baseUrl}/blocks-antd/meta/DateSelector.json`,
},
DateTimeSelector: {
url: `${baseUrl}/blocks-antd/meta/DateTimeSelector.json`,
},
Descriptions: {
url: `${baseUrl}/blocks-antd/meta/Descriptions.json`,
},
Divider: {
url: `${baseUrl}/blocks-antd/meta/Divider.json`,
},
Drawer: {
url: `${baseUrl}/blocks-antd/meta/Drawer.json`,
},
Footer: {
url: `${baseUrl}/blocks-antd/meta/Footer.json`,
},
Header: {
url: `${baseUrl}/blocks-antd/meta/Header.json`,
},
Icon: {
url: `${baseUrl}/blocks-antd/meta/Icon.json`,
},
Label: {
url: `${baseUrl}/blocks-antd/meta/Label.json`,
},
Layout: {
url: `${baseUrl}/blocks-antd/meta/Layout.json`,
},
Menu: {
url: `${baseUrl}/blocks-antd/meta/Menu.json`,
},
Message: {
url: `${baseUrl}/blocks-antd/meta/Message.json`,
},
MobileMenu: {
url: `${baseUrl}/blocks-antd/meta/MobileMenu.json`,
},
Modal: {
url: `${baseUrl}/blocks-antd/meta/Modal.json`,
},
MonthSelector: {
url: `${baseUrl}/blocks-antd/meta/MonthSelector.json`,
},
MultipleSelector: {
url: `${baseUrl}/blocks-antd/meta/MultipleSelector.json`,
},
Notification: {
url: `${baseUrl}/blocks-antd/meta/Notification.json`,
},
NumberInput: {
url: `${baseUrl}/blocks-antd/meta/NumberInput.json`,
},
PageHCF: {
url: `${baseUrl}/blocks-antd/meta/PageHCF.json`,
},
PageHCSF: {
url: `${baseUrl}/blocks-antd/meta/PageHCSF.json`,
},
PageHeaderMenu: {
url: `${baseUrl}/blocks-antd/meta/PageHeaderMenu.json`,
},
PageHSCF: {
url: `${baseUrl}/blocks-antd/meta/PageHSCF.json`,
},
PageSHCF: {
url: `${baseUrl}/blocks-antd/meta/PageSHCF.json`,
},
PageSiderMenu: {
url: `${baseUrl}/blocks-antd/meta/PageSiderMenu.json`,
},
Pagination: {
url: `${baseUrl}/blocks-antd/meta/Pagination.json`,
},
Paragraph: {
url: `${baseUrl}/blocks-antd/meta/Paragraph.json`,
},
ParagraphInput: {
url: `${baseUrl}/blocks-antd/meta/ParagraphInput.json`,
},
PasswordInput: {
url: `${baseUrl}/blocks-antd/meta/PasswordInput.json`,
},
Progress: {
url: `${baseUrl}/blocks-antd/meta/Progress.json`,
},
RadioSelector: {
url: `${baseUrl}/blocks-antd/meta/RadioSelector.json`,
},
RatingSlider: {
url: `${baseUrl}/blocks-antd/meta/RatingSlider.json`,
},
Result: {
url: `${baseUrl}/blocks-antd/meta/Result.json`,
},
S3UploadButton: {
url: `${baseUrl}/blocks-antd/meta/S3UploadButton.json`,
},
Selector: {
url: `${baseUrl}/blocks-antd/meta/Selector.json`,
},
Slider: {
url: `${baseUrl}/blocks-antd/meta/Slider.json`,
},
Skeleton: {
url: `${baseUrl}/blocks-antd/meta/Skeleton.json`,
},
Spin: {
url: `${baseUrl}/blocks-antd/meta/Spin.json`,
},
Statistic: {
url: `${baseUrl}/blocks-antd/meta/Statistic.json`,
},
Switch: {
url: `${baseUrl}/blocks-antd/meta/Switch.json`,
},
Tabs: {
url: `${baseUrl}/blocks-antd/meta/Tabs.json`,
},
TextArea: {
url: `${baseUrl}/blocks-antd/meta/TextArea.json`,
},
TextInput: {
url: `${baseUrl}/blocks-antd/meta/TextInput.json`,
},
TimelineList: {
url: `${baseUrl}/blocks-antd/meta/TimelineList.json`,
},
Title: {
url: `${baseUrl}/blocks-antd/meta/Title.json`,
},
TitleInput: {
url: `${baseUrl}/blocks-antd/meta/TitleInput.json`,
},
Tooltip: {
url: `${baseUrl}/blocks-antd/meta/Tooltip.json`,
},
UserAvatar: {
url: `${baseUrl}/blocks-antd/meta/UserAvatar.json`,
},
WeekSelector: {
url: `${baseUrl}/blocks-antd/meta/WeekSelector.json`,
},
// @lowdefy/blocks-color-selectors-selectors
ColorSelector: {
url: `${baseUrl}/blocks-color-selectors/meta/ColorSelector.json`,
},
ChromeColorSelector: {
url: `${baseUrl}/blocks-color-selectors/meta/ChromeColorSelector.json`,
},
CircleColorSelector: {
url: `${baseUrl}/blocks-color-selectors/meta/CircleColorSelector.json`,
},
CompactColorSelector: {
url: `${baseUrl}/blocks-color-selectors/meta/CompactColorSelector.json`,
},
GithubColorSelector: {
url: `${baseUrl}/blocks-color-selectors/meta/GithubColorSelector.json`,
},
SliderColorSelector: {
url: `${baseUrl}/blocks-color-selectors/meta/SliderColorSelector.json`,
},
SwatchesColorSelector: {
url: `${baseUrl}/blocks-color-selectors/meta/SwatchesColorSelector.json`,
},
TwitterColorSelector: {
url: `${baseUrl}/blocks-color-selectors/meta/TwitterColorSelector.json`,
},
// @lowdefy/blocks-markdown
Markdown: {
url: `${baseUrl}/blocks-markdown/meta/Markdown.json`,
},
MarkdownWithCode: {
url: `${baseUrl}/blocks-markdown/meta/MarkdownWithCode.json`,
},
DangerousMarkdown: {
url: `${baseUrl}/blocks-markdown/meta/DangerousMarkdown.json`,
},
// @lowdefy/blocks-echarts
EChart: {
url: `${baseUrl}/blocks-echarts/meta/EChart.json`,
},
};
}
export default metaLocations;

View File

@ -1,542 +0,0 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import metaLocations from './metaLocations.js';
// import packageJson from '../../../package.json';
// const { version } = packageJson;
const version = '3.22.0';
test('metaLocations default URL', async () => {
expect(metaLocations({ version })).toEqual({
Affix: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Affix.json`,
},
Alert: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Alert.json`,
},
Anchor: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Anchor.json`,
},
AutoComplete: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/AutoComplete.json`,
},
Avatar: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Avatar.json`,
},
Badge: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Badge.json`,
},
Box: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-basic/meta/Box.json`,
},
Breadcrumb: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Breadcrumb.json`,
},
Button: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Button.json`,
},
ButtonSelector: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/ButtonSelector.json`,
},
Card: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Card.json`,
},
CheckboxSelector: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/CheckboxSelector.json`,
},
CheckboxSwitch: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/CheckboxSwitch.json`,
},
ChromeColorSelector: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-color-selectors/meta/ChromeColorSelector.json`,
},
CircleColorSelector: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-color-selectors/meta/CircleColorSelector.json`,
},
Collapse: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Collapse.json`,
},
ColorSelector: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-color-selectors/meta/ColorSelector.json`,
},
Comment: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Comment.json`,
},
CompactColorSelector: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-color-selectors/meta/CompactColorSelector.json`,
},
ConfirmModal: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/ConfirmModal.json`,
},
Content: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Content.json`,
},
Context: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-basic/meta/Context.json`,
},
ControlledList: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/ControlledList.json`,
},
DangerousHtml: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-basic/meta/DangerousHtml.json`,
},
DangerousMarkdown: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-markdown/meta/DangerousMarkdown.json`,
},
DateRangeSelector: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/DateRangeSelector.json`,
},
DateSelector: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/DateSelector.json`,
},
DateTimeSelector: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/DateTimeSelector.json`,
},
Descriptions: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Descriptions.json`,
},
Divider: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Divider.json`,
},
Drawer: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Drawer.json`,
},
EChart: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-echarts/meta/EChart.json`,
},
Footer: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Footer.json`,
},
GithubColorSelector: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-color-selectors/meta/GithubColorSelector.json`,
},
Header: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Header.json`,
},
Html: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-basic/meta/Html.json`,
},
Icon: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Icon.json`,
},
Img: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-basic/meta/Img.json`,
},
Label: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Label.json`,
},
Layout: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Layout.json`,
},
List: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-basic/meta/List.json`,
},
Markdown: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-markdown/meta/Markdown.json`,
},
MarkdownWithCode: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-markdown/meta/MarkdownWithCode.json`,
},
Menu: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Menu.json`,
},
Message: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Message.json`,
},
MobileMenu: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/MobileMenu.json`,
},
Modal: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Modal.json`,
},
MonthSelector: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/MonthSelector.json`,
},
MultipleSelector: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/MultipleSelector.json`,
},
Notification: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Notification.json`,
},
NumberInput: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/NumberInput.json`,
},
PageHCF: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/PageHCF.json`,
},
PageHCSF: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/PageHCSF.json`,
},
PageHSCF: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/PageHSCF.json`,
},
PageHeaderMenu: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/PageHeaderMenu.json`,
},
PageSHCF: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/PageSHCF.json`,
},
PageSiderMenu: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/PageSiderMenu.json`,
},
Pagination: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Pagination.json`,
},
Paragraph: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Paragraph.json`,
},
ParagraphInput: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/ParagraphInput.json`,
},
PasswordInput: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/PasswordInput.json`,
},
Progress: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Progress.json`,
},
RadioSelector: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/RadioSelector.json`,
},
RatingSlider: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/RatingSlider.json`,
},
Result: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Result.json`,
},
S3UploadButton: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/S3UploadButton.json`,
},
Selector: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Selector.json`,
},
Skeleton: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Skeleton.json`,
},
Slider: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Slider.json`,
},
SliderColorSelector: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-color-selectors/meta/SliderColorSelector.json`,
},
Span: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-basic/meta/Span.json`,
},
Spin: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Spin.json`,
},
Statistic: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Statistic.json`,
},
SwatchesColorSelector: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-color-selectors/meta/SwatchesColorSelector.json`,
},
Switch: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Switch.json`,
},
Tabs: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Tabs.json`,
},
TextArea: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/TextArea.json`,
},
TextInput: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/TextInput.json`,
},
TimelineList: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/TimelineList.json`,
},
Title: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Title.json`,
},
TitleInput: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/TitleInput.json`,
},
Tooltip: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/Tooltip.json`,
},
TwitterColorSelector: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-color-selectors/meta/TwitterColorSelector.json`,
},
UserAvatar: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/UserAvatar.json`,
},
WeekSelector: {
url: `https://blocks-cdn.lowdefy.com/v${version}/blocks-antd/meta/WeekSelector.json`,
},
});
});
test('metaLocations configured URL', async () => {
expect(metaLocations({ blocksServerUrl: 'https://blocks.server.com' })).toEqual({
Affix: {
url: 'https://blocks.server.com/blocks-antd/meta/Affix.json',
},
Alert: {
url: 'https://blocks.server.com/blocks-antd/meta/Alert.json',
},
Anchor: {
url: 'https://blocks.server.com/blocks-antd/meta/Anchor.json',
},
AutoComplete: {
url: 'https://blocks.server.com/blocks-antd/meta/AutoComplete.json',
},
Avatar: {
url: 'https://blocks.server.com/blocks-antd/meta/Avatar.json',
},
Badge: {
url: 'https://blocks.server.com/blocks-antd/meta/Badge.json',
},
Box: {
url: 'https://blocks.server.com/blocks-basic/meta/Box.json',
},
Breadcrumb: {
url: 'https://blocks.server.com/blocks-antd/meta/Breadcrumb.json',
},
Button: {
url: 'https://blocks.server.com/blocks-antd/meta/Button.json',
},
ButtonSelector: {
url: 'https://blocks.server.com/blocks-antd/meta/ButtonSelector.json',
},
Card: {
url: 'https://blocks.server.com/blocks-antd/meta/Card.json',
},
CheckboxSelector: {
url: 'https://blocks.server.com/blocks-antd/meta/CheckboxSelector.json',
},
CheckboxSwitch: {
url: 'https://blocks.server.com/blocks-antd/meta/CheckboxSwitch.json',
},
ChromeColorSelector: {
url: 'https://blocks.server.com/blocks-color-selectors/meta/ChromeColorSelector.json',
},
CircleColorSelector: {
url: 'https://blocks.server.com/blocks-color-selectors/meta/CircleColorSelector.json',
},
Collapse: {
url: 'https://blocks.server.com/blocks-antd/meta/Collapse.json',
},
ColorSelector: {
url: 'https://blocks.server.com/blocks-color-selectors/meta/ColorSelector.json',
},
Comment: {
url: 'https://blocks.server.com/blocks-antd/meta/Comment.json',
},
CompactColorSelector: {
url: 'https://blocks.server.com/blocks-color-selectors/meta/CompactColorSelector.json',
},
ConfirmModal: {
url: 'https://blocks.server.com/blocks-antd/meta/ConfirmModal.json',
},
Content: {
url: 'https://blocks.server.com/blocks-antd/meta/Content.json',
},
Context: {
url: 'https://blocks.server.com/blocks-basic/meta/Context.json',
},
ControlledList: {
url: 'https://blocks.server.com/blocks-antd/meta/ControlledList.json',
},
DangerousHtml: {
url: 'https://blocks.server.com/blocks-basic/meta/DangerousHtml.json',
},
DangerousMarkdown: {
url: 'https://blocks.server.com/blocks-markdown/meta/DangerousMarkdown.json',
},
DateRangeSelector: {
url: 'https://blocks.server.com/blocks-antd/meta/DateRangeSelector.json',
},
DateSelector: {
url: 'https://blocks.server.com/blocks-antd/meta/DateSelector.json',
},
DateTimeSelector: {
url: 'https://blocks.server.com/blocks-antd/meta/DateTimeSelector.json',
},
Descriptions: {
url: 'https://blocks.server.com/blocks-antd/meta/Descriptions.json',
},
Divider: {
url: 'https://blocks.server.com/blocks-antd/meta/Divider.json',
},
Drawer: {
url: 'https://blocks.server.com/blocks-antd/meta/Drawer.json',
},
EChart: {
url: 'https://blocks.server.com/blocks-echarts/meta/EChart.json',
},
Footer: {
url: 'https://blocks.server.com/blocks-antd/meta/Footer.json',
},
GithubColorSelector: {
url: 'https://blocks.server.com/blocks-color-selectors/meta/GithubColorSelector.json',
},
Header: {
url: 'https://blocks.server.com/blocks-antd/meta/Header.json',
},
Html: {
url: 'https://blocks.server.com/blocks-basic/meta/Html.json',
},
Icon: {
url: 'https://blocks.server.com/blocks-antd/meta/Icon.json',
},
Img: {
url: 'https://blocks.server.com/blocks-basic/meta/Img.json',
},
Label: {
url: 'https://blocks.server.com/blocks-antd/meta/Label.json',
},
Layout: {
url: 'https://blocks.server.com/blocks-antd/meta/Layout.json',
},
List: {
url: 'https://blocks.server.com/blocks-basic/meta/List.json',
},
Markdown: {
url: 'https://blocks.server.com/blocks-markdown/meta/Markdown.json',
},
MarkdownWithCode: {
url: 'https://blocks.server.com/blocks-markdown/meta/MarkdownWithCode.json',
},
Menu: {
url: 'https://blocks.server.com/blocks-antd/meta/Menu.json',
},
Message: {
url: 'https://blocks.server.com/blocks-antd/meta/Message.json',
},
MobileMenu: {
url: 'https://blocks.server.com/blocks-antd/meta/MobileMenu.json',
},
Modal: {
url: 'https://blocks.server.com/blocks-antd/meta/Modal.json',
},
MonthSelector: {
url: 'https://blocks.server.com/blocks-antd/meta/MonthSelector.json',
},
MultipleSelector: {
url: 'https://blocks.server.com/blocks-antd/meta/MultipleSelector.json',
},
Notification: {
url: 'https://blocks.server.com/blocks-antd/meta/Notification.json',
},
NumberInput: {
url: 'https://blocks.server.com/blocks-antd/meta/NumberInput.json',
},
PageHCF: {
url: 'https://blocks.server.com/blocks-antd/meta/PageHCF.json',
},
PageHCSF: {
url: 'https://blocks.server.com/blocks-antd/meta/PageHCSF.json',
},
PageHSCF: {
url: 'https://blocks.server.com/blocks-antd/meta/PageHSCF.json',
},
PageHeaderMenu: {
url: 'https://blocks.server.com/blocks-antd/meta/PageHeaderMenu.json',
},
PageSHCF: {
url: 'https://blocks.server.com/blocks-antd/meta/PageSHCF.json',
},
PageSiderMenu: {
url: 'https://blocks.server.com/blocks-antd/meta/PageSiderMenu.json',
},
Pagination: {
url: 'https://blocks.server.com/blocks-antd/meta/Pagination.json',
},
Paragraph: {
url: 'https://blocks.server.com/blocks-antd/meta/Paragraph.json',
},
ParagraphInput: {
url: 'https://blocks.server.com/blocks-antd/meta/ParagraphInput.json',
},
PasswordInput: {
url: 'https://blocks.server.com/blocks-antd/meta/PasswordInput.json',
},
Progress: {
url: 'https://blocks.server.com/blocks-antd/meta/Progress.json',
},
RadioSelector: {
url: 'https://blocks.server.com/blocks-antd/meta/RadioSelector.json',
},
RatingSlider: {
url: 'https://blocks.server.com/blocks-antd/meta/RatingSlider.json',
},
Result: {
url: 'https://blocks.server.com/blocks-antd/meta/Result.json',
},
S3UploadButton: {
url: 'https://blocks.server.com/blocks-antd/meta/S3UploadButton.json',
},
Selector: {
url: 'https://blocks.server.com/blocks-antd/meta/Selector.json',
},
Skeleton: {
url: 'https://blocks.server.com/blocks-antd/meta/Skeleton.json',
},
Slider: {
url: 'https://blocks.server.com/blocks-antd/meta/Slider.json',
},
SliderColorSelector: {
url: 'https://blocks.server.com/blocks-color-selectors/meta/SliderColorSelector.json',
},
Span: {
url: 'https://blocks.server.com/blocks-basic/meta/Span.json',
},
Spin: {
url: 'https://blocks.server.com/blocks-antd/meta/Spin.json',
},
Statistic: {
url: 'https://blocks.server.com/blocks-antd/meta/Statistic.json',
},
SwatchesColorSelector: {
url: 'https://blocks.server.com/blocks-color-selectors/meta/SwatchesColorSelector.json',
},
Switch: {
url: 'https://blocks.server.com/blocks-antd/meta/Switch.json',
},
Tabs: {
url: 'https://blocks.server.com/blocks-antd/meta/Tabs.json',
},
TextArea: {
url: 'https://blocks.server.com/blocks-antd/meta/TextArea.json',
},
TextInput: {
url: 'https://blocks.server.com/blocks-antd/meta/TextInput.json',
},
TimelineList: {
url: 'https://blocks.server.com/blocks-antd/meta/TimelineList.json',
},
Title: {
url: 'https://blocks.server.com/blocks-antd/meta/Title.json',
},
TitleInput: {
url: 'https://blocks.server.com/blocks-antd/meta/TitleInput.json',
},
Tooltip: {
url: 'https://blocks.server.com/blocks-antd/meta/Tooltip.json',
},
TwitterColorSelector: {
url: 'https://blocks.server.com/blocks-color-selectors/meta/TwitterColorSelector.json',
},
UserAvatar: {
url: 'https://blocks.server.com/blocks-antd/meta/UserAvatar.json',
},
WeekSelector: {
url: 'https://blocks.server.com/blocks-antd/meta/WeekSelector.json',
},
});
});

View File

@ -1,32 +0,0 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import path from 'path';
import { writeFile } from '@lowdefy/node-utils';
import createCacheKey from './createCacheKey.js';
function createWriteMetaCache({ cacheDirectory }) {
async function writeMetaCache({ location, meta }) {
const cacheKey = createCacheKey(location);
return writeFile({
filePath: path.resolve(cacheDirectory, 'meta/', cacheKey),
content: JSON.stringify(meta, null, 2),
});
}
return writeMetaCache;
}
export default createWriteMetaCache;

View File

@ -1,47 +0,0 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import fs from 'fs';
import path from 'path';
import createWriteMetaCache from './writeMetaCache.js';
const cacheDirectory = path.resolve(process.cwd(), 'src/test/fetchMetaCache');
const writeMetaCache = createWriteMetaCache({ cacheDirectory });
test('writeMetaCache writes to cache', async () => {
const filePath = path.resolve(cacheDirectory, 'meta/', 'writemetacache.json');
try {
fs.unlinkSync(filePath);
} catch (error) {
//pass
}
expect(fs.existsSync(filePath)).toBe(false);
await writeMetaCache({
location: { url: 'writemetacache.json' },
meta: {
key: 'value',
},
});
const content = fs.readFileSync(filePath, 'utf8');
expect(content).toEqual(`{
"key": "value"
}`);
try {
fs.unlinkSync(filePath);
} catch (error) {
//pass
}
});