@embeddable.com/sdk-core 0.0.4 → 0.0.5
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/bin/embeddable +2 -2
- package/lib/index.cjs.js +92 -0
- package/lib/index.umd.js +18816 -0
- package/package.json +9 -2
- package/src/index.ts +3 -0
- package/src/loadData.ts +31 -0
- package/src/build.js +0 -20
- package/src/cleanup.js +0 -30
- package/src/createContext.js +0 -20
- package/src/generate.js +0 -68
- package/src/prepare.js +0 -26
- package/src/push.js +0 -40
package/package.json
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embeddable.com/sdk-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Core Embeddable SDK module responsible for web-components bundling and publishing.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"embeddable",
|
|
7
7
|
"sdk",
|
|
8
8
|
"web-components"
|
|
9
9
|
],
|
|
10
|
+
"main": "lib/index.cjs.js",
|
|
11
|
+
"module": "lib/index.esm.js",
|
|
12
|
+
"browser": "lib/index.umd.js",
|
|
13
|
+
"types": "lib/index.d.ts",
|
|
10
14
|
"repository": {
|
|
11
15
|
"type": "git",
|
|
12
16
|
"url": "git+https://github.com/embeddable-hq/embeddable-sdk.git",
|
|
13
17
|
"directory": "packages/core"
|
|
14
18
|
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "rollup -c"
|
|
21
|
+
},
|
|
15
22
|
"author": "Oleg Kapustin <oleg@trevor.io>",
|
|
16
23
|
"files": [
|
|
17
24
|
"src/",
|
|
@@ -24,7 +31,7 @@
|
|
|
24
31
|
"license": "MIT",
|
|
25
32
|
"dependencies": {
|
|
26
33
|
"@stencil/core": "^4.0.0",
|
|
27
|
-
"
|
|
34
|
+
"axios": "^1.4.0",
|
|
28
35
|
"prompt": "^1.3.0"
|
|
29
36
|
}
|
|
30
37
|
}
|
package/src/index.ts
ADDED
package/src/loadData.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
export type TimeDimensions = {
|
|
4
|
+
dimension: string;
|
|
5
|
+
granularity: string;
|
|
6
|
+
}
|
|
7
|
+
export type LoadDataRequest = {
|
|
8
|
+
from: string;
|
|
9
|
+
measures?: string[];
|
|
10
|
+
dimensions: string[];
|
|
11
|
+
timeDimensions?: TimeDimensions[];
|
|
12
|
+
orderBy?: string[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function loadData (request: LoadDataRequest) {
|
|
16
|
+
const dimensions = request.dimensions?.filter(Boolean);
|
|
17
|
+
const measures = request.measures?.filter(Boolean);
|
|
18
|
+
const timeDimensions = request.timeDimensions?.filter((d) => d.dimension);
|
|
19
|
+
|
|
20
|
+
const query = {
|
|
21
|
+
dimensions: dimensions?.length ? dimensions : undefined,
|
|
22
|
+
measures: measures?.length ? measures : undefined,
|
|
23
|
+
timeDimensions: timeDimensions?.length ? timeDimensions : undefined
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
if (!query.dimensions && !query.timeDimensions) return null;
|
|
27
|
+
|
|
28
|
+
const response = await axios.post(`${process.env.API_URL}/data-modeling/query?datasourceId=${request.from}`, query)
|
|
29
|
+
|
|
30
|
+
return response.data;
|
|
31
|
+
}
|
package/src/build.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const path = require("path");
|
|
2
|
-
const { prepare } = require("./prepare");
|
|
3
|
-
const { generate } = require("./generate");
|
|
4
|
-
const { cleanup } = require("./cleanup");
|
|
5
|
-
const {createContext} = require("./createContext");
|
|
6
|
-
|
|
7
|
-
async function build(pluginOptions = {}) {
|
|
8
|
-
const ctx = {
|
|
9
|
-
...createContext(path.resolve(__dirname, '..'), process.cwd()),
|
|
10
|
-
pluginOptions
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
await prepare(ctx);
|
|
14
|
-
|
|
15
|
-
await generate(ctx);
|
|
16
|
-
|
|
17
|
-
await cleanup(ctx);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
module.exports = { build };
|
package/src/cleanup.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const fs = require('fs/promises');
|
|
2
|
-
const path = require("path");
|
|
3
|
-
|
|
4
|
-
async function cleanup (ctx) {
|
|
5
|
-
await extractBuild(ctx);
|
|
6
|
-
|
|
7
|
-
await removeObsoleteDir(ctx.client.buildDir);
|
|
8
|
-
|
|
9
|
-
await moveBuildTOBuildDir(ctx);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
module.exports = { cleanup };
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
async function extractBuild(ctx) {
|
|
16
|
-
await fs.rename(
|
|
17
|
-
path.resolve(ctx.client.buildDir, ctx.client.stencilBuild),
|
|
18
|
-
ctx.client.tmpDir
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
async function removeObsoleteDir(dir) {
|
|
24
|
-
await fs.rm(dir, { recursive: true });
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
async function moveBuildTOBuildDir(ctx) {
|
|
29
|
-
await fs.rename(ctx.client.tmpDir, ctx.client.buildDir);
|
|
30
|
-
}
|
package/src/createContext.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
|
|
3
|
-
function createContext (coreRoot, clientRoot) {
|
|
4
|
-
return {
|
|
5
|
-
core: {
|
|
6
|
-
rootDir: coreRoot,
|
|
7
|
-
templatesDir: path.resolve(coreRoot, 'templates'),
|
|
8
|
-
configsDir: path.resolve(coreRoot, 'configs')
|
|
9
|
-
},
|
|
10
|
-
client: {
|
|
11
|
-
rootDir: clientRoot,
|
|
12
|
-
buildDir: path.resolve(clientRoot, '.embeddable-build'),
|
|
13
|
-
tmpDir: path.resolve(clientRoot, '.embeddable-tmp'),
|
|
14
|
-
componentDir: path.resolve(clientRoot, '.embeddable-build', 'component'),
|
|
15
|
-
stencilBuild: path.resolve(clientRoot, '.embeddable-build', 'dist', 'embeddable-wrapper')
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
module.exports = { createContext };
|
package/src/generate.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
const fs = require("fs/promises");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
|
|
4
|
-
const stencilNodeApi = require("@stencil/core/sys/node");
|
|
5
|
-
const stencil = require("@stencil/core/cli");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const STYLE_IMPORTS_TOKEN = '{{STYLES_IMPORT}}';
|
|
9
|
-
const RENDER_IMPORT_TOKEN = '{{RENDER_IMPORT}}';
|
|
10
|
-
|
|
11
|
-
const NODE_LOGGER = stencilNodeApi.createNodeLogger({ process: process });
|
|
12
|
-
const NODE_SYS = stencilNodeApi.createNodeSys({ process: process, logger: NODE_LOGGER });
|
|
13
|
-
|
|
14
|
-
async function generate(ctx) {
|
|
15
|
-
await injectCSS(ctx);
|
|
16
|
-
|
|
17
|
-
await injectBundleRender(ctx);
|
|
18
|
-
|
|
19
|
-
await runStencil(ctx);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
module.exports = { generate };
|
|
23
|
-
|
|
24
|
-
async function injectCSS (ctx) {
|
|
25
|
-
const CUSTOMER_BUILD = path.resolve(ctx.client.buildDir, ctx.pluginOptions.outDir);
|
|
26
|
-
const allFiles = await fs.readdir(CUSTOMER_BUILD);
|
|
27
|
-
|
|
28
|
-
const cssFilesImportsStr = allFiles
|
|
29
|
-
.filter(fileName => fileName.endsWith('.css'))
|
|
30
|
-
.map(fileName => `@import '../${ctx.pluginOptions.outDir}/${fileName}';`).join('\n');
|
|
31
|
-
|
|
32
|
-
const content = await fs.readFile(
|
|
33
|
-
path.resolve(ctx.core.templatesDir, 'style.css.template'),
|
|
34
|
-
'utf8'
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
await fs.writeFile(
|
|
38
|
-
path.resolve(ctx.client.componentDir, 'style.css'),
|
|
39
|
-
content.replace(STYLE_IMPORTS_TOKEN, cssFilesImportsStr)
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
async function injectBundleRender(ctx) {
|
|
45
|
-
const importStr = `import render from '../${ctx.pluginOptions.outDir}/${ctx.pluginOptions.renderFunctionFileName}';`;
|
|
46
|
-
|
|
47
|
-
const content = await fs.readFile(
|
|
48
|
-
path.resolve(ctx.core.templatesDir, 'component.tsx.template'),
|
|
49
|
-
'utf8'
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
await fs.writeFile(
|
|
53
|
-
path.resolve(ctx.client.componentDir, 'component.tsx'),
|
|
54
|
-
content.replace(RENDER_IMPORT_TOKEN, importStr)
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
async function runStencil(ctx) {
|
|
60
|
-
process.chdir(ctx.client.buildDir);
|
|
61
|
-
|
|
62
|
-
await stencil.run({
|
|
63
|
-
args: ['build'],
|
|
64
|
-
logger: NODE_LOGGER,
|
|
65
|
-
sys: NODE_SYS,
|
|
66
|
-
checkVersion: stencilNodeApi.checkVersion,
|
|
67
|
-
});
|
|
68
|
-
}
|
package/src/prepare.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const fsSync = require('fs');
|
|
2
|
-
const fs = require('fs/promises');
|
|
3
|
-
|
|
4
|
-
async function prepare (ctx) {
|
|
5
|
-
await removeIfExists(ctx);
|
|
6
|
-
|
|
7
|
-
await copyStencilConfigsToClient(ctx);
|
|
8
|
-
|
|
9
|
-
await createComponentDir(ctx.client.componentDir);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
module.exports = { prepare }
|
|
13
|
-
|
|
14
|
-
async function removeIfExists(ctx) {
|
|
15
|
-
if (ctx.pluginOptions) return;
|
|
16
|
-
|
|
17
|
-
if (fsSync.existsSync(ctx.client.buildDir)) await fs.rm(ctx.client.buildDir, { recursive: true });
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async function copyStencilConfigsToClient(ctx) {
|
|
21
|
-
await fs.cp(ctx.core.configsDir, ctx.client.buildDir, { recursive: true });
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async function createComponentDir(dir) {
|
|
25
|
-
await fs.mkdir(dir);
|
|
26
|
-
}
|
package/src/push.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const fsSync = require("fs");
|
|
2
|
-
const { execSync } = require("child_process");
|
|
3
|
-
const prompt = require('prompt');
|
|
4
|
-
const {createContext} = require("./createContext");
|
|
5
|
-
const path = require("path");
|
|
6
|
-
|
|
7
|
-
const PROMPT_SCHEMA = {
|
|
8
|
-
properties: {
|
|
9
|
-
clientName: {
|
|
10
|
-
description: 'Client name',
|
|
11
|
-
type: 'string',
|
|
12
|
-
default: 'customer-1'
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* TODO:
|
|
19
|
-
* 1. use client id from the login session instead of prompting clientName.
|
|
20
|
-
* 2. use our API endpoint to send archived bundle files + meta yaml files.
|
|
21
|
-
*/
|
|
22
|
-
async function push () {
|
|
23
|
-
const ctx = createContext(path.resolve(__dirname, '..'), process.cwd());
|
|
24
|
-
|
|
25
|
-
prompt.start();
|
|
26
|
-
|
|
27
|
-
const { clientName } = await prompt.get(PROMPT_SCHEMA);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (!fsSync.existsSync(ctx.client.buildDir)) {
|
|
31
|
-
console.error('No embeddable build was produced.');
|
|
32
|
-
process.exit(1);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
execSync(`gsutil -m rm -r gs://embeddable-bundle-tmp/${clientName}`, {cwd: ctx.client.rootDir});
|
|
36
|
-
execSync(`gsutil -m cp -r .embeddable-build gs://embeddable-bundle-tmp/${clientName}`, {cwd: ctx.client.rootDir});
|
|
37
|
-
execSync(`gsutil -m setmeta -h "Cache-Control: no-store" gs://embeddable-bundle-tmp/${clientName}/**`);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
module.exports = { push }
|