@webiny/cli 0.0.0-mt-2 → 0.0.0-unstable.5e7233243f
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 +625 -0
- package/README.md +1 -1
- package/bin.js +12 -10
- package/cli.js +1 -1
- package/commands/index.js +7 -0
- package/commands/run/index.js +9 -1
- package/commands/wcp/hooks.js +133 -0
- package/commands/wcp/index.js +8 -0
- package/commands/wcp/login.js +228 -0
- package/commands/wcp/logout.js +28 -0
- package/commands/wcp/project.js +202 -0
- package/commands/wcp/utils/getProjectEnvironment.js +120 -0
- package/commands/wcp/utils/getUser.js +100 -0
- package/commands/wcp/utils/getWcpPat.js +5 -0
- package/commands/wcp/utils/index.js +17 -0
- package/commands/wcp/utils/setProjectId.js +44 -0
- package/commands/wcp/utils/setWcpPat.js +5 -0
- package/commands/wcp/utils/sleep.js +1 -0
- package/commands/wcp/utils/updateUserLastActiveOn.js +28 -0
- package/commands/wcp/whoami.js +43 -0
- package/context.js +2 -2
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/package.json +16 -11
- package/types.d.ts +5 -41
- package/utils/createProjectApplicationWorkspace.js +16 -0
- package/utils/getApiProjectApplicationFolder.js +12 -0
- package/utils/getProjectApplication.js +31 -7
- package/utils/index.d.ts +1 -0
- package/utils/index.js +10 -1
- package/utils/log.js +15 -17
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
const { localStorage, log } = require("@webiny/cli/utils");
|
|
2
|
+
const { request } = require("graphql-request");
|
|
3
|
+
const { getWcpGqlApiUrl } = require("@webiny/wcp");
|
|
4
|
+
|
|
5
|
+
const ENVIRONMENT_FIELDS = /* GraphQL */ `
|
|
6
|
+
fragment EnvironmentFields on Environment {
|
|
7
|
+
id
|
|
8
|
+
status
|
|
9
|
+
name
|
|
10
|
+
apiKey
|
|
11
|
+
org {
|
|
12
|
+
id
|
|
13
|
+
name
|
|
14
|
+
}
|
|
15
|
+
project {
|
|
16
|
+
id
|
|
17
|
+
name
|
|
18
|
+
}
|
|
19
|
+
user {
|
|
20
|
+
id
|
|
21
|
+
email
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
const CREATE_ENVIRONMENT = /* GraphQL */ `
|
|
27
|
+
${ENVIRONMENT_FIELDS}
|
|
28
|
+
mutation CreateEnvironment(
|
|
29
|
+
$orgId: ID!
|
|
30
|
+
$projectId: ID!
|
|
31
|
+
$userId: ID
|
|
32
|
+
$data: CreateEnvironmentDataInput!
|
|
33
|
+
) {
|
|
34
|
+
projects {
|
|
35
|
+
createEnvironment(orgId: $orgId, projectId: $projectId, userId: $userId, data: $data) {
|
|
36
|
+
...EnvironmentFields
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
`;
|
|
41
|
+
|
|
42
|
+
const GET_ENVIRONMENT = /* GraphQL */ `
|
|
43
|
+
${ENVIRONMENT_FIELDS}
|
|
44
|
+
query GetEnvironment(
|
|
45
|
+
$environmentId: ID
|
|
46
|
+
$orgId: ID
|
|
47
|
+
$projectId: ID
|
|
48
|
+
$userId: ID
|
|
49
|
+
$apiKey: String
|
|
50
|
+
) {
|
|
51
|
+
projects {
|
|
52
|
+
getEnvironment(
|
|
53
|
+
environmentId: $environmentId
|
|
54
|
+
orgId: $orgId
|
|
55
|
+
projectId: $projectId
|
|
56
|
+
userId: $userId
|
|
57
|
+
apiKey: $apiKey
|
|
58
|
+
) {
|
|
59
|
+
...EnvironmentFields
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
module.exports.getProjectEnvironment = async ({
|
|
66
|
+
orgId,
|
|
67
|
+
projectId,
|
|
68
|
+
userId,
|
|
69
|
+
environmentId,
|
|
70
|
+
apiKey
|
|
71
|
+
}) => {
|
|
72
|
+
if (apiKey) {
|
|
73
|
+
return request(getWcpGqlApiUrl(), GET_ENVIRONMENT, { apiKey })
|
|
74
|
+
.then(response => response.projects.getEnvironment)
|
|
75
|
+
.catch(() => {
|
|
76
|
+
throw new Error(
|
|
77
|
+
`It seems the API key you provided is incorrect or disabled. Please double check the API key and try again.`
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const pat = localStorage().get("wcpPat");
|
|
83
|
+
if (!pat) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
`It seems you are not logged in. Please login using the ${log.error.hl(
|
|
86
|
+
"webiny login"
|
|
87
|
+
)} command.`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const headers = { authorization: pat };
|
|
92
|
+
return request(
|
|
93
|
+
getWcpGqlApiUrl(),
|
|
94
|
+
GET_ENVIRONMENT,
|
|
95
|
+
{
|
|
96
|
+
orgId,
|
|
97
|
+
projectId,
|
|
98
|
+
userId,
|
|
99
|
+
environmentId,
|
|
100
|
+
apiKey
|
|
101
|
+
},
|
|
102
|
+
headers
|
|
103
|
+
)
|
|
104
|
+
.then(async response => response.projects.getEnvironment)
|
|
105
|
+
.catch(() => {
|
|
106
|
+
return request(
|
|
107
|
+
getWcpGqlApiUrl(),
|
|
108
|
+
CREATE_ENVIRONMENT,
|
|
109
|
+
{
|
|
110
|
+
orgId,
|
|
111
|
+
projectId,
|
|
112
|
+
userId,
|
|
113
|
+
data: {
|
|
114
|
+
name: environmentId
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
headers
|
|
118
|
+
).then(async response => response.projects.createEnvironment);
|
|
119
|
+
});
|
|
120
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
const { log } = require("@webiny/cli/utils");
|
|
2
|
+
const { request } = require("graphql-request");
|
|
3
|
+
const { getWcpPat } = require("./getWcpPat");
|
|
4
|
+
const { getWcpGqlApiUrl } = require("@webiny/wcp");
|
|
5
|
+
|
|
6
|
+
const GET_CURRENT_USER = /* GraphQL */ `
|
|
7
|
+
query GetUser {
|
|
8
|
+
users {
|
|
9
|
+
getCurrentUser {
|
|
10
|
+
id
|
|
11
|
+
email
|
|
12
|
+
firstName
|
|
13
|
+
lastName
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
const LIST_ORGS = /* GraphQL */ `
|
|
20
|
+
query ListOrgs {
|
|
21
|
+
orgs {
|
|
22
|
+
listOrgs {
|
|
23
|
+
data {
|
|
24
|
+
id
|
|
25
|
+
name
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
|
|
32
|
+
const LIST_PROJECTS = /* GraphQL */ `
|
|
33
|
+
query ListProjects($orgId: ID!) {
|
|
34
|
+
projects {
|
|
35
|
+
listProjects(orgId: $orgId) {
|
|
36
|
+
data {
|
|
37
|
+
id
|
|
38
|
+
name
|
|
39
|
+
org {
|
|
40
|
+
id
|
|
41
|
+
name
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
|
|
49
|
+
let user;
|
|
50
|
+
module.exports.getUser = async () => {
|
|
51
|
+
if (user) {
|
|
52
|
+
return user;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const pat = getWcpPat();
|
|
56
|
+
if (!pat) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
`It seems you are not logged into your WCP project. Please log in using the ${log.error.hl(
|
|
59
|
+
"yarn webiny login"
|
|
60
|
+
)} command. If you are not using WCP, make sure you don't have an "id" property in your "webiny.project.ts" file.`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
const headers = { authorization: pat };
|
|
66
|
+
user = await request(getWcpGqlApiUrl(), GET_CURRENT_USER, {}, headers).then(
|
|
67
|
+
async response => {
|
|
68
|
+
const user = response.users.getCurrentUser;
|
|
69
|
+
|
|
70
|
+
const orgs = await request(getWcpGqlApiUrl(), LIST_ORGS, {}, headers).then(
|
|
71
|
+
async response => {
|
|
72
|
+
const orgs = response.orgs.listOrgs.data;
|
|
73
|
+
for (let i = 0; i < orgs.length; i++) {
|
|
74
|
+
const org = orgs[i];
|
|
75
|
+
org.projects = await request(
|
|
76
|
+
getWcpGqlApiUrl(),
|
|
77
|
+
LIST_PROJECTS,
|
|
78
|
+
{ orgId: org.id },
|
|
79
|
+
headers
|
|
80
|
+
).then(response => response.projects.listProjects.data);
|
|
81
|
+
}
|
|
82
|
+
return orgs;
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const projects = orgs.map(org => org.projects).flat();
|
|
87
|
+
|
|
88
|
+
return { ...user, orgs, projects };
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
} catch {
|
|
92
|
+
throw new Error(
|
|
93
|
+
`It seems the personal access token is incorrect or does not exist. Please log out and log in again using the ${log.error.hl(
|
|
94
|
+
"yarn webiny login"
|
|
95
|
+
)} command.`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return user;
|
|
100
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const { getUser } = require("./getUser");
|
|
2
|
+
const { getProjectEnvironment } = require("./getProjectEnvironment");
|
|
3
|
+
const { updateUserLastActiveOn } = require("./updateUserLastActiveOn");
|
|
4
|
+
const { setProjectId } = require("./setProjectId");
|
|
5
|
+
const { setWcpPat } = require("./setWcpPat");
|
|
6
|
+
const { getWcpPat } = require("./getWcpPat");
|
|
7
|
+
const { sleep } = require("./sleep");
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
getUser,
|
|
11
|
+
getProjectEnvironment,
|
|
12
|
+
updateUserLastActiveOn,
|
|
13
|
+
setProjectId,
|
|
14
|
+
setWcpPat,
|
|
15
|
+
getWcpPat,
|
|
16
|
+
sleep
|
|
17
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const tsMorph = require("ts-morph");
|
|
3
|
+
const { log } = require("@webiny/cli/utils");
|
|
4
|
+
|
|
5
|
+
module.exports.setProjectId = async ({ project, orgId, projectId }) => {
|
|
6
|
+
// Assign the necessary IDs into root `webiny.project.ts` project file.
|
|
7
|
+
const webinyProjectPath = path.join(project.root, "webiny.project.ts");
|
|
8
|
+
|
|
9
|
+
const tsMorphProject = new tsMorph.Project();
|
|
10
|
+
tsMorphProject.addSourceFileAtPath(webinyProjectPath);
|
|
11
|
+
|
|
12
|
+
const source = tsMorphProject.getSourceFile(webinyProjectPath);
|
|
13
|
+
|
|
14
|
+
const defaultExport = source.getFirstDescendant(node => {
|
|
15
|
+
if (tsMorph.Node.isExportAssignment(node) === false) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return node.getText().startsWith("export default ");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
if (!defaultExport) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
`Could not find the default export in ${log.error.hl("webiny.project.ts")}.`
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Get ObjectLiteralExpression within the default export and assign the `id` property to it.
|
|
28
|
+
const exportedObjectLiteral = defaultExport.getFirstDescendant(
|
|
29
|
+
node => tsMorph.Node.isObjectLiteralExpression(node) === true
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const existingIdProperty = exportedObjectLiteral.getProperty(node => {
|
|
33
|
+
return tsMorph.Node.isPropertyAssignment(node) && node.getName() === "id";
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const fullId = `${orgId}/${projectId}`;
|
|
37
|
+
if (tsMorph.Node.isPropertyAssignment(existingIdProperty)) {
|
|
38
|
+
existingIdProperty.setInitializer(`"${fullId}"`);
|
|
39
|
+
} else {
|
|
40
|
+
exportedObjectLiteral.insertProperty(0, `id: "${fullId}"`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
await tsMorphProject.save();
|
|
44
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports.sleep = () => new Promise(resolve => setTimeout(resolve, 1500));
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const { request } = require("graphql-request");
|
|
2
|
+
const { localStorage, log } = require("@webiny/cli/utils");
|
|
3
|
+
const { getWcpGqlApiUrl } = require("@webiny/wcp");
|
|
4
|
+
|
|
5
|
+
const UPDATE_LAST_ACTIVE_TO_NOW = /* GraphQL */ `
|
|
6
|
+
mutation UpdateLastActiveToNow {
|
|
7
|
+
users {
|
|
8
|
+
updateLastActiveToNow {
|
|
9
|
+
id
|
|
10
|
+
lastActiveOn
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
module.exports.updateUserLastActiveOn = async () => {
|
|
17
|
+
const pat = localStorage().get("wcpPat");
|
|
18
|
+
if (!pat) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
`It seems you are not logged in. Please login using the ${log.error.hl(
|
|
21
|
+
"webiny login"
|
|
22
|
+
)} command.`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const headers = { authorization: pat };
|
|
27
|
+
return request(getWcpGqlApiUrl(), UPDATE_LAST_ACTIVE_TO_NOW, {}, headers);
|
|
28
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const { getUser } = require("./utils");
|
|
2
|
+
|
|
3
|
+
module.exports.command = () => ({
|
|
4
|
+
type: "cli-command",
|
|
5
|
+
name: "cli-command-wcp-whoami",
|
|
6
|
+
create({ yargs, context }) {
|
|
7
|
+
yargs.command(
|
|
8
|
+
"whoami",
|
|
9
|
+
`Display the current logged-in user`,
|
|
10
|
+
yargs => {
|
|
11
|
+
yargs.example("$0 whoami");
|
|
12
|
+
yargs.option("debug", {
|
|
13
|
+
describe: `Turn on debug logs`,
|
|
14
|
+
type: "boolean"
|
|
15
|
+
});
|
|
16
|
+
yargs.option("debug-level", {
|
|
17
|
+
default: 1,
|
|
18
|
+
describe: `Set the debug logs verbosity level`,
|
|
19
|
+
type: "number"
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
async ({ debug }) => {
|
|
23
|
+
try {
|
|
24
|
+
const user = await getUser();
|
|
25
|
+
console.log(
|
|
26
|
+
`You are logged in to Webiny Control Panel as ${context.info.hl(
|
|
27
|
+
user.email
|
|
28
|
+
)}.`
|
|
29
|
+
);
|
|
30
|
+
} catch (e) {
|
|
31
|
+
if (debug) {
|
|
32
|
+
context.debug(e);
|
|
33
|
+
}
|
|
34
|
+
throw new Error(
|
|
35
|
+
`It seems you are not logged in. Please login using the ${context.error.hl(
|
|
36
|
+
"webiny login"
|
|
37
|
+
)} command.`
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
});
|
package/context.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
2
|
const path = require("path");
|
|
3
|
-
const { importModule, getProject, PluginsContainer, log, localStorage } = require("./utils");
|
|
3
|
+
const { importModule, getProject, PluginsContainer, log, localStorage, noop } = require("./utils");
|
|
4
4
|
|
|
5
5
|
const project = getProject();
|
|
6
6
|
|
|
@@ -92,7 +92,7 @@ class Context {
|
|
|
92
92
|
log = log.log;
|
|
93
93
|
info = log.info;
|
|
94
94
|
success = log.success;
|
|
95
|
-
debug = log.debug;
|
|
95
|
+
debug = process.argv.includes("--debug") ? log.debug : noop;
|
|
96
96
|
warning = log.warning;
|
|
97
97
|
error = log.error;
|
|
98
98
|
|
package/index.d.ts
ADDED
package/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/cli",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-unstable.5e7233243f",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"bin": {
|
|
6
6
|
"webiny": "./bin.js"
|
|
@@ -13,19 +13,26 @@
|
|
|
13
13
|
"author": "Pavel Denisjuk <pavel@webiny.com>",
|
|
14
14
|
"description": "A tool to bootstrap a Webiny project.",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@webiny/telemetry": "0.0.0-
|
|
16
|
+
"@webiny/telemetry": "0.0.0-unstable.5e7233243f",
|
|
17
|
+
"@webiny/wcp": "0.0.0-unstable.5e7233243f",
|
|
17
18
|
"boolean": "3.1.4",
|
|
18
19
|
"camelcase": "5.3.1",
|
|
19
20
|
"chalk": "4.1.2",
|
|
20
21
|
"dotenv": "8.2.0",
|
|
21
|
-
"execa": "
|
|
22
|
+
"execa": "5.1.1",
|
|
22
23
|
"fast-glob": "3.2.7",
|
|
23
24
|
"find-up": "5.0.0",
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
25
|
+
"fs-extra": "9.1.0",
|
|
26
|
+
"graphql-request": "3.7.0",
|
|
27
|
+
"inquirer": "7.3.3",
|
|
28
|
+
"ncp": "2.0.0",
|
|
29
|
+
"open": "8.4.0",
|
|
30
|
+
"pirates": "4.0.5",
|
|
31
|
+
"semver": "7.3.7",
|
|
32
|
+
"ts-morph": "11.0.3",
|
|
33
|
+
"typescript": "4.7.4",
|
|
27
34
|
"uniqid": "5.4.0",
|
|
28
|
-
"yargs": "
|
|
35
|
+
"yargs": "17.5.1"
|
|
29
36
|
},
|
|
30
37
|
"license": "MIT",
|
|
31
38
|
"publishConfig": {
|
|
@@ -43,9 +50,7 @@
|
|
|
43
50
|
"@webiny/project-utils",
|
|
44
51
|
"@webiny/api-file-manager",
|
|
45
52
|
"@webiny/cli-plugin-deploy-pulumi",
|
|
46
|
-
"@webiny/
|
|
47
|
-
"@webiny/handler-http",
|
|
48
|
-
"@webiny/handler-args",
|
|
53
|
+
"@webiny/api",
|
|
49
54
|
"@webiny/handler-client",
|
|
50
55
|
"@webiny/api-elasticsearch",
|
|
51
56
|
"@webiny/api-tenancy",
|
|
@@ -59,5 +64,5 @@
|
|
|
59
64
|
]
|
|
60
65
|
}
|
|
61
66
|
},
|
|
62
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "995a4b337db9b8497c6615e335dcd206afe26f8f"
|
|
63
68
|
}
|
package/types.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export interface PluginsContainer {
|
|
|
15
15
|
* A simplified plugin interface, used specifically within the Webiny CLI.
|
|
16
16
|
* Not in relation with "@webiny/plugins" package.
|
|
17
17
|
*/
|
|
18
|
-
export interface Plugin
|
|
18
|
+
export interface Plugin {
|
|
19
19
|
type: string;
|
|
20
20
|
name?: string;
|
|
21
21
|
[key: string]: any;
|
|
@@ -40,9 +40,9 @@ interface Project {
|
|
|
40
40
|
* A type that represents the logging method.
|
|
41
41
|
*/
|
|
42
42
|
interface Log {
|
|
43
|
-
(...args): string;
|
|
44
|
-
hl: (...args) => string;
|
|
45
|
-
highlight: (...args) => string;
|
|
43
|
+
(...args: any): string;
|
|
44
|
+
hl: (...args: any) => string;
|
|
45
|
+
highlight: (...args: any) => string;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
@@ -100,7 +100,7 @@ export interface CliContext {
|
|
|
100
100
|
/**
|
|
101
101
|
* Resolve given dir or dirs against project root path.
|
|
102
102
|
*/
|
|
103
|
-
resolve: (dir) => string;
|
|
103
|
+
resolve: (dir: string) => string;
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
106
|
* Provides a way to store some meta data in the project's local ".webiny/cli.json" file.
|
|
@@ -111,39 +111,3 @@ export interface CliContext {
|
|
|
111
111
|
get: (key: string) => any;
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Args received from the CLI.
|
|
117
|
-
*/
|
|
118
|
-
interface CliUpgradePluginOptions {
|
|
119
|
-
/**
|
|
120
|
-
* Targeted version of the upgrade.
|
|
121
|
-
*/
|
|
122
|
-
targetVersion: string;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
*
|
|
126
|
-
*/
|
|
127
|
-
export interface CliUpgradePlugin extends Plugin {
|
|
128
|
-
/**
|
|
129
|
-
* Name of the plugin to differentiate from others.
|
|
130
|
-
* Something like: cli-upgrade-5.0.0
|
|
131
|
-
*/
|
|
132
|
-
name: string;
|
|
133
|
-
/**
|
|
134
|
-
* Type of the plugin.
|
|
135
|
-
*/
|
|
136
|
-
type: "cli-upgrade";
|
|
137
|
-
/**
|
|
138
|
-
* Version the plugin is for.
|
|
139
|
-
*/
|
|
140
|
-
version: string;
|
|
141
|
-
/**
|
|
142
|
-
* Is this plugin usable for the upgrade?
|
|
143
|
-
*/
|
|
144
|
-
canUpgrade?: (options: CliUpgradePluginOptions, context: CliContext) => Promise<boolean>;
|
|
145
|
-
/**
|
|
146
|
-
* Apply the upgrade.
|
|
147
|
-
*/
|
|
148
|
-
upgrade: (options: CliUpgradePluginOptions, context: CliContext) => Promise<void>;
|
|
149
|
-
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const util = require("util");
|
|
2
|
+
const fs = require("fs-extra");
|
|
3
|
+
const ncpBase = require("ncp");
|
|
4
|
+
const ncp = util.promisify(ncpBase.ncp);
|
|
5
|
+
|
|
6
|
+
module.exports = async projectApplication => {
|
|
7
|
+
if (await fs.pathExists(projectApplication.paths.workspace)) {
|
|
8
|
+
await fs.remove(projectApplication.paths.workspace);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
await fs.ensureDir(projectApplication.paths.workspace);
|
|
12
|
+
await ncp(projectApplication.paths.absolute, projectApplication.paths.workspace);
|
|
13
|
+
|
|
14
|
+
// Wait a bit and make sure the files are ready to have its content replaced.
|
|
15
|
+
return new Promise(resolve => setTimeout(resolve, 10));
|
|
16
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
|
|
4
|
+
// This function has been created in order to help preserve backwards compatibility
|
|
5
|
+
// (from 5.29.0, the `api` app has been moved into the `apps/api` directory).
|
|
6
|
+
module.exports = project => {
|
|
7
|
+
if (fs.existsSync(path.join(project.root, "api"))) {
|
|
8
|
+
return "api";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return "apps/api";
|
|
12
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { dirname, basename, join } = require("path");
|
|
1
|
+
const { dirname, basename, join, relative } = require("path");
|
|
2
2
|
const findUp = require("find-up");
|
|
3
3
|
const getProject = require("./getProject");
|
|
4
4
|
const { importModule } = require("./importModule");
|
|
@@ -15,31 +15,55 @@ module.exports = args => {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const rootFile = applicationRootFile.replace(/\\/g, "/");
|
|
18
|
-
const
|
|
18
|
+
const projectAppRootPath = dirname(rootFile);
|
|
19
19
|
|
|
20
20
|
let applicationConfig;
|
|
21
21
|
if (appConfigs.includes(basename(rootFile))) {
|
|
22
22
|
applicationConfig = importModule(rootFile);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
let name,
|
|
25
|
+
let id, name, description;
|
|
26
26
|
if (applicationConfig) {
|
|
27
27
|
id = applicationConfig.id;
|
|
28
28
|
name = applicationConfig.name;
|
|
29
|
+
description = applicationConfig.description;
|
|
29
30
|
} else {
|
|
30
|
-
name = basename(
|
|
31
|
+
name = basename(projectAppRootPath);
|
|
32
|
+
description = name;
|
|
31
33
|
id = name;
|
|
32
34
|
}
|
|
33
35
|
|
|
36
|
+
const project = getProject(args);
|
|
37
|
+
|
|
38
|
+
const projectAppRelativePath = relative(project.root, projectAppRootPath);
|
|
39
|
+
const projectAppWorkspacePath = join(
|
|
40
|
+
project.root,
|
|
41
|
+
".webiny",
|
|
42
|
+
"workspaces",
|
|
43
|
+
projectAppRelativePath
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
// If we're missing the `pulumi` property in the `applicationConfig` object, that
|
|
47
|
+
// means we're dealing with an old project application where all of the Pulumi code is
|
|
48
|
+
// located in user's project. New projects applications have this code abstracted away.
|
|
49
|
+
const type = applicationConfig.pulumi ? "v5-workspaces" : "v5";
|
|
50
|
+
|
|
34
51
|
return {
|
|
35
52
|
id,
|
|
36
53
|
name,
|
|
37
|
-
|
|
54
|
+
description,
|
|
55
|
+
type,
|
|
56
|
+
root: projectAppRootPath,
|
|
57
|
+
paths: {
|
|
58
|
+
relative: projectAppRelativePath,
|
|
59
|
+
absolute: projectAppRootPath,
|
|
60
|
+
workspace: projectAppWorkspacePath
|
|
61
|
+
},
|
|
38
62
|
config: applicationConfig,
|
|
39
|
-
project
|
|
63
|
+
project,
|
|
40
64
|
get packages() {
|
|
41
65
|
const webinyConfigs = glob.sync(
|
|
42
|
-
join(
|
|
66
|
+
join(projectAppRootPath, "**/webiny.config*.{ts,js}").replace(/\\/g, "/")
|
|
43
67
|
);
|
|
44
68
|
|
|
45
69
|
return webinyConfigs.map(config => {
|
package/utils/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function getApiProjectApplicationFolder(project: Record<string, any>): boolean;
|
package/utils/index.js
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
const { importModule } = require("./importModule");
|
|
2
|
+
const createProjectApplicationWorkspace = require("./createProjectApplicationWorkspace");
|
|
2
3
|
const getProject = require("./getProject");
|
|
3
4
|
const getProjectApplication = require("./getProjectApplication");
|
|
5
|
+
const getApiProjectApplicationFolder = require("./getApiProjectApplicationFolder");
|
|
4
6
|
const localStorage = require("./localStorage");
|
|
5
7
|
const log = require("./log");
|
|
6
8
|
const sendEvent = require("./sendEvent");
|
|
7
9
|
const PluginsContainer = require("./PluginsContainer");
|
|
8
10
|
|
|
11
|
+
const noop = () => {
|
|
12
|
+
// Do nothing.
|
|
13
|
+
};
|
|
14
|
+
|
|
9
15
|
module.exports = {
|
|
10
|
-
|
|
16
|
+
createProjectApplicationWorkspace,
|
|
17
|
+
getApiProjectApplicationFolder,
|
|
11
18
|
getProject,
|
|
12
19
|
getProjectApplication,
|
|
20
|
+
importModule,
|
|
13
21
|
localStorage,
|
|
14
22
|
log,
|
|
23
|
+
noop,
|
|
15
24
|
sendEvent,
|
|
16
25
|
PluginsContainer
|
|
17
26
|
};
|