-
Notifications
You must be signed in to change notification settings - Fork 618
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve Webiny /
create-webiny-project
CLIs (#4045)
- Loading branch information
Showing
130 changed files
with
3,080 additions
and
1,915 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/app-admin-rmwc/src/modules/Navigation/WebinyVersionListItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, { useMemo } from "react"; | ||
import styled from "@emotion/styled"; | ||
import { useWcp } from "@webiny/app-admin"; | ||
import { ListItem } from "@webiny/ui/List"; | ||
import { subFooter } from "./Styled"; | ||
import { config as appConfig } from "@webiny/app/config"; | ||
import { Typography } from "@webiny/ui/Typography"; | ||
import { Tooltip } from "@webiny/ui/Tooltip"; | ||
|
||
const WcpBadge = styled.div` | ||
background-color: var(--mdc-theme-primary, #6200ee); | ||
display: inline-block; | ||
color: white; | ||
padding: 2px 4px; | ||
border-radius: 5px; | ||
font-size: 12px; | ||
font-weight: bold; | ||
line-height: 14px; | ||
margin-left: 5px; | ||
`; | ||
|
||
export const WebinyVersionListItem = () => { | ||
const wbyVersion = appConfig.getKey("WEBINY_VERSION", process.env.REACT_APP_WEBINY_VERSION); | ||
const wcp = useWcp(); | ||
|
||
const wcpBadge = useMemo(() => { | ||
const wcpProject = wcp.getProject(); | ||
if (!wcpProject) { | ||
return null; | ||
} | ||
|
||
const tooltipContent = ( | ||
<span> | ||
{wcpProject.orgId}/{wcpProject.projectId} | ||
</span> | ||
); | ||
|
||
return ( | ||
<Tooltip content={tooltipContent}> | ||
<WcpBadge>WCP</WcpBadge> | ||
</Tooltip> | ||
); | ||
}, []); | ||
|
||
return ( | ||
<ListItem ripple={false} className={subFooter}> | ||
<Typography use={"body2"}> | ||
Webiny v{wbyVersion} | ||
{wcpBadge} | ||
</Typography> | ||
</ListItem> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/cli-plugin-deploy-pulumi/commands/buildPackages/BasePackagesBuilder.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class BasePackagesBuilder { | ||
constructor({ packages, inputs, context }) { | ||
this.packages = packages; | ||
this.inputs = inputs; | ||
this.context = context; | ||
} | ||
|
||
async build() { | ||
throw new Error("Not implemented."); | ||
} | ||
} | ||
|
||
module.exports = { BasePackagesBuilder }; |
111 changes: 111 additions & 0 deletions
111
packages/cli-plugin-deploy-pulumi/commands/buildPackages/MultiplePackagesBuilder.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
const path = require("path"); | ||
const { Worker } = require("worker_threads"); | ||
const Listr = require("listr"); | ||
const { BasePackagesBuilder } = require("./BasePackagesBuilder"); | ||
const { gray } = require("chalk"); | ||
const { measureDuration } = require("../../utils"); | ||
|
||
class MultiplePackagesBuilder extends BasePackagesBuilder { | ||
async build() { | ||
const packages = this.packages; | ||
const context = this.context; | ||
const inputs = this.inputs; | ||
|
||
const getBuildDuration = measureDuration(); | ||
|
||
const { env, variant, debug } = inputs; | ||
|
||
context.info(`Building %s packages...`, packages.length); | ||
|
||
const buildTasks = []; | ||
|
||
for (let i = 0; i < packages.length; i++) { | ||
const pkg = packages[i]; | ||
|
||
buildTasks.push({ | ||
pkg: pkg, | ||
task: new Promise((resolve, reject) => { | ||
const enableLogs = inputs.logs === true; | ||
|
||
const workerData = { | ||
options: { | ||
env, | ||
variant, | ||
debug, | ||
logs: enableLogs | ||
}, | ||
package: { ...pkg.paths } | ||
}; | ||
|
||
const worker = new Worker(path.join(__dirname, "./worker.js"), { | ||
workerData, | ||
stderr: true, | ||
stdout: true | ||
}); | ||
|
||
worker.on("message", threadMessage => { | ||
const { type, stdout, stderr, error } = JSON.parse(threadMessage); | ||
|
||
const result = { | ||
package: pkg, | ||
stdout, | ||
stderr, | ||
error, | ||
duration: getBuildDuration() | ||
}; | ||
|
||
if (type === "error") { | ||
reject(result); | ||
return; | ||
} | ||
|
||
if (type === "success") { | ||
resolve(result); | ||
} | ||
}); | ||
}) | ||
}); | ||
} | ||
|
||
const tasks = new Listr( | ||
buildTasks.map(({ pkg, task }) => { | ||
return { | ||
title: this.getPackageLabel(pkg), | ||
task: () => task | ||
}; | ||
}), | ||
{ concurrent: true, exitOnError: false } | ||
); | ||
|
||
await tasks.run().catch(err => { | ||
console.log(); | ||
context.error(`Failed to build all packages. For more details, check the logs below.`); | ||
console.log(); | ||
|
||
err.errors.forEach(({ package: pkg, error }, i) => { | ||
const number = `${i + 1}.`; | ||
const name = context.error.hl(pkg.name); | ||
const relativePath = gray(`(${pkg.paths.relative})`); | ||
const title = [number, name, relativePath].join(" "); | ||
|
||
console.log(title); | ||
console.log(error.message); | ||
console.log(); | ||
}); | ||
|
||
throw new Error(`Failed to build all packages.`); | ||
}); | ||
|
||
console.log(); | ||
|
||
context.success(`Successfully built ${packages.length} packages in ${getBuildDuration()}.`); | ||
} | ||
|
||
getPackageLabel(pkg) { | ||
const pkgName = pkg.name; | ||
const pkgRelativePath = gray(`(${pkg.paths.relative})`); | ||
return `${pkgName} ${pkgRelativePath}`; | ||
} | ||
} | ||
|
||
module.exports = { MultiplePackagesBuilder }; |
33 changes: 33 additions & 0 deletions
33
packages/cli-plugin-deploy-pulumi/commands/buildPackages/PackagesBuilder.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const { BasePackagesBuilder } = require("./BasePackagesBuilder"); | ||
|
||
class PackagesBuilder extends BasePackagesBuilder { | ||
async build() { | ||
const BuilderClass = this.getBuilderClass(); | ||
|
||
const builder = new BuilderClass({ | ||
packages: this.packages, | ||
inputs: this.inputs, | ||
context: this.context | ||
}); | ||
|
||
await builder.build(); | ||
} | ||
|
||
getBuilderClass() { | ||
const packagesCount = this.packages.length; | ||
if (packagesCount === 0) { | ||
const { ZeroPackagesBuilder } = require("./ZeroPackagesBuilder"); | ||
return ZeroPackagesBuilder; | ||
} | ||
|
||
if (packagesCount === 1) { | ||
const { SinglePackageBuilder } = require("./SinglePackageBuilder"); | ||
return SinglePackageBuilder; | ||
} | ||
|
||
const { MultiplePackagesBuilder } = require("./MultiplePackagesBuilder"); | ||
return MultiplePackagesBuilder; | ||
} | ||
} | ||
|
||
module.exports = { PackagesBuilder }; |
Oops, something went wrong.