Skip to content

Commit

Permalink
Including the bundle system to parse the based configuration file and…
Browse files Browse the repository at this point in the history
… including find-up as a dependency
  • Loading branch information
luiguild committed Oct 10, 2024
1 parent 4a5a13b commit 5561a7f
Show file tree
Hide file tree
Showing 5 changed files with 261 additions and 59 deletions.
2 changes: 1 addition & 1 deletion dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -37781,7 +37781,7 @@ async function run() {
);
}
core.info('\u2705 Parsed "based.json"');
env = env === "#branch" ? branchName : env;
env = env.endsWith("#branch") ? branchName : env;
const client = new BasedClient({
org: "saulx",
project: "based-cloud",
Expand Down
193 changes: 157 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"@actions/exec": "^1.1.1",
"@actions/github": "^6.0.0",
"@based/client": "^6.9.1",
"@saulx/utils": "^5.0.0"
"@saulx/utils": "^5.0.0",
"find-up": "^7.0.0",
"@based/bundle": "../bundle"
},
"devDependencies": {
"@based/cli": "^7.2.3",
Expand Down
39 changes: 39 additions & 0 deletions src/getBasedFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { findUp } from 'find-up'
import { readJSON } from 'fs-extra/esm'
import { bundle } from '@based/bundle'

export type Project = {
cluster?: string
project?: string
org?: string
env?: string
apiKey?: string
}

export const getBasedFile = async (file: string[]): Promise<Project | null> => {
if (!file || !file.length) {
throw new Error()
}

const basedFile = await findUp(file)
let basedFileContent: Project = {}
const basedProject: Project = {}

if (basedFile) {
if (basedFile.endsWith('.json')) {
basedFileContent = await readJSON(basedFile)
} else {
const bundled = await bundle({
entryPoints: [basedFile],
})
const compiled = bundled.require()

basedFileContent = compiled.default || compiled
}

Object.assign(basedProject, basedFileContent)
return basedProject
} else {
throw new Error()
}
}
Loading

0 comments on commit 5561a7f

Please sign in to comment.