@squiz/dxp-cli-next 5.19.0-develop.4 → 5.19.0-develop.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/lib/cmp/deploy.js CHANGED
@@ -41,7 +41,6 @@ const cli_color_1 = __importDefault(require("cli-color"));
41
41
  const ApiService_1 = require("../ApiService");
42
42
  const ApplicationStore_1 = require("../ApplicationStore");
43
43
  const ApplicationConfig_1 = require("../ApplicationConfig");
44
- const compiler_1 = require("./edge-components/compiler");
45
44
  const definitions_1 = require("./utils/definitions");
46
45
  const fs = __importStar(require("node:fs/promises"));
47
46
  const path = __importStar(require("node:path"));
@@ -65,7 +64,7 @@ const deployCommand = new commander_1.Command()
65
64
  console.warn(cli_color_1.default.yellow('WARN: Component service URL no longer requires /v1/ suffix'));
66
65
  }
67
66
  try {
68
- const dxpCacheDirPath = path.resolve(source, '.dxp');
67
+ const dxpCacheDirPath = path.resolve(source, '../.dxp');
69
68
  yield fs.mkdir(dxpCacheDirPath, { recursive: true });
70
69
  const outputDir = yield fs.mkdtemp(path.resolve(dxpCacheDirPath, 'cmp-'));
71
70
  const def = yield definitions_1.ComponentDefinition.load(source);
@@ -75,20 +74,18 @@ const deployCommand = new commander_1.Command()
75
74
  const componentServiceUrl = ((_b = options.componentServiceUrl) === null || _b === void 0 ? void 0 : _b.replace(/v1\/?$/, '')) ||
76
75
  (yield buildComponentServiceUrl(options.tenant));
77
76
  if (def.type === 'server') {
77
+ yield definitions_1.ComponentPreUpload.forServer(def, outputDir);
78
78
  if (options.dryRun) {
79
79
  console.info(cli_color_1.default.yellow('INFO: Cancelling deployment due to --dry-run flag'));
80
80
  return;
81
81
  }
82
- return yield (0, component_cli_lib_1.uploadComponentFolder)(apiService.client, componentServiceUrl, source, dxpCacheDirPath);
82
+ return yield (0, component_cli_lib_1.uploadComponentFolder)(apiService.client, componentServiceUrl, outputDir, dxpCacheDirPath);
83
83
  }
84
84
  if (def.type === 'edge') {
85
85
  if (process.env.FEATURE_EDGE_COMPONENTS !== 'true') {
86
86
  throw new Error('Component type "edge" is still in development. Run with environment variable "FEATURE_EDGE_COMPONENTS=true" to enable');
87
87
  }
88
- yield (0, compiler_1.compileUserCode)(def.mainEntryFilePath, path.join(outputDir, definitions_1.COMPILED_ENTRY_FILE));
89
- yield def.copyManifest(outputDir);
90
- yield def.copyPreviewFiles(outputDir);
91
- yield def.copyMockedUriFiles(outputDir);
88
+ yield definitions_1.ComponentPreUpload.forEdge(def, outputDir);
92
89
  if (options.dryRun) {
93
90
  console.info(cli_color_1.default.yellow('INFO: Cancelling deployment due to --dry-run flag'));
94
91
  return;
@@ -1,19 +1,22 @@
1
1
  import { z } from 'zod';
2
+ export declare class ComponentPreUpload {
3
+ static forEdge(component: ComponentDefinition, outputDir: string): Promise<void>;
4
+ static forServer(component: ComponentDefinition, outputDir: string): Promise<void>;
5
+ private static copyMockedUriFiles;
6
+ private static copyPreviewFiles;
7
+ }
2
8
  export declare class ComponentDefinition {
3
9
  baseDir: string;
4
10
  definition: BasicDefinition;
5
11
  static load(componentDirectory: string): Promise<ComponentDefinition | undefined>;
6
12
  private constructor();
7
13
  get mainEntryFilePath(): string;
8
- get mainFunction(): {
9
- name: string;
10
- entry: string;
11
- };
14
+ get mainFunction(): z.objectOutputType<{
15
+ name: z.ZodString;
16
+ entry: z.ZodString;
17
+ }, z.ZodTypeAny, "passthrough">;
12
18
  get manifestPath(): string;
13
19
  get type(): "server" | "edge";
14
- copyManifest(copyDir: string): Promise<void>;
15
- copyPreviewFiles(copyDir: string): Promise<void>;
16
- copyMockedUriFiles(copyDir: string): Promise<void>;
17
20
  }
18
21
  export declare const BasicDefinition: z.ZodIntersection<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
19
22
  type: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"server">>>;
@@ -21,57 +24,57 @@ export declare const BasicDefinition: z.ZodIntersection<z.ZodDiscriminatedUnion<
21
24
  functions: z.ZodEffects<z.ZodArray<z.ZodObject<{
22
25
  name: z.ZodString;
23
26
  entry: z.ZodString;
24
- }, "strip", z.ZodTypeAny, {
25
- name: string;
26
- entry: string;
27
- }, {
28
- name: string;
29
- entry: string;
30
- }>, "many">, {
31
- name: string;
32
- entry: string;
33
- }[], {
34
- name: string;
35
- entry: string;
36
- }[]>;
27
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
28
+ name: z.ZodString;
29
+ entry: z.ZodString;
30
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
31
+ name: z.ZodString;
32
+ entry: z.ZodString;
33
+ }, z.ZodTypeAny, "passthrough">>, "many">, z.objectOutputType<{
34
+ name: z.ZodString;
35
+ entry: z.ZodString;
36
+ }, z.ZodTypeAny, "passthrough">[], z.objectInputType<{
37
+ name: z.ZodString;
38
+ entry: z.ZodString;
39
+ }, z.ZodTypeAny, "passthrough">[]>;
37
40
  }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
38
41
  type: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"server">>>;
39
42
  mainFunction: z.ZodString;
40
43
  functions: z.ZodEffects<z.ZodArray<z.ZodObject<{
41
44
  name: z.ZodString;
42
45
  entry: z.ZodString;
43
- }, "strip", z.ZodTypeAny, {
44
- name: string;
45
- entry: string;
46
- }, {
47
- name: string;
48
- entry: string;
49
- }>, "many">, {
50
- name: string;
51
- entry: string;
52
- }[], {
53
- name: string;
54
- entry: string;
55
- }[]>;
46
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
47
+ name: z.ZodString;
48
+ entry: z.ZodString;
49
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
50
+ name: z.ZodString;
51
+ entry: z.ZodString;
52
+ }, z.ZodTypeAny, "passthrough">>, "many">, z.objectOutputType<{
53
+ name: z.ZodString;
54
+ entry: z.ZodString;
55
+ }, z.ZodTypeAny, "passthrough">[], z.objectInputType<{
56
+ name: z.ZodString;
57
+ entry: z.ZodString;
58
+ }, z.ZodTypeAny, "passthrough">[]>;
56
59
  }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
