@webiny/cli 5.17.4 → 5.18.0-beta.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/commands/upgrade/index.js +52 -11
  3. package/context.js +1 -2
  4. package/package.json +4 -15
  5. package/utils/getProjectApplication.js +25 -2
  6. package/utils/log.js +2 -2
  7. package/commands/upgrade/upgrades/5.10.0/index.js +0 -123
  8. package/commands/upgrade/upgrades/5.10.0/upgradeApiFileManager.js +0 -111
  9. package/commands/upgrade/upgrades/5.10.0/upgradeApolloCachePlugins.js +0 -114
  10. package/commands/upgrade/upgrades/5.10.0/upgradeDeliveryPath.js +0 -19
  11. package/commands/upgrade/upgrades/5.10.0/upgradeLambdaConfig.js +0 -30
  12. package/commands/upgrade/upgrades/5.11.0/index.js +0 -109
  13. package/commands/upgrade/upgrades/5.11.0/upgradeApiI18n.js +0 -59
  14. package/commands/upgrade/upgrades/5.11.0/upgradeObjectField.js +0 -59
  15. package/commands/upgrade/upgrades/5.11.0/upgradeWebsite.js +0 -21
  16. package/commands/upgrade/upgrades/5.12.0/index.js +0 -106
  17. package/commands/upgrade/upgrades/5.12.0/upgradeApiSecurity.js +0 -53
  18. package/commands/upgrade/upgrades/5.12.0/upgradeElasticsearch.js +0 -111
  19. package/commands/upgrade/upgrades/5.13.0/addDotWebinyToGitIgnore.js +0 -25
  20. package/commands/upgrade/upgrades/5.13.0/addNewScaffolds.js +0 -75
  21. package/commands/upgrade/upgrades/5.13.0/createTypesTsFiles.js +0 -101
  22. package/commands/upgrade/upgrades/5.13.0/files/types/graphql.ts +0 -34
  23. package/commands/upgrade/upgrades/5.13.0/files/types/headlessCMS.ts +0 -28
  24. package/commands/upgrade/upgrades/5.13.0/index.js +0 -49
  25. package/commands/upgrade/upgrades/5.15.0/index.js +0 -97
  26. package/commands/upgrade/upgrades/5.15.0/upgradeApiPageBuilder.js +0 -121
  27. package/commands/upgrade/upgrades/5.16.0/index.js +0 -207
  28. package/commands/upgrade/upgrades/5.17.0/apiPrerenderingService.js +0 -182
  29. package/commands/upgrade/upgrades/5.17.0/index.js +0 -93
  30. package/commands/upgrade/upgrades/5.17.0/security.js +0 -611
  31. package/commands/upgrade/upgrades/5.5.0/index.js +0 -426
  32. package/commands/upgrade/upgrades/5.5.0/templates/api/default.webiny.config.js +0 -8
  33. package/commands/upgrade/upgrades/5.5.0/templates/api/fileManagerTransform.webiny.config.js +0 -9
  34. package/commands/upgrade/upgrades/5.5.0/templates/api/prerenderingService.webiny.config.js +0 -30
  35. package/commands/upgrade/upgrades/5.5.0/templates/customPackages/webiny.config.js +0 -8
  36. package/commands/upgrade/upgrades/5.5.0/templates/webinyApplication/api/webiny.application.js +0 -9
  37. package/commands/upgrade/upgrades/5.5.0/templates/webinyApplication/apps/admin/webiny.application.js +0 -15
  38. package/commands/upgrade/upgrades/5.5.0/templates/webinyApplication/apps/site/webiny.application.js +0 -16
  39. package/commands/upgrade/upgrades/5.5.0/templates/webinyApplication/apps/website/webiny.application.js +0 -16
  40. package/commands/upgrade/upgrades/5.8.0/index.js +0 -137
  41. package/commands/upgrade/upgrades/5.9.0/index.js +0 -144
  42. package/commands/upgrade/upgrades/5.9.0/upgradeScaffolding/babelrc.js +0 -1
  43. package/commands/upgrade/upgrades/5.9.0/upgradeScaffolding/jestConfig.js +0 -40
  44. package/commands/upgrade/upgrades/5.9.0/upgradeScaffolding.js +0 -337
  45. package/commands/upgrade/upgrades/5.9.0/upgradeSecurity.js +0 -280
  46. package/commands/upgrade/upgrades/5.9.0/upgradeTelemetry.js +0 -30
  47. package/commands/upgrade/upgrades/fileUtils.js +0 -152
  48. package/commands/upgrade/upgrades/upgrade.js +0 -1
  49. package/commands/upgrade/upgrades/utils.js +0 -792
