Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page Builder - New PB Element Plugins #4342

Merged
merged 17 commits into from
Oct 18, 2024
Prev Previous commit
Next Next commit
wip
  • Loading branch information
adrians5j committed Oct 18, 2024
commit 49f3a455d52e93ea683cbc614ab620abfedb78c7
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import chalk from "chalk";
import { JsxFragment, Node, Project } from "ts-morph";
import { formatCode } from "@webiny/cli-plugin-scaffold/utils";
import { updateDependencies, updateWorkspaces } from "~/utils";
import readJson from "load-json-file";
import writeJson from "write-json-file";

export class PbElementExtension extends AbstractExtension {
async link() {
Expand All @@ -23,9 +21,6 @@ export class PbElementExtension extends AbstractExtension {
[this.params.packageName]: "1.0.0"
});

await this.updateTsConfigPaths("admin");
await this.updateTsConfigPaths("website");

await updateWorkspaces(this.params.location);
}

Expand Down Expand Up @@ -59,7 +54,7 @@ export class PbElementExtension extends AbstractExtension {
const componentName = ucFirstExtName + "Extension";

const importName = "{ Extension as " + componentName + " }";
const importPath = packageName;
const importPath = packageName + "/src/" + app;

const project = new Project();
project.addSourceFileAtPath(extensionsFilePath);
Expand All @@ -81,7 +76,7 @@ export class PbElementExtension extends AbstractExtension {

source.insertImportDeclaration(index, {
defaultImport: importName,
moduleSpecifier: importPath + "/" + app
moduleSpecifier: importPath
});

const extensionsIdentifier = source.getFirstDescendant(node => {
Expand Down Expand Up @@ -125,31 +120,4 @@ export class PbElementExtension extends AbstractExtension {

await formatCode(extensionsFilePath, {});
}

private async updateTsConfigPaths(app: "admin" | "website") {
const { name: extensionName, packageName } = this.params;

const tsConfigJsonPath = path.join("apps", app, "tsconfig.json");

const tsConfigJson = await readJson<Record<string, any>>(tsConfigJsonPath);

if (!tsConfigJson) {
throw new Error(`Could not read "${tsConfigJsonPath}" file.`);
}

if (!tsConfigJson.compilerOptions) {
tsConfigJson.compilerOptions = {};
}

if (!tsConfigJson.compilerOptions.paths) {
tsConfigJson.compilerOptions.paths = {};
}

tsConfigJson.compilerOptions.paths[packageName] = [`./extensions/${extensionName}/src`];
tsConfigJson.compilerOptions.paths[`${packageName}/*`] = [
`./extensions/${extensionName}/src/*`
];

await writeJson(tsConfigJsonPath, tsConfigJson);
}
}
}
Loading