57
60
  type: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"server">>>;
58
61
  mainFunction: z.ZodString;
59
62
  functions: z.ZodEffects<z.ZodArray<z.ZodObject<{
60
63
  name: z.ZodString;
61
64
  entry: z.ZodString;
62
- }, "strip", z.ZodTypeAny, {
63
- name: string;
64
- entry: string;
65
- }, {
66
- name: string;
67
- entry: string;
68
- }>, "many">, {
69
- name: string;
70
- entry: string;
71
- }[], {
72
- name: string;
73
- entry: string;
74
- }[]>;
65
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
66
+ name: z.ZodString;
67
+ entry: z.ZodString;
68
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
69
+ name: z.ZodString;
70
+ entry: z.ZodString;
71
+ }, z.ZodTypeAny, "passthrough">>, "many">, z.objectOutputType<{
72
+ name: z.ZodString;
73
+ entry: z.ZodString;
74
+ }, z.ZodTypeAny, "passthrough">[], z.objectInputType<{
75
+ name: z.ZodString;
76
+ entry: z.ZodString;
77
+ }, z.ZodTypeAny, "passthrough">[]>;
75
78
  }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
76
79
  type: z.ZodLiteral<"edge">;
77
80
  mainFunction: z.ZodString;
@@ -82,79 +85,79 @@ export declare const BasicDefinition: z.ZodIntersection<z.ZodDiscriminatedUnion<
82
85
  output: z.ZodDiscriminatedUnion<"responseType", [z.ZodObject<{
83
86
  responseType: z.ZodLiteral<"html">;
84
87
  staticFiles: z.ZodOptional<z.ZodNever>;
85
- }, "strip", z.ZodTypeAny, {
86
- responseType: "html";
87
- staticFiles?: undefined;
88
- }, {
89
- responseType: "html";
90
- staticFiles?: undefined;
91
- }>, z.ZodObject<{
88
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
89
+ responseType: z.ZodLiteral<"html">;
90
+ staticFiles: z.ZodOptional<z.ZodNever>;
91
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
92
+ responseType: z.ZodLiteral<"html">;
93
+ staticFiles: z.ZodOptional<z.ZodNever>;
94
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
92
95
  responseType: z.ZodLiteral<"json">;
93
- }, "strip", z.ZodTypeAny, {
94
- responseType: "json";
95
- }, {
96
- responseType: "json";
97
- }>]>;
96
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
97
+ responseType: z.ZodLiteral<"json">;
98
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
99
+ responseType: z.ZodLiteral<"json">;
100
+ }, z.ZodTypeAny, "passthrough">>]>;
98
101
  }, "strip", z.ZodTypeAny, {
99
102
  name: string;
100
103
  input: Record<string, any>;
101
104
  entry: string;
102
- output: {
103
- responseType: "html";
104
- staticFiles?: undefined;
105
- } | {
106
- responseType: "json";
107
- };
105
+ output: z.objectOutputType<{
106
+ responseType: z.ZodLiteral<"html">;
107
+ staticFiles: z.ZodOptional<z.ZodNever>;
108
+ }, z.ZodTypeAny, "passthrough"> | z.objectOutputType<{
109
+ responseType: z.ZodLiteral<"json">;
110
+ }, z.ZodTypeAny, "passthrough">;
108
111
  }, {
109
112
  name: string;
110
113
  input: Record<string, any>;
111
114
  entry: string;
112
- output: {
113
- responseType: "html";
114
- staticFiles?: undefined;
115
- } | {
116
- responseType: "json";
117
- };
115
+ output: z.objectInputType<{
116
+ responseType: z.ZodLiteral<"html">;
117
+ staticFiles: z.ZodOptional<z.ZodNever>;
118
+ }, z.ZodTypeAny, "passthrough"> | z.objectInputType<{
119
+ responseType: z.ZodLiteral<"json">;
120
+ }, z.ZodTypeAny, "passthrough">;
118
121
  }>, "many">, {
119
122
  name: string;
120
123
  input: Record<string, any>;
121
124
  entry: string;
122
- output: {
123
- responseType: "html";
124
- staticFiles?: undefined;
125
- } | {
126
- responseType: "json";
127
- };
125
+ output: z.objectOutputType<{
126
+ responseType: z.ZodLiteral<"html">;
127
+ staticFiles: z.ZodOptional<z.ZodNever>;
128
+ }, z.ZodTypeAny, "passthrough"> | z.objectOutputType<{
129
+ responseType: z.ZodLiteral<"json">;
130
+ }, z.ZodTypeAny, "passthrough">;
128
131
  }[], {
129
132
  name: string;
130
133
  input: Record<string, any>;
131
134
  entry: string;
132
- output: {
133
- responseType: "html";
134
- staticFiles?: undefined;
135
- } | {
136
- responseType: "json";
137
- };
135
+ output: z.objectInputType<{
136
+ responseType: z.ZodLiteral<"html">;
137
+ staticFiles: z.ZodOptional<z.ZodNever>;
138
+ }, z.ZodTypeAny, "passthrough"> | z.objectInputType<{
139
+ responseType: z.ZodLiteral<"json">;
140
+ }, z.ZodTypeAny, "passthrough">;
138
141
  }[]>, {
139
142
  name: string;
140
143
  input: Record<string, any>;
141
144
  entry: string;
142
- output: {
143
- responseType: "html";
144
- staticFiles?: undefined;
145
- } | {
146
- responseType: "json";
147
- };
145
+ output: z.objectOutputType<{
146
+ responseType: z.ZodLiteral<"html">;
147
+ staticFiles: z.ZodOptional<z.ZodNever>;
148
+ }, z.ZodTypeAny, "passthrough"> | z.objectOutputType<{
149
+ responseType: z.ZodLiteral<"json">;
150
+ }, z.ZodTypeAny, "passthrough">;
148
151
  }[], {
149
152
  name: string;
150
153
  input: Record<string, any>;
151
154
  entry: string;
152
- output: {
153
- responseType: "html";
154
- staticFiles?: undefined;
155
- } | {
156
- responseType: "json";
157
- };
155
+ output: z.objectInputType<{
156
+ responseType: z.ZodLiteral<"html">;
157
+ staticFiles: z.ZodOptional<z.ZodNever>;
158
+ }, z.ZodTypeAny, "passthrough"> | z.objectInputType<{
159
+ responseType: z.ZodLiteral<"json">;
160
+ }, z.ZodTypeAny, "passthrough">;
158
161
  }[]>;
159
162
  }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
160
163
  type: z.ZodLiteral<"edge">;