@@ -1,426 +0,0 @@
1
- const { join } = require("path");
2
- const fs = require("fs");
3
- const util = require("util");
4
- const { getProjectApplication } = require("../../../../utils");
5
- const execa = require("execa");
6
- const loadJson = require("load-json-file");
7
- const writeJson = require("write-json-file");
8
- const prettier = require("prettier");
9
- const ncpBase = require("ncp");
10
- const ncp = util.promisify(ncpBase.ncp);
11
- const rimraf = require("rimraf");
12
-
13
- module.exports = {
14
- name: "upgrade-5.5.0",
15
- type: "cli-upgrade",
16
- version: "5.5.0",
17
- canUpgrade() {
18
- return true;
19
- },
20
- async upgrade(options, context) {
21
- const { info, success, error } = context;
22
- try {
23
- const start = new Date();
24
- const getDuration = () => {
25
- return (new Date() - start) / 1000;
26
- };
27
-
28
- info(`Applying ${info.hl("Webiny 5.5.0")} project changes...`);
29
- console.log();
30
-
31
- // 1. Move all .pulumi folders to project root
32
- console.log(info.hl("Step 1 of 6:"));
33
- await movePulumiFolders(context);
34
- console.log();
35
-
36
- // 2. Rename `webiny.root.js` to `webiny.project.js`.
37
- console.log(info.hl("Step 2 of 6:"));
38
- await renameWebinyRoot(context);
39
- console.log();
40
-
41
- // 3. Create `webiny.application.js` files
42
- console.log(info.hl("Step 3 of 6:"));
43
- await createWebinyApplication(context);
44
- console.log();
45
-
46
- // 4 . Add `watch` command to all packages within the API project application.
47
- console.log(info.hl("Step 4 of 6:"));
48
- await addWatchCommandToApi(context);
49
- console.log();
50
-
51
- // 5. Add the `watch` command to React apps in apps/admin and apps/website project applications.
52
- console.log(info.hl("Step 5 of 6:"));
53
- await addWatchCommandToReactApps(context);
54
- console.log();
55
-
56
- // 6. Custom packages.
57
- // - add `webiny.config.js` with `build` and `watch` scripts.
58
- // - add `@webiny/cli` and `@webiny/project-utils` to `package.json` files
59
- // - replace existing `build` and `watch` commands with new ones
60
- console.log(info.hl("Step 6 of 6:"));
61
- await updateCustomPackages(context);
62
- console.log();
63
-
64
- // -------------------------------- Finish --------------------------------
65
-
66
- const duration = getDuration();
67
- success(`Done! Update of project files finished in ${success.hl(duration + "s")}.`);
68
- console.log();
69
-
70
- // Enabling logs (optional)
71
- // Add WEBINY_LOGS_FORWARD_URL to `api` and `headless-cms` functions
72
- // add `@webiny/handler-logs` package in `api` packages
73
- info(
74
- `Optionally, you can also enable the new ${info.hl(
75
- "logging"
76
- )} feature, that's part of the new ${info.hl("watch")} command.`
77
- );
78
- info(
79
- `To learn more, please visit https://www.webiny.com/docs/how-to-guides/upgrade-webiny/5.4.0-to-5.5.0`
80
- );
81
- } catch (e) {
82
- error(
83
- `An error occurred while executing the ${error.hl(
84
- "Webiny 5.5.0"
85
- )} project upgrade script:`
86
- );
87
- console.log(e);
88
- console.log();
89
- info(
90
- `For more information on how to execute the upgrade steps manually, please visit https://www.webiny.com/docs/how-to-guides/upgrade-webiny/5.4.0-to-5.5.0`
91
- );
92
- }
93
- }
94
- };
95
-
96
- const WEBINY_CONFIG_JS_MAP = {
97
- "api/code/prerenderingService": {
98
- match: "return watchFunction\\(",
99
- file: "prerenderingService.webiny.config.js"
100
- },
101
- "api/code/fileManager/transform": {
102
- match: "watch: watchFunction",
103
- file: "fileManagerTransform.webiny.config.js"
104
- },
105
- ".*": {
106
- match: "watch: watchFunction",
107
- file: "default.webiny.config.js"
108
- }
109
- };
110
-
111
- const PROJECT_APPLICATIONS = ["api", "apps/admin", "apps/site", "apps/website"];
112
-
113
- const movePulumiFolders = async context => {
114
- const { project, info, warning, success } = context;
115
-
116
- info(`Moving ${info.hl(".pulumi")} folders to project root...`);
117
-
118
- for (let i = 0; i < PROJECT_APPLICATIONS.length; i++) {
119
- const projectApplicationPath = PROJECT_APPLICATIONS[i];
120
- const pulumiFolderPath = join(projectApplicationPath, ".pulumi");
121
- const stateFolder = join(project.root, ".pulumi", projectApplicationPath, ".pulumi");
122
- if (fs.existsSync(pulumiFolderPath)) {
123
- info(
124
- `Moving ${info.hl(pulumiFolderPath)} folder to project root (${info.hl(
125
- stateFolder
126
- )}).`
127
- );
128
-
129
- if (!fs.existsSync(stateFolder)) {
130
- fs.mkdirSync(stateFolder, { recursive: true });
131
-
132
- await ncp(pulumiFolderPath, stateFolder);
133
-
134
- rimraf.sync(join(pulumiFolderPath));
135
-
136
- success(`Moved ${info.hl(".pulumi")} folder to project root.`);
137
- } else {
138
- warning(`Skipping... folder ${warning.hl(stateFolder)} already exists.`);
139
- }
140
- } else {
141
- info(`Folder ${info.hl(pulumiFolderPath)} doesn't exist, continuing.`);
142
- }
143
- }
144
- };
145
-
146
- const renameWebinyRoot = context => {
147
- const { project, info, warning, success } = context;
148
-
149
- info(`Renaming ${info.hl("webiny.root.js")} to ${info.hl("webiny.project.js")}...`);
150
-
151
- const webinyRootPath = join(project.root, "webiny.root.js");
152
- const webinyProjectPath = join(project.root, "webiny.project.js");
153
- if (fs.existsSync(webinyProjectPath)) {
154
- warning(`Could not rename - ${warning.hl("webiny.project.js")} already exists.`);
155
- } else {
156
- fs.renameSync(webinyRootPath, webinyProjectPath);
157
- success(
158
- `Successfully renamed ${success.hl("webiny.root.js")} to ${success.hl(
159
- "webiny.project.js"
160
- )}.`
161
- );
162
- }
163
- };
164
-
165
- const createWebinyApplication = context => {
166
- const { info, warning, success } = context;
167
-
168
- info(`Creating ${info.hl("webiny.application.js")} files...`);
169
-
170
- for (let i = 0; i < PROJECT_APPLICATIONS.length; i++) {
171
- let projectApplication;
172
- try {
173
- projectApplication = getProjectApplication({ cwd: PROJECT_APPLICATIONS[i] });
174
- } catch {
175
- continue;
176
- }
177
- const applicationFilePath = join(projectApplication.root, "webiny.application.js");
178
- if (fs.existsSync(applicationFilePath)) {
179
- warning(
180
- `Skipping creation of ${warning.hl("webiny.application.js")} file in ${warning.hl(
181
- projectApplication.name
182
- )} project application - already exists.`
183
- );
184
- } else {
185
- const from = join(
186
- __dirname,
187
- "templates",
188
- "webinyApplication",
189
- `${PROJECT_APPLICATIONS[i]}/webiny.application.js`
190
- );
191
-
192
- const to = join(projectApplication.root, "webiny.application.js");
193
-
194
- fs.copyFileSync(from, to);
195
-
196
- projectApplication = getProjectApplication({ cwd: PROJECT_APPLICATIONS[i] });
197
- success(
198
- `Successfully created ${success.hl("webiny.application.js")} in ${success.hl(
199
- projectApplication.name
200
- )} project application.`
201
- );
202
- }
203
- }
204
- };
205
-
206
- const addWatchCommandToApi = async context => {
207
- const { info, warning, success } = context;
208
-
209
- info(
210
- `Adding ${info.hl("watch")} command to all ${info.hl("webiny.config.js")} and ${info.hl(
211
- "package.json"
212
- )} files located within the ${info.hl("API")} project application...`
213
- );
214
-
215
- let apiPackages;
216
- try {
217
- apiPackages = await execa("yarn", [
218
- "webiny",
219
- "ws",
220
- "list",
221
- "--folder",
222
- "api",
223
- "--json",
224
- "--with-path"
225
- ])
226
- .then(({ stdout }) => stdout)
227
- .then(JSON.parse)
228
- .then(Object.values);
229
- } catch {}
230
-
231
- info(`Found ${info.hl(apiPackages.length)} packages.`);
232
-
233
- for (let i = 0; i < apiPackages.length; i++) {
234
- const packagePath = apiPackages[i];
235
- const packageJsonPath = join(packagePath, "package.json");
236
- const packageJson = loadJson.sync(packageJsonPath);
237
- info(info.hl(packagePath));
238
- if (packageJson.scripts.watch) {
239
- warning(
240
- `Skipped updating ${warning.hl("package.json")} - ${warning.hl(
241
- "watch"
242
- )} script already exists.`
243
- );
244
- } else {
245
- packageJson.scripts.watch = "yarn webiny run watch";
246
- writeJson.sync(packageJsonPath, packageJson);
247
- success(`Updated ${warning.hl("package.json")} - ${warning.hl("watch")} script added.`);
248
- }
249
-
250
- const webinyConfigJsPath = join(packagePath, "webiny.config.js");
251
- const contents = fs.readFileSync(webinyConfigJsPath, "utf8");
252
-
253
- let map;
254
- for (const regex in WEBINY_CONFIG_JS_MAP) {
255
- if (webinyConfigJsPath.match(new RegExp(regex))) {
256
- map = WEBINY_CONFIG_JS_MAP[regex];
257
- break;
258
- }
259
- }
260
-
261
- if (contents.match(new RegExp(map.match))) {
262
- warning(
263
- `Skipped updating ${warning.hl("webiny.config.js")} - ${warning.hl(
264
- "watch"
265
- )} command already exists.`
266
- );
267
- } else {
268
- const from = join(__dirname, "templates", "api", map.file);
269
- const to = join(packagePath, "webiny.config.js");
270
- fs.copyFileSync(from, to);
271
-
272
- success(
273
- `Updated ${warning.hl("webiny.config.js")} - ${warning.hl("watch")} command added.`
274
- );
275
- }
276
- }
277
- };
278
-
279
- const addWatchCommandToReactApps = async context => {
280
- const { info, warning, success } = context;
281
-
282
- info(
283
- `Adding ${info.hl("watch")} command to all ${info.hl(
284
- "package.json"
285
- )} files located within the ${info.hl("Admin Area")} and ${info.hl(
286
- "Website"
287
- )} project application...`
288
- );
289
-
290
- let appsPackages;
291
- try {
292
- appsPackages = await execa("yarn", [
293
- "webiny",
294
- "ws",
295
- "list",
296
- "--folder",
297
- "apps/admin",
298
- "--folder",
299
- "apps/website",
300
- "--folder",
301
- "apps/site",
302
- "--json",
303
- "--with-path"
304
- ])
305
- .then(({ stdout }) => stdout)
306
- .then(JSON.parse)
307
- .then(Object.values);
308
- } catch {}
309
-
310
- info(`Found ${info.hl(appsPackages.length)} packages.`);
311
-
312
- for (let i = 0; i < appsPackages.length; i++) {
313
- const packagePath = appsPackages[i];
314
- const packageJsonPath = join(packagePath, "package.json");
315
- const packageJson = loadJson.sync(packageJsonPath);
316
- if (!packageJson.scripts || !packageJson.scripts.start) {
317
- continue;
318
- }
319
-
320
- info(info.hl(packagePath));
321
- if (packageJson.scripts.watch) {
322
- warning(
323
- `Skipped updating ${warning.hl("package.json")} - ${warning.hl(
324
- "watch"
325
- )} script already exists.`
326
- );
327
- } else {
328
- packageJson.scripts.watch = packageJson.scripts.start;
329
- writeJson.sync(packageJsonPath, packageJson);
330
- success(`Updated ${warning.hl("package.json")} - ${warning.hl("watch")} script added.`);
331
- }
332
- }
333
- };
334
-
335
- const updateCustomPackages = async context => {
336
- const { info, warning, success } = context;
337
-
338
- info(
339
- `Adding ${info.hl("watch")} command to all ${info.hl("webiny.config.js")} and ${info.hl(
340
- "package.json"
341
- )} files located within the ${info.hl("packages")} folder...`
342
- );
343
-
344
- let customPackages;
345
- try {
346
- customPackages = await execa("yarn", [
347
- "webiny",
348
- "ws",
349
- "list",
350
- "--ignore-folder",
351
- "api",
352
- "--ignore-folder",
353
- "apps",
354
- "--json",
355
- "--with-path"
356
- ])
357
- .then(({ stdout }) => stdout)
358
- .then(JSON.parse)
359
- .then(Object.values);
360
- } catch {}
361
-
362
- info(`Found ${info.hl(customPackages.length)} packages.`);
363
-
364
- for (let i = 0; i < customPackages.length; i++) {
365
- const packagePath = customPackages[i];
366
- const packageJsonPath = join(packagePath, "package.json");
367
- const packageJson = loadJson.sync(packageJsonPath);
368
-
369
- const tsConfigPath = join(packagePath, "tsconfig.json");
370
- if (!fs.existsSync(tsConfigPath)) {
371
- continue;
372
- }
373
-
374
- info(info.hl(packagePath));
375
- if (!packageJson.scripts.build || packageJson.scripts.build.includes("babel")) {
376
- packageJson.scripts.build = "yarn webiny run build";
377
- success(`Updated ${warning.hl("package.json")} - ${warning.hl("build")} script added.`);
378
- } else {
379
- warning(
380
- `Skipped updating ${warning.hl("package.json")} - ${warning.hl(
381
- "build"
382
- )} script already exists.`
383
- );
384
- }
385
-
386
- if (!packageJson.scripts.watch || packageJson.scripts.watch.includes("babel")) {
387
- packageJson.scripts.watch = "yarn webiny run watch";
388
- success(`Updated ${warning.hl("package.json")} - ${warning.hl("watch")} script added.`);
389
- } else {
390
- warning(
391
- `Skipped updating ${warning.hl("package.json")} - ${warning.hl(
392
- "watch"
393
- )} script already exists.`
394
- );
395
- }
396
-
397
- await prettier.resolveConfig(packageJsonPath).then(options => {
398
- const content = prettier.format(JSON.stringify(packageJson, null, 2), {
399
- ...options,
400
- parser: "json"
401
- });
402
- fs.writeFileSync(packageJsonPath, content);
403
- });
404
-
405
- if (packageJson.scripts.postbuild) {
406
- warning(
407
- `Detected ${warning.hl(
408
- "postbuild"
409
- )} script. You might want to remove it since its no longer used by the new ${warning.hl(
410
- "build"
411
- )} script`
412
- );
413
- }
414
-
415
- const webinyConfigJsPath = join(packagePath, "webiny.config.js");
416
- if (!fs.existsSync(webinyConfigJsPath)) {
417
- const from = join(__dirname, "templates", "customPackages", "webiny.config.js");
418
- const to = join(packagePath, "webiny.config.js");
419
- fs.copyFileSync(from, to);
420
-
421
- success(`Created ${warning.hl("webiny.config.js")}.`);
422
- } else {
423
- warning(`Skipping creation of ${warning.hl("webiny.config.js")} - already exists.`);
424
- }
425
- }
426
- };
@@ -1,8 +0,0 @@
1
- const { buildFunction, watchFunction } = require("@webiny/project-utils");
2
-
3
- module.exports = {
4
- commands: {
5
- build: buildFunction,
6
- watch: watchFunction
7
- }
8
- };
@@ -1,9 +0,0 @@
1
- const { buildFunction } = require("@webiny/api-file-manager/handlers/transform/bundle");
2
- const { watchFunction } = require("@webiny/project-utils");
3
-
4
- module.exports = {
5
- commands: {
6
- build: buildFunction,
7
- watch: watchFunction
8
- }
9
- };
@@ -1,30 +0,0 @@
1
- const { buildFunction, watchFunction } = require("@webiny/project-utils");
2
-
3
- module.exports = {
4
- commands: {
5
- build(options, context) {
6
- return buildFunction(
7
- {
8
- ...options,
9
- webpack(config) {
10
- config.externals.push("chrome-aws-lambda");
11
- return config;
12
- }
13
- },
14
- context
15
- );
16
- },
17
- watch(options, context) {
18
- return watchFunction(
19
- {
20
- ...options,
21
- webpack(config) {
22
- config.externals.push("chrome-aws-lambda");
23
- return config;
24
- }
25
- },
26
- context
27
- );
28
- }
29
- }
30
- };
@@ -1,8 +0,0 @@
1
- const { watchPackage, buildPackage } = require("@webiny/project-utils");
2
-
3
- module.exports = {
4
- commands: {
5
- build: buildPackage,
6
- watch: watchPackage
7
- }
8
- };
@@ -1,9 +0,0 @@
1
- /**
2
- * For more information on the API project application, please see:
3
- * https://www.webiny.com/docs/key-topics/cloud-infrastructure/api/introduction
4
- */
5
- module.exports = {
6
- id: "api",
7
- name: "API",
8
- description: "Your GraphQL API and all of the backend services."
9
- };
@@ -1,15 +0,0 @@
1
- /**
2
- * For more information on the Admin Area project application, please see:
3
- * https://www.webiny.com/docs/key-topics/cloud-infrastructure/admin/introduction
4
- */
5
- module.exports = {
6
- id: "admin",
7
- name: "Admin Area",
8
- description: "Your project's admin area.",
9
- cli: {
10
- // Default args for the "yarn webiny watch ..." command (we don't need deploy option while developing).
11
- watch: {
12
- deploy: false
13
- }
14
- }
15
- };
@@ -1,16 +0,0 @@
1
- /**
2
- * For more information on the Website project application, please see:
3
- * https://www.webiny.com/docs/key-topics/cloud-infrastructure/website/introduction
4
- */
5
-
6
- module.exports = {
7
- id: "website",
8
- name: "Website",
9
- description: "Your project's public website.",
10
- cli: {
11
- // Default args for the "yarn webiny watch ..." command (we don't need deploy option while developing).
12
- watch: {
13
- deploy: false
14
- }
15
- }
16
- };
@@ -1,16 +0,0 @@
1
- /**
2
- * For more information on the Website project application, please see:
3
- * https://www.webiny.com/docs/key-topics/cloud-infrastructure/website/introduction
4
- */
5
-
6
- module.exports = {
7
- id: "website",
8
- name: "Website",
9
- description: "Your project's public website.",
10
- cli: {
11
- // Default args for the "yarn webiny watch ..." command (we don't need deploy option while developing).
12
- watch: {
13
- deploy: false
14
- }
15
- }
16
- };
@@ -1,137 +0,0 @@
1
- const tsMorph = require("ts-morph");
2
- const path = require("path");
3
- const execa = require("execa");
4
- const { createMorphProject, insertImport, addPackagesToDependencies } = require("../utils");
5
-
6
- const targetVersion = "5.8.0";
7
- const headlessCMS = "api/code/headlessCMS";
8
- const graphQL = "api/code/graphql";
9
-
10
- const traverseAndAddNewPlugin = (node, traversal) => {
11
- const kind = node.getKind();
12
- if (kind === tsMorph.SyntaxKind.ImportDeclaration) {
13
- traversal.skip();
14
- } else if (kind === tsMorph.SyntaxKind.ArrayLiteralExpression) {
15
- const parent = node.getParent();
16
- if (!parent.compilerNode || !parent.compilerNode.name) {
17
- traversal.skip();
18
- return;
19
- }
20
- const compilerNode = parent.compilerNode || {};
21
- const name = compilerNode.name || {};
22
- const escapedText = name.escapedText;
23
- if (escapedText !== "plugins") {
24
- traversal.skip();
25
- return;
26
- }
27
- node.addElement("headlessCmsDynamoDbElasticStorageOperation()");
28
- traversal.stop();
29
- }
30
- };
31
- /**
32
- * @type {CliUpgradePlugin}
33
- */
34
- const plugin = {
35
- name: "upgrade-5.8.0",
36
- type: "cli-upgrade",
37
- version: targetVersion,
38
- /**
39
- * @param options {CliUpgradePluginOptions}
40
- * @param context {CliContext}
41
- * @returns {Promise<boolean>}
42
- */
43
- async canUpgrade(options, context) {
44
- if (context.version === targetVersion) {
45
- return true;
46
- }
47
- throw new Error(
48
- `Upgrade must be on Webiny CLI version "${targetVersion}". Current CLI version is "${context.version}".`
49
- );
50
- },
51
- /**
52
- * @param options {CliUpgradePluginOptions}
53
- * @param context {CliContext}
54
- * @returns {Promise<void>}
55
- */
56
- async upgrade(options, context) {
57
- const { info, error, project } = context;
58
- /**
59
- * Configurations
60
- */
61
- const headlessCmsPath = path.resolve(project.root, headlessCMS);
62
- const graphQLPath = path.resolve(project.root, graphQL);
63
- const headlessCmsIndexFilePath = `${headlessCmsPath}/src/index.ts`;
64
- const graphQlIndexFilePath = `${graphQLPath}/src/index.ts`;
65
- const packages = {
66
- "@webiny/api-headless-cms-ddb-es": "^5.8.0"
67
- };
68
- /**
69
- * Headless CMS API upgrade
70
- */
71
- console.log(info.hl("Step 1 of 3: Headless CMS API upgrade"));
72
- /**
73
- * Add new package to the headless cms package.json file
74
- */
75
- console.log("Adding new package to the package.json file.");
76
- addPackagesToDependencies(headlessCmsPath, packages);
77
- /**
78
- * Update the index.ts file in the headless cms directory.
79
- */
80
- const headlessCmsProject = createMorphProject([headlessCmsIndexFilePath]);
81
- const headlessCmsIndexSourceFile =
82
- headlessCmsProject.getSourceFileOrThrow(headlessCmsIndexFilePath);
83
- console.log("Adding new plugin to index.ts file.");
84
- insertImport(
85
- headlessCmsIndexSourceFile,
86
- "headlessCmsDynamoDbElasticStorageOperation",
87
- "@webiny/api-headless-cms-ddb-es"
88
- );
89
- headlessCmsIndexSourceFile.forEachDescendant(traverseAndAddNewPlugin);
90
- console.log("Saving Headless CMS index.ts file.");
91
- await headlessCmsIndexSourceFile.save();
92
-
93
- /**
94
- * GraphQL API upgrade
95
- */
96
- console.log(info.hl("Step 2 of 3: GraphQL API upgrade"));
97
- /**
98
- * Add new package to the graphql package.json file
99
- */
100
- console.log("Adding new package to the package.json file.");
101
- addPackagesToDependencies(graphQLPath, packages);
102
- /**
103
- * Update the index.ts file in the headless cms directory.
104
- */
105
- const graphQlProject = createMorphProject([graphQlIndexFilePath]);
106
- const graphQlIndexSourceFile = graphQlProject.getSourceFileOrThrow(graphQlIndexFilePath);
107
- console.log("Adding new plugin to index.ts file.");
108
- insertImport(
109
- graphQlIndexSourceFile,
110
- "headlessCmsDynamoDbElasticStorageOperation",
111
- "@webiny/api-headless-cms-ddb-es"
112
- );
113
-
114
- graphQlIndexSourceFile.forEachDescendant(traverseAndAddNewPlugin);
115
- console.log("Saving GraphQL index.ts file.");
116
- await graphQlIndexSourceFile.save();
117
-
118
- /**
119
- * Run yarn to install new package
120
- */
121
- try {
122
- console.log(info.hl("Step 3 of 3: Installing new packages."));
123
- await execa("yarn");
124
- console.log("Installed new packages.");
125
- } catch (ex) {
126
- console.log(error.hl("Install of new packages failed."));
127
- console.log(error(ex.message));
128
- if (ex.stdout) {
129
- console.log(ex.stdout);
130
- }
131
- }
132
- }
133
- };
134
-
135
- module.exports = () => {
136
- return plugin;
137
- };