@embeddable.com/sdk-core 3.14.0-next.2 → 3.14.0-next.3
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/index.esm.js +107 -74
- package/lib/index.esm.js.map +1 -1
- package/lib/push.d.ts +2 -1
- package/package.json +1 -1
- package/src/dev.test.ts +75 -10
- package/src/dev.ts +145 -101
- package/src/push.ts +14 -5
package/lib/push.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Ora } from "ora";
|
|
2
2
|
import { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
3
3
|
export declare const CUBE_FILES: RegExp;
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const CLIENT_CONTEXT_FILES: RegExp;
|
|
5
|
+
export declare const SECURITY_CONTEXT_FILES: RegExp;
|
|
5
6
|
declare const _default: () => Promise<void>;
|
|
6
7
|
export default _default;
|
|
7
8
|
export declare function buildArchive(config: ResolvedEmbeddableConfig): Promise<Ora>;
|
package/package.json
CHANGED
package/src/dev.test.ts
CHANGED
|
@@ -10,9 +10,11 @@ import { checkNodeVersion } from "./utils";
|
|
|
10
10
|
import { createManifest } from "./cleanup";
|
|
11
11
|
import prepare from "./prepare";
|
|
12
12
|
import { WebSocketServer } from "ws";
|
|
13
|
+
import * as open from "open";
|
|
13
14
|
import { logError } from "./logger";
|
|
14
15
|
import { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
15
16
|
import { RollupWatcher } from "rollup";
|
|
17
|
+
import build from "./build";
|
|
16
18
|
// Mock dependencies
|
|
17
19
|
vi.mock("./buildTypes", () => ({ default: vi.fn() }));
|
|
18
20
|
vi.mock("./buildGlobalHooks", () => ({ default: vi.fn() }));
|
|
@@ -23,10 +25,11 @@ vi.mock("@stencil/core/sys/node", () => ({
|
|
|
23
25
|
createNodeLogger: vi.fn(),
|
|
24
26
|
createNodeSys: vi.fn(),
|
|
25
27
|
}));
|
|
28
|
+
vi.mock("open", () => ({ default: vi.fn() }));
|
|
26
29
|
vi.mock("ws", () => ({ WebSocketServer: vi.fn() }));
|
|
27
|
-
vi.mock("chokidar", () => ({ watch: vi.fn() }));
|
|
30
|
+
vi.mock("chokidar", () => ({ watch: vi.fn((_) => ({ on: vi.fn() })) }));
|
|
28
31
|
vi.mock("./login", () => ({ getToken: vi.fn(), default: vi.fn() }));
|
|
29
|
-
vi.mock("axios", () => ({ default: { get: vi.fn() } }));
|
|
32
|
+
vi.mock("axios", () => ({ default: { get: vi.fn(), post: vi.fn() } }));
|
|
30
33
|
vi.mock("@embeddable.com/sdk-utils", () => ({ findFiles: vi.fn() }));
|
|
31
34
|
vi.mock("./push", () => ({ archive: vi.fn(), sendBuild: vi.fn() }));
|
|
32
35
|
vi.mock("./validate", () => ({ default: vi.fn() }));
|
|
@@ -65,7 +68,7 @@ describe("dev command", () => {
|
|
|
65
68
|
() =>
|
|
66
69
|
({
|
|
67
70
|
listen: listenMock,
|
|
68
|
-
}) as any
|
|
71
|
+
}) as any
|
|
69
72
|
);
|
|
70
73
|
vi.mocked(WebSocketServer).mockImplementation(() => {
|
|
71
74
|
return {
|
|
@@ -73,19 +76,20 @@ describe("dev command", () => {
|
|
|
73
76
|
on: vi.fn(),
|
|
74
77
|
} as any;
|
|
75
78
|
});
|
|
76
|
-
|
|
77
|
-
on: vi.fn(),
|
|
78
|
-
} as any);
|
|
79
|
+
|
|
79
80
|
// Mock process.on to avoid actually setting up process listeners
|
|
80
81
|
vi.spyOn(process, "on").mockImplementation(() => process);
|
|
81
82
|
vi.spyOn(process, "exit").mockImplementation(() => undefined as never);
|
|
82
83
|
|
|
83
84
|
vi.mocked(provideConfig).mockResolvedValue(
|
|
84
|
-
mockConfig as unknown as ResolvedEmbeddableConfig
|
|
85
|
+
mockConfig as unknown as ResolvedEmbeddableConfig
|
|
85
86
|
);
|
|
86
87
|
vi.mocked(getToken).mockResolvedValue("mock-token");
|
|
87
88
|
vi.mocked(axios.get).mockResolvedValue({
|
|
88
|
-
data: [{
|
|
89
|
+
data: [{ workspaceId: "mock-workspace" }],
|
|
90
|
+
});
|
|
91
|
+
vi.mocked(axios.post).mockResolvedValue({
|
|
92
|
+
data: "mock-workspace",
|
|
89
93
|
});
|
|
90
94
|
|
|
91
95
|
// @ts-ignore
|
|
@@ -100,7 +104,69 @@ describe("dev command", () => {
|
|
|
100
104
|
vi.restoreAllMocks();
|
|
101
105
|
});
|
|
102
106
|
|
|
103
|
-
it("should set up the development
|
|
107
|
+
it("should set up the development and open workspace page with pushComponents false", async () => {
|
|
108
|
+
vi.mocked(provideConfig).mockResolvedValue({
|
|
109
|
+
...mockConfig,
|
|
110
|
+
pushComponents: false,
|
|
111
|
+
pushModels: true,
|
|
112
|
+
} as unknown as ResolvedEmbeddableConfig);
|
|
113
|
+
|
|
114
|
+
// Run the dev command
|
|
115
|
+
await dev();
|
|
116
|
+
|
|
117
|
+
// Verify that the necessary functions were called
|
|
118
|
+
expect(checkNodeVersion).toHaveBeenCalled();
|
|
119
|
+
expect(prepare).toHaveBeenCalled();
|
|
120
|
+
expect(http.createServer).toHaveBeenCalled();
|
|
121
|
+
expect(WebSocketServer).toHaveBeenCalled();
|
|
122
|
+
|
|
123
|
+
// Verify that the server was set up to listen on the correct port
|
|
124
|
+
expect(listenMock).toHaveBeenCalledWith(8926, expect.any(Function));
|
|
125
|
+
|
|
126
|
+
// Call the listen callback to simulate the server being set up
|
|
127
|
+
listenMock.mock.calls[0][1]();
|
|
128
|
+
expect(createManifest).toHaveBeenCalled();
|
|
129
|
+
|
|
130
|
+
await expect.poll(() => chokidar.watch).toBeCalledTimes(1);
|
|
131
|
+
|
|
132
|
+
expect(open.default).toHaveBeenCalledWith(
|
|
133
|
+
"http://preview.example.com/workspace/mock-workspace"
|
|
134
|
+
);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("should set up the development with pushComponents false", async () => {
|
|
138
|
+
vi.mocked(provideConfig).mockResolvedValue({
|
|
139
|
+
...mockConfig,
|
|
140
|
+
pushComponents: false,
|
|
141
|
+
pushModels: true,
|
|
142
|
+
} as unknown as ResolvedEmbeddableConfig);
|
|
143
|
+
|
|
144
|
+
// Run the dev command
|
|
145
|
+
await dev();
|
|
146
|
+
|
|
147
|
+
// Verify that the necessary functions were called
|
|
148
|
+
expect(checkNodeVersion).toHaveBeenCalled();
|
|
149
|
+
expect(prepare).toHaveBeenCalled();
|
|
150
|
+
expect(http.createServer).toHaveBeenCalled();
|
|
151
|
+
expect(WebSocketServer).toHaveBeenCalled();
|
|
152
|
+
|
|
153
|
+
// Verify that the server was set up to listen on the correct port
|
|
154
|
+
expect(listenMock).toHaveBeenCalledWith(8926, expect.any(Function));
|
|
155
|
+
|
|
156
|
+
// Call the listen callback to simulate the server being set up
|
|
157
|
+
listenMock.mock.calls[0][1]();
|
|
158
|
+
expect(createManifest).toHaveBeenCalled();
|
|
159
|
+
|
|
160
|
+
await expect.poll(() => chokidar.watch).toBeCalledTimes(1);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("should set up the development environment with pushComponents true", async () => {
|
|
164
|
+
vi.mocked(provideConfig).mockResolvedValue({
|
|
165
|
+
...mockConfig,
|
|
166
|
+
pushComponents: true,
|
|
167
|
+
pushModels: true,
|
|
168
|
+
} as unknown as ResolvedEmbeddableConfig);
|
|
169
|
+
|
|
104
170
|
// Run the dev command
|
|
105
171
|
await dev();
|
|
106
172
|
|
|
@@ -115,7 +181,6 @@ describe("dev command", () => {
|
|
|
115
181
|
|
|
116
182
|
// Call the listen callback to simulate the server being set up
|
|
117
183
|
listenMock.mock.calls[0][1]();
|
|
118
|
-
expect(buildGlobalHooks).toHaveBeenCalled();
|
|
119
184
|
expect(createManifest).toHaveBeenCalled();
|
|
120
185
|
|
|
121
186
|
await expect.poll(() => chokidar.watch).toBeCalledTimes(2);
|
package/src/dev.ts
CHANGED
|
@@ -17,11 +17,16 @@ import { ChildProcess } from "node:child_process";
|
|
|
17
17
|
import { WebSocketServer } from "ws";
|
|
18
18
|
import * as chokidar from "chokidar";
|
|
19
19
|
import * as path from "path";
|
|
20
|
-
import { FSWatcher } from "chokidar";
|
|
21
20
|
import { getToken, default as login } from "./login";
|
|
22
21
|
import axios from "axios";
|
|
23
22
|
import { findFiles } from "@embeddable.com/sdk-utils";
|
|
24
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
archive,
|
|
25
|
+
CUBE_FILES,
|
|
26
|
+
sendBuild,
|
|
27
|
+
SECURITY_CONTEXT_FILES,
|
|
28
|
+
CLIENT_CONTEXT_FILES,
|
|
29
|
+
} from "./push";
|
|
25
30
|
import validate from "./validate";
|
|
26
31
|
import { checkNodeVersion } from "./utils";
|
|
27
32
|
import { createManifest } from "./cleanup";
|
|
@@ -36,6 +41,9 @@ import finalhandler from "finalhandler";
|
|
|
36
41
|
import serveStatic from "serve-static";
|
|
37
42
|
import { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
38
43
|
import buildGlobalHooks from "./buildGlobalHooks";
|
|
44
|
+
|
|
45
|
+
type FSWatcher = chokidar.FSWatcher;
|
|
46
|
+
|
|
39
47
|
dotenv.config();
|
|
40
48
|
|
|
41
49
|
let wss: WebSocketServer;
|
|
@@ -106,7 +114,7 @@ export default async () => {
|
|
|
106
114
|
stencilBuild: path.resolve(buildDir, "dist", "embeddable-wrapper"),
|
|
107
115
|
tmpDir: path.resolve(
|
|
108
116
|
defaultConfig.client.rootDir,
|
|
109
|
-
".embeddable-dev-tmp"
|
|
117
|
+
".embeddable-dev-tmp"
|
|
110
118
|
),
|
|
111
119
|
},
|
|
112
120
|
};
|
|
@@ -122,7 +130,7 @@ export default async () => {
|
|
|
122
130
|
try {
|
|
123
131
|
previewWorkspace = await getPreviewWorkspace(
|
|
124
132
|
workspacePreparation,
|
|
125
|
-
config
|
|
133
|
+
config
|
|
126
134
|
);
|
|
127
135
|
} catch (e: any) {
|
|
128
136
|
if (e.response?.status === 401) {
|
|
@@ -131,11 +139,11 @@ export default async () => {
|
|
|
131
139
|
workspacePreparation = ora("Preparing workspace...").start();
|
|
132
140
|
previewWorkspace = await getPreviewWorkspace(
|
|
133
141
|
workspacePreparation,
|
|
134
|
-
config
|
|
142
|
+
config
|
|
135
143
|
);
|
|
136
144
|
} else {
|
|
137
145
|
workspacePreparation.fail(
|
|
138
|
-
e.response?.data?.errorMessage || "Unknown error: " + e.message
|
|
146
|
+
e.response?.data?.errorMessage || "Unknown error: " + e.message
|
|
139
147
|
);
|
|
140
148
|
process.exit(1);
|
|
141
149
|
}
|
|
@@ -143,25 +151,16 @@ export default async () => {
|
|
|
143
151
|
|
|
144
152
|
workspacePreparation.succeed("Workspace is ready");
|
|
145
153
|
|
|
146
|
-
const { themeWatcher, lifecycleWatcher } = await buildGlobalHooks(config);
|
|
147
|
-
|
|
148
|
-
if (themeWatcher) {
|
|
149
|
-
await globalHookWatcher(themeWatcher, config);
|
|
150
|
-
}
|
|
151
|
-
if (lifecycleWatcher) {
|
|
152
|
-
await globalHookWatcher(lifecycleWatcher, config);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
154
|
const server = http.createServer(
|
|
156
155
|
async (request: IncomingMessage, res: ServerResponse) => {
|
|
157
156
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
158
157
|
res.setHeader(
|
|
159
158
|
"Access-Control-Allow-Methods",
|
|
160
|
-
"GET, POST, PUT, DELETE, OPTIONS"
|
|
159
|
+
"GET, POST, PUT, DELETE, OPTIONS"
|
|
161
160
|
);
|
|
162
161
|
res.setHeader(
|
|
163
162
|
"Access-Control-Allow-Headers",
|
|
164
|
-
"Content-Type, Authorization"
|
|
163
|
+
"Content-Type, Authorization"
|
|
165
164
|
);
|
|
166
165
|
|
|
167
166
|
if (request.method === "OPTIONS") {
|
|
@@ -182,16 +181,17 @@ export default async () => {
|
|
|
182
181
|
} catch {}
|
|
183
182
|
|
|
184
183
|
serve(request, res, done);
|
|
185
|
-
}
|
|
184
|
+
}
|
|
186
185
|
);
|
|
187
186
|
|
|
188
|
-
|
|
187
|
+
const { themeWatcher, lifecycleWatcher } = await buildGlobalHooks(config);
|
|
189
188
|
|
|
189
|
+
wss = new WebSocketServer({ server });
|
|
190
190
|
server.listen(SERVER_PORT, async () => {
|
|
191
191
|
const watchers: Array<RollupWatcher | FSWatcher> = [];
|
|
192
192
|
if (sys?.onProcessInterrupt) {
|
|
193
193
|
sys.onProcessInterrupt(
|
|
194
|
-
async () => await onClose(server, sys, watchers, config)
|
|
194
|
+
async () => await onClose(server, sys, watchers, config)
|
|
195
195
|
);
|
|
196
196
|
}
|
|
197
197
|
|
|
@@ -210,31 +210,39 @@ export default async () => {
|
|
|
210
210
|
editorsMetaFileName: "embeddable-editors-meta.js",
|
|
211
211
|
});
|
|
212
212
|
|
|
213
|
-
await
|
|
213
|
+
await sendBuildChanges(config);
|
|
214
214
|
|
|
215
|
-
|
|
216
|
-
const
|
|
215
|
+
if (config.pushComponents) {
|
|
216
|
+
for (const getPlugin of config.plugins) {
|
|
217
|
+
const plugin = getPlugin();
|
|
217
218
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
219
|
+
breadcrumbs.push("validate plugin");
|
|
220
|
+
await plugin.validate(config);
|
|
221
|
+
breadcrumbs.push("build plugin");
|
|
222
|
+
const watcher = await plugin.build(config);
|
|
223
|
+
breadcrumbs.push("configure watcher");
|
|
224
|
+
await configureWatcher(watcher as RollupWatcher, config);
|
|
225
|
+
watchers.push(watcher as RollupWatcher);
|
|
226
|
+
}
|
|
226
227
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
228
|
+
const customGlobalCssWatch = globalCssWatcher(config);
|
|
229
|
+
watchers.push(customGlobalCssWatch);
|
|
230
|
+
|
|
231
|
+
if (themeWatcher) {
|
|
232
|
+
await globalHookWatcher(themeWatcher, config);
|
|
233
|
+
watchers.push(themeWatcher);
|
|
234
|
+
}
|
|
235
|
+
if (lifecycleWatcher) {
|
|
236
|
+
await globalHookWatcher(lifecycleWatcher, config);
|
|
237
|
+
watchers.push(lifecycleWatcher);
|
|
238
|
+
}
|
|
239
|
+
} else {
|
|
240
|
+
await openDevWorkspacePage(config.previewBaseUrl);
|
|
237
241
|
}
|
|
242
|
+
|
|
243
|
+
const cubeSecurityContextAndClientContextWatch =
|
|
244
|
+
await cubeSecurityContextAndClientContextWatcher(config);
|
|
245
|
+
watchers.push(cubeSecurityContextAndClientContextWatch);
|
|
238
246
|
});
|
|
239
247
|
} catch (error: any) {
|
|
240
248
|
await logError({ command: "dev", breadcrumbs, error });
|
|
@@ -245,7 +253,7 @@ export default async () => {
|
|
|
245
253
|
|
|
246
254
|
const configureWatcher = async (
|
|
247
255
|
watcher: RollupWatcher,
|
|
248
|
-
ctx: ResolvedEmbeddableConfig
|
|
256
|
+
ctx: ResolvedEmbeddableConfig
|
|
249
257
|
) => {
|
|
250
258
|
watcher.on("change", (path) => {
|
|
251
259
|
changedFiles.push(path);
|
|
@@ -306,40 +314,52 @@ const onBuildStart = async (ctx: ResolvedEmbeddableConfig) => {
|
|
|
306
314
|
sendMessage("componentsBuildStart", { changedFiles });
|
|
307
315
|
};
|
|
308
316
|
|
|
317
|
+
const openDevWorkspacePage = async (previewBaseUrl: string) => {
|
|
318
|
+
const open = (await import("open")).default;
|
|
319
|
+
return await open(`${previewBaseUrl}/workspace/${previewWorkspace}`);
|
|
320
|
+
};
|
|
321
|
+
|
|
309
322
|
const onBundleBuildEnd = async (ctx: ResolvedEmbeddableConfig) => {
|
|
310
323
|
if (!onlyTypesChanged() || changedFiles.length === 0) {
|
|
311
324
|
await buildWebComponent(ctx);
|
|
312
325
|
}
|
|
313
326
|
if (browserWindow == null) {
|
|
314
|
-
|
|
315
|
-
browserWindow = await open(
|
|
316
|
-
`${ctx.previewBaseUrl}/workspace/${previewWorkspace}`,
|
|
317
|
-
);
|
|
327
|
+
browserWindow = await openDevWorkspacePage(ctx.previewBaseUrl);
|
|
318
328
|
} else {
|
|
319
329
|
sendMessage("componentsBuildSuccess");
|
|
320
330
|
}
|
|
321
331
|
};
|
|
322
332
|
|
|
323
|
-
const
|
|
324
|
-
ctx: ResolvedEmbeddableConfig
|
|
333
|
+
const cubeSecurityContextAndClientContextWatcher = async (
|
|
334
|
+
ctx: ResolvedEmbeddableConfig
|
|
325
335
|
): Promise<FSWatcher> => {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}),
|
|
331
|
-
fg("**/*.{sc,cc}.{yaml,yml}", {
|
|
336
|
+
let filesToWatch: any = [];
|
|
337
|
+
|
|
338
|
+
if (ctx.pushComponents) {
|
|
339
|
+
const cubeFiles = await fg("**/*.cc.{yaml,yml}", {
|
|
332
340
|
cwd: ctx.client.presetsSrc,
|
|
333
341
|
absolute: true,
|
|
334
|
-
})
|
|
335
|
-
|
|
342
|
+
});
|
|
343
|
+
filesToWatch = [...filesToWatch, ...cubeFiles];
|
|
344
|
+
}
|
|
336
345
|
|
|
337
|
-
|
|
338
|
-
[
|
|
339
|
-
|
|
340
|
-
|
|
346
|
+
if (ctx.pushModels) {
|
|
347
|
+
const [modelsFiles, securityContextFiles] = await Promise.all([
|
|
348
|
+
fg("**/*.cube.{yaml,yml,js}", {
|
|
349
|
+
cwd: ctx.client.modelsSrc,
|
|
350
|
+
absolute: true,
|
|
351
|
+
}),
|
|
352
|
+
fg("**/*.sc.{yaml,yml}", {
|
|
353
|
+
cwd: ctx.client.presetsSrc,
|
|
354
|
+
absolute: true,
|
|
355
|
+
}),
|
|
356
|
+
]);
|
|
357
|
+
filesToWatch = [...modelsFiles, ...securityContextFiles];
|
|
358
|
+
}
|
|
341
359
|
|
|
342
|
-
fsWatcher.
|
|
360
|
+
const fsWatcher = chokidar.watch(filesToWatch, chokidarWatchOptions);
|
|
361
|
+
|
|
362
|
+
fsWatcher.on("all", () => sendBuildChanges(ctx));
|
|
343
363
|
|
|
344
364
|
return fsWatcher;
|
|
345
365
|
};
|
|
@@ -354,51 +374,72 @@ const globalCssWatcher = (ctx: ResolvedEmbeddableConfig): FSWatcher => {
|
|
|
354
374
|
return fsWatcher;
|
|
355
375
|
};
|
|
356
376
|
|
|
357
|
-
const
|
|
358
|
-
ctx: ResolvedEmbeddableConfig,
|
|
359
|
-
) => {
|
|
360
|
-
sendMessage("dataModelsAndOrSecurityContextUpdateStart");
|
|
377
|
+
const sendBuildChanges = async (ctx: ResolvedEmbeddableConfig) => {
|
|
361
378
|
const isValid = await validate(ctx);
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
379
|
+
|
|
380
|
+
if (!isValid) {
|
|
381
|
+
return sendMessage("dataModelsAndOrSecurityContextUpdateError");
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const sending = ora(
|
|
385
|
+
"Synchronising data models and/or security contexts..."
|
|
386
|
+
).start();
|
|
387
|
+
|
|
388
|
+
let filesList: [string, string][] = [];
|
|
389
|
+
if (ctx.pushComponents) {
|
|
390
|
+
const clientContextFilesList = await findFiles(
|
|
369
391
|
ctx.client.presetsSrc,
|
|
370
|
-
|
|
392
|
+
CLIENT_CONTEXT_FILES
|
|
371
393
|
);
|
|
372
394
|
|
|
373
395
|
// Map the files to include their full filenames
|
|
374
|
-
const
|
|
375
|
-
(entry): [string, string] => [path.basename(entry[1]), entry[1]]
|
|
396
|
+
const clientContextFileList = [...clientContextFilesList].map(
|
|
397
|
+
(entry): [string, string] => [path.basename(entry[1]), entry[1]]
|
|
376
398
|
);
|
|
377
399
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
"embeddable-manifest.json",
|
|
381
|
-
path.resolve(ctx.client.buildDir, "embeddable-manifest.json"),
|
|
382
|
-
]);
|
|
400
|
+
filesList = [...clientContextFileList];
|
|
401
|
+
}
|
|
383
402
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
403
|
+
if (ctx.pushModels) {
|
|
404
|
+
const cubeFilesList = await findFiles(ctx.client.modelsSrc, CUBE_FILES);
|
|
405
|
+
const securityContextFilesList = await findFiles(
|
|
406
|
+
ctx.client.presetsSrc,
|
|
407
|
+
SECURITY_CONTEXT_FILES
|
|
408
|
+
);
|
|
409
|
+
|
|
410
|
+
// Map the files to include their full filenames
|
|
411
|
+
const cubeAndSecurityContextFileList = [
|
|
412
|
+
...cubeFilesList,
|
|
413
|
+
...securityContextFilesList,
|
|
414
|
+
].map((entry): [string, string] => [path.basename(entry[1]), entry[1]]);
|
|
415
|
+
|
|
416
|
+
filesList = [
|
|
417
|
+
...filesList,
|
|
418
|
+
...cubeAndSecurityContextFileList,
|
|
419
|
+
// add manifest to the archive
|
|
420
|
+
[
|
|
421
|
+
"embeddable-manifest.json",
|
|
422
|
+
path.resolve(ctx.client.buildDir, "embeddable-manifest.json"),
|
|
423
|
+
],
|
|
424
|
+
];
|
|
394
425
|
}
|
|
426
|
+
|
|
427
|
+
const token = await getToken();
|
|
428
|
+
await archive({
|
|
429
|
+
ctx,
|
|
430
|
+
filesList,
|
|
431
|
+
isDev: true,
|
|
432
|
+
});
|
|
433
|
+
await sendBuild(ctx, { workspaceId: previewWorkspace, token });
|
|
434
|
+
sending.succeed(`Data models and/or security context synchronized`);
|
|
435
|
+
sendMessage("dataModelsAndOrSecurityContextUpdateSuccess");
|
|
395
436
|
};
|
|
396
437
|
|
|
397
438
|
const onClose = async (
|
|
398
439
|
server: Server,
|
|
399
440
|
sys: CompilerSystem,
|
|
400
441
|
watchers: Array<RollupWatcher | FSWatcher>,
|
|
401
|
-
config: ResolvedEmbeddableConfig
|
|
442
|
+
config: ResolvedEmbeddableConfig
|
|
402
443
|
) => {
|
|
403
444
|
server.close();
|
|
404
445
|
wss.close();
|
|
@@ -419,33 +460,36 @@ const onClose = async (
|
|
|
419
460
|
|
|
420
461
|
const getPreviewWorkspace = async (
|
|
421
462
|
startedOra: Ora,
|
|
422
|
-
ctx: ResolvedEmbeddableConfig
|
|
463
|
+
ctx: ResolvedEmbeddableConfig
|
|
423
464
|
): Promise<string> => {
|
|
424
465
|
const token = await getToken();
|
|
425
466
|
|
|
426
467
|
const params = minimist(process.argv.slice(2));
|
|
427
|
-
let
|
|
468
|
+
let primaryWorkspaceId = params.w || params.workspace;
|
|
428
469
|
|
|
429
|
-
if (!
|
|
470
|
+
if (!primaryWorkspaceId) {
|
|
430
471
|
startedOra.stop(); // Stop current Ora, otherwise the last option will get hidden by it.
|
|
431
472
|
const { workspaceId } = await selectWorkspace(ora, ctx, token);
|
|
432
|
-
|
|
473
|
+
primaryWorkspaceId = workspaceId;
|
|
433
474
|
startedOra.start();
|
|
434
475
|
}
|
|
435
476
|
|
|
436
477
|
try {
|
|
437
478
|
const instanceUrl = process.env.CUBE_CLOUD_ENDPOINT;
|
|
438
|
-
|
|
479
|
+
|
|
480
|
+
const response = await axios.post(
|
|
439
481
|
`${ctx.pushBaseUrl}/workspace/dev-workspace`,
|
|
440
482
|
{
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
483
|
+
primaryWorkspaceId,
|
|
484
|
+
instanceUrl,
|
|
485
|
+
pushModels: ctx.pushModels,
|
|
486
|
+
pushComponents: ctx.pushComponents,
|
|
487
|
+
},
|
|
488
|
+
{
|
|
445
489
|
headers: {
|
|
446
490
|
Authorization: `Bearer ${token}`,
|
|
447
491
|
},
|
|
448
|
-
}
|
|
492
|
+
}
|
|
449
493
|
);
|
|
450
494
|
return response.data;
|
|
451
495
|
} catch (e: any) {
|
package/src/push.ts
CHANGED
|
@@ -19,8 +19,8 @@ import { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
|
19
19
|
// grab cube files
|
|
20
20
|
export const CUBE_FILES = /^(.*)\.cube\.(ya?ml|js)$/;
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
export const
|
|
22
|
+
export const CLIENT_CONTEXT_FILES = /^(.*)\.cc\.ya?ml$/;
|
|
23
|
+
export const SECURITY_CONTEXT_FILES = /^(.*)\.sc\.ya?ml$/;
|
|
24
24
|
|
|
25
25
|
export default async () => {
|
|
26
26
|
await initLogger("push");
|
|
@@ -162,16 +162,25 @@ export async function buildArchive(config: ResolvedEmbeddableConfig) {
|
|
|
162
162
|
config.client.modelsSrc || config.client.srcDir,
|
|
163
163
|
CUBE_FILES,
|
|
164
164
|
);
|
|
165
|
-
const
|
|
165
|
+
const clientContextFilesList = await findFiles(
|
|
166
166
|
config.client.presetsSrc || config.client.srcDir,
|
|
167
|
-
|
|
167
|
+
CLIENT_CONTEXT_FILES,
|
|
168
168
|
);
|
|
169
|
+
const securityContextFilesList = await findFiles(
|
|
170
|
+
config.client.presetsSrc || config.client.srcDir,
|
|
171
|
+
SECURITY_CONTEXT_FILES,
|
|
172
|
+
);
|
|
173
|
+
|
|
169
174
|
filesList.push(
|
|
170
175
|
...cubeFilesList.map((entry): [string, string] => [
|
|
171
176
|
path.basename(entry[1]),
|
|
172
177
|
entry[1],
|
|
173
178
|
]),
|
|
174
|
-
...
|
|
179
|
+
...clientContextFilesList.map((entry): [string, string] => [
|
|
180
|
+
path.basename(entry[1]),
|
|
181
|
+
entry[1],
|
|
182
|
+
]),
|
|
183
|
+
...securityContextFilesList.map((entry): [string, string] => [
|
|
175
184
|
path.basename(entry[1]),
|
|
176
185
|
entry[1],
|
|
177
186
|
]),
|