@@ -166,79 +169,79 @@ export declare const BasicDefinition: z.ZodIntersection<z.ZodDiscriminatedUnion<
166
169
  output: z.ZodDiscriminatedUnion<"responseType", [z.ZodObject<{
167
170
  responseType: z.ZodLiteral<"html">;
168
171
  staticFiles: z.ZodOptional<z.ZodNever>;
169
- }, "strip", z.ZodTypeAny, {
170
- responseType: "html";
171
- staticFiles?: undefined;
172
- }, {
173
- responseType: "html";
174
- staticFiles?: undefined;
175
- }>, z.ZodObject<{
172
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
173
+ responseType: z.ZodLiteral<"html">;
174
+ staticFiles: z.ZodOptional<z.ZodNever>;
175
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
176
+ responseType: z.ZodLiteral<"html">;
177
+ staticFiles: z.ZodOptional<z.ZodNever>;
178
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
176
179
  responseType: z.ZodLiteral<"json">;
177
- }, "strip", z.ZodTypeAny, {
178
- responseType: "json";
179
- }, {
180
- responseType: "json";
181
- }>]>;
180
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
181
+ responseType: z.ZodLiteral<"json">;
182
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
183
+ responseType: z.ZodLiteral<"json">;
184
+ }, z.ZodTypeAny, "passthrough">>]>;
182
185
  }, "strip", z.ZodTypeAny, {
183
186
  name: string;
184
187
  input: Record<string, any>;
185
188
  entry: string;
186
- output: {
187
- responseType: "html";
188
- staticFiles?: undefined;
189
- } | {
190
- responseType: "json";
191
- };
189
+ output: z.objectOutputType<{
190
+ responseType: z.ZodLiteral<"html">;
191
+ staticFiles: z.ZodOptional<z.ZodNever>;
192
+ }, z.ZodTypeAny, "passthrough"> | z.objectOutputType<{
193
+ responseType: z.ZodLiteral<"json">;
194
+ }, z.ZodTypeAny, "passthrough">;
192
195
  }, {
193
196
  name: string;
194
197
  input: Record<string, any>;
195
198
  entry: string;
196
- output: {
197
- responseType: "html";
198
- staticFiles?: undefined;
199
- } | {
200
- responseType: "json";
201
- };
199
+ output: z.objectInputType<{
200
+ responseType: z.ZodLiteral<"html">;
201
+ staticFiles: z.ZodOptional<z.ZodNever>;
202
+ }, z.ZodTypeAny, "passthrough"> | z.objectInputType<{
203
+ responseType: z.ZodLiteral<"json">;
204
+ }, z.ZodTypeAny, "passthrough">;
202
205
  }>, "many">, {
203
206
  name: string;
204
207
  input: Record<string, any>;
205
208
  entry: string;
206
- output: {
207
- responseType: "html";
208
- staticFiles?: undefined;
209
- } | {
210
- responseType: "json";
211
- };
209
+ output: z.objectOutputType<{
210
+ responseType: z.ZodLiteral<"html">;
211
+ staticFiles: z.ZodOptional<z.ZodNever>;
212
+ }, z.ZodTypeAny, "passthrough"> | z.objectOutputType<{
213
+ responseType: z.ZodLiteral<"json">;
214
+ }, z.ZodTypeAny, "passthrough">;
212
215
  }[], {
213
216
  name: string;
214
217
  input: Record<string, any>;
215
218
  entry: string;
216
- output: {
217
- responseType: "html";
218
- staticFiles?: undefined;
219
- } | {
220
- responseType: "json";
221
- };
219
+ output: z.objectInputType<{
220
+ responseType: z.ZodLiteral<"html">;
221
+ staticFiles: z.ZodOptional<z.ZodNever>;
222
+ }, z.ZodTypeAny, "passthrough"> | z.objectInputType<{
223
+ responseType: z.ZodLiteral<"json">;
224
+ }, z.ZodTypeAny, "passthrough">;
222
225
  }[]>, {
223
226
  name: string;
224
227
  input: Record<string, any>;
225
228
  entry: string;
226
- output: {
227
- responseType: "html";
228
- staticFiles?: undefined;
229
- } | {
230
- responseType: "json";
231
- };
229
+ output: z.objectOutputType<{
230
+ responseType: z.ZodLiteral<"html">;
231
+ staticFiles: z.ZodOptional<z.ZodNever>;
232
+ }, z.ZodTypeAny, "passthrough"> | z.objectOutputType<{
233
+ responseType: z.ZodLiteral<"json">;
234
+ }, z.ZodTypeAny, "passthrough">;
232
235
  }[], {
233
236
  name: string;
234
237
  input: Record<string, any>;
235
238
  entry: string;
236
- output: {
237
- responseType: "html";
238
- staticFiles?: undefined;
239
- } | {
240
- responseType: "json";
241
- };
239
+ output: z.objectInputType<{
240
+ responseType: z.ZodLiteral<"html">;
241
+ staticFiles: z.ZodOptional<z.ZodNever>;
242
+ }, z.ZodTypeAny, "passthrough"> | z.objectInputType<{
243
+ responseType: z.ZodLiteral<"json">;
244
+ }, z.ZodTypeAny, "passthrough">;
242
245
  }[]>;
243
246
  }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
244
247
  type: z.ZodLiteral<"edge">;
