@webiny/cli 5.17.4-beta.1 → 5.18.0-beta.2

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 +53 -0
  2. package/commands/upgrade/index.js +60 -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,280 +0,0 @@
1
- const { Node } = require("ts-morph");
2
-
3
- function isSecurityPlugins(node) {
4
- return Node.isCallExpression(node) && node.getExpression().getText() === "securityPlugins";
5
- }
6
-
7
- async function upgradeGraphQLIndex(file, filePath, { info, error }) {
8
- info(`Upgrading ${info.hl(filePath)}`);
9
-
10
- let importPath = "@webiny/api-security-admin-users";
11
- const adminUsersImport = file.getImportDeclaration("@webiny/api-security-admin-users");
12
- if (!adminUsersImport) {
13
- const lastImport = file.getImportDeclarations().pop();
14
-
15
- file.insertImportDeclaration(lastImport.getChildIndex() + 1, {
16
- defaultImport: "adminUsersPlugins",
17
- moduleSpecifier: importPath
18
- });
19
-
20
- // Try fetching plugins from handler config object
21
- let plugins = file.getFirstDescendant(
22
- node => Node.isPropertyAssignment(node) && node.getName() === "plugins"
23
- );
24
-
25
- if (plugins) {
26
- const security = plugins.getInitializer().getElements().findIndex(isSecurityPlugins);
27
- plugins.getInitializer().insertElement(security, "adminUsersPlugins()");
28
- } else {
29
- // If not found, the project may still be using the old array-like syntax
30
- plugins = file.getFirstDescendant(
31
- node =>
32
- Node.isCallExpression(node) &&
33
- node.getExpression().getText() === "createHandler"
34
- );
35
-
36
- if (!plugins) {
37
- error(`Unable to upgrade automatically!`);
38
- return;
39
- }
40
-
41
- const security = plugins.getArguments().findIndex(isSecurityPlugins);
42
- plugins.insertArgument(security, "adminUsersPlugins()");
43
- }
44
- }
45
- }
46
-
47
- async function upgradeGraphQLSecurity(file, filePath, { info }) {
48
- info(`Upgrading ${info.hl(filePath)}`);
49
-
50
- // Rename default import variable name
51
- const authenticatorImport = file.getImportDeclaration("@webiny/api-security/authenticator");
52
- if (authenticatorImport) {
53
- authenticatorImport.renameDefaultImport("security");
54
- }
55
-
56
- // Update imports
57
- const map = {
58
- "@webiny/api-security-tenancy": "@webiny/api-tenancy",
59
- "@webiny/api-security/authenticator": "@webiny/api-security",
60
- "@webiny/api-plugin-security-cognito/authentication":
61
- "@webiny/api-security-cognito-authentication",
62
- "@webiny/api-plugin-security-cognito/identityProvider": "@webiny/api-admin-users-cognito"
63
- };
64
-
65
- file.getImportDeclarations().forEach(imp => {
66
- const moduleSpecifier = imp.getModuleSpecifier().getLiteralValue();
67
- if (moduleSpecifier in map) {
68
- imp.setModuleSpecifier(map[moduleSpecifier]);
69
- } else {
70
- if (moduleSpecifier.includes("@webiny/api-security-tenancy")) {
71
- imp.setModuleSpecifier(
72
- moduleSpecifier.replace("api-security-tenancy", "api-security-admin-users")
73
- );
74
- }
75
- }
76
- });
77
-
78
- // Update plugin factories
79
- const authenticator = file.getFirstDescendant(node => {
80
- return Node.isCallExpression(node) && node.getExpression().getText() === "authenticator";
81
- });
82
-
83
- if (authenticator) {
84
- authenticator.setExpression("security");
85
- }
86
-
87
- // Update tenancy comments
88
- const tenancy = file.getFirstDescendant(node => {
89
- return Node.isCallExpression(node) && node.getExpression().getText() === "tenancy";
90
- });
91
-
92
- const tenancyComments = tenancy.getLeadingCommentRanges();
93
- if (tenancyComments) {
94
- file.replaceText(
95
- [tenancyComments[0].getPos(), tenancyComments[0].getEnd()],
96
- `/**
97
- * Setup tenancy context which is a requirement for all Webiny projects.
98
- * Learn more: https://www.webiny.com/docs/key-topics/multi-tenancy
99
- */`
100
- );
101
- }
102
-
103
- // Update security comments
104
- const security = file.getFirstDescendant(node => {
105
- return Node.isCallExpression(node) && node.getExpression().getText() === "security";
106
- });
107
-
108
- if (security) {
109
- const securityComments = security.getLeadingCommentRanges();
110
- if (securityComments) {
111
- file.replaceText(
112
- [securityComments[0].getPos(), securityComments[0].getEnd()],
113
- `/**
114
- * Setup Webiny Security Framework to handle authentication and authorization.
115
- * Learn more: https://www.webiny.com/docs/key-topics/security-framework/introduction
116
- */`
117
- );
118
- }
119
- }
120
-
121
- // Update security comments
122
- const cognitoIdP = file.getFirstDescendant(node => {
123
- return (
124
- Node.isCallExpression(node) &&
125
- node.getExpression().getText() === "cognitoIdentityProvider"
126
- );
127
- });
128
-
129
- if (cognitoIdP) {
130
- const cognitoComments = cognitoIdP.getLeadingCommentRanges();
131
- if (cognitoComments) {
132
- file.replaceText(
133
- [cognitoComments[0].getPos(), cognitoComments[0].getEnd()],
134
- `/**
135
- * Cognito IDP plugin (hooks for User CRUD methods).
136
- * This plugin will perform CRUD operations on Amazon Cognito when you do something with the user
137
- * via the UI or API. Its purpose is to push changes to Cognito when they happen in your app.
138
- */`
139
- );
140
- }
141
- }
142
- }
143
-
144
- async function upgradeHeadlessSecurity(file, filePath, context) {
145
- // Headless security is almost identical and we can reuse graphql upgrade
146
- await upgradeGraphQLSecurity(file, filePath, context);
147
-
148
- const cognitoIdPImport = file.getImportDeclaration("@webiny/api-admin-users-cognito");
149
- if (cognitoIdPImport) {
150
- cognitoIdPImport.renameDefaultImport("adminUsersContext");
151
- cognitoIdPImport.setModuleSpecifier("@webiny/api-security-admin-users/context");
152
- }
153
-
154
- const adminUsers = file.getFirstDescendant(node => {
155
- return (
156
- Node.isCallExpression(node) && node.getExpression().getText() === "adminUsersContext"
157
- );
158
- });
159
-
160
- if (adminUsers) {
161
- if (adminUsers.getArguments().length > 0) {
162
- adminUsers.removeArgument(0);
163
- }
164
-
165
- const adminUsersComments = adminUsers.getLeadingCommentRanges();
166
- if (adminUsersComments) {
167
- file.replaceText(
168
- [adminUsersComments[0].getPos(), adminUsersComments[0].getEnd()],
169
- `/**
170
- * Add Admin Users context to support authentication and authorization plugins.
171
- */`
172
- );
173
- }
174
- }
175
- }
176
-
177
- async function upgradeAdminApp(file, filePath, { info }) {
178
- info(`Upgrading ${info.hl(filePath)}`);
179
-
180
- const tenancyImport = file.getImportDeclaration(
181
- "@webiny/app-security-tenancy/contexts/Tenancy"
182
- );
183
-
184
- if (tenancyImport) {
185
- tenancyImport.setModuleSpecifier("@webiny/app-tenancy/contexts/Tenancy");
186
- }
187
-
188
- const authenticationImport = file.getImportDeclaration(
189
- "@webiny/app-plugin-security-cognito/Authentication"
190
- );
191
-
192
- if (authenticationImport) {
193
- authenticationImport.setModuleSpecifier(
194
- "@webiny/app-security-admin-users-cognito/Authentication"
195
- );
196
- }
197
- }
198
-
199
- async function upgradeAdminGetIdentityData(file, filePath, { info }) {
200
- info(`Upgrading ${info.hl(filePath)}`);
201
-
202
- const queryImport = file.getImportDeclaration("@webiny/app-security-tenancy/graphql");
203
-
204
- if (queryImport) {
205
- queryImport.setModuleSpecifier("@webiny/app-security-admin-users/graphql");
206
- }
207
- }
208
-
209
- async function upgradeAdminSecurity(file, filePath, { info }) {
210
- info(`Upgrading ${info.hl(filePath)}`);
211
-
212
- // Remove obsolete import
213
- const cognitoIdentityProviderImport = file.getImportDeclaration(
214
- "@webiny/app-plugin-security-cognito/identityProvider"
215
- );
216
-
217
- if (cognitoIdentityProviderImport) {
218
- cognitoIdentityProviderImport.remove();
219
- }
220
-
221
- // Remove cognitoIdentityProvider plugins
222
- const cognitoIdentityProvider = file.getFirstDescendant(node => {
223
- return (
224
- Node.isCallExpression(node) &&
225
- node.getExpression().getText() === "cognitoIdentityProvider"
226
- );
227
- });
228
-
229
- if (cognitoIdentityProvider) {
230
- cognitoIdentityProvider.getParent().removeElement(cognitoIdentityProvider);
231
- }
232
-
233
- // Refactor imports
234
- file.getImportDeclarations().forEach(imp => {
235
- const moduleSpecifier = imp.getModuleSpecifier().getLiteralValue();
236
-
237
- if (moduleSpecifier.includes("@webiny/app-plugin-security-cognito")) {
238
- imp.setModuleSpecifier("@webiny/app-security-admin-users-cognito");
239
- return;
240
- }
241
-
242
- const defaultImport = imp.getDefaultImport();
243
- if (defaultImport && defaultImport.getText() === "securityTenancy") {
244
- imp.renameDefaultImport("adminUsers");
245
- }
246
-
247
- if (moduleSpecifier.includes("@webiny/app-security-tenancy")) {
248
- imp.setModuleSpecifier(
249
- moduleSpecifier.replace("app-security-tenancy", "app-security-admin-users")
250
- );
251
- }
252
- });
253
-
254
- // Update comments
255
- const cognitoSecurity = file.getFirstDescendant(node => {
256
- return Node.isCallExpression(node) && node.getExpression().getText() === "cognitoSecurity";
257
- });
258
-
259
- if (cognitoSecurity) {
260
- const comments = cognitoSecurity.getLeadingCommentRanges();
261
- if (comments) {
262
- file.replaceText(
263
- [comments[0].getPos(), comments[0].getEnd()],
264
- `/**
265
- * Configure Amplify, add Cognito related UI fields, and attach Authorization header
266
- * on every GraphQL request using the authenticated identity.
267
- */`
268
- );
269
- }
270
- }
271
- }
272
-
273
- module.exports = {
274
- upgradeGraphQLIndex,
275
- upgradeGraphQLSecurity,
276
- upgradeHeadlessSecurity,
277
- upgradeAdminApp,
278
- upgradeAdminGetIdentityData,
279
- upgradeAdminSecurity
280
- };
@@ -1,30 +0,0 @@
1
- const os = require("os");
2
- const path = require("path");
3
- const readJson = require("load-json-file");
4
- const writeJson = require("write-json-file");
5
-
6
- const configPath = path.join(os.homedir(), ".webiny", "config");
7
-
8
- module.exports.upgradeTelemetry = async (file, filePath, { info }) => {
9
- // Upgrade config file
10
- try {
11
- const config = await readJson(configPath);
12
- if (config) {
13
- const telemetry = "tracking" in config ? config.tracking : true;
14
- delete config["tracking"];
15
- config.telemetry = telemetry;
16
- writeJson.sync(configPath, config);
17
- }
18
- } catch {
19
- // Do nothing
20
- }
21
-
22
- // Upgrade telemetry import
23
- info(`Upgrading ${info.hl(filePath)}`);
24
-
25
- const telemetryImport = file.getImportDeclaration("@webiny/tracking/react");
26
-
27
- if (telemetryImport) {
28
- telemetryImport.setModuleSpecifier("@webiny/telemetry/react");
29
- }
30
- };
@@ -1,152 +0,0 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const fsExtra = require("fs-extra");
4
-
5
- const checkFiles = files => {
6
- for (const initialFile of files) {
7
- const file = createFullFile(initialFile);
8
- if (!fs.existsSync(file)) {
9
- /**
10
- * We throw error because if any of the files does not exist, it should not go any further.
11
- */
12
- throw new Error(`There is no file "${file}".`);
13
- }
14
- }
15
- };
16
-
17
- const createBackupFileName = file => {
18
- const ext = `.${file.split(".").pop()}`;
19
-
20
- const now = Math.floor(Date.now() / 1000);
21
-
22
- const backup = file.replace(new RegExp(`${ext}$`), `.${now}${ext}`);
23
-
24
- const backupFile = createFullFile(backup);
25
- if (!fs.existsSync(backupFile)) {
26
- return backup;
27
- }
28
- throw new Error(`Backup file "${backupFile}" already exists.`);
29
- };
30
-
31
- const createFullFile = file => {
32
- return path.join(process.cwd(), file);
33
- };
34
- /**
35
- *
36
- * @param context {CliContext}
37
- * @param initialTargets {{source: string, destination: string}[]}
38
- * @param createBackup: {boolean}
39
- */
40
- const copyFiles = (context, initialTargets, createBackup = true) => {
41
- context.info("Copying files...");
42
- /**
43
- * First check if source and target files exist and create a backup file name.
44
- * @type {{source: string, destination: string, backup: string}[]}
45
- */
46
- const targets = [];
47
- for (const target of initialTargets) {
48
- /**
49
- * No need to check target.destination because it might not exist.
50
- */
51
- checkFiles([target.source]);
52
- let backup = false;
53
- if (createBackup) {
54
- try {
55
- backup = createBackupFileName(target.destination);
56
- } catch (ex) {
57
- context.error(ex.message);
58
- process.exit(1);
59
- }
60
- }
61
-
62
- targets.push({
63
- source: target.source,
64
- destination: target.destination,
65
- backup
66
- });
67
- }
68
- /**
69
- * Then:
70
- * - make backups of the targets files
71
- * - copy new files to their destinations
72
- */
73
- if (createBackup) {
74
- const backups = [];
75
- context.info("Creating backups...");
76
- for (const target of targets) {
77
- const destination = createFullFile(target.destination);
78
- if (!fs.existsSync(destination)) {
79
- continue;
80
- }
81
- try {
82
- fs.copyFileSync(destination, createFullFile(target.backup));
83
- context.info(`Backed up "${target.destination}" to "${target.backup}".`);
84
- backups.push(target.backup);
85
- } catch (ex) {
86
- context.error(
87
- `Could not create backup "${target.destination}" to "${target.backup}".`
88
- );
89
- for (const backup of backups) {
90
- context.info(`Removing created backup "${backup}".`);
91
- fs.unlinkSync(createFullFile(backup));
92
- }
93
- process.exit(1);
94
- }
95
- }
96
- }
97
-
98
- const files = [];
99
- context.info("Copying new files...");
100
- for (const target of targets) {
101
- try {
102
- fs.copyFileSync(createFullFile(target.source), createFullFile(target.destination));
103
- context.info(`Copying new file "${target.source}" to "${target.destination}".`);
104
- files.push({
105
- destination: target.destination,
106
- backup: target.backup
107
- });
108
- } catch (ex) {
109
- context.error(`Could not copy new file "${target.source}" to "${target.destination}".`);
110
- for (const file of files) {
111
- if (!file.backup) {
112
- continue;
113
- }
114
- context.info(`Restoring backup file "${file.backup}" to "${file.destination}".`);
115
- fs.copyFileSync(createFullFile(file.backup), createFullFile(file.destination));
116
- fs.unlinkSync(createFullFile(file.backup));
117
- }
118
- process.exit(1);
119
- }
120
- }
121
- context.info("File copying complete!");
122
- };
123
-
124
- /**
125
- * @param context {CliContext}
126
- * @param targets {{source: string, destination: string}[]}
127
- */
128
- const copyFolders = (context, targets) => {
129
- context.info(`Copy folders...`);
130
-
131
- for (const target of targets) {
132
- fsExtra.copySync(target.source, target.destination);
133
- }
134
- };
135
-
136
- const deleteFiles = (context, files) => {
137
- context.info("Deleting files...");
138
- for (const file of files) {
139
- const target = createFullFile(file);
140
- if (fs.existsSync(target) === false) {
141
- continue;
142
- }
143
- context.info(`Removing file "${file}".`);
144
- fs.unlinkSync(target);
145
- }
146
- };
147
-
148
- module.exports = {
149
- copyFolders,
150
- copyFiles,
151
- deleteFiles
152
- };
@@ -1 +0,0 @@
1
- module.exports = require("./5.17.0");