@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.
- package/CHANGELOG.md +56 -0
- package/commands/upgrade/index.js +52 -11
- package/context.js +1 -2
- package/package.json +4 -15
- package/utils/getProjectApplication.js +25 -2
- package/utils/log.js +2 -2
- package/commands/upgrade/upgrades/5.10.0/index.js +0 -123
- package/commands/upgrade/upgrades/5.10.0/upgradeApiFileManager.js +0 -111
- package/commands/upgrade/upgrades/5.10.0/upgradeApolloCachePlugins.js +0 -114
- package/commands/upgrade/upgrades/5.10.0/upgradeDeliveryPath.js +0 -19
- package/commands/upgrade/upgrades/5.10.0/upgradeLambdaConfig.js +0 -30
- package/commands/upgrade/upgrades/5.11.0/index.js +0 -109
- package/commands/upgrade/upgrades/5.11.0/upgradeApiI18n.js +0 -59
- package/commands/upgrade/upgrades/5.11.0/upgradeObjectField.js +0 -59
- package/commands/upgrade/upgrades/5.11.0/upgradeWebsite.js +0 -21
- package/commands/upgrade/upgrades/5.12.0/index.js +0 -106
- package/commands/upgrade/upgrades/5.12.0/upgradeApiSecurity.js +0 -53
- package/commands/upgrade/upgrades/5.12.0/upgradeElasticsearch.js +0 -111
- package/commands/upgrade/upgrades/5.13.0/addDotWebinyToGitIgnore.js +0 -25
- package/commands/upgrade/upgrades/5.13.0/addNewScaffolds.js +0 -75
- package/commands/upgrade/upgrades/5.13.0/createTypesTsFiles.js +0 -101
- package/commands/upgrade/upgrades/5.13.0/files/types/graphql.ts +0 -34
- package/commands/upgrade/upgrades/5.13.0/files/types/headlessCMS.ts +0 -28
- package/commands/upgrade/upgrades/5.13.0/index.js +0 -49
- package/commands/upgrade/upgrades/5.15.0/index.js +0 -97
- package/commands/upgrade/upgrades/5.15.0/upgradeApiPageBuilder.js +0 -121
- package/commands/upgrade/upgrades/5.16.0/index.js +0 -207
- package/commands/upgrade/upgrades/5.17.0/apiPrerenderingService.js +0 -182
- package/commands/upgrade/upgrades/5.17.0/index.js +0 -93
- package/commands/upgrade/upgrades/5.17.0/security.js +0 -611
- package/commands/upgrade/upgrades/5.5.0/index.js +0 -426
- package/commands/upgrade/upgrades/5.5.0/templates/api/default.webiny.config.js +0 -8
- package/commands/upgrade/upgrades/5.5.0/templates/api/fileManagerTransform.webiny.config.js +0 -9
- package/commands/upgrade/upgrades/5.5.0/templates/api/prerenderingService.webiny.config.js +0 -30
- package/commands/upgrade/upgrades/5.5.0/templates/customPackages/webiny.config.js +0 -8
- package/commands/upgrade/upgrades/5.5.0/templates/webinyApplication/api/webiny.application.js +0 -9
- package/commands/upgrade/upgrades/5.5.0/templates/webinyApplication/apps/admin/webiny.application.js +0 -15
- package/commands/upgrade/upgrades/5.5.0/templates/webinyApplication/apps/site/webiny.application.js +0 -16
- package/commands/upgrade/upgrades/5.5.0/templates/webinyApplication/apps/website/webiny.application.js +0 -16
- package/commands/upgrade/upgrades/5.8.0/index.js +0 -137
- package/commands/upgrade/upgrades/5.9.0/index.js +0 -144
- package/commands/upgrade/upgrades/5.9.0/upgradeScaffolding/babelrc.js +0 -1
- package/commands/upgrade/upgrades/5.9.0/upgradeScaffolding/jestConfig.js +0 -40
- package/commands/upgrade/upgrades/5.9.0/upgradeScaffolding.js +0 -337
- package/commands/upgrade/upgrades/5.9.0/upgradeSecurity.js +0 -280
- package/commands/upgrade/upgrades/5.9.0/upgradeTelemetry.js +0 -30
- package/commands/upgrade/upgrades/fileUtils.js +0 -152
- package/commands/upgrade/upgrades/upgrade.js +0 -1
- package/commands/upgrade/upgrades/utils.js +0 -792
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,62 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [5.18.0-beta.3](https://github.com/webiny/webiny-js/compare/v5.18.0-beta.2...v5.18.0-beta.3) (2021-11-22)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* remove context ([ec4566a](https://github.com/webiny/webiny-js/commit/ec4566af26fe67cc7cb26728e7f65e54e7f16968))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [5.18.0-beta.2](https://github.com/webiny/webiny-js/compare/v5.18.0-beta.1...v5.18.0-beta.2) (2021-11-21)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @webiny/cli
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# [5.18.0-beta.1](https://github.com/webiny/webiny-js/compare/v5.18.0-beta.0...v5.18.0-beta.1) (2021-11-19)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* improve logging ([2dd751f](https://github.com/webiny/webiny-js/commit/2dd751fffb52a407cb5679bb7395e7601dea9463))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# [5.18.0-beta.0](https://github.com/webiny/webiny-js/compare/v5.17.4...v5.18.0-beta.0) (2021-11-19)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Bug Fixes
|
|
40
|
+
|
|
41
|
+
* adjust messaging ([3c867c6](https://github.com/webiny/webiny-js/commit/3c867c6b0ca59ad579f8a605afe5f94f8bccfef9))
|
|
42
|
+
* adjust messaging ([ce0cfd6](https://github.com/webiny/webiny-js/commit/ce0cfd65552552370053855567782e2847b3f956))
|
|
43
|
+
* determine target upgrade version using `package.json` / `semver` ([4a3e10f](https://github.com/webiny/webiny-js/commit/4a3e10fafbe63fe3a822083ecf52a95c714e9f61))
|
|
44
|
+
* remove old upgrade scripts ([c34f40a](https://github.com/webiny/webiny-js/commit/c34f40ab76d4c7c85087553884b64813b0b9e4eb))
|
|
45
|
+
* remove unneeded dependencies ([dabf981](https://github.com/webiny/webiny-js/commit/dabf98163bbc5c6cf4a382c3197cf64ea6337a25))
|
|
46
|
+
* update dependencies ([d69c6be](https://github.com/webiny/webiny-js/commit/d69c6be8ac22ad732012b9f81a035e93d3df674d))
|
|
47
|
+
* use "blueBright" for info ([e0b96fd](https://github.com/webiny/webiny-js/commit/e0b96fdb5939d6a0b9dac359a57e2ed3f4c42fd5))
|
|
48
|
+
* use debug function instead of chalk ([dc94492](https://github.com/webiny/webiny-js/commit/dc94492056e1882b15800209d844fd5b5ab212b1))
|
|
49
|
+
* use fast-glob lib ([eff106b](https://github.com/webiny/webiny-js/commit/eff106b3e6a3f2e806df86209596b2672f81949f))
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
### Features
|
|
53
|
+
|
|
54
|
+
* add "packages" getter ([77dc207](https://github.com/webiny/webiny-js/commit/77dc207b90dc9b85d3f516d18df9505f12ecf3d3))
|
|
55
|
+
* add packageJson ([204135a](https://github.com/webiny/webiny-js/commit/204135aaa8021b8fc3e91dd73d2b8b338ea1f728))
|
|
56
|
+
* run upgrade scripts from a remote code repository ([3c0cc49](https://github.com/webiny/webiny-js/commit/3c0cc490b155a1331c5132dbe0f0fca0af0a4e58))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
6
62
|
## [5.17.4](https://github.com/webiny/webiny-js/compare/v5.17.4-beta.1...v5.17.4) (2021-11-19)
|
|
7
63
|
|
|
8
64
|
**Note:** Version bump only for package @webiny/cli
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const { red } = require("chalk");
|
|
2
2
|
const execa = require("execa");
|
|
3
|
+
const semver = require("semver");
|
|
3
4
|
|
|
4
5
|
module.exports = [
|
|
5
6
|
{
|
|
@@ -16,6 +17,16 @@ module.exports = [
|
|
|
16
17
|
type: "boolean",
|
|
17
18
|
default: false
|
|
18
19
|
});
|
|
20
|
+
yargs.option("debug", {
|
|
21
|
+
default: false,
|
|
22
|
+
describe: `Turn on debug logs`,
|
|
23
|
+
type: "boolean"
|
|
24
|
+
});
|
|
25
|
+
yargs.option("use-version", {
|
|
26
|
+
describe:
|
|
27
|
+
"Use upgrade script for a specific version. Should only be used for development/testing purposes.",
|
|
28
|
+
type: "string"
|
|
29
|
+
});
|
|
19
30
|
},
|
|
20
31
|
async argv => {
|
|
21
32
|
if (!argv.skipChecks) {
|
|
@@ -45,20 +56,50 @@ module.exports = [
|
|
|
45
56
|
}
|
|
46
57
|
}
|
|
47
58
|
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
const defaultUpgradeTargetVersion = semver.coerce(context.version).version;
|
|
60
|
+
|
|
61
|
+
const command = [
|
|
62
|
+
"https://github.com/webiny/webiny-upgrades",
|
|
63
|
+
argv.useVersion || defaultUpgradeTargetVersion
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
if (yargs.argv.debug) {
|
|
67
|
+
context.debug("npx", ...command);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const npx = execa("npx", command, {
|
|
71
|
+
env: {
|
|
72
|
+
FORCE_COLOR: true
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
npx.stdout.on("data", data => {
|
|
77
|
+
const lines = data.toString().replace(/\n$/, "").split("\n");
|
|
78
|
+
for (let i = 0; i < lines.length; i++) {
|
|
79
|
+
const line = lines[i];
|
|
80
|
+
try {
|
|
81
|
+
const json = JSON.parse(line);
|
|
82
|
+
if (json.type === "error") {
|
|
83
|
+
context.error(
|
|
84
|
+
"An error occurred while performing the upgrade."
|
|
85
|
+
);
|
|
86
|
+
console.log(json.message);
|
|
87
|
+
if (yargs.argv.debug) {
|
|
88
|
+
context.debug(json.data.stack);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
} catch {
|
|
92
|
+
// Not JSON, let's just print the line then.
|
|
93
|
+
console.log(line);
|
|
54
94
|
}
|
|
55
|
-
} catch (ex) {
|
|
56
|
-
const msg = ex.message || "unknown";
|
|
57
|
-
throw new Error(`Upgrade failed. Reason: ${msg}`);
|
|
58
95
|
}
|
|
59
|
-
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
npx.stderr.on("data", data => {
|
|
99
|
+
console.log(data.toString());
|
|
100
|
+
});
|
|
60
101
|
|
|
61
|
-
await
|
|
102
|
+
await npx;
|
|
62
103
|
}
|
|
63
104
|
);
|
|
64
105
|
}
|
package/context.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
2
|
const path = require("path");
|
|
3
|
-
const chalk = require("chalk");
|
|
4
3
|
const { importModule, getProject, PluginsContainer, log, localStorage } = require("./utils");
|
|
5
4
|
|
|
6
5
|
const project = getProject();
|
|
@@ -117,7 +116,7 @@ class Context {
|
|
|
117
116
|
}
|
|
118
117
|
|
|
119
118
|
if (!fs.existsSync(filePath)) {
|
|
120
|
-
debug && this.
|
|
119
|
+
debug && this.debug(`No environment file found on ${this.debug.hl(filePath)}.`);
|
|
121
120
|
return;
|
|
122
121
|
}
|
|
123
122
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/cli",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.18.0-beta.3",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"bin": {
|
|
6
6
|
"webiny": "./bin.js"
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"author": "Pavel Denisjuk <pavel@webiny.com>",
|
|
14
14
|
"description": "A tool to bootstrap a Webiny project.",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@webiny/telemetry": "5.
|
|
16
|
+
"@webiny/telemetry": "5.18.0-beta.3",
|
|
17
17
|
"boolean": "3.1.4",
|
|
18
18
|
"camelcase": "5.3.1",
|
|
19
19
|
"chalk": "4.1.2",
|
|
@@ -21,24 +21,12 @@
|
|
|
21
21
|
"execa": "2.1.0",
|
|
22
22
|
"fast-glob": "3.2.7",
|
|
23
23
|
"find-up": "5.0.0",
|
|
24
|
-
"fs-extra": "7.0.1",
|
|
25
|
-
"load-json-file": "6.2.0",
|
|
26
|
-
"ncp": "2.0.0",
|
|
27
24
|
"pirates": "4.0.1",
|
|
28
|
-
"prettier": "2.4.1",
|
|
29
|
-
"replace-in-path": "1.1.0",
|
|
30
|
-
"rimraf": "3.0.2",
|
|
31
25
|
"semver": "7.3.4",
|
|
32
|
-
"ts-morph": "11.0.3",
|
|
33
26
|
"typescript": "4.1.3",
|
|
34
27
|
"uniqid": "5.4.0",
|
|
35
|
-
"write-json-file": "4.3.0",
|
|
36
28
|
"yargs": "14.2.3"
|
|
37
29
|
},
|
|
38
|
-
"devDependencies": {
|
|
39
|
-
"@webiny/handler": "^5.17.4",
|
|
40
|
-
"@webiny/plugins": "^5.17.4"
|
|
41
|
-
},
|
|
42
30
|
"license": "MIT",
|
|
43
31
|
"publishConfig": {
|
|
44
32
|
"access": "public",
|
|
@@ -56,6 +44,7 @@
|
|
|
56
44
|
"@webiny/project-utils",
|
|
57
45
|
"@webiny/api-file-manager",
|
|
58
46
|
"@webiny/cli-plugin-deploy-pulumi",
|
|
47
|
+
"@webiny/handler",
|
|
59
48
|
"@webiny/handler-http",
|
|
60
49
|
"@webiny/handler-args",
|
|
61
50
|
"@webiny/handler-client",
|
|
@@ -71,5 +60,5 @@
|
|
|
71
60
|
]
|
|
72
61
|
}
|
|
73
62
|
},
|
|
74
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "9c86670476a62348ce391b091bf768e425ab6ee9"
|
|
75
64
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
const { dirname, basename } = require("path");
|
|
1
|
+
const { dirname, basename, join } = require("path");
|
|
2
2
|
const findUp = require("find-up");
|
|
3
3
|
const getProject = require("./getProject");
|
|
4
4
|
const { importModule } = require("./importModule");
|
|
5
|
+
const glob = require("fast-glob");
|
|
5
6
|
|
|
6
7
|
const appConfigs = ["webiny.application.js", "webiny.application.ts"];
|
|
7
8
|
|
|
@@ -35,6 +36,28 @@ module.exports = args => {
|
|
|
35
36
|
name,
|
|
36
37
|
root: applicationRoot,
|
|
37
38
|
config: applicationConfig,
|
|
38
|
-
project: getProject(args)
|
|
39
|
+
project: getProject(args),
|
|
40
|
+
get packages() {
|
|
41
|
+
const webinyConfigs = glob.sync(
|
|
42
|
+
join(applicationRoot, "**/webiny.config*.{ts,js}").replace(/\\/g, "/")
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
return webinyConfigs.map(config => {
|
|
46
|
+
const dirPath = dirname(config);
|
|
47
|
+
const packageJson = require(join(dirPath, "package.json"));
|
|
48
|
+
return {
|
|
49
|
+
name: packageJson.name,
|
|
50
|
+
paths: {
|
|
51
|
+
root: dirname(config),
|
|
52
|
+
packageJson: join(dirPath, "package.json"),
|
|
53
|
+
config
|
|
54
|
+
},
|
|
55
|
+
packageJson,
|
|
56
|
+
get config() {
|
|
57
|
+
return require(config).default || require(config);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
}
|
|
39
62
|
};
|
|
40
63
|
};
|
package/utils/log.js
CHANGED
|
@@ -5,7 +5,7 @@ const getLogType = type => {
|
|
|
5
5
|
case "log":
|
|
6
6
|
return type;
|
|
7
7
|
case "info":
|
|
8
|
-
return `${chalk.
|
|
8
|
+
return `${chalk.blueBright(type)}`;
|
|
9
9
|
case "error":
|
|
10
10
|
return `${chalk.red(type)}`;
|
|
11
11
|
case "warning":
|
|
@@ -56,7 +56,7 @@ const functions = {
|
|
|
56
56
|
functions.log.highlight = chalk.highlight;
|
|
57
57
|
functions.log.hl = chalk.highlight;
|
|
58
58
|
functions.info.highlight = chalk.blue;
|
|
59
|
-
functions.info.hl = chalk.
|
|
59
|
+
functions.info.hl = chalk.blueBright;
|
|
60
60
|
functions.success.highlight = chalk.green;
|
|
61
61
|
functions.success.hl = chalk.green;
|
|
62
62
|
functions.debug.highlight = chalk.gray;
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
const path = require("path");
|
|
2
|
-
const targetVersion = "5.10.0";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @type {CliUpgradePlugin}
|
|
6
|
-
*/
|
|
7
|
-
module.exports = {
|
|
8
|
-
name: "upgrade-5.10.0",
|
|
9
|
-
type: "cli-upgrade",
|
|
10
|
-
version: targetVersion,
|
|
11
|
-
/**
|
|
12
|
-
* @param options {CliUpgradePluginOptions}
|
|
13
|
-
* @param context {CliContext}
|
|
14
|
-
* @returns {Promise<boolean>}
|
|
15
|
-
*/
|
|
16
|
-
async canUpgrade(options, context) {
|
|
17
|
-
if (context.version === targetVersion) {
|
|
18
|
-
return true;
|
|
19
|
-
} else if (
|
|
20
|
-
context.version.match(
|
|
21
|
-
new RegExp(
|
|
22
|
-
/**
|
|
23
|
-
* This is for beta testing.
|
|
24
|
-
*/
|
|
25
|
-
`^${targetVersion}-`
|
|
26
|
-
)
|
|
27
|
-
)
|
|
28
|
-
) {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
throw new Error(
|
|
32
|
-
`Upgrade must be on Webiny CLI version "${targetVersion}". Current CLI version is "${context.version}".`
|
|
33
|
-
);
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @param options {CliUpgradePluginOptions}
|
|
38
|
-
* @param context {CliContext}
|
|
39
|
-
* @returns {Promise<void>}
|
|
40
|
-
*/
|
|
41
|
-
async upgrade(options, context) {
|
|
42
|
-
const { info } = context;
|
|
43
|
-
const glob = require("fast-glob");
|
|
44
|
-
const { upgradeLambdaConfig } = require("./upgradeLambdaConfig");
|
|
45
|
-
const {
|
|
46
|
-
upgradeGraphQLIndex,
|
|
47
|
-
upgradeHeadlessCMSIndex,
|
|
48
|
-
upgradeDynamoDbToElasticIndex
|
|
49
|
-
} = require("./upgradeApiFileManager");
|
|
50
|
-
const { upgradeDeliveryPath } = require("./upgradeDeliveryPath");
|
|
51
|
-
const { upgradeApolloCachePlugins } = require("./upgradeApolloCachePlugins");
|
|
52
|
-
|
|
53
|
-
const {
|
|
54
|
-
createMorphProject,
|
|
55
|
-
addPackagesToDependencies,
|
|
56
|
-
yarnInstall,
|
|
57
|
-
prettierFormat
|
|
58
|
-
} = require("../utils");
|
|
59
|
-
|
|
60
|
-
const files = await glob(
|
|
61
|
-
[
|
|
62
|
-
"api/pulumi/**/*.ts",
|
|
63
|
-
...Object.values(upgradeGraphQLIndex.files),
|
|
64
|
-
...Object.values(upgradeHeadlessCMSIndex.files),
|
|
65
|
-
...Object.values(upgradeDynamoDbToElasticIndex.files),
|
|
66
|
-
...Object.values(upgradeApolloCachePlugins.files)
|
|
67
|
-
],
|
|
68
|
-
{
|
|
69
|
-
cwd: context.project.root,
|
|
70
|
-
onlyFiles: true,
|
|
71
|
-
ignore: ["**/node_modules/**"]
|
|
72
|
-
}
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const project = createMorphProject(files);
|
|
76
|
-
await upgradeLambdaConfig(project, context);
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Upgrade the graphql with new packages.
|
|
80
|
-
*/
|
|
81
|
-
await upgradeGraphQLIndex(project, context);
|
|
82
|
-
/**
|
|
83
|
-
* Upgrade the headless cms with new packages.
|
|
84
|
-
*/
|
|
85
|
-
await upgradeHeadlessCMSIndex(project, context);
|
|
86
|
-
/**
|
|
87
|
-
* Upgrade the dynamodbToElastic with new packages.
|
|
88
|
-
*/
|
|
89
|
-
await upgradeDynamoDbToElasticIndex(project, context);
|
|
90
|
-
|
|
91
|
-
info("Adding dependencies...");
|
|
92
|
-
|
|
93
|
-
addPackagesToDependencies(path.resolve(process.cwd(), "api/code/graphql"), {
|
|
94
|
-
"@webiny/api-file-manager-ddb-es": targetVersion
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Adds the Apollo Cache plugin to the Website's React application.
|
|
99
|
-
* Also, makes sure that both...
|
|
100
|
-
* packages/cwp-template-aws/template/apps/website/code/src/components/apolloClient.ts
|
|
101
|
-
* packages/cwp-template-aws/template/apps/admin/code/src/components/apolloClient.ts
|
|
102
|
-
*
|
|
103
|
-
* ... are using `plugins.byType<ApolloCacheObjectIdPlugin>` when setting `dataIdFromObject`
|
|
104
|
-
*/
|
|
105
|
-
await upgradeApolloCachePlugins(project, context);
|
|
106
|
-
|
|
107
|
-
// Changes "/static-*" to "/static/*", in delivery.ts Pulumi file.
|
|
108
|
-
// Not using TS Morph, but a simple replace-in-path approach.
|
|
109
|
-
upgradeDeliveryPath({ context });
|
|
110
|
-
|
|
111
|
-
info("Writing changes...");
|
|
112
|
-
await project.save();
|
|
113
|
-
|
|
114
|
-
await prettierFormat(files, context);
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Install new packages.
|
|
118
|
-
*/
|
|
119
|
-
await yarnInstall({
|
|
120
|
-
context
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
};
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
const { Node } = require("ts-morph");
|
|
2
|
-
const importPath = "@webiny/api-file-manager-ddb-es";
|
|
3
|
-
const importedVariableName = "fileManagerDynamoDbElasticPlugins";
|
|
4
|
-
|
|
5
|
-
const FM_FILES = { index: "api/code/graphql/src/index.ts" };
|
|
6
|
-
const CMS_FILES = { index: "api/code/headlessCMS/src/index.ts" };
|
|
7
|
-
const DDB2ES_FILES = { index: "api/code/dynamoToElastic/src/index.ts" };
|
|
8
|
-
|
|
9
|
-
const pluginElasticsearchClientImportPath = "@webiny/api-plugin-elastic-search-client";
|
|
10
|
-
|
|
11
|
-
const isFileManagerPlugins = node => {
|
|
12
|
-
return Node.isCallExpression(node) && node.getExpression().getText() === "fileManagerPlugins";
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const upgradeGraphQLIndex = async (project, context) => {
|
|
16
|
-
const { info } = context;
|
|
17
|
-
info(`Upgrading ${info.hl(FM_FILES.index)}`);
|
|
18
|
-
|
|
19
|
-
const source = project.getSourceFile(FM_FILES.index);
|
|
20
|
-
|
|
21
|
-
const fileManagerDynamoDbElasticPluginsImport = source.getImportDeclaration(importPath);
|
|
22
|
-
if (fileManagerDynamoDbElasticPluginsImport) {
|
|
23
|
-
info(`Import ${info.hl(importPath)} already exists in ${info.hl(FM_FILES.index)}.`);
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
const lastImport = source.getImportDeclarations().pop();
|
|
27
|
-
if (lastImport) {
|
|
28
|
-
source.insertImportDeclaration(lastImport.getChildIndex() + 1, {
|
|
29
|
-
defaultImport: importedVariableName,
|
|
30
|
-
moduleSpecifier: importPath
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Try fetching plugins from handler config object
|
|
35
|
-
const plugins = source.getFirstDescendant(
|
|
36
|
-
node => Node.isPropertyAssignment(node) && node.getName() === "plugins"
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Add new the DynamoDB/Elasticsearch plugins to the array of plugins.
|
|
41
|
-
*/
|
|
42
|
-
if (plugins) {
|
|
43
|
-
// New "createHandler" syntax
|
|
44
|
-
const fileManagerPlugins = plugins
|
|
45
|
-
.getInitializer()
|
|
46
|
-
.getElements()
|
|
47
|
-
.findIndex(isFileManagerPlugins);
|
|
48
|
-
|
|
49
|
-
if (fileManagerPlugins > -1) {
|
|
50
|
-
plugins
|
|
51
|
-
.getInitializer()
|
|
52
|
-
.insertElement(fileManagerPlugins + 1, `${importedVariableName}()`);
|
|
53
|
-
}
|
|
54
|
-
} else {
|
|
55
|
-
// Old "createHandler" syntax
|
|
56
|
-
const plugins = file.getFirstDescendant(
|
|
57
|
-
node =>
|
|
58
|
-
Node.isCallExpression(node) && node.getExpression().getText() === "createHandler"
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
const fileManagerPlugins = plugins.getArguments().findIndex(isFileManagerPlugins);
|
|
62
|
-
if (fileManagerPlugins > -1) {
|
|
63
|
-
plugins.insertArgument(fileManagerPlugins + 1, `${importedVariableName}()`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Find the position of the file manager plugins in the createHandler.plugins array.
|
|
69
|
-
*/
|
|
70
|
-
|
|
71
|
-
replaceElasticsearchImportDeclarationPath(source);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const upgradeHeadlessCMSIndex = async (project, context) => {
|
|
75
|
-
const { info } = context;
|
|
76
|
-
info(`Upgrading ${info.hl(CMS_FILES.index)}`);
|
|
77
|
-
|
|
78
|
-
const source = project.getSourceFile(CMS_FILES.index);
|
|
79
|
-
replaceElasticsearchImportDeclarationPath(source);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const upgradeDynamoDbToElasticIndex = async (project, context) => {
|
|
83
|
-
const { info } = context;
|
|
84
|
-
info(`Upgrading ${info.hl(DDB2ES_FILES.index)}`);
|
|
85
|
-
|
|
86
|
-
const source = project.getSourceFile(DDB2ES_FILES.index);
|
|
87
|
-
replaceElasticsearchImportDeclarationPath(source);
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const replaceElasticsearchImportDeclarationPath = source => {
|
|
91
|
-
/**
|
|
92
|
-
* Find the old package and replace it with the "api-elasticsearch".
|
|
93
|
-
*/
|
|
94
|
-
const elasticsearchImportDeclaration = source.getImportDeclaration(
|
|
95
|
-
pluginElasticsearchClientImportPath
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
if (elasticsearchImportDeclaration) {
|
|
99
|
-
elasticsearchImportDeclaration.setModuleSpecifier("@webiny/api-elasticsearch");
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
upgradeGraphQLIndex.files = FM_FILES;
|
|
104
|
-
upgradeHeadlessCMSIndex.files = CMS_FILES;
|
|
105
|
-
upgradeDynamoDbToElasticIndex.files = DDB2ES_FILES;
|
|
106
|
-
|
|
107
|
-
module.exports = {
|
|
108
|
-
upgradeGraphQLIndex,
|
|
109
|
-
upgradeHeadlessCMSIndex,
|
|
110
|
-
upgradeDynamoDbToElasticIndex
|
|
111
|
-
};
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
const { Node } = require("ts-morph");
|
|
2
|
-
|
|
3
|
-
const FILES = {
|
|
4
|
-
websitePbPlugins: "apps/website/code/src/plugins/pageBuilder.ts",
|
|
5
|
-
websiteApolloClient: "apps/website/code/src/components/apolloClient.ts"
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
const upgradeApolloCachePlugins = async (tsmProject, context) => {
|
|
9
|
-
const { info } = context;
|
|
10
|
-
|
|
11
|
-
info(`Updating ${info.hl(upgradeApolloCachePlugins.files.websitePbPlugins)}`);
|
|
12
|
-
|
|
13
|
-
// 1. Update Apollo Clients...
|
|
14
|
-
{
|
|
15
|
-
let source = tsmProject.getSourceFile(FILES.websiteApolloClient);
|
|
16
|
-
const dataIdFromObjectProperty = source.getFirstDescendant(node => {
|
|
17
|
-
if (Node.isPropertyAssignment(node) && node.getName() === "dataIdFromObject") {
|
|
18
|
-
return node;
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
dataIdFromObjectProperty.setInitializer(dataIdFromObjectValueInitializer);
|
|
23
|
-
|
|
24
|
-
const pluginsImport = source.getImportDeclaration("@webiny/plugins");
|
|
25
|
-
const index = source.getImportDeclarations().pop().getChildIndex() + 1;
|
|
26
|
-
if (!pluginsImport) {
|
|
27
|
-
source.insertImportDeclaration(index, {
|
|
28
|
-
defaultImport: "{ plugins }",
|
|
29
|
-
moduleSpecifier: "@webiny/plugins"
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const apolloCachePluginImport = source.getImportDeclaration(
|
|
34
|
-
"@webiny/app/plugins/ApolloCacheObjectIdPlugin"
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
if (!apolloCachePluginImport) {
|
|
38
|
-
source.insertImportDeclaration(index + 1, {
|
|
39
|
-
defaultImport: "{ ApolloCacheObjectIdPlugin }",
|
|
40
|
-
moduleSpecifier: "@webiny/app/plugins/ApolloCacheObjectIdPlugin"
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Remove old `if` statement
|
|
45
|
-
const ifStatement = source.getFirstDescendant(
|
|
46
|
-
node => Node.isIfStatement(node) && node.getFullText().includes("REACT_APP_ENV")
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
if (ifStatement) {
|
|
50
|
-
ifStatement.remove();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Remove `isProduction` variable
|
|
54
|
-
const isProduction = source.getFirstDescendant(
|
|
55
|
-
node => Node.isVariableDeclaration(node) && node.getName() === "isProduction"
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
if (isProduction) {
|
|
59
|
-
isProduction.remove();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// 2. Update "apps/website/code/src/plugins/pageBuilder.ts"...
|
|
64
|
-
{
|
|
65
|
-
let source = tsmProject.getSourceFile(FILES.websitePbPlugins);
|
|
66
|
-
|
|
67
|
-
const apolloCachePluginImport = source.getImportDeclaration(
|
|
68
|
-
"@webiny/app-page-builder/render/plugins/apolloCacheObjectId"
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
if (!apolloCachePluginImport) {
|
|
72
|
-
const index = source.getImportDeclarations().pop().getChildIndex() + 1;
|
|
73
|
-
|
|
74
|
-
source.insertImportDeclaration(index, {
|
|
75
|
-
defaultImport: "apolloCacheObjectId",
|
|
76
|
-
moduleSpecifier: "@webiny/app-page-builder/render/plugins/apolloCacheObjectId"
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const defaultExport = source.getFirstDescendant(node => Node.isExportAssignment(node));
|
|
80
|
-
const exportedArray = defaultExport.getFirstDescendant(node =>
|
|
81
|
-
Node.isArrayLiteralExpression(node)
|
|
82
|
-
);
|
|
83
|
-
exportedArray.addElement("apolloCacheObjectId");
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
upgradeApolloCachePlugins.files = FILES;
|
|
89
|
-
|
|
90
|
-
module.exports = {
|
|
91
|
-
upgradeApolloCachePlugins
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const dataIdFromObjectValueInitializer = `obj => {
|
|
95
|
-
/**
|
|
96
|
-
* Since every data type coming from API can have a different data structure,
|
|
97
|
-
* we cannot rely on having an \`id\` field.
|
|
98
|
-
*/
|
|
99
|
-
const getters = plugins.byType<ApolloCacheObjectIdPlugin>(
|
|
100
|
-
ApolloCacheObjectIdPlugin.type
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
for (let i = 0; i < getters.length; i++) {
|
|
104
|
-
const id = getters[i].getObjectId(obj);
|
|
105
|
-
if (typeof id !== "undefined") {
|
|
106
|
-
return id;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* As a fallback, try getting object's \`id\`.
|
|
112
|
-
*/
|
|
113
|
-
return obj.id || null;
|
|
114
|
-
}`;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
const { replaceInPath } = require("replace-in-path");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
|
|
4
|
-
const upgradeDeliveryPath = ({ context }) => {
|
|
5
|
-
const { info } = context;
|
|
6
|
-
info(`Updating ${info.hl("delivery")} CloudFront distribution's cache behaviours...`);
|
|
7
|
-
|
|
8
|
-
const replacement = {
|
|
9
|
-
find: `pathPattern: "\\/static-\\*"`,
|
|
10
|
-
replaceWith: `pathPattern: "/static/*"`
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
replaceInPath(path.join(context.project.root, "apps", "site", "**/*.ts"), replacement);
|
|
14
|
-
replaceInPath(path.join(context.project.root, "apps", "website", "**/*.ts"), replacement);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
module.exports = {
|
|
18
|
-
upgradeDeliveryPath
|
|
19
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const { Node, SyntaxKind } = require("ts-morph");
|
|
2
|
-
|
|
3
|
-
module.exports.upgradeLambdaConfig = (project, context) => {
|
|
4
|
-
context.info("Updating Lambda runtime and layers...");
|
|
5
|
-
|
|
6
|
-
const sourceFiles = project.getSourceFiles("api/pulumi/**/*.ts");
|
|
7
|
-
for (const file of sourceFiles) {
|
|
8
|
-
file.getDescendantsOfKind(SyntaxKind.PropertyAccessExpression)
|
|
9
|
-
.filter(node => node.getText() === "aws.lambda.Function")
|
|
10
|
-
.forEach(lambda => {
|
|
11
|
-
lambda.getParent().forEachDescendant(node => {
|
|
12
|
-
// Update runtime
|
|
13
|
-
if (Node.isPropertyAssignment(node) && node.getName() === "runtime") {
|
|
14
|
-
const string = node.getInitializer();
|
|
15
|
-
if (string.getLiteralValue() === "nodejs10.x") {
|
|
16
|
-
string.setLiteralValue("nodejs12.x");
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Update layer
|
|
21
|
-
if (
|
|
22
|
-
Node.isStringLiteral(node) &&
|
|
23
|
-
node.getLiteralValue() === "webiny-v4-sharp"
|
|
24
|
-
) {
|
|
25
|
-
node.setLiteralValue("sharp");
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
};
|