@@ -250,79 +253,79 @@ export declare const BasicDefinition: z.ZodIntersection<z.ZodDiscriminatedUnion<
250
253
  output: z.ZodDiscriminatedUnion<"responseType", [z.ZodObject<{
251
254
  responseType: z.ZodLiteral<"html">;
252
255
  staticFiles: z.ZodOptional<z.ZodNever>;
253
- }, "strip", z.ZodTypeAny, {
254
- responseType: "html";
255
- staticFiles?: undefined;
256
- }, {
257
- responseType: "html";
258
- staticFiles?: undefined;
259
- }>, z.ZodObject<{
256
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
257
+ responseType: z.ZodLiteral<"html">;
258
+ staticFiles: z.ZodOptional<z.ZodNever>;
259
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
260
+ responseType: z.ZodLiteral<"html">;
261
+ staticFiles: z.ZodOptional<z.ZodNever>;
262
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
260
263
  responseType: z.ZodLiteral<"json">;
261
- }, "strip", z.ZodTypeAny, {
262
- responseType: "json";
263
- }, {
264
- responseType: "json";
265
- }>]>;
264
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
265
+ responseType: z.ZodLiteral<"json">;
266
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
267
+ responseType: z.ZodLiteral<"json">;
268
+ }, z.ZodTypeAny, "passthrough">>]>;
266
269
  }, "strip", z.ZodTypeAny, {
267
270
  name: string;
268
271
  input: Record<string, any>;
269
272
  entry: string;
270
- output: {
271
- responseType: "html";
272
- staticFiles?: undefined;
273
- } | {
274
- responseType: "json";
275
- };
273
+ output: z.objectOutputType<{
274
+ responseType: z.ZodLiteral<"html">;
275
+ staticFiles: z.ZodOptional<z.ZodNever>;
276
+ }, z.ZodTypeAny, "passthrough"> | z.objectOutputType<{
277
+ responseType: z.ZodLiteral<"json">;
278
+ }, z.ZodTypeAny, "passthrough">;
276
279
  }, {
277
280
  name: string;
278
281
  input: Record<string, any>;
279
282
  entry: string;
280
- output: {
281
- responseType: "html";
282
- staticFiles?: undefined;
283
- } | {
284
- responseType: "json";
285
- };
283
+ output: z.objectInputType<{
284
+ responseType: z.ZodLiteral<"html">;
285
+ staticFiles: z.ZodOptional<z.ZodNever>;
286
+ }, z.ZodTypeAny, "passthrough"> | z.objectInputType<{
287
+ responseType: z.ZodLiteral<"json">;
288
+ }, z.ZodTypeAny, "passthrough">;
286
289
  }>, "many">, {
287
290
  name: string;
288
291
  input: Record<string, any>;
289
292
  entry: string;
290
- output: {
291
- responseType: "html";
292
- staticFiles?: undefined;
293
- } | {
294
- responseType: "json";
295
- };
293
+ output: z.objectOutputType<{
294
+ responseType: z.ZodLiteral<"html">;
295
+ staticFiles: z.ZodOptional<z.ZodNever>;
296
+ }, z.ZodTypeAny, "passthrough"> | z.objectOutputType<{
297
+ responseType: z.ZodLiteral<"json">;
298
+ }, z.ZodTypeAny, "passthrough">;
296
299
  }[], {
297
300
  name: string;
298
301
  input: Record<string, any>;
299
302
  entry: string;
300
- output: {
301
- responseType: "html";
302
- staticFiles?: undefined;
303
- } | {
304
- responseType: "json";
305
- };
303
+ output: z.objectInputType<{
304
+ responseType: z.ZodLiteral<"html">;
305
+ staticFiles: z.ZodOptional<z.ZodNever>;
306
+ }, z.ZodTypeAny, "passthrough"> | z.objectInputType<{
307
+ responseType: z.ZodLiteral<"json">;
308
+ }, z.ZodTypeAny, "passthrough">;
306
309
  }[]>, {
307
310
  name: string;
308
311
  input: Record<string, any>;
309
312
  entry: string;
310
- output: {
311
- responseType: "html";
312
- staticFiles?: undefined;
313
- } | {
314
- responseType: "json";
315
- };
313
+ output: z.objectOutputType<{
314
+ responseType: z.ZodLiteral<"html">;
315
+ staticFiles: z.ZodOptional<z.ZodNever>;
316
+ }, z.ZodTypeAny, "passthrough"> | z.objectOutputType<{
317
+ responseType: z.ZodLiteral<"json">;
318
+ }, z.ZodTypeAny, "passthrough">;
316
319
  }[], {
317
320
  name: string;
318
321
  input: Record<string, any>;
319
322
  entry: string;
320
- output: {
321
- responseType: "html";
322
- staticFiles?: undefined;
323
- } | {
324
- responseType: "json";
325
- };
323
+ output: z.objectInputType<{
324
+ responseType: z.ZodLiteral<"html">;
325
+ staticFiles: z.ZodOptional<z.ZodNever>;
326
+ }, z.ZodTypeAny, "passthrough"> | z.objectInputType<{
327
+ responseType: z.ZodLiteral<"json">;
328
+ }, z.ZodTypeAny, "passthrough">;
326
329
  }[]>;
