@webiny/cli 6.0.0-alpha.5 → 6.0.0-rc.0
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/README.md +10 -6
- package/bin.js +9 -97
- package/files/duplicates.json +1 -1
- package/files/references.json +1 -1
- package/index.js +2 -4
- package/package.json +16 -56
- package/commands/about/getDatabaseSetup.js +0 -45
- package/commands/about/getNpmVersion.js +0 -5
- package/commands/about/getNpxVersion.js +0 -5
- package/commands/about/getPulumiVersions.js +0 -43
- package/commands/about/getYarnVersion.js +0 -5
- package/commands/about/index.js +0 -97
- package/commands/index.js +0 -21
- package/commands/run/index.js +0 -38
- package/commands/telemetry/index.js +0 -31
- package/commands/upgrade/index.js +0 -108
- package/commands/wcp/hooks.js +0 -133
- package/commands/wcp/index.js +0 -8
- package/commands/wcp/login.js +0 -228
- package/commands/wcp/logout.js +0 -28
- package/commands/wcp/project.js +0 -203
- package/commands/wcp/utils/getProjectEnvironment.js +0 -120
- package/commands/wcp/utils/getUser.js +0 -100
- package/commands/wcp/utils/getWcpOrgProjectId.js +0 -9
- package/commands/wcp/utils/getWcpPat.js +0 -5
- package/commands/wcp/utils/getWcpProjectId.js +0 -3
- package/commands/wcp/utils/index.js +0 -19
- package/commands/wcp/utils/setProjectId.js +0 -44
- package/commands/wcp/utils/setWcpPat.js +0 -5
- package/commands/wcp/utils/updateUserLastActiveOn.js +0 -28
- package/commands/wcp/whoami.js +0 -43
- package/context.js +0 -137
- package/files/README.md +0 -1
- package/index.d.ts +0 -5
- package/regions.d.ts +0 -6
- package/regions.js +0 -30
- package/types.d.ts +0 -234
- package/utils/PluginsContainer.js +0 -49
- package/utils/createProjectApplicationWorkspace.js +0 -16
- package/utils/getProject.js +0 -48
- package/utils/getProjectApplication.js +0 -83
- package/utils/importModule.js +0 -43
- package/utils/index.d.ts +0 -28
- package/utils/index.js +0 -28
- package/utils/loadEnvVariables.js +0 -63
- package/utils/localStorage.js +0 -44
- package/utils/log.js +0 -67
- package/utils/sendEvent.js +0 -11
- package/utils/sleep.js +0 -3
- package/utils/sleepSync.js +0 -8
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,70 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/cli",
|
|
3
|
-
"version": "6.0.0-
|
|
3
|
+
"version": "6.0.0-rc.0",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"main": "index.js",
|
|
5
|
-
"bin": {
|
|
6
|
-
"webiny": "./bin.js"
|
|
7
|
-
},
|
|
8
6
|
"repository": {
|
|
9
7
|
"type": "git",
|
|
10
|
-
"url": "https://github.com/webiny/webiny-js.git"
|
|
11
|
-
|
|
8
|
+
"url": "https://github.com/webiny/webiny-js.git"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"webiny": "./bin.js"
|
|
12
12
|
},
|
|
13
|
-
"
|
|
14
|
-
"
|
|
13
|
+
"description": "A command line interface (CLI) for managing Webiny projects.",
|
|
14
|
+
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@webiny/
|
|
17
|
-
"@webiny/
|
|
18
|
-
"@webiny/wcp": "6.0.0-alpha.5",
|
|
19
|
-
"boolean": "3.2.0",
|
|
20
|
-
"camelcase": "6.3.0",
|
|
21
|
-
"chalk": "4.1.2",
|
|
22
|
-
"ci-info": "4.2.0",
|
|
23
|
-
"dotenv": "8.6.0",
|
|
16
|
+
"@webiny/cli-core": "6.0.0-rc.0",
|
|
17
|
+
"@webiny/system-requirements": "6.0.0-rc.0",
|
|
24
18
|
"execa": "5.1.1",
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"ncp": "2.0.0",
|
|
31
|
-
"open": "8.4.2",
|
|
32
|
-
"pirates": "4.0.6",
|
|
33
|
-
"semver": "7.6.3",
|
|
34
|
-
"ts-morph": "11.0.3",
|
|
35
|
-
"typescript": "5.3.3",
|
|
36
|
-
"uniqid": "5.4.0",
|
|
37
|
-
"yargs": "17.7.2"
|
|
19
|
+
"tsx": "4.21.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/lodash": "4.17.23",
|
|
23
|
+
"@webiny/build-tools": "6.0.0-rc.0"
|
|
38
24
|
},
|
|
39
|
-
"license": "MIT",
|
|
40
25
|
"publishConfig": {
|
|
41
26
|
"access": "public",
|
|
42
27
|
"directory": "."
|
|
43
28
|
},
|
|
44
|
-
"
|
|
45
|
-
"ignoreDirs": [
|
|
46
|
-
"/create/template/",
|
|
47
|
-
"/node_modules/",
|
|
48
|
-
"/dist/"
|
|
49
|
-
],
|
|
50
|
-
"ignore": {
|
|
51
|
-
"src": [
|
|
52
|
-
"@webiny/project-utils",
|
|
53
|
-
"@webiny/api-file-manager",
|
|
54
|
-
"@webiny/cli-plugin-deploy-pulumi",
|
|
55
|
-
"@webiny/api",
|
|
56
|
-
"@webiny/handler-client",
|
|
57
|
-
"@webiny/api-elasticsearch",
|
|
58
|
-
"@webiny/api-tenancy",
|
|
59
|
-
"@webiny/api-security",
|
|
60
|
-
"@webiny/api-i18n",
|
|
61
|
-
"@webiny/api-i18n-content",
|
|
62
|
-
"@webiny/api-page-builder",
|
|
63
|
-
"@webiny/api-prerendering-service",
|
|
64
|
-
"@webiny/api-form-builder",
|
|
65
|
-
"@webiny/api-headless-cms"
|
|
66
|
-
]
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
"gitHead": "b7e120541b093e91f214904a9f13e4c2c4640978"
|
|
29
|
+
"gitHead": "0f2aa699f4642e550ab62c96fcd050e8d02345c9"
|
|
70
30
|
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
const { getProject } = require("@webiny/cli/utils");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
|
|
5
|
-
const DATABASE_SETUPS = {
|
|
6
|
-
DDB: "ddb",
|
|
7
|
-
DDB_ES: "ddb-es",
|
|
8
|
-
DDB_OS: "ddb-os"
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const DATABASE_SETUPS_LABELS = {
|
|
12
|
-
[DATABASE_SETUPS.DDB]: "Amazon DynamoDB",
|
|
13
|
-
[DATABASE_SETUPS.DDB_ES]: "Amazon DynamoDB + Amazon Elasticsearch Service",
|
|
14
|
-
[DATABASE_SETUPS.DDB_OS]: "Amazon DynamoDB + Amazon OpenSearch Service"
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// In order to get the database setup, we check for existence of `elasticSearch`
|
|
18
|
-
// or `openSearch` strings within the `apps/core/webiny.application.ts` file.
|
|
19
|
-
const getDatabaseSetup = () => {
|
|
20
|
-
const project = getProject();
|
|
21
|
-
const webinyAppTsPath = path.join(project.root, "apps", "core", "webiny.application.ts");
|
|
22
|
-
|
|
23
|
-
const webinyAppTs = fs.readFileSync(webinyAppTsPath, "utf8");
|
|
24
|
-
if (webinyAppTs.includes("elasticSearch")) {
|
|
25
|
-
return "ddb-es";
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (webinyAppTs.includes("openSearch")) {
|
|
29
|
-
return "ddb-os";
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return "ddb";
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const getDatabaseSetupLabel = () => {
|
|
36
|
-
const setup = getDatabaseSetup();
|
|
37
|
-
return DATABASE_SETUPS_LABELS[setup];
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
module.exports = {
|
|
41
|
-
getDatabaseSetup,
|
|
42
|
-
getDatabaseSetupLabel,
|
|
43
|
-
DATABASE_SETUPS,
|
|
44
|
-
DATABASE_SETUPS_LABELS
|
|
45
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
const execa = require("execa");
|
|
2
|
-
|
|
3
|
-
module.exports.getPulumiVersions = async () => {
|
|
4
|
-
let pulumi, pulumiAws;
|
|
5
|
-
|
|
6
|
-
try {
|
|
7
|
-
{
|
|
8
|
-
const { stdout } = await execa("yarn", [
|
|
9
|
-
"info",
|
|
10
|
-
"@pulumi/pulumi",
|
|
11
|
-
"-A",
|
|
12
|
-
"-R",
|
|
13
|
-
"--name-only",
|
|
14
|
-
"--json"
|
|
15
|
-
]);
|
|
16
|
-
|
|
17
|
-
const match = stdout.match(/npm:(.*?)"/);
|
|
18
|
-
if (match) {
|
|
19
|
-
pulumi = match[1];
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
{
|
|
24
|
-
const { stdout } = await execa("yarn", [
|
|
25
|
-
"info",
|
|
26
|
-
"@pulumi/aws",
|
|
27
|
-
"-A",
|
|
28
|
-
"-R",
|
|
29
|
-
"--name-only",
|
|
30
|
-
"--json"
|
|
31
|
-
]);
|
|
32
|
-
|
|
33
|
-
const match = stdout.match(/npm:(.*?)"/);
|
|
34
|
-
if (match) {
|
|
35
|
-
pulumiAws = match[1];
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
} catch (err) {
|
|
39
|
-
return "";
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return [pulumi, pulumiAws];
|
|
43
|
-
};
|
package/commands/about/index.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
const NO_VALUE = "-";
|
|
2
|
-
const { isCI } = require("ci-info");
|
|
3
|
-
|
|
4
|
-
const getData = async context => {
|
|
5
|
-
const { getUser } = require("../wcp/utils");
|
|
6
|
-
const { getNpxVersion } = require("./getNpxVersion");
|
|
7
|
-
const { getNpmVersion } = require("./getNpmVersion");
|
|
8
|
-
const { getPulumiVersions } = require("./getPulumiVersions");
|
|
9
|
-
const { getYarnVersion } = require("./getYarnVersion");
|
|
10
|
-
const { getDatabaseSetupLabel } = require("./getDatabaseSetup");
|
|
11
|
-
|
|
12
|
-
const [pulumiVersion, pulumiAwsVersion] = await getPulumiVersions();
|
|
13
|
-
|
|
14
|
-
const wcpProjectId = process.env.WCP_PROJECT_ID;
|
|
15
|
-
const wcpUser = await getUser().catch(() => null);
|
|
16
|
-
const wcpUsingProjectEnvironmentApiKey = Boolean(process.env.WCP_ENVIRONMENT_API_KEY);
|
|
17
|
-
|
|
18
|
-
return [
|
|
19
|
-
{
|
|
20
|
-
sectionName: "Webiny Project",
|
|
21
|
-
data: {
|
|
22
|
-
Name: context.project.name,
|
|
23
|
-
Version: context.version,
|
|
24
|
-
"Database Setup": getDatabaseSetupLabel(),
|
|
25
|
-
"Debug Enabled": process.env.DEBUG === "true" ? "Yes" : "No",
|
|
26
|
-
"Feature Flags": process.env.WEBINY_FEATURE_FLAGS || "N/A"
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
sectionName: "Webiny Control Panel (WCP)",
|
|
31
|
-
data: {
|
|
32
|
-
"Project ID": wcpProjectId,
|
|
33
|
-
User: wcpUser?.email || "N/A",
|
|
34
|
-
"Using Project Environment API Key": wcpUsingProjectEnvironmentApiKey ? "Yes" : "No"
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
sectionName: "Host",
|
|
39
|
-
data: {
|
|
40
|
-
OS: `${process.platform} (${process.arch})`,
|
|
41
|
-
"Node.js": process.version,
|
|
42
|
-
NPM: await getNpmVersion(),
|
|
43
|
-
NPX: await getNpxVersion(),
|
|
44
|
-
Yarn: await getYarnVersion(),
|
|
45
|
-
"Is CI": isCI ? "Yes" : "No"
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
sectionName: "Pulumi",
|
|
50
|
-
data: {
|
|
51
|
-
"@pulumi/pulumi": pulumiVersion,
|
|
52
|
-
"@pulumi/aws": pulumiAwsVersion,
|
|
53
|
-
"Secrets Provider": process.env.PULUMI_SECRETS_PROVIDER,
|
|
54
|
-
"Using Password": process.env.PULUMI_CONFIG_PASSPHRASE ? "Yes" : "No"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
];
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
module.exports = {
|
|
61
|
-
type: "cli-command",
|
|
62
|
-
name: "cli-command-about",
|
|
63
|
-
create({ yargs, context }) {
|
|
64
|
-
yargs.command(
|
|
65
|
-
"about",
|
|
66
|
-
`Prints out information helpful for debugging purposes.`,
|
|
67
|
-
yargs => {
|
|
68
|
-
yargs.option("json", {
|
|
69
|
-
describe: "Emit output as JSON.",
|
|
70
|
-
type: "boolean",
|
|
71
|
-
default: false
|
|
72
|
-
});
|
|
73
|
-
},
|
|
74
|
-
async yargs => {
|
|
75
|
-
const data = await getData(context);
|
|
76
|
-
|
|
77
|
-
if (yargs.json) {
|
|
78
|
-
console.log(JSON.stringify(data, null, 2));
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
data.forEach(({ sectionName, data }, index) => {
|
|
83
|
-
if (index > 0) {
|
|
84
|
-
console.log();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const { bold } = require("chalk");
|
|
88
|
-
console.log(bold(sectionName));
|
|
89
|
-
|
|
90
|
-
Object.keys(data).forEach(key => {
|
|
91
|
-
console.log(key.padEnd(36), data[key] || NO_VALUE);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
};
|
package/commands/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const about = require("./about");
|
|
2
|
-
const run = require("./run");
|
|
3
|
-
const telemetry = require("./telemetry");
|
|
4
|
-
const upgrade = require("./upgrade");
|
|
5
|
-
|
|
6
|
-
module.exports.createCommands = async (yargs, context) => {
|
|
7
|
-
context.plugins.register(about, run, telemetry, upgrade);
|
|
8
|
-
|
|
9
|
-
try {
|
|
10
|
-
const wcp = require("./wcp");
|
|
11
|
-
context.plugins.register(wcp);
|
|
12
|
-
} catch {
|
|
13
|
-
// Skip WCP command
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
await context.loadUserPlugins();
|
|
17
|
-
|
|
18
|
-
context.plugins.byType("cli-command").forEach(plugin => {
|
|
19
|
-
plugin.create({ yargs, context });
|
|
20
|
-
});
|
|
21
|
-
};
|
package/commands/run/index.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
type: "cli-command",
|
|
3
|
-
name: "cli-command-run",
|
|
4
|
-
create({ yargs, context }) {
|
|
5
|
-
yargs.command(
|
|
6
|
-
"run <command> [options]",
|
|
7
|
-
`Run command defined in webiny.config.{js,ts}.\nNote: run from folder containing webiny.config.{js,ts} file.`,
|
|
8
|
-
yargs => {
|
|
9
|
-
yargs.positional("command", {
|
|
10
|
-
describe: `Command to run in webiny.config.{js,ts}`,
|
|
11
|
-
type: "string"
|
|
12
|
-
});
|
|
13
|
-
},
|
|
14
|
-
async argv => {
|
|
15
|
-
const camelCase = require("camelcase");
|
|
16
|
-
const findUp = require("find-up");
|
|
17
|
-
const path = require("path");
|
|
18
|
-
|
|
19
|
-
const configFile = findUp.sync(["webiny.config.ts", "webiny.config.js"]);
|
|
20
|
-
let config = context.import(configFile);
|
|
21
|
-
|
|
22
|
-
const command = camelCase(argv.command);
|
|
23
|
-
if (typeof config === "function") {
|
|
24
|
-
config = config({
|
|
25
|
-
options: { ...argv, cwd: path.dirname(configFile) },
|
|
26
|
-
context
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (config.commands && typeof config.commands[command] === "function") {
|
|
31
|
-
return await config.commands[command]({ ...argv }, context);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
throw Error(`Command "${command}" is not defined in "${configFile}"!`);
|
|
35
|
-
}
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
type: "cli-command",
|
|
3
|
-
name: "cli-command-telemetry",
|
|
4
|
-
create({ yargs, context }) {
|
|
5
|
-
yargs.command("enable-telemetry", "Enable anonymous telemetry.", async () => {
|
|
6
|
-
const telemetry = require("@webiny/telemetry/cli");
|
|
7
|
-
|
|
8
|
-
telemetry.enable();
|
|
9
|
-
await telemetry.sendEvent({ event: "enable-telemetry" });
|
|
10
|
-
context.info(
|
|
11
|
-
`Webiny telemetry is now %s! Thank you for helping us in making Webiny better!`,
|
|
12
|
-
"enabled"
|
|
13
|
-
);
|
|
14
|
-
context.info(
|
|
15
|
-
`For more information, please visit the following link: https://www.webiny.com/telemetry.`
|
|
16
|
-
);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
yargs.command("disable-telemetry", "Disable anonymous telemetry.", async () => {
|
|
20
|
-
const telemetry = require("@webiny/telemetry/cli");
|
|
21
|
-
|
|
22
|
-
await telemetry.sendEvent({ event: "disable-telemetry" });
|
|
23
|
-
telemetry.disable();
|
|
24
|
-
context.info(`Webiny telemetry is now %s!`, "disabled");
|
|
25
|
-
context.info(
|
|
26
|
-
`Note that, in order to complete the process, you will also need to re-deploy your project, using the %s command.`,
|
|
27
|
-
"yarn webiny deploy"
|
|
28
|
-
);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
};
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
module.exports = [
|
|
2
|
-
{
|
|
3
|
-
type: "cli-command",
|
|
4
|
-
name: "cli-command-upgrade",
|
|
5
|
-
create({ yargs, context }) {
|
|
6
|
-
yargs.example("$0 upgrade");
|
|
7
|
-
yargs.command(
|
|
8
|
-
"upgrade",
|
|
9
|
-
`Run an upgrade script for currently installed version of Webiny`,
|
|
10
|
-
yargs => {
|
|
11
|
-
yargs.option("skip-checks", {
|
|
12
|
-
describe: "Do not perform CLI version and Git tree checks.",
|
|
13
|
-
type: "boolean",
|
|
14
|
-
default: false
|
|
15
|
-
});
|
|
16
|
-
yargs.option("debug", {
|
|
17
|
-
default: false,
|
|
18
|
-
describe: `Turn on debug logs`,
|
|
19
|
-
type: "boolean"
|
|
20
|
-
});
|
|
21
|
-
yargs.option("use-version", {
|
|
22
|
-
describe:
|
|
23
|
-
"Use upgrade script for a specific version. Should only be used for development/testing purposes.",
|
|
24
|
-
type: "string"
|
|
25
|
-
});
|
|
26
|
-
},
|
|
27
|
-
async argv => {
|
|
28
|
-
const { red } = require("chalk");
|
|
29
|
-
const execa = require("execa");
|
|
30
|
-
const semver = require("semver");
|
|
31
|
-
|
|
32
|
-
if (!argv.skipChecks) {
|
|
33
|
-
// Before doing any upgrading, there must not be any active changes in the current branch.
|
|
34
|
-
let gitStatus = "";
|
|
35
|
-
try {
|
|
36
|
-
let { stdout } = execa.sync("git", ["status", "--porcelain"]);
|
|
37
|
-
gitStatus = stdout.trim();
|
|
38
|
-
} catch {}
|
|
39
|
-
|
|
40
|
-
if (gitStatus) {
|
|
41
|
-
console.error(
|
|
42
|
-
red(
|
|
43
|
-
"This git repository has untracked files or uncommitted changes:"
|
|
44
|
-
) +
|
|
45
|
-
"\n\n" +
|
|
46
|
-
gitStatus
|
|
47
|
-
.split("\n")
|
|
48
|
-
.map(line => line.match(/ .*/g)[0].trim())
|
|
49
|
-
.join("\n") +
|
|
50
|
-
"\n\n" +
|
|
51
|
-
red(
|
|
52
|
-
"Remove untracked files, stash or commit any changes, and try again."
|
|
53
|
-
)
|
|
54
|
-
);
|
|
55
|
-
process.exit(1);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
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
|
-
stdin: process.stdin
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
npx.stdout.on("data", data => {
|
|
78
|
-
const lines = data.toString().replace(/\n$/, "").split("\n");
|
|
79
|
-
for (let i = 0; i < lines.length; i++) {
|
|
80
|
-
const line = lines[i];
|
|
81
|
-
try {
|
|
82
|
-
const json = JSON.parse(line);
|
|
83
|
-
if (json.type === "error") {
|
|
84
|
-
context.error(
|
|
85
|
-
"An error occurred while performing the upgrade."
|
|
86
|
-
);
|
|
87
|
-
console.log(json.message);
|
|
88
|
-
if (yargs.argv.debug) {
|
|
89
|
-
context.debug(json.data.stack);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
} catch {
|
|
93
|
-
// Not JSON, let's just print the line then.
|
|
94
|
-
console.log(line);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
npx.stderr.on("data", data => {
|
|
100
|
-
console.log(data.toString());
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
await npx;
|
|
104
|
-
}
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
];
|
package/commands/wcp/hooks.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
const { encrypt, decrypt } = require("@webiny/wcp");
|
|
2
|
-
const { getUser, getProjectEnvironment, updateUserLastActiveOn } = require("./utils");
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The two environment variables we set via these hooks are the following:
|
|
6
|
-
* - WCP_PROJECT_ENVIRONMENT - contains encrypted data about the deployed project environment
|
|
7
|
-
* - WCP_PROJECT_ENVIRONMENT_API_KEY - for easier access, we also set the API key
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* There are multiple ways the hooks below prepare the WCP-enabled project for deployment.
|
|
12
|
-
* 1. If `WCP_PROJECT_ENVIRONMENT` metadata env var is defined, we decrypt it, retrieve the
|
|
13
|
-
* API key from it, and assign it as the `WCP_PROJECT_ENVIRONMENT_API_KEY` env var.
|
|
14
|
-
* 2. If `WCP_PROJECT_ENVIRONMENT_API_KEY` env var is defined, then we use that as the
|
|
15
|
-
* project environment API key. We use that to load the project environment data
|
|
16
|
-
* and to also assign the `WCP_PROJECT_ENVIRONMENT` metadata env var.
|
|
17
|
-
* 3. If none of the above is defined, we retrieve (or create) the project environment,
|
|
18
|
-
* retrieve its API key and again assign it as `WCP_PROJECT_ENVIRONMENT_API_KEY` env var.
|
|
19
|
-
* As in 2), we also assign the `WCP_PROJECT_ENVIRONMENT` metadata env var.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
let projectEnvironment;
|
|
23
|
-
|
|
24
|
-
const getEnvironmentHookHandler = async (args, context) => {
|
|
25
|
-
// If the project isn't linked with WCP, do nothing.
|
|
26
|
-
const wcpProjectId = context.project.config.id || process.env.WCP_PROJECT_ID;
|
|
27
|
-
if (!wcpProjectId) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// For development purposes, we allow setting the WCP_PROJECT_ENVIRONMENT env var directly.
|
|
32
|
-
if (process.env.WCP_PROJECT_ENVIRONMENT) {
|
|
33
|
-
// If we have WCP_PROJECT_ENVIRONMENT env var, we set the WCP_PROJECT_ENVIRONMENT_API_KEY too.
|
|
34
|
-
const decryptedProjectEnvironment = decrypt(process.env.WCP_PROJECT_ENVIRONMENT);
|
|
35
|
-
process.env.WCP_PROJECT_ENVIRONMENT_API_KEY = decryptedProjectEnvironment.apiKey;
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// The `id` has the orgId/projectId structure, for example `my-org-x/my-project-y`.
|
|
40
|
-
const [orgId, projectId] = wcpProjectId.split("/");
|
|
41
|
-
|
|
42
|
-
const apiKey = process.env.WCP_PROJECT_ENVIRONMENT_API_KEY;
|
|
43
|
-
|
|
44
|
-
let projectEnvironment;
|
|
45
|
-
if (apiKey) {
|
|
46
|
-
projectEnvironment = await getProjectEnvironment({ apiKey });
|
|
47
|
-
} else {
|
|
48
|
-
const isValidId = orgId && projectId;
|
|
49
|
-
if (!isValidId) {
|
|
50
|
-
throw new Error(
|
|
51
|
-
`It seems the project ID, specified in "webiny.project.ts" file, is invalid.`
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// If there is no API key, that means we need to retrieve the currently logged-in user.
|
|
56
|
-
const user = await getUser();
|
|
57
|
-
const project = user.projects.find(item => item.id === projectId);
|
|
58
|
-
if (!project) {
|
|
59
|
-
throw new Error(
|
|
60
|
-
`It seems you don't belong to the current project or the current project has been deleted.`
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
projectEnvironment = await getProjectEnvironment({
|
|
65
|
-
orgId,
|
|
66
|
-
projectId,
|
|
67
|
-
userId: user.id,
|
|
68
|
-
environmentId: args.env
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (projectEnvironment.org.id !== orgId) {
|
|
73
|
-
throw new Error(
|
|
74
|
-
`Cannot proceed with the deployment because the "${projectEnvironment.name}" project environment doesn't belong to the "${orgId}" organization. Please check your WCP project ID (currently set to "${wcpProjectId}").`
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (projectEnvironment.project.id !== projectId) {
|
|
79
|
-
throw new Error(
|
|
80
|
-
`Cannot proceed with the deployment because the "${projectEnvironment.name}" project environment doesn't belong to the "${wcpProjectId}" project. Please check your WCP project ID (currently set to "${wcpProjectId}").`
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (projectEnvironment && projectEnvironment.status !== "enabled") {
|
|
85
|
-
throw new Error(
|
|
86
|
-
`Cannot proceed with the deployment because the "${projectEnvironment.name}" project environment has been disabled.`
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Assign `WCP_PROJECT_ENVIRONMENT` and `WCP_PROJECT_ENVIRONMENT_API_KEY`
|
|
91
|
-
const wcpProjectEnvironment = {
|
|
92
|
-
id: projectEnvironment.id,
|
|
93
|
-
apiKey: projectEnvironment.apiKey,
|
|
94
|
-
org: { id: projectEnvironment.org.id },
|
|
95
|
-
project: { id: projectEnvironment.project.id }
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
process.env.WCP_PROJECT_ENVIRONMENT = encrypt(wcpProjectEnvironment);
|
|
99
|
-
process.env.WCP_PROJECT_ENVIRONMENT_API_KEY = projectEnvironment.apiKey;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const updateLastActiveOnHookHandler = async () => {
|
|
103
|
-
if (!projectEnvironment) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Is this a user environment? If so, let's update his "last active" field.
|
|
108
|
-
if (projectEnvironment.user) {
|
|
109
|
-
await updateUserLastActiveOn();
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
// Export hooks plugins for deploy and watch commands.
|
|
114
|
-
module.exports = () => [
|
|
115
|
-
// Deploy hook handlers.
|
|
116
|
-
{
|
|
117
|
-
type: "hook-before-deploy",
|
|
118
|
-
name: "hook-before-deploy-environment-get-environment",
|
|
119
|
-
hook: getEnvironmentHookHandler
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
type: "hook-before-deploy",
|
|
123
|
-
name: "hook-before-deploy-update-last-active-on",
|
|
124
|
-
hook: updateLastActiveOnHookHandler
|
|
125
|
-
},
|
|
126
|
-
|
|
127
|
-
// Watch hook handlers.
|
|
128
|
-
{
|
|
129
|
-
type: "hook-before-watch",
|
|
130
|
-
name: "hook-before-watch-environment-get-environment",
|
|
131
|
-
hook: getEnvironmentHookHandler
|
|
132
|
-
}
|
|
133
|
-
];
|
package/commands/wcp/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
const { command: login } = require("./login");
|
|
2
|
-
const { command: logout } = require("./logout");
|
|
3
|
-
const { command: whoami } = require("./whoami");
|
|
4
|
-
const { command: project } = require("./project");
|
|
5
|
-
|
|
6
|
-
const hooks = require("./hooks");
|
|
7
|
-
|
|
8
|
-
module.exports = [login(), logout(), whoami(), project(), hooks()];
|