feat: add plugin build command (#10935)
Fixes: FRMW-2863 Adds the `plugin:build` command that is used to compile the source code of a plugin for publishing it to a package registry. The command is similar to the `build` command, except it does not copy the `package.json` and the `lock` files to the build output
This commit is contained in:
@@ -382,8 +382,55 @@ export class Compiler {
|
||||
}
|
||||
}
|
||||
|
||||
// @todo
|
||||
buildPluginBackend() {}
|
||||
/**
|
||||
* Compiles the plugin source code to JavaScript using the
|
||||
* TypeScript's official compiler
|
||||
*/
|
||||
async buildPluginBackend(tsConfig: tsStatic.ParsedCommandLine) {
|
||||
const tracker = this.#trackDuration()
|
||||
const dist = ".medusa/server"
|
||||
this.#logger.info("Compiling plugin source...")
|
||||
|
||||
/**
|
||||
* Step 1: Cleanup existing build output
|
||||
*/
|
||||
this.#logger.info(
|
||||
`Removing existing "${path.relative(this.#projectRoot, dist)}" folder`
|
||||
)
|
||||
await this.#clean(dist)
|
||||
|
||||
/**
|
||||
* Step 2: Compile TypeScript source code
|
||||
*/
|
||||
const { emitResult, diagnostics } = await this.#emitBuildOutput(
|
||||
tsConfig,
|
||||
["integration-tests", "test", "unit-tests", "src/admin"],
|
||||
dist
|
||||
)
|
||||
|
||||
/**
|
||||
* Exit early if no output is written to the disk
|
||||
*/
|
||||
if (emitResult.emitSkipped) {
|
||||
this.#logger.warn("Plugin build completed without emitting any output")
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify about the state of build
|
||||
*/
|
||||
if (diagnostics.length) {
|
||||
this.#logger.warn(
|
||||
`Plugin build completed with errors (${tracker.getSeconds()}s)`
|
||||
)
|
||||
} else {
|
||||
this.#logger.info(
|
||||
`Plugin build completed successfully (${tracker.getSeconds()}s)`
|
||||
)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles the backend source code of a plugin project in watch
|
||||
|
||||
Reference in New Issue
Block a user