327
330
  }, z.ZodTypeAny, "passthrough">>]>, z.ZodObject<{
328
331
  mockedUris: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
@@ -35,12 +35,89 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.COMPILED_ENTRY_FILE = exports.BasicDefinition = exports.ComponentDefinition = void 0;
38
+ exports.COMPILED_ENTRY_FILE = exports.BasicDefinition = exports.ComponentDefinition = exports.ComponentPreUpload = void 0;
39
39
  const fs = __importStar(require("node:fs/promises"));
40
40
  const path = __importStar(require("node:path"));
41
41
  const cli_color_1 = __importDefault(require("cli-color"));
42
42
  const zod_1 = require("zod");
43
43
  const zod_validation_error_1 = require("zod-validation-error");
44
+ const compiler_1 = require("../edge-components/compiler");
45
+ class ComponentPreUpload {
46
+ static forEdge(component, outputDir) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ if (component.type !== 'edge') {
49
+ throw new Error('Attempted preUpload forEdge for a component type other than "edge"');
50
+ }
51
+ // NOTE: this mutates the componentDefinition in place
52
+ // compileUserCode
53
+ yield (0, compiler_1.compileUserCode)(component.mainEntryFilePath, path.join(outputDir, exports.COMPILED_ENTRY_FILE));
54
+ // updateFunctionEntry
55
+ for (const fn of component.definition.functions) {
56
+ fn.entry = exports.COMPILED_ENTRY_FILE;
57
+ }
58
+ // copyPreviewFiles
59
+ yield ComponentPreUpload.copyPreviewFiles(component, outputDir);
60
+ // copyMockedUri
61
+ yield ComponentPreUpload.copyMockedUriFiles(component, outputDir);
62
+ // writeCopyManifest
63
+ yield fs.writeFile(path.resolve(outputDir, 'manifest.json'), JSON.stringify(component.definition));
64
+ });
65
+ }
66
+ static forServer(component, outputDir) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ if (component.type !== 'server') {
69
+ throw new Error('Attempted preUpload forServer with a component type other than "server"');
70
+ }
71
+ // NOTE: this mutates the componentDefinition in place
72
+ // copyDirectory
73
+ yield fs.cp(component.baseDir, outputDir, {
74
+ recursive: true,
75
+ });
76
+ // copyPreviewFiles
77
+ yield ComponentPreUpload.copyPreviewFiles(component, outputDir);
78
+ // copyMockedUriFiles
79
+ yield ComponentPreUpload.copyMockedUriFiles(component, outputDir);
80
+ // copyStaticFiles - not needed as static files are already
81
+ // validated to be in component directory and initial copy
82
+ // sorts that out
83
+ yield fs.writeFile(path.resolve(outputDir, 'manifest.json'), JSON.stringify(component.definition));
84
+ });
85
+ }
86
+ static copyMockedUriFiles(component, outputDir) {
87
+ var _a;
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ for (const [uriName, uriValue] of Object.entries((_a = component.definition.mockedUris) !== null && _a !== void 0 ? _a : {})) {
90
+ if (uriValue.type === 'file') {
91
+ const newUriPath = `mocked-uri.${uriName}.json`;
92
+ yield fs.copyFile(path.resolve(component.baseDir, uriValue.path), path.resolve(outputDir, newUriPath));
93
+ uriValue.path = newUriPath;
94
+ }
95
+ }
96
+ });
97
+ }
98
+ static copyPreviewFiles(component, outputDir) {
99
+ var _a;
100
+ return __awaiter(this, void 0, void 0, function* () {
101
+ for (const [key, { functionData }] of Object.entries((_a = component.definition.previews) !== null && _a !== void 0 ? _a : {})) {
102
+ for (const [fnName, previewConfig] of Object.entries(functionData)) {
103
+ const previewFilePrefix = `preview.${key}.${fnName}`;
104
+ if (previewConfig.inputData.type === 'file') {
105
+ const fileType = path.extname(previewConfig.inputData.path);
106
+ const newPreview = `${previewFilePrefix}.data${fileType}`;
107
+ yield fs.copyFile(path.resolve(component.baseDir, previewConfig.inputData.path), path.resolve(outputDir, newPreview));
108
+ previewConfig.inputData.path = newPreview;
109
+ }
110
+ if (previewConfig.wrapper) {
111
+ const newWrapper = `${previewFilePrefix}.wrapper.html`;
112
+ yield fs.copyFile(path.resolve(component.baseDir, previewConfig.wrapper.path), path.resolve(outputDir, newWrapper));
113
+ previewConfig.wrapper.path = newWrapper;
114
+ }
115
+ }
116
+ }
117
+ });
118
+ }
119
+ }
120
+ exports.ComponentPreUpload = ComponentPreUpload;
44
121
  class ComponentDefinition {
45
122
  constructor(baseDir, definition) {
46
123
  this.baseDir = baseDir;
@@ -91,44 +168,6 @@ class ComponentDefinition {
91
168
  get type() {
92
169
  return this.definition.type;
93
170
  }
94
- copyManifest(copyDir) {
95
- return __awaiter(this, void 0, void 0, function* () {
96
- const copy = yield exports.BasicDefinition.parseAsync(this.definition);
97
- copy.functions = this.definition.functions.map(func => {
98
- return Object.assign(Object.assign({}, func), { entry: exports.COMPILED_ENTRY_FILE });
99
- });
100
- return yield fs.writeFile(path.resolve(copyDir, 'manifest.json'), JSON.stringify(copy));
101
- });
102
- }
103
- copyPreviewFiles(copyDir) {
104
- return __awaiter(this, void 0, void 0, function* () {
105
- if (!this.definition.previews) {
106
- return;
107
- }
108
- for (const [_previewKey, value] of Object.entries(this.definition.previews)) {
109
- for (const [_funcName, funcInput] of Object.entries(value.functionData)) {
110
- if (funcInput.inputData.type === 'file') {
111
- yield fs.copyFile(path.resolve(this.baseDir, funcInput.inputData.path), path.resolve(copyDir, funcInput.inputData.path));
112
- }
113
- if (funcInput.wrapper) {
114
- yield fs.copyFile(path.resolve(this.baseDir, funcInput.wrapper.path), path.resolve(copyDir, funcInput.wrapper.path));
115
- }
116
- }
117
- }
118
- });
119
- }
120
- copyMockedUriFiles(copyDir) {
121
- return __awaiter(this, void 0, void 0, function* () {
122
- if (!this.definition.mockedUris) {
123
- return;
124
- }
125
- for (const [_mockedUriName, mockedUriValue] of Object.entries(this.definition.mockedUris)) {
126
- if (mockedUriValue.type === 'file') {
127
- yield fs.copyFile(path.resolve(this.baseDir, mockedUriValue.path), path.resolve(copyDir, mockedUriValue.path));
128
- }
129
- }
130
- });
131
- }
132
171
  }
133
172
  exports.ComponentDefinition = ComponentDefinition;
134
173
  const ServerDefinition = zod_1.z
@@ -136,10 +175,12 @@ const ServerDefinition = zod_1.z
136
175
  type: zod_1.z.literal('server').optional().default('server'),
137
176
  mainFunction: zod_1.z.string(),
138
177
  functions: zod_1.z
139
- .array(zod_1.z.object({
178
+ .array(zod_1.z
179
+ .object({
140
180
  name: zod_1.z.string(),
141
181
  entry: zod_1.z.string(),
142
- }))
182
+ })
183
+ .passthrough())
143
184
  .refine(fns => new Set(fns.map(f => f.name)).size === fns.length),
144
185
  })
145
186
  .passthrough();
@@ -153,17 +194,21 @@ const EdgeDefinition = zod_1.z
153
194
  entry: zod_1.z.string(),
154
195
  input: zod_1.z.record(zod_1.z.any()),
155
196
  output: zod_1.z.discriminatedUnion('responseType', [
156
- zod_1.z.object({
197
+ zod_1.z
198
+ .object({
157
199
  responseType: zod_1.z.literal('html'),
158
200
  staticFiles: zod_1.z
159
201
  .never({
160
202
  invalid_type_error: 'Static files are not supported in edge and have been removed',
161
203
  })
162
204
  .optional(),
163
- }),
164
- zod_1.z.object({
205
+ })
206
+ .passthrough(),
207
+ zod_1.z
208
+ .object({
165
209
  responseType: zod_1.z.literal('json'),
166
- }),
210
+ })
211
+ .passthrough(),
167
212
  ]),
168
213
  }))
169
214
  // All names should be unique
@@ -207,230 +207,297 @@ describe('cmp > utils > definitions', () => {
207
207
  expect(definition.type).toEqual(manifest.type);
208
208
  }));
209
209
  });
