@embeddable.com/sdk-core 3.13.5-next.0 → 3.13.6-next.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.
- package/lib/buildTypes.d.ts +2 -1
- package/lib/cleanup.d.ts +3 -2
- package/lib/defineConfig.d.ts +25 -2
- package/lib/generate.d.ts +2 -1
- package/lib/globalCleanup.d.ts +2 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.esm.js +246 -67
- package/lib/index.esm.js.map +1 -1
- package/lib/prepare.d.ts +3 -2
- package/lib/provideConfig.d.ts +2 -1
- package/lib/validate.d.ts +2 -1
- package/lib/workspaceUtils.d.ts +4 -2
- package/package.json +4 -3
- package/src/build.test.ts +4 -1
- package/src/buildTypes.test.ts +6 -3
- package/src/buildTypes.ts +5 -5
- package/src/cleanup.test.ts +2 -2
- package/src/cleanup.ts +5 -4
- package/src/defineConfig.test.ts +6 -0
- package/src/defineConfig.ts +26 -2
- package/src/dev.test.ts +4 -2
- package/src/dev.ts +20 -14
- package/src/generate.test.ts +4 -3
- package/src/generate.ts +20 -8
- package/src/globalCleanup.ts +4 -2
- package/src/index.ts +1 -0
- package/src/prepare.ts +12 -7
- package/src/provideConfig.ts +2 -1
- package/src/push.test.ts +12 -6
- package/src/rollbar.test.ts +4 -1
- package/src/validate.ts +2 -2
- package/src/workspaceUtils.test.ts +24 -9
- package/src/workspaceUtils.ts +9 -3
package/lib/prepare.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
2
|
+
declare const _default: (ctx: ResolvedEmbeddableConfig) => Promise<void>;
|
|
2
3
|
export default _default;
|
|
3
|
-
export declare function removeIfExists(ctx:
|
|
4
|
+
export declare function removeIfExists(ctx: ResolvedEmbeddableConfig): Promise<void>;
|
package/lib/provideConfig.d.ts
CHANGED
package/lib/validate.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
2
|
+
declare const _default: (ctx: ResolvedEmbeddableConfig) => Promise<boolean>;
|
|
2
3
|
export default _default;
|
|
3
4
|
export declare function dataModelsValidation(filesList: [string, string][]): Promise<string[]>;
|
|
4
5
|
export declare function securityContextValidation(filesList: [string, string][]): Promise<string[]>;
|
package/lib/workspaceUtils.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
2
|
+
import { Options, Ora } from "ora";
|
|
3
|
+
export declare function getWorkspaces(ctx: ResolvedEmbeddableConfig, token: string, workspaceSpinner: Ora): Promise<any>;
|
|
4
|
+
export declare function selectWorkspace(ora: (options?: string | Options) => Ora, ctx: ResolvedEmbeddableConfig, token: string): Promise<any>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embeddable.com/sdk-core",
|
|
3
|
-
"version": "3.13.
|
|
3
|
+
"version": "3.13.6-next.0",
|
|
4
4
|
"description": "Core Embeddable SDK module responsible for web-components bundling and publishing.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"embeddable",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"build": "rollup -c",
|
|
21
21
|
"test": "vitest run",
|
|
22
22
|
"test:watch": "vitest",
|
|
23
|
+
"types:check": "tsc --noEmit",
|
|
23
24
|
"license-report": "license-report --output=csv --csvHeaders --fields name --fields link --fields licenseType --fields installedVersion --fields author > license-report-sdk-core-sdk.csv"
|
|
24
25
|
},
|
|
25
26
|
"author": "Embeddable.com <engineering@embeddable.com>",
|
|
@@ -39,7 +40,7 @@
|
|
|
39
40
|
},
|
|
40
41
|
"license": "MIT",
|
|
41
42
|
"dependencies": {
|
|
42
|
-
"@embeddable.com/sdk-utils": "0.7.
|
|
43
|
+
"@embeddable.com/sdk-utils": "0.7.4-next.0",
|
|
43
44
|
"@inquirer/prompts": "^7.2.1",
|
|
44
45
|
"@stencil/core": "^4.23.0",
|
|
45
46
|
"@swc-node/register": "^1.10.9",
|
|
@@ -71,4 +72,4 @@
|
|
|
71
72
|
"@types/serve-static": "^1.15.7",
|
|
72
73
|
"@types/ws": "^8.5.13"
|
|
73
74
|
}
|
|
74
|
-
}
|
|
75
|
+
}
|
package/src/build.test.ts
CHANGED
|
@@ -9,6 +9,7 @@ import cleanup from "./cleanup";
|
|
|
9
9
|
// @ts-ignore
|
|
10
10
|
import reportErrorToRollbar from "./rollbar.mjs";
|
|
11
11
|
import { storeBuildSuccessFlag } from "./utils";
|
|
12
|
+
import { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
12
13
|
|
|
13
14
|
vi.mock("./logger", () => ({
|
|
14
15
|
initLogger: vi.fn().mockResolvedValue(undefined),
|
|
@@ -63,7 +64,9 @@ const config = {
|
|
|
63
64
|
|
|
64
65
|
describe("build", () => {
|
|
65
66
|
beforeEach(() => {
|
|
66
|
-
vi.mocked(provideConfig).mockResolvedValue(
|
|
67
|
+
vi.mocked(provideConfig).mockResolvedValue(
|
|
68
|
+
config as unknown as ResolvedEmbeddableConfig,
|
|
69
|
+
);
|
|
67
70
|
});
|
|
68
71
|
|
|
69
72
|
it("should call all the necessary functions", async () => {
|
package/src/buildTypes.test.ts
CHANGED
|
@@ -3,7 +3,7 @@ import buildTypes, { EMB_TYPE_FILE_REGEX } from "./buildTypes";
|
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import { build } from "vite";
|
|
5
5
|
import { findFiles, getContentHash } from "@embeddable.com/sdk-utils";
|
|
6
|
-
|
|
6
|
+
import { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
7
7
|
const config = {
|
|
8
8
|
client: {
|
|
9
9
|
srcDir: "src",
|
|
@@ -58,7 +58,7 @@ describe("buildTypes", () => {
|
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
it("should build types", async () => {
|
|
61
|
-
await buildTypes(config);
|
|
61
|
+
await buildTypes(config as unknown as ResolvedEmbeddableConfig);
|
|
62
62
|
|
|
63
63
|
expect(findFiles).toHaveBeenCalledWith("src", EMB_TYPE_FILE_REGEX);
|
|
64
64
|
|
|
@@ -90,7 +90,10 @@ import '../relativePath';`,
|
|
|
90
90
|
});
|
|
91
91
|
|
|
92
92
|
it("should not add hash to the file name when watch is enabled", async () => {
|
|
93
|
-
await buildTypes({
|
|
93
|
+
await buildTypes({
|
|
94
|
+
...config,
|
|
95
|
+
dev: { watch: true, logger: undefined, sys: undefined },
|
|
96
|
+
} as unknown as ResolvedEmbeddableConfig);
|
|
94
97
|
|
|
95
98
|
expect(getContentHash).not.toHaveBeenCalled();
|
|
96
99
|
expect(fs.rename).not.toHaveBeenCalled();
|
package/src/buildTypes.ts
CHANGED
|
@@ -3,11 +3,11 @@ import * as path from "node:path";
|
|
|
3
3
|
import * as vite from "vite";
|
|
4
4
|
import ora from "ora";
|
|
5
5
|
import { findFiles, getContentHash } from "@embeddable.com/sdk-utils";
|
|
6
|
-
|
|
6
|
+
import { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
7
7
|
export const EMB_TYPE_FILE_REGEX = /^(.*)\.type\.emb\.[jt]s$/;
|
|
8
8
|
export const EMB_OPTIONS_FILE_REGEX = /^(.*)\.options\.emb\.[jt]s$/;
|
|
9
9
|
|
|
10
|
-
export default async (ctx:
|
|
10
|
+
export default async (ctx: ResolvedEmbeddableConfig) => {
|
|
11
11
|
const progress = ora("Building types...").start();
|
|
12
12
|
|
|
13
13
|
await generate(ctx);
|
|
@@ -19,7 +19,7 @@ export default async (ctx: any) => {
|
|
|
19
19
|
progress.succeed("Types built completed");
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
async function generate(ctx:
|
|
22
|
+
async function generate(ctx: ResolvedEmbeddableConfig) {
|
|
23
23
|
const typeFiles = await findFiles(ctx.client.srcDir, EMB_TYPE_FILE_REGEX);
|
|
24
24
|
const optionsFiles = await findFiles(
|
|
25
25
|
ctx.client.srcDir,
|
|
@@ -45,7 +45,7 @@ async function generate(ctx: any) {
|
|
|
45
45
|
);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
async function build(ctx:
|
|
48
|
+
async function build(ctx: ResolvedEmbeddableConfig) {
|
|
49
49
|
const typesFilePath = path.resolve(
|
|
50
50
|
ctx.client.buildDir,
|
|
51
51
|
ctx.outputOptions.typesEntryPointFilename,
|
|
@@ -78,7 +78,7 @@ async function build(ctx: any) {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
async function cleanup(ctx:
|
|
81
|
+
async function cleanup(ctx: ResolvedEmbeddableConfig) {
|
|
82
82
|
await fs.rm(
|
|
83
83
|
path.resolve(ctx.client.buildDir, "embeddable-types-entry-point.js"),
|
|
84
84
|
);
|
package/src/cleanup.test.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as fs from "node:fs/promises";
|
|
|
2
2
|
import * as path from "node:path";
|
|
3
3
|
import { createManifest } from "./cleanup";
|
|
4
4
|
import { findFiles } from "@embeddable.com/sdk-utils";
|
|
5
|
-
|
|
5
|
+
import { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
6
6
|
const ctx = {
|
|
7
7
|
client: {
|
|
8
8
|
tmpDir: "tmpDir",
|
|
@@ -57,7 +57,7 @@ describe("cleanup", () => {
|
|
|
57
57
|
});
|
|
58
58
|
it("should create manifest", async () => {
|
|
59
59
|
await createManifest({
|
|
60
|
-
ctx,
|
|
60
|
+
ctx: ctx as unknown as ResolvedEmbeddableConfig,
|
|
61
61
|
typesFileName: "typesFileName",
|
|
62
62
|
metaFileName: "metaFileName",
|
|
63
63
|
editorsMetaFileName: "editorsMetaFileName",
|
package/src/cleanup.ts
CHANGED
|
@@ -2,8 +2,9 @@ import { findFiles } from "@embeddable.com/sdk-utils";
|
|
|
2
2
|
import * as fs from "node:fs/promises";
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import { getSDKVersions, hrtimeToISO8601 } from "./utils";
|
|
5
|
+
import { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
5
6
|
|
|
6
|
-
export default async (ctx:
|
|
7
|
+
export default async (ctx: ResolvedEmbeddableConfig) => {
|
|
7
8
|
await extractBuild(ctx);
|
|
8
9
|
|
|
9
10
|
await removeObsoleteDir(ctx.client.buildDir);
|
|
@@ -12,7 +13,7 @@ export default async (ctx: any) => {
|
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
type ManifestArgs = {
|
|
15
|
-
ctx:
|
|
16
|
+
ctx: ResolvedEmbeddableConfig;
|
|
16
17
|
typesFileName: string;
|
|
17
18
|
metaFileName: string;
|
|
18
19
|
editorsMetaFileName: string;
|
|
@@ -68,7 +69,7 @@ export async function createManifest({
|
|
|
68
69
|
);
|
|
69
70
|
}
|
|
70
71
|
|
|
71
|
-
async function extractBuild(ctx:
|
|
72
|
+
async function extractBuild(ctx: ResolvedEmbeddableConfig) {
|
|
72
73
|
const stencilBuildFiles = await findFiles(
|
|
73
74
|
ctx.client.stencilBuild,
|
|
74
75
|
/embeddable-wrapper.esm-[a-z0-9]+\.js/,
|
|
@@ -126,6 +127,6 @@ async function removeObsoleteDir(dir: string) {
|
|
|
126
127
|
await fs.rm(dir, { recursive: true });
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
async function moveBuildTOBuildDir(ctx:
|
|
130
|
+
async function moveBuildTOBuildDir(ctx: ResolvedEmbeddableConfig) {
|
|
130
131
|
await fs.rename(ctx.client.tmpDir, ctx.client.buildDir);
|
|
131
132
|
}
|
package/src/defineConfig.test.ts
CHANGED
|
@@ -48,6 +48,7 @@ describe("defineConfig", () => {
|
|
|
48
48
|
"audienceUrl": "audienceUrl",
|
|
49
49
|
"authClientId": "authClientId",
|
|
50
50
|
"authDomain": "authDomain",
|
|
51
|
+
"buildTime": undefined,
|
|
51
52
|
"client": {
|
|
52
53
|
"archiveFile": "/embeddable-sdk/packages/core-sdk",
|
|
53
54
|
"buildDir": "/embeddable-sdk/packages/core-sdk",
|
|
@@ -69,6 +70,11 @@ describe("defineConfig", () => {
|
|
|
69
70
|
"rootDir": "/embeddable-sdk/packages/core-sdk",
|
|
70
71
|
"templatesDir": "/embeddable-sdk/packages/core-sdk",
|
|
71
72
|
},
|
|
73
|
+
"dev": {
|
|
74
|
+
"logger": undefined,
|
|
75
|
+
"sys": undefined,
|
|
76
|
+
"watch": false,
|
|
77
|
+
},
|
|
72
78
|
"outputOptions": {
|
|
73
79
|
"typesEntryPointFilename": "embeddable-types-entry-point.js",
|
|
74
80
|
},
|
package/src/defineConfig.ts
CHANGED
|
@@ -36,6 +36,9 @@ export type EmbeddableConfig = {
|
|
|
36
36
|
region?: Region;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
+
const PLUGIN_NAME = "sdk-react" as const;
|
|
40
|
+
|
|
41
|
+
export type PluginName = typeof PLUGIN_NAME;
|
|
39
42
|
export type ResolvedEmbeddableConfig = {
|
|
40
43
|
core: {
|
|
41
44
|
rootDir: string;
|
|
@@ -45,8 +48,8 @@ export type ResolvedEmbeddableConfig = {
|
|
|
45
48
|
client: {
|
|
46
49
|
rootDir: string;
|
|
47
50
|
srcDir: string;
|
|
48
|
-
modelsSrc
|
|
49
|
-
presetsSrc
|
|
51
|
+
modelsSrc: string;
|
|
52
|
+
presetsSrc: string;
|
|
50
53
|
buildDir: string;
|
|
51
54
|
tmpDir: string;
|
|
52
55
|
globalCss: string;
|
|
@@ -75,6 +78,21 @@ export type ResolvedEmbeddableConfig = {
|
|
|
75
78
|
applicationEnvironment: string;
|
|
76
79
|
rollbarAccessToken: string;
|
|
77
80
|
plugins: EmbeddableConfig["plugins"];
|
|
81
|
+
buildTime: [number, number];
|
|
82
|
+
dev: {
|
|
83
|
+
watch: boolean;
|
|
84
|
+
logger: any;
|
|
85
|
+
sys: any;
|
|
86
|
+
};
|
|
87
|
+
[PLUGIN_NAME]: {
|
|
88
|
+
rootDir: string;
|
|
89
|
+
templatesDir: string;
|
|
90
|
+
outputOptions: {
|
|
91
|
+
fileName: string;
|
|
92
|
+
buildName: string;
|
|
93
|
+
componentsEntryPointFilename: string;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
78
96
|
};
|
|
79
97
|
|
|
80
98
|
const REGION_CONFIGS = {
|
|
@@ -234,6 +252,12 @@ export default (config: EmbeddableConfig) => {
|
|
|
234
252
|
outputOptions: {
|
|
235
253
|
typesEntryPointFilename: "embeddable-types-entry-point.js",
|
|
236
254
|
},
|
|
255
|
+
buildTime: undefined, // This will be set by the build process
|
|
256
|
+
dev: {
|
|
257
|
+
watch: false,
|
|
258
|
+
logger: undefined,
|
|
259
|
+
sys: undefined,
|
|
260
|
+
},
|
|
237
261
|
pushModels,
|
|
238
262
|
pushComponents,
|
|
239
263
|
pushBaseUrl: pushBaseUrl ?? regionConfig.pushBaseUrl,
|
package/src/dev.test.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { createManifest } from "./cleanup";
|
|
|
10
10
|
import prepare from "./prepare";
|
|
11
11
|
import { WebSocketServer } from "ws";
|
|
12
12
|
import { initLogger, logError } from "./logger";
|
|
13
|
-
|
|
13
|
+
import { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
14
14
|
// Mock dependencies
|
|
15
15
|
vi.mock("./buildTypes", () => ({ default: vi.fn() }));
|
|
16
16
|
vi.mock("./prepare", () => ({ default: vi.fn(), removeIfExists: vi.fn() }));
|
|
@@ -76,7 +76,9 @@ describe("dev command", () => {
|
|
|
76
76
|
vi.spyOn(process, "on").mockImplementation(() => process);
|
|
77
77
|
vi.spyOn(process, "exit").mockImplementation(() => undefined as never);
|
|
78
78
|
|
|
79
|
-
vi.mocked(provideConfig).mockResolvedValue(
|
|
79
|
+
vi.mocked(provideConfig).mockResolvedValue(
|
|
80
|
+
mockConfig as unknown as ResolvedEmbeddableConfig,
|
|
81
|
+
);
|
|
80
82
|
vi.mocked(getToken).mockResolvedValue("mock-token");
|
|
81
83
|
vi.mocked(axios.get).mockResolvedValue({
|
|
82
84
|
data: [{ id: "mock-workspace" }],
|
package/src/dev.ts
CHANGED
|
@@ -14,7 +14,7 @@ import { RollupWatcher } from "rollup";
|
|
|
14
14
|
import * as http from "node:http";
|
|
15
15
|
import { IncomingMessage, Server, ServerResponse } from "http";
|
|
16
16
|
import { ChildProcess } from "node:child_process";
|
|
17
|
-
import { WebSocketServer
|
|
17
|
+
import { WebSocketServer } from "ws";
|
|
18
18
|
import * as chokidar from "chokidar";
|
|
19
19
|
import * as path from "path";
|
|
20
20
|
import { FSWatcher } from "chokidar";
|
|
@@ -31,12 +31,13 @@ import minimist from "minimist";
|
|
|
31
31
|
import { initLogger, logError } from "./logger";
|
|
32
32
|
import fg from "fast-glob";
|
|
33
33
|
import * as dotenv from "dotenv";
|
|
34
|
-
import ora from "ora";
|
|
34
|
+
import ora, { Ora } from "ora";
|
|
35
35
|
import finalhandler from "finalhandler";
|
|
36
36
|
import serveStatic from "serve-static";
|
|
37
|
+
import { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
37
38
|
dotenv.config();
|
|
38
39
|
|
|
39
|
-
let wss:
|
|
40
|
+
let wss: WebSocketServer;
|
|
40
41
|
let changedFiles: string[] = [];
|
|
41
42
|
let browserWindow: ChildProcess | null = null;
|
|
42
43
|
|
|
@@ -209,8 +210,8 @@ export default async () => {
|
|
|
209
210
|
breadcrumbs.push("build plugin");
|
|
210
211
|
const watcher = await plugin.build(config);
|
|
211
212
|
breadcrumbs.push("configure watcher");
|
|
212
|
-
await configureWatcher(watcher, config);
|
|
213
|
-
watchers.push(watcher);
|
|
213
|
+
await configureWatcher(watcher as RollupWatcher, config);
|
|
214
|
+
watchers.push(watcher as RollupWatcher);
|
|
214
215
|
}
|
|
215
216
|
|
|
216
217
|
const dataModelAndSecurityContextWatch =
|
|
@@ -226,7 +227,10 @@ export default async () => {
|
|
|
226
227
|
}
|
|
227
228
|
};
|
|
228
229
|
|
|
229
|
-
const configureWatcher = async (
|
|
230
|
+
const configureWatcher = async (
|
|
231
|
+
watcher: RollupWatcher,
|
|
232
|
+
ctx: ResolvedEmbeddableConfig,
|
|
233
|
+
) => {
|
|
230
234
|
watcher.on("change", (path) => {
|
|
231
235
|
changedFiles.push(path);
|
|
232
236
|
});
|
|
@@ -259,14 +263,14 @@ const onlyTypesChanged = () =>
|
|
|
259
263
|
changedFiles.filter(typeFilesFilter).length === changedFiles.length;
|
|
260
264
|
const isTypeFileChanged = () => changedFiles.findIndex(typeFilesFilter) >= 0;
|
|
261
265
|
|
|
262
|
-
const onBuildStart = async (ctx:
|
|
266
|
+
const onBuildStart = async (ctx: ResolvedEmbeddableConfig) => {
|
|
263
267
|
if (changedFiles.length === 0 || isTypeFileChanged()) {
|
|
264
268
|
await buildTypes(ctx);
|
|
265
269
|
}
|
|
266
270
|
sendMessage("componentsBuildStart", { changedFiles });
|
|
267
271
|
};
|
|
268
272
|
|
|
269
|
-
const onBundleBuildEnd = async (ctx:
|
|
273
|
+
const onBundleBuildEnd = async (ctx: ResolvedEmbeddableConfig) => {
|
|
270
274
|
if (!onlyTypesChanged() || changedFiles.length === 0) {
|
|
271
275
|
await buildWebComponent(ctx);
|
|
272
276
|
}
|
|
@@ -281,7 +285,7 @@ const onBundleBuildEnd = async (ctx: any) => {
|
|
|
281
285
|
};
|
|
282
286
|
|
|
283
287
|
const dataModelAndSecurityContextWatcher = async (
|
|
284
|
-
ctx:
|
|
288
|
+
ctx: ResolvedEmbeddableConfig,
|
|
285
289
|
): Promise<FSWatcher> => {
|
|
286
290
|
const [modelsFiles, presetsFiles] = await Promise.all([
|
|
287
291
|
fg("**/*.cube.{yaml,yml,js}", {
|
|
@@ -304,7 +308,7 @@ const dataModelAndSecurityContextWatcher = async (
|
|
|
304
308
|
return fsWatcher;
|
|
305
309
|
};
|
|
306
310
|
|
|
307
|
-
const globalCssWatcher = (ctx:
|
|
311
|
+
const globalCssWatcher = (ctx: ResolvedEmbeddableConfig): FSWatcher => {
|
|
308
312
|
const fsWatcher = chokidar.watch(ctx.client.globalCss, chokidarWatchOptions);
|
|
309
313
|
|
|
310
314
|
fsWatcher.on("all", async () => {
|
|
@@ -314,7 +318,9 @@ const globalCssWatcher = (ctx: any): FSWatcher => {
|
|
|
314
318
|
return fsWatcher;
|
|
315
319
|
};
|
|
316
320
|
|
|
317
|
-
const sendDataModelsAndContextsChanges = async (
|
|
321
|
+
const sendDataModelsAndContextsChanges = async (
|
|
322
|
+
ctx: ResolvedEmbeddableConfig,
|
|
323
|
+
) => {
|
|
318
324
|
sendMessage("dataModelsAndOrSecurityContextUpdateStart");
|
|
319
325
|
const isValid = await validate(ctx);
|
|
320
326
|
if (isValid) {
|
|
@@ -356,7 +362,7 @@ const onClose = async (
|
|
|
356
362
|
server: Server,
|
|
357
363
|
sys: CompilerSystem,
|
|
358
364
|
watchers: Array<RollupWatcher | FSWatcher>,
|
|
359
|
-
config:
|
|
365
|
+
config: ResolvedEmbeddableConfig,
|
|
360
366
|
) => {
|
|
361
367
|
server.close();
|
|
362
368
|
wss.close();
|
|
@@ -376,8 +382,8 @@ const onClose = async (
|
|
|
376
382
|
};
|
|
377
383
|
|
|
378
384
|
const getPreviewWorkspace = async (
|
|
379
|
-
startedOra:
|
|
380
|
-
ctx:
|
|
385
|
+
startedOra: Ora,
|
|
386
|
+
ctx: ResolvedEmbeddableConfig,
|
|
381
387
|
): Promise<string> => {
|
|
382
388
|
const token = await getToken();
|
|
383
389
|
|
package/src/generate.test.ts
CHANGED
|
@@ -4,7 +4,7 @@ import * as path from "node:path";
|
|
|
4
4
|
import { checkNodeVersion } from "./utils";
|
|
5
5
|
import { loadConfig, createCompiler } from "@stencil/core/compiler";
|
|
6
6
|
import { findFiles, getContentHash } from "@embeddable.com/sdk-utils";
|
|
7
|
-
|
|
7
|
+
import { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
8
8
|
const config = {
|
|
9
9
|
client: {
|
|
10
10
|
rootDir: "rootDir",
|
|
@@ -96,7 +96,7 @@ describe("generate", () => {
|
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
it("should generate bundle", async () => {
|
|
99
|
-
await generate(config, "sdk-react");
|
|
99
|
+
await generate(config as unknown as ResolvedEmbeddableConfig, "sdk-react");
|
|
100
100
|
|
|
101
101
|
// should inject css
|
|
102
102
|
expect(fs.writeFile).toHaveBeenCalledWith("componentDir/style.css", "");
|
|
@@ -119,6 +119,7 @@ describe("generate", () => {
|
|
|
119
119
|
const ctx = {
|
|
120
120
|
...config,
|
|
121
121
|
dev: {
|
|
122
|
+
watch: true,
|
|
122
123
|
logger: vi.fn(),
|
|
123
124
|
sys: vi.fn(),
|
|
124
125
|
},
|
|
@@ -127,7 +128,7 @@ describe("generate", () => {
|
|
|
127
128
|
vi.mocked(fs.readFile).mockResolvedValue(
|
|
128
129
|
"replace-this-with-component-name",
|
|
129
130
|
);
|
|
130
|
-
await generate(ctx, "sdk-react");
|
|
131
|
+
await generate(ctx as unknown as ResolvedEmbeddableConfig, "sdk-react");
|
|
131
132
|
|
|
132
133
|
expect(createCompiler).toHaveBeenCalled();
|
|
133
134
|
|
package/src/generate.ts
CHANGED
|
@@ -3,7 +3,7 @@ import * as path from "node:path";
|
|
|
3
3
|
import { createNodeLogger, createNodeSys } from "@stencil/core/sys/node";
|
|
4
4
|
import { createCompiler, loadConfig } from "@stencil/core/compiler";
|
|
5
5
|
import { findFiles, getContentHash } from "@embeddable.com/sdk-utils";
|
|
6
|
-
|
|
6
|
+
import { PluginName, ResolvedEmbeddableConfig } from "./defineConfig";
|
|
7
7
|
import * as sorcery from "sorcery";
|
|
8
8
|
|
|
9
9
|
const STYLE_IMPORTS_TOKEN = "{{STYLES_IMPORT}}";
|
|
@@ -12,7 +12,10 @@ const RENDER_IMPORT_TOKEN = "{{RENDER_IMPORT}}";
|
|
|
12
12
|
// stencil doesn't support dynamic component tag name, so we need to replace it manually
|
|
13
13
|
const COMPONENT_TAG_TOKEN = "replace-this-with-component-name";
|
|
14
14
|
|
|
15
|
-
export default async (
|
|
15
|
+
export default async (
|
|
16
|
+
ctx: ResolvedEmbeddableConfig,
|
|
17
|
+
pluginName: PluginName,
|
|
18
|
+
) => {
|
|
16
19
|
await injectCSS(ctx, pluginName);
|
|
17
20
|
|
|
18
21
|
await injectBundleRender(ctx, pluginName);
|
|
@@ -22,7 +25,10 @@ export default async (ctx: any, pluginName: string) => {
|
|
|
22
25
|
await generateSourceMap(ctx, pluginName);
|
|
23
26
|
};
|
|
24
27
|
|
|
25
|
-
async function injectCSS(
|
|
28
|
+
async function injectCSS(
|
|
29
|
+
ctx: ResolvedEmbeddableConfig,
|
|
30
|
+
pluginName: PluginName,
|
|
31
|
+
) {
|
|
26
32
|
const CUSTOMER_BUILD = path.resolve(
|
|
27
33
|
ctx.client.buildDir,
|
|
28
34
|
ctx[pluginName].outputOptions.buildName,
|
|
@@ -48,7 +54,10 @@ async function injectCSS(ctx: any, pluginName: string) {
|
|
|
48
54
|
);
|
|
49
55
|
}
|
|
50
56
|
|
|
51
|
-
async function injectBundleRender(
|
|
57
|
+
async function injectBundleRender(
|
|
58
|
+
ctx: ResolvedEmbeddableConfig,
|
|
59
|
+
pluginName: PluginName,
|
|
60
|
+
) {
|
|
52
61
|
const importStr = `import render from '../${ctx[pluginName].outputOptions.buildName}/${ctx[pluginName].outputOptions.fileName}';`;
|
|
53
62
|
|
|
54
63
|
let content = await fs.readFile(
|
|
@@ -96,10 +105,10 @@ async function addComponentTagName(filePath: string, bundleHash: string) {
|
|
|
96
105
|
]);
|
|
97
106
|
}
|
|
98
107
|
|
|
99
|
-
async function runStencil(ctx:
|
|
108
|
+
async function runStencil(ctx: ResolvedEmbeddableConfig): Promise<void> {
|
|
100
109
|
const logger = ctx.dev?.logger || createNodeLogger();
|
|
101
110
|
const sys = ctx.dev?.sys || createNodeSys({ process });
|
|
102
|
-
const devMode = !!ctx.dev;
|
|
111
|
+
const devMode = !!ctx.dev?.watch;
|
|
103
112
|
|
|
104
113
|
const isWindows = process.platform === "win32";
|
|
105
114
|
|
|
@@ -148,7 +157,7 @@ async function runStencil(ctx: any): Promise<void> {
|
|
|
148
157
|
process.chdir(ctx.client.rootDir);
|
|
149
158
|
}
|
|
150
159
|
|
|
151
|
-
async function handleStencilBuildOutput(ctx:
|
|
160
|
+
async function handleStencilBuildOutput(ctx: ResolvedEmbeddableConfig) {
|
|
152
161
|
const entryFilePath = path.resolve(
|
|
153
162
|
ctx.client.stencilBuild,
|
|
154
163
|
"embeddable-wrapper.esm.js",
|
|
@@ -174,7 +183,10 @@ async function handleStencilBuildOutput(ctx: any) {
|
|
|
174
183
|
);
|
|
175
184
|
}
|
|
176
185
|
|
|
177
|
-
async function generateSourceMap(
|
|
186
|
+
async function generateSourceMap(
|
|
187
|
+
ctx: ResolvedEmbeddableConfig,
|
|
188
|
+
pluginName: PluginName,
|
|
189
|
+
) {
|
|
178
190
|
const componentBuildDir = path.resolve(
|
|
179
191
|
ctx.client.buildDir,
|
|
180
192
|
ctx[pluginName].outputOptions.buildName,
|
package/src/globalCleanup.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import * as fsP from "node:fs/promises";
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
|
+
import { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
3
4
|
|
|
4
|
-
export default async (ctx:
|
|
5
|
-
if (fs.existsSync(ctx.client.buildDir))
|
|
5
|
+
export default async (ctx: ResolvedEmbeddableConfig) => {
|
|
6
|
+
if (fs.existsSync(ctx.client.buildDir)) {
|
|
6
7
|
await fsP.rm(ctx.client.buildDir, { recursive: true });
|
|
8
|
+
}
|
|
7
9
|
};
|
package/src/index.ts
CHANGED
package/src/prepare.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as fsSync from "node:fs";
|
|
2
2
|
import * as fs from "node:fs/promises";
|
|
3
|
+
import { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
3
4
|
|
|
4
|
-
export default async (ctx:
|
|
5
|
+
export default async (ctx: ResolvedEmbeddableConfig) => {
|
|
5
6
|
await removeIfExists(ctx);
|
|
6
7
|
|
|
7
8
|
await copyStencilConfigsToClient(ctx);
|
|
@@ -9,14 +10,18 @@ export default async (ctx: any) => {
|
|
|
9
10
|
await createComponentDir(ctx.client.componentDir);
|
|
10
11
|
};
|
|
11
12
|
|
|
12
|
-
export async function removeIfExists(ctx:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
export async function removeIfExists(ctx: ResolvedEmbeddableConfig) {
|
|
14
|
+
const promises = [];
|
|
15
|
+
if (fsSync.existsSync(ctx.client.buildDir)) {
|
|
16
|
+
promises.push(fs.rm(ctx.client.buildDir, { recursive: true }));
|
|
17
|
+
}
|
|
18
|
+
if (fsSync.existsSync(ctx.client.tmpDir)) {
|
|
19
|
+
promises.push(fs.rm(ctx.client.tmpDir, { recursive: true }));
|
|
20
|
+
}
|
|
21
|
+
await Promise.all(promises);
|
|
17
22
|
}
|
|
18
23
|
|
|
19
|
-
async function copyStencilConfigsToClient(ctx:
|
|
24
|
+
async function copyStencilConfigsToClient(ctx: ResolvedEmbeddableConfig) {
|
|
20
25
|
await fs.cp(ctx.core.configsDir, ctx.client.buildDir, { recursive: true });
|
|
21
26
|
}
|
|
22
27
|
|
package/src/provideConfig.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as url from "node:url";
|
|
3
|
+
import { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
3
4
|
|
|
4
|
-
export default async () => {
|
|
5
|
+
export default async (): Promise<ResolvedEmbeddableConfig> => {
|
|
5
6
|
const configFilePath = `${process.cwd()}/embeddable.config.js`;
|
|
6
7
|
const tsConfigFilePath = `${process.cwd()}/embeddable.config.ts`;
|
|
7
8
|
|
package/src/push.test.ts
CHANGED
|
@@ -107,7 +107,9 @@ describe("push", () => {
|
|
|
107
107
|
vi.mocked(checkNodeVersion).mockResolvedValue(true);
|
|
108
108
|
vi.mocked(checkBuildSuccess).mockResolvedValue(true);
|
|
109
109
|
vi.mocked(getArgumentByKey).mockReturnValue(undefined);
|
|
110
|
-
vi.mocked(provideConfig).mockResolvedValue(
|
|
110
|
+
vi.mocked(provideConfig).mockResolvedValue(
|
|
111
|
+
config as ResolvedEmbeddableConfig,
|
|
112
|
+
);
|
|
111
113
|
vi.mocked(fs.access).mockResolvedValue(undefined);
|
|
112
114
|
vi.mocked(fs.readFile).mockImplementation(async () =>
|
|
113
115
|
Buffer.from(`{"access_token":"mocked-token"}`),
|
|
@@ -217,7 +219,7 @@ describe("push", () => {
|
|
|
217
219
|
...config,
|
|
218
220
|
pushModels: false,
|
|
219
221
|
pushComponents: false,
|
|
220
|
-
});
|
|
222
|
+
} as ResolvedEmbeddableConfig);
|
|
221
223
|
|
|
222
224
|
await push();
|
|
223
225
|
|
|
@@ -240,7 +242,7 @@ describe("push", () => {
|
|
|
240
242
|
...config,
|
|
241
243
|
pushModels: false,
|
|
242
244
|
pushComponents: true,
|
|
243
|
-
});
|
|
245
|
+
} as ResolvedEmbeddableConfig);
|
|
244
246
|
|
|
245
247
|
await push();
|
|
246
248
|
|
|
@@ -346,7 +348,9 @@ describe("push", () => {
|
|
|
346
348
|
it("should fail if build directory does not exist", async () => {
|
|
347
349
|
vi.spyOn(console, "error").mockImplementation(() => undefined);
|
|
348
350
|
vi.mocked(fs.access).mockRejectedValue(new Error("No such directory"));
|
|
349
|
-
vi.mocked(provideConfig).mockResolvedValue(
|
|
351
|
+
vi.mocked(provideConfig).mockResolvedValue(
|
|
352
|
+
config as ResolvedEmbeddableConfig,
|
|
353
|
+
);
|
|
350
354
|
|
|
351
355
|
await push();
|
|
352
356
|
|
|
@@ -360,7 +364,9 @@ describe("push", () => {
|
|
|
360
364
|
vi.spyOn(console, "error").mockImplementation(() => undefined);
|
|
361
365
|
vi.mocked(fs.access).mockResolvedValue(undefined);
|
|
362
366
|
vi.mocked(fs.readFile).mockResolvedValue(Buffer.from("{}"));
|
|
363
|
-
vi.mocked(provideConfig).mockResolvedValue(
|
|
367
|
+
vi.mocked(provideConfig).mockResolvedValue(
|
|
368
|
+
config as ResolvedEmbeddableConfig,
|
|
369
|
+
);
|
|
364
370
|
|
|
365
371
|
await push();
|
|
366
372
|
|
|
@@ -540,7 +546,7 @@ describe("push", () => {
|
|
|
540
546
|
modelsSrc: undefined,
|
|
541
547
|
presetsSrc: undefined,
|
|
542
548
|
},
|
|
543
|
-
} as ResolvedEmbeddableConfig;
|
|
549
|
+
} as unknown as ResolvedEmbeddableConfig;
|
|
544
550
|
|
|
545
551
|
await buildArchive(testConfig);
|
|
546
552
|
|