Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Bouquillon committed Dec 18, 2023
1 parent 9e4c12d commit f4d3bd2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 36 deletions.
1 change: 0 additions & 1 deletion packages/common/utils/async-shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ module.exports = (
extraOptions = {}
) => {
const [cmd, args] = parseCommand(arg)
logger.pouet(42)
const defaultOptions = { encoding: "utf-8" }
const childProcess = spawn(cmd, args, {
...defaultOptions,
Expand Down
6 changes: 6 additions & 0 deletions packages/common/utils/deepmerge.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const mergeWith = require("lodash.mergewith")

/**
* Helm like deep merge
* @param {object} objValue
* @param {...object} srcValues
* @returns {object}
*/
module.exports = (objValue, ...srcValues) =>
mergeWith(objValue, ...srcValues, (oValue, srcValue) => {
if (Array.isArray(oValue)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/utils/direct-logger-factory.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Logger = require("direct-logger")
const { Logger } = require("direct-logger")

module.exports = (opts = {}) => {
const { streams = process.stderr } = opts
Expand Down
2 changes: 1 addition & 1 deletion plugins/contrib/values-compilers/09-maildev.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ export type MailDevValues = {

export type MailDevParams = {
config: any;
//utils: Kontinuous.Utils;
utils: keyof Kontinuous.Utils;
ctx: any;
};
60 changes: 27 additions & 33 deletions plugins/contrib/values-compilers/09-maildev.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @return {component is import("./09-maildev").MailDevComponent}
*/
function isMaildevComponent(component) {
return component[`~chart`].endsWith(".contrib.maildev")
return component[`~chart`]?.endsWith(".contrib.maildev")
}

/**
Expand All @@ -15,9 +15,9 @@ function isMaildevComponent(component) {
function extractMaildevComponents(values, acc = []) {
Object.entries(values).forEach(([key, component]) => {
if (typeof component === "object" && component !== null) {
extractMaildevComponents(values, acc)
if (values._isChartValues && isMaildevComponent(values)) {
acc.push(values)
extractMaildevComponents(component, acc)
if (component._isChartValues && isMaildevComponent(component)) {
acc.push([key, component])
}
}
})
Expand All @@ -30,41 +30,35 @@ function extractMaildevComponents(values, acc = []) {
* @param {import("./09-maildev").MailDevParams} param2
* @returns
*/
const maildev = async (values, _options, { _config, _utils, _ctx }) => {
const maildev = async (values, _options, { _config, utils, _ctx }) => {
console.log("maildev", values)
const { deepmerge } = utils

const components = extractMaildevComponents(values)

console.log("component", components)
//
// todo: find all [`~chart`] === "project.fabrique.contrib.maildev"
//
Object.entries(values.project.fabrique.contrib).forEach(
([key, component]) => {
if (isMaildevComponent(component)) {
const persistenceEnabled =
component.persistence.enabled !== null
? component.persistence.enabled
: !!values.global.env.preprod
components.forEach(([key, component]) => {
const persistenceEnabled =
component.persistence.enabled !== null
? component.persistence.enabled
: !!values.global.env.preprod

component.maildev = {
...component.maildev,
host: component.host || `${key}-${values.global.host}`,
repositoryName: values.global.repositoryName,
ingress: {
...(component.ingress || {}),
annotations: values.global.ingress.annotations,
},
persistence: {
enabled: persistenceEnabled,
},
cron: {
enabled: persistenceEnabled,
},
}
}
/** @type {import("./09-maildev-schema").MailDevSchema} */
const maildevValues = {
host: component.host || `${key}-${values.global.host}`,
repositoryName: values.global.repositoryName,
ingress: {
annotations: values.global.ingress.annotations,
},
persistence: {
enabled: persistenceEnabled,
},
cron: {
enabled: persistenceEnabled,
},
}
)

deepmerge(component, maildevValues)
})
}

// @ts-ignore
Expand Down

0 comments on commit f4d3bd2

Please sign in to comment.