Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Bouquillon committed Dec 17, 2023
1 parent 5fba127 commit 154c540
Show file tree
Hide file tree
Showing 23 changed files with 274 additions and 81 deletions.
3 changes: 1 addition & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ type CronJob = import("kubernetes-models/batch/v1").ICronJob;
type ConfigMap = import("kubernetes-models/v1").IConfigMap;
type Secret = import("kubernetes-models/v1").ISecret;


type Utils = import("./packages/common/utils").Utils;
type Utils = typeof import("./packages/common/utils");

// todo: use officiel model
interface KappConfig {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"packages/*"
],
"devDependencies": {
"@types/jest": "^29.5.11",
"@types/lodash.camelcase": "^4.3.7",
"@types/lodash.clonedeep": "^4.5.7",
"@types/lodash.defaults": "^4.2.7",
Expand All @@ -16,7 +17,7 @@
"@types/lodash.pick": "^4.4.7",
"@types/lodash.set": "^4.3.7",
"@types/micromatch": "^4.0.2",
"@types/node": "^18.11.18",
"@types/node": "^20.10.5",
"@types/pino": "^7.0.5",
"commit-and-tag-version": "^11.0.0",
"docsify-cli": "^4.4.4",
Expand Down
7 changes: 6 additions & 1 deletion packages/common/config/load-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ const configDependencyKey = require("~common/utils/config-dependency-key")
const lowerKeys = require("~common/utils/lower-keys")
const ctx = require("../ctx")
const patternMatch = require("../utils/pattern-match")
const loadStructuredConfig = require("../utils/load-structured-config")

const loadStructuredConfig =
/** @type {import("../utils/load-structured-config").LoadStructuredConfig} */ (
/** @type {unknown} */ (require("../utils/load-structured-config"))
)

const getGitRef = require("../utils/get-git-ref")
const getGitSha = require("../utils/get-git-sha")
const getGitUrl = require("../utils/get-git-url")
Expand Down
7 changes: 7 additions & 0 deletions packages/common/config/load-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ const patternMatch = require("../utils/pattern-match")
const copyFilter = require("./copy-filter")
const loadGitOrgConfig = require("./load-git-org-config")

/**
*
* @param {*} config
* @param {import("../utils")["logger"]} logger
* @param {*} reloadConfig
* @returns {Promise<object>}
*/
module.exports = async (config, logger, reloadConfig) => {
logger.debug("🔻 load dependencies")

Expand Down
13 changes: 12 additions & 1 deletion packages/common/config/load-git-org-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@ const defaultsDeep = require("lodash.defaultsdeep")
const normalizeRepositoryUrl = require("~common/utils/normalize-repository-url")

const getGitRemoteDefaultBranch = require("~common/utils/get-git-remote-default-branch")
const parseGitUrl = require("~common/utils/parse-git-url")

const parseGitUrl =
/** @type {import("../utils/parse-git-url").ParseGithubUrl} */ (
/** @type {unknown} */ (require("~common/utils/parse-git-url"))
)

const downloadGitOrgConfig = require("./download-git-org-config")

/**
*
* @param {object} config
* @param {Function} reloadConfig
* @returns
*/
module.exports = async (config, reloadConfig) => {
const {
gitOrg,
Expand Down
41 changes: 0 additions & 41 deletions packages/common/utils/index.d.ts

This file was deleted.

4 changes: 3 additions & 1 deletion packages/common/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
const utils = {
degit: require("tiged"),
fs: require("fs-extra"),
get logger() {
Expand Down Expand Up @@ -119,3 +119,5 @@ module.exports = {
matchLinkRemap: require("./match-link-remap"),
detectKubeVersion: require("./detect-kube-version"),
}

module.exports = utils
2 changes: 1 addition & 1 deletion packages/common/utils/kind-is-runnable.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const kindsRunnable = require("./kinds-runnable")
const kindsRunnable = ["Deployment", "Job", "DaemonSet", "StatefulSet"]

/**
*
Expand Down
2 changes: 2 additions & 0 deletions packages/common/utils/kubectl-retry.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ const kubectlRun = async (kubectlArgs, options = {}) => {
* @typedef {Object} KubectlRetryOptions
* @prop {any} [logger]
* @prop {any} [sentry]
* @prop {string} [kubeconfig]
* @prop {string} [kubeconfigContext]
* @prop {Record<string, any>} [retryOptions]
* @prop {boolean} [logError]
* @prop {boolean} [logInfo]
Expand Down
21 changes: 21 additions & 0 deletions packages/common/utils/load-structured-config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export type CompilerConfig = object;

export type StructuredconfigOptions = {
configBasename?: string;
inlineConfigs?: object[];
configDirs?: string[];
configPreCompilers?: CompilerConfig[];
configOverride?: object;
env: Record<string, string>;
options: object;
mergeWith?: void;
emptyAsUndefined?: boolean;
rootConfig: object;
configMeta: object;
};

export type LoadStructuredConfig = (
arg0: StructuredconfigOptions
) => Promise<Record<string, any>>;

export default LoadStructuredConfig;
3 changes: 2 additions & 1 deletion packages/common/utils/load-structured-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const undefinedCheck = (val) => val === undefined
const emptyAsUndefinedCheck = (val) =>
val === undefined || val === "" || val === null

module.exports = async ({
/** @type {import("./load-structured-config") } */
module.exports = /** @type {import("./load-structured-config") } */ async ({
configBasename = "config",
inlineConfigs = [],
configDirs = [],
Expand Down
17 changes: 17 additions & 0 deletions packages/common/utils/parse-github-url.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import ParsedUrl from "parse-url";

type AdditionalInfos = {
host: string;
repository: string;
owner: string;
name: string;
repo: string;
href: string;
branch: string;
blob: string;
path: string;
filepath: string;
};
type GitHubUrl = Partial<ReturnType<typeof ParsedUrl> & AdditionalInfos>;

type ParseGithubUrl = (string) => GitHubUrl;
2 changes: 2 additions & 0 deletions packages/common/utils/parse-github-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module.exports = (str) => {
}

// parse the URL
/** @type {Partial<ReturnType<import("parse-url")> & { host:string, repository: string, owner: string,name: string,repo: string,href: string,branch: string, blob:string, path:string, filepath:string}>} */
let obj
if (str.includes(":")) {
obj = parseUrl(str)
Expand All @@ -56,6 +57,7 @@ module.exports = (str) => {
if (!obj.host && /^git@/.test(str) === true) {
// return the correct host for git@ URLs
const urlObject = parseUrl(`http://${str}`)
// @ts-ignore waiting for update parse-url types... https://github.com/IonicaBizau/parse-url/issues/71
obj.host = urlObject.host
}

Expand Down
6 changes: 5 additions & 1 deletion packages/common/utils/time-logger.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
const prettyTime = require("./pretty-time")

function TimeLogger({
Expand All @@ -11,6 +12,7 @@ function TimeLogger({
this.label = label
this.logLevel = logLevel
}

Object.assign(TimeLogger.prototype, {
end(options = {}) {
if (options.logger) {
Expand All @@ -23,7 +25,9 @@ Object.assign(TimeLogger.prototype, {
this.logLevel = options.logLevel
}
this.logger[this.logLevel](
`${this.label}: ${prettyTime(new Date() - this.startTime)}`
`${this.label}: ${prettyTime(
new Date().getTime() - this.startTime.getTime()
)}`
)
},
})
Expand Down
4 changes: 3 additions & 1 deletion packages/kontinuous/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"allowJs": true,
"checkJs": true,
"noImplicitAny": false,
"isolatedModules": false,
"noEmit": true,
Expand All @@ -19,5 +20,6 @@
"helm-tree/*": ["../helm-tree/*"]
}
},
"exclude": ["./node_modules"]
"exclude": ["./node_modules"],
"include": ["./packages/common/utils/**.js"]
}
6 changes: 6 additions & 0 deletions plugins/contrib/deploy-sidecars/stern.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const { spawn } = require("child_process")

/**
*
* @param {*} options
* @param {{utils: Utils}} param1
* @returns
*/
module.exports = async (
options,
{ config, logger, utils, needBin, manifests, dryRun, ctx }
Expand Down
18 changes: 0 additions & 18 deletions plugins/contrib/jsconfig.json

This file was deleted.

7 changes: 7 additions & 0 deletions plugins/contrib/patches/30-janitor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
const { persistPatterns } = require("../lib/persist-convention")

/**
* Takes any object with a name prop and removes it
* @param {Kontinuous.Manifest[]} manifests
* @param {object} options
* @param {{config:object, values:object, utils:Utils}} param2
* @returns {Kontinuous.Manifest[]}
*/
module.exports = (manifests, options, { config, values, utils }) => {
if (config.environment !== "dev") {
return manifests
Expand Down
5 changes: 4 additions & 1 deletion plugins/contrib/patches/tests/janitor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ metadata:

const runJanitor = async (config, values) => {
const ctx = require("~common/ctx")
const utils = require("~common/utils")

// warn: JSDOC weird cast notation
const utils = /** @type {import("~common/utils").Utils} */ (
/** @type {unknown} */ (require("~common/utils"))
)
const manifests = utils.yaml.loadAll(rawNs)
const { logger } = utils
logger.minLevel("debug")
Expand Down
1 change: 1 addition & 0 deletions plugins/contrib/post-deploy/notify-mattermost.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module.exports = async (manifests, options, context) => {
}
} else {
deploymentMessage.push(
// @ts-ignore
new AggregateError(errors, "errors encountered during deployment").message
)
// if we're running through GitHub actions
Expand Down
2 changes: 1 addition & 1 deletion plugins/contrib/values-compilers/10-tpl-meta-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const renderTplRecurse = async (
}
value = yaml.loadValue(value)
if (isTplCast) {
const cast = prefix.slice(1, -1).split(":").slice(1)
const cast = prefix.slice(1, -1).split(":").slice(1).join("")
switch (true) {
case cast === "int" || cast === "integer": {
value = parseInt(value, 10)
Expand Down
13 changes: 11 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"module": "es6",
"module": "es2022",
"target": "es2015",
"checkJs": true,
"allowJs": true,
Expand All @@ -12,5 +12,14 @@
"noEmit": true,
"strict": false
},
"include": ["**.js", "**.d.ts"]
"exclude": ["node_modules"],
"include": [
"./index.d.ts",
"./plugins/**/*.js",
"./plugins/**/*.d.ts",
"./packages/common/**/*.js",
"./packages/common/**/*.d.ts",
"./packages/kontinuous/**/*.js",
"./packages/kontinuous/**/*.d.ts"
]
}
Loading

0 comments on commit 154c540

Please sign in to comment.