210
- describe('ComponentDefinition#copyManifest', () => {
211
- test('copies the manifest.json to target directory', () => __awaiter(void 0, void 0, void 0, function* () {
212
- const definition = yield createComponentDefinition();
213
- const copyTarget = yield makeTempDirectory();
214
- yield definition.copyManifest(copyTarget);
215
- yield expect(fs.access(path.join(copyTarget, 'manifest.json'))).resolves.toBeUndefined();
216
- }));
217
- test('copied manifest.json sets file entry to compiled file name', () => __awaiter(void 0, void 0, void 0, function* () {
218
- const definition = yield createComponentDefinition();
219
- const copyTarget = yield makeTempDirectory();
220
- yield definition.copyManifest(copyTarget);
221
- const copiedDefinition = yield definitions_1.ComponentDefinition.load(copyTarget);
222
- expect(copiedDefinition === null || copiedDefinition === void 0 ? void 0 : copiedDefinition.mainEntryFilePath).toMatch(`${definitions_1.COMPILED_ENTRY_FILE}`);
223
- }));
224
- test('does not remove extraneous properties in manifest', () => __awaiter(void 0, void 0, void 0, function* () {
225
- const definition = yield createComponentDefinition({
226
- extraValue: 'string',
227
- });
228
- const copyTarget = yield makeTempDirectory();
229
- yield definition.copyManifest(copyTarget);
230
- const copiedDefinition = yield definitions_1.ComponentDefinition.load(copyTarget);
231
- expect(copiedDefinition === null || copiedDefinition === void 0 ? void 0 : copiedDefinition.definition).toMatchObject({
232
- extraValue: 'string',
233
- });
234
- }));
235
- });
236
- describe('ComponentDefinition#copyPreviewFiles', () => {
237
- test('preview data in files are copied to target', () => __awaiter(void 0, void 0, void 0, function* () {
238
- const definition = yield createComponentDefinition({
239
- previews: {
240
- 'file-preview': {
241
- functionData: {
242
- main: {
243
- inputData: {
244
- type: 'file',
245
- path: 'file-preview.data.json',
246
- },
247
- wrapper: {
248
- path: 'preview-wrapper.html',
249
- },
250
- },
251
- },
252
- },
253
- },
254
- });
255
- yield fs.writeFile(path.join(definition.baseDir, 'file-preview.data.json'), '{}');
256
- yield fs.writeFile(path.join(definition.baseDir, 'preview-wrapper.html'), '<html></html>');
257
- const copyTarget = yield makeTempDirectory();
258
- yield definition.copyPreviewFiles(copyTarget);
259
- yield expect(fs.access(path.join(copyTarget, 'file-preview.data.json'))).resolves.toBe(undefined);
260
- yield expect(fs.access(path.join(copyTarget, 'preview-wrapper.html'))).resolves.toBe(undefined);
261
- }));
262
- test('multiple previews are copied to target', () => __awaiter(void 0, void 0, void 0, function* () {
263
- const definition = yield createComponentDefinition({
264
- previews: {
265
- 'file-preview': {
266
- functionData: {
267
- main: {
268
- inputData: {
269
- type: 'file',
270
- path: 'file-preview.data.json',
271
- },
272
- },
273
- },
274
- },
275
- 'another-file-preview': {
276
- functionData: {
277
- main: {
278
- inputData: {
279
- type: 'file',
280
- path: 'another-file-preview.data.json',
281
- },
282
- },
283
- },
284
- },
285
- },
286
- });
287
- yield fs.writeFile(path.join(definition.baseDir, 'file-preview.data.json'), '{}');
288
- yield fs.writeFile(path.join(definition.baseDir, 'another-file-preview.data.json'), '{}');
289
- const copyTarget = yield makeTempDirectory();
290
- yield definition.copyPreviewFiles(copyTarget);
291
- yield expect(fs.access(path.join(copyTarget, 'file-preview.data.json'))).resolves.toBeUndefined();
292
- yield expect(fs.access(path.join(copyTarget, 'another-file-preview.data.json'))).resolves.toBeUndefined();
293
- }));
294
- test('multiple functions in a preview are copied to target', () => __awaiter(void 0, void 0, void 0, function* () {
295
- const definition = yield createComponentDefinition({
296
- previews: {
297
- 'file-preview': {
298
- functionData: {
299
- main: {
300
- inputData: {
301
- type: 'file',
302
- path: 'file-preview.data.json',
303
- },
304
- },
305
- other: {
306
- inputData: {
307
- type: 'file',
308
- path: 'another-file-preview.data.json',
309
- },
310
- },
311
- },
312
- },
313
- },
314
- });
315
- yield fs.writeFile(path.join(definition.baseDir, 'file-preview.data.json'), '{}');
316
- yield fs.writeFile(path.join(definition.baseDir, 'another-file-preview.data.json'), '{}');
317
- const copyTarget = yield makeTempDirectory();
318
- yield definition.copyPreviewFiles(copyTarget);
319
- yield expect(fs.access(path.join(copyTarget, 'file-preview.data.json'))).resolves.toBeUndefined();
320
- yield expect(fs.access(path.join(copyTarget, 'another-file-preview.data.json'))).resolves.toBeUndefined();
321
- }));
322
- test('preview wrapper is copied when inputData is inline', () => __awaiter(void 0, void 0, void 0, function* () {
323
- const definition = yield createComponentDefinition({
324
- previews: {
325
- 'file-wrapper': {
326
- functionData: {
327
- main: {
328
- inputData: {
329
- type: 'inline',
330
- value: {
331
- message: 'inline-preview',
332
- },
333
- },
334
- wrapper: {
335
- path: 'preview-wrapper.html',
336
- },
337
- },
338
- },
339
- },
340
- },
341
- });
342
- yield fs.writeFile(path.join(definition.baseDir, 'preview-wrapper.html'), '<html></html>');
343
- const copyTarget = yield makeTempDirectory();
344
- yield definition.copyPreviewFiles(copyTarget);
345
- yield expect(fs.access(path.join(copyTarget, 'preview-wrapper.html'))).resolves.toBeUndefined();
346
- }));
347
- test('files not defined in previews are not copied to target', () => __awaiter(void 0, void 0, void 0, function* () {
348
- const definition = yield createComponentDefinition({
349
- previews: {
350
- 'file-preview': {
351
- functionData: {
352
- main: {
353
- inputData: {
354
- type: 'file',
355
- path: 'file-preview.data.json',
356
- },
357
- },
358
- },
359
- },
360
- },
361
- });
362
- yield fs.writeFile(path.join(definition.baseDir, 'file-preview.data.json'), '{}');
363
- yield fs.writeFile(path.join(definition.baseDir, 'not-preview.data-json'), '{}');
364
- const copyTarget = yield makeTempDirectory();
365
- yield definition.copyPreviewFiles(copyTarget);
366
- expect(fs.access(path.join(copyTarget, 'not-preview.data.json'))).rejects.toBeTruthy();
367
- }));
368
- test('inline preview data is not attempted to copy', () => __awaiter(void 0, void 0, void 0, function* () {
369
- const definition = yield createComponentDefinition({
370
- previews: {
371
- 'inline-preview': {
372
- functionData: {
373
- main: {
374
- inputData: {
375
- type: 'inline',
376
- value: {
377
- message: 'inline-preview',
378
- },
379
- },
380
- },
381
- },
382
- },
383
- },
384
- });
385
- const copyTarget = yield makeTempDirectory();
386
- yield definition.copyPreviewFiles(copyTarget);
387
- yield expect(fs.readdir(copyTarget)).resolves.toEqual([]);
388
- }));
389
- test('does not error when a component has no previews', () => __awaiter(void 0, void 0, void 0, function* () {
390
- const definition = yield createComponentDefinition({});
391
- const copyTarget = yield makeTempDirectory();
392
- yield expect(definition.copyPreviewFiles(copyTarget)).resolves.toBeUndefined();
393
- }));
394
- });
395
- describe('ComponentDefinition#copyMockedUriFiles', () => {
396
- test('mockedUri defined in a file is copied to target', () => __awaiter(void 0, void 0, void 0, function* () {
397
- const definition = yield createComponentDefinition({
398
- mockedUris: {
399
- 'test-uri': {
400
- type: 'file',
401
- path: 'test-uri.data.json',
402
- },
403
- },
404
- });
405
- yield fs.writeFile(path.join(definition.baseDir, 'test-uri.data.json'), '{}');
406
- const copyTarget = yield makeTempDirectory();
407
- yield definition.copyMockedUriFiles(copyTarget);
408
- yield expect(fs.access(path.join(copyTarget, 'test-uri.data.json'))).resolves.toBeUndefined();
409
- }));
410
- test('multiple mockedUri files are copied to target', () => __awaiter(void 0, void 0, void 0, function* () {
411
- const definition = yield createComponentDefinition({
412
- mockedUris: {
413
- 'test-uri': {
414
- type: 'file',
415
- path: 'test-uri.data.json',
416
- },
417
- 'another-test-uri': {
418
- type: 'file',
419
- path: 'another-test-uri.data.json',
420
- },
421
- },
422
- });
423
- yield fs.writeFile(path.join(definition.baseDir, 'test-uri.data.json'), '{}');
424
- yield fs.writeFile(path.join(definition.baseDir, 'another-test-uri.data.json'), '{}');
425
- const copyTarget = yield makeTempDirectory();
426
- yield definition.copyMockedUriFiles(copyTarget);
427
- yield expect(fs.access(path.join(copyTarget, 'test-uri.data.json'))).resolves.toBeUndefined();
428
- yield expect(fs.access(path.join(copyTarget, 'another-test-uri.data.json'))).resolves.toBeUndefined();
429
- }));
430
- test('no error when no mockedUris defined', () => __awaiter(void 0, void 0, void 0, function* () {
431
- const definition = yield createComponentDefinition();
432
- const copyTarget = yield makeTempDirectory();
433
- yield expect(definition.copyMockedUriFiles(copyTarget)).resolves.toBeUndefined();
434
- }));
435
- });
210
+ // TODO: Revise to test the ComponentPreUpload class
211
+ // describe('ComponentDefinition#copyManifest', () => {
212
+ // test('copies the manifest.json to target directory', async () => {
213
+ // const definition = await createComponentDefinition();
214
+ // const copyTarget = await makeTempDirectory();
215
+ // await definition.copyManifest(copyTarget);
216
+ // await expect(
217
+ // fs.access(path.join(copyTarget, 'manifest.json'))
218
+ // ).resolves.toBeUndefined();
219
+ // });
220
+ // test('copied manifest.json sets file entry to compiled file name', async () => {
221
+ // const definition = await createComponentDefinition();
222
+ // const copyTarget = await makeTempDirectory();
223
+ // await definition.copyManifest(copyTarget);
224
+ // const copiedDefinition = await ComponentDefinition.load(copyTarget);
225
+ // expect(copiedDefinition?.mainEntryFilePath).toMatch(
226
+ // `${COMPILED_ENTRY_FILE}`
227
+ // );
228
+ // });
229
+ // test('does not remove extraneous properties in manifest', async () => {
230
+ // const definition = await createComponentDefinition({
231
+ // extraValue: 'string',
232
+ // });
233
+ // const copyTarget = await makeTempDirectory();
234
+ // await definition.copyManifest(copyTarget);
235
+ // const copiedDefinition = await ComponentDefinition.load(copyTarget);
236
+ // expect(copiedDefinition?.definition).toMatchObject({
237
+ // extraValue: 'string',
238
+ // });
239
+ // });
240
+ // });
241
+ // describe('ComponentDefinition#copyPreviewFiles', () => {
242
+ // test('preview data in files are copied to target', async () => {
243
+ // const definition = await createComponentDefinition({
244
+ // previews: {
245
+ // 'file-preview': {
246
+ // functionData: {
247
+ // main: {
248
+ // inputData: {
249
+ // type: 'file',
250
+ // path: 'file-preview.data.json',
251
+ // },
252
+ // wrapper: {
253
+ // path: 'preview-wrapper.html',
254
+ // },
255
+ // },
256
+ // },
257
+ // },
258
+ // },
259
+ // });
260
+ // await fs.writeFile(
261
+ // path.join(definition.baseDir, 'file-preview.data.json'),
262
+ // '{}'
263
+ // );
264
+ // await fs.writeFile(
265
+ // path.join(definition.baseDir, 'preview-wrapper.html'),
266
+ // '<html></html>'
267
+ // );
268
+ // const copyTarget = await makeTempDirectory();
269
+ // await definition.copyPreviewFiles(copyTarget);
270
+ // await expect(
271
+ // fs.access(path.join(copyTarget, 'file-preview.data.json'))
272
+ // ).resolves.toBe(undefined);
273
+ // await expect(
274
+ // fs.access(path.join(copyTarget, 'preview-wrapper.html'))
275
+ // ).resolves.toBe(undefined);
276
+ // });
277
+ // test('multiple previews are copied to target', async () => {
278
+ // const definition = await createComponentDefinition({
279
+ // previews: {
280
+ // 'file-preview': {
281
+ // functionData: {
282
+ // main: {
283
+ // inputData: {
284
+ // type: 'file',
285
+ // path: 'file-preview.data.json',
286
+ // },
287
+ // },
288
+ // },
289
+ // },
290
+ // 'another-file-preview': {
291
+ // functionData: {
292
+ // main: {
293
+ // inputData: {
294
+ // type: 'file',
295
+ // path: 'another-file-preview.data.json',
296
+ // },
297
+ // },
298
+ // },
299
+ // },
300
+ // },
301
+ // });
302
+ // await fs.writeFile(
303
+ // path.join(definition.baseDir, 'file-preview.data.json'),
304
+ // '{}'
305
+ // );
306
+ // await fs.writeFile(
307
+ // path.join(definition.baseDir, 'another-file-preview.data.json'),
308
+ // '{}'
309
+ // );
310
+ // const copyTarget = await makeTempDirectory();
311
+ // await definition.copyPreviewFiles(copyTarget);
312
+ // await expect(
313
+ // fs.access(path.join(copyTarget, 'file-preview.data.json'))
314
+ // ).resolves.toBeUndefined();
315
+ // await expect(
316
+ // fs.access(path.join(copyTarget, 'another-file-preview.data.json'))
317
+ // ).resolves.toBeUndefined();
318
+ // });
319
+ // test('multiple functions in a preview are copied to target', async () => {
320
+ // const definition = await createComponentDefinition({
321
+ // previews: {
322
+ // 'file-preview': {
323
+ // functionData: {
324
+ // main: {
325
+ // inputData: {
326
+ // type: 'file',
327
+ // path: 'file-preview.data.json',
328
+ // },
329
+ // },
330
+ // other: {
331
+ // inputData: {
332
+ // type: 'file',
333
+ // path: 'another-file-preview.data.json',
334
+ // },
335
+ // },
336
+ // },
337
+ // },
338
+ // },
339
+ // });
340
+ // await fs.writeFile(
341
+ // path.join(definition.baseDir, 'file-preview.data.json'),
342
+ // '{}'
343
+ // );
344
+ // await fs.writeFile(
345
+ // path.join(definition.baseDir, 'another-file-preview.data.json'),
346
+ // '{}'
347
+ // );
348
+ // const copyTarget = await makeTempDirectory();
349
+ // await definition.copyPreviewFiles(copyTarget);
350
+ // await expect(
351
+ // fs.access(path.join(copyTarget, 'file-preview.data.json'))
352
+ // ).resolves.toBeUndefined();
353
+ // await expect(
354
+ // fs.access(path.join(copyTarget, 'another-file-preview.data.json'))
355
+ // ).resolves.toBeUndefined();
356
+ // });
357
+ // test('preview wrapper is copied when inputData is inline', async () => {
358
+ // const definition = await createComponentDefinition({
359
+ // previews: {
360
+ // 'file-wrapper': {
361
+ // functionData: {
362
+ // main: {
363
+ // inputData: {
364
+ // type: 'inline',
365
+ // value: {
366
+ // message: 'inline-preview',
367
+ // },
368
+ // },
369
+ // wrapper: {
370
+ // path: 'preview-wrapper.html',
371
+ // },
372
+ // },
373
+ // },
374
+ // },
375
+ // },
376
+ // });
377
+ // await fs.writeFile(
378
+ // path.join(definition.baseDir, 'preview-wrapper.html'),
379
+ // '<html></html>'
380
+ // );
381
+ // const copyTarget = await makeTempDirectory();
382
+ // await definition.copyPreviewFiles(copyTarget);
383
+ // await expect(
384
+ // fs.access(path.join(copyTarget, 'preview-wrapper.html'))
385
+ // ).resolves.toBeUndefined();
386
+ // });
387
+ // test('files not defined in previews are not copied to target', async () => {
388
+ // const definition = await createComponentDefinition({
389
+ // previews: {
390
+ // 'file-preview': {
391
+ // functionData: {
392
+ // main: {
393
+ // inputData: {
394
+ // type: 'file',
395
+ // path: 'file-preview.data.json',
396
+ // },
397
+ // },
398
+ // },
399
+ // },
400
+ // },
401
+ // });
402
+ // await fs.writeFile(
403
+ // path.join(definition.baseDir, 'file-preview.data.json'),
404
+ // '{}'
405
+ // );
406
+ // await fs.writeFile(
407
+ // path.join(definition.baseDir, 'not-preview.data-json'),
408
+ // '{}'
409
+ // );
410
+ // const copyTarget = await makeTempDirectory();
411
+ // await definition.copyPreviewFiles(copyTarget);
412
+ // expect(
413
+ // fs.access(path.join(copyTarget, 'not-preview.data.json'))
414
+ // ).rejects.toBeTruthy();
415
+ // });
416
+ // test('inline preview data is not attempted to copy', async () => {
417
+ // const definition = await createComponentDefinition({
418
+ // previews: {
419
+ // 'inline-preview': {
420
+ // functionData: {
421
+ // main: {
422
+ // inputData: {
423
+ // type: 'inline',
424
+ // value: {
425
+ // message: 'inline-preview',
426
+ // },
427
+ // },
428
+ // },
429
+ // },
430
+ // },
431
+ // },
432
+ // });
433
+ // const copyTarget = await makeTempDirectory();
434
+ // await definition.copyPreviewFiles(copyTarget);
435
+ // await expect(fs.readdir(copyTarget)).resolves.toEqual([]);
436
+ // });
437
+ // test('does not error when a component has no previews', async () => {
438
+ // const definition = await createComponentDefinition({});
439
+ // const copyTarget = await makeTempDirectory();
440
+ // await expect(
441
+ // definition.copyPreviewFiles(copyTarget)
442
+ // ).resolves.toBeUndefined();
443
+ // });
444
+ // });
445
+ // describe('ComponentDefinition#copyMockedUriFiles', () => {
446
+ // test('mockedUri defined in a file is copied to target', async () => {
447
+ // const definition = await createComponentDefinition({
448
+ // mockedUris: {
449
+ // 'test-uri': {
450
+ // type: 'file',
451
+ // path: 'test-uri.data.json',
452
+ // },
453
+ // },
454
+ // });
455
+ // await fs.writeFile(
456
+ // path.join(definition.baseDir, 'test-uri.data.json'),
457
+ // '{}'
458
+ // );
459
+ // const copyTarget = await makeTempDirectory();
460
+ // await definition.copyMockedUriFiles(copyTarget);
461
+ // await expect(
462
+ // fs.access(path.join(copyTarget, 'test-uri.data.json'))
463
+ // ).resolves.toBeUndefined();
464
+ // });
465
+ // test('multiple mockedUri files are copied to target', async () => {
466
+ // const definition = await createComponentDefinition({
467
+ // mockedUris: {
468
+ // 'test-uri': {
469
+ // type: 'file',
470
+ // path: 'test-uri.data.json',
471
+ // },
472
+ // 'another-test-uri': {
473
+ // type: 'file',
474
+ // path: 'another-test-uri.data.json',
475
+ // },
476
+ // },
477
+ // });
478
+ // await fs.writeFile(
479
+ // path.join(definition.baseDir, 'test-uri.data.json'),
480
+ // '{}'
481
+ // );
482
+ // await fs.writeFile(
483
+ // path.join(definition.baseDir, 'another-test-uri.data.json'),
484
+ // '{}'
485
+ // );
486
+ // const copyTarget = await makeTempDirectory();
487
+ // await definition.copyMockedUriFiles(copyTarget);
488
+ // await expect(
489
+ // fs.access(path.join(copyTarget, 'test-uri.data.json'))
490
+ // ).resolves.toBeUndefined();
491
+ // await expect(
492
+ // fs.access(path.join(copyTarget, 'another-test-uri.data.json'))
493
+ // ).resolves.toBeUndefined();
494
+ // });
495
+ // test('no error when no mockedUris defined', async () => {
496
+ // const definition = await createComponentDefinition();
497
+ // const copyTarget = await makeTempDirectory();
498
+ // await expect(
499
+ // definition.copyMockedUriFiles(copyTarget)
500
+ // ).resolves.toBeUndefined();
501
+ // });
502
+ // });
436
503
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/dxp-cli-next",
3
- "version": "5.19.0-develop.4",
3
+ "version": "5.19.0-develop.5",
4
4
  "repository": {
5
5
  "url": "https://gitlab.squiz.net/dxp/dxp-cli-next"
6
6
  },