Skip to content

Commit

Permalink
fix(cli-plugin-deploy-pulumi): update config resolution logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Apr 30, 2024
1 parent cdc9bea commit ced7982
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const fs = require("fs");
const path = require("path");

class LocalFile {
constructor(filePath) {
this.filePath = filePath;
}

exists() {
return fs.existsSync(this.filePath);
}

getAbsolutePath() {
return this.filePath;
}
}

class WebinyConfigFile {
constructor(root) {
this.potentialConfigs = [
new LocalFile(path.join(root, "webiny.config.ts")),
new LocalFile(path.join(root, "webiny.config.js"))
];
}

static forWorkspace(workspace) {
return new WebinyConfigFile(path.resolve(workspace));
}

getAbsolutePath() {
const file = this.potentialConfigs.find(file => file.exists());
if (!file) {
return undefined;
}

return file.getAbsolutePath();
}
}

module.exports = { WebinyConfigFile };
11 changes: 6 additions & 5 deletions packages/cli-plugin-deploy-pulumi/commands/watch/listPackages.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const execa = require("execa");
const fs = require("fs");
const path = require("path");
const { WebinyConfigFile } = require("./WebinyConfigFile");

const listPackages = async ({ inputs }) => {
let packagesList = [];
Expand Down Expand Up @@ -41,9 +40,11 @@ const listPackages = async ({ inputs }) => {
const packages = [];
for (const packageName in result) {
const root = result[packageName];
const configPath = fs.existsSync(path.join(root, "webiny.config.ts"))
? path.join(root, "webiny.config.ts")
: path.join(root, "webiny.config.js");
const configPath = WebinyConfigFile.forWorkspace(root).getAbsolutePath();

if (!configPath) {
continue;
}

packages.push({
name: packageName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const path = require("path");
const fs = require("fs");
const { Worker } = require("worker_threads");
const chalk = require("chalk");
const execa = require("execa");
const { getRandomColorForString } = require("../../utils");
const { WebinyConfigFile } = require("./WebinyConfigFile");

const parseMessage = message => {
try {
Expand Down Expand Up @@ -135,9 +135,11 @@ const getPackages = async ({ inputs, context, output }) => {
const packages = [];
for (const packageName in result) {
const root = result[packageName];
const configPath = fs.existsSync(path.join(root, "webiny.config.ts"))
? path.join(root, "webiny.config.ts")
: path.join(root, "webiny.config.js");
const configPath = WebinyConfigFile.forWorkspace(root).getAbsolutePath();

if (!configPath) {
continue;
}

try {
packages.push({
Expand Down

0 comments on commit ced7982

Please sign in to comment.