Skip to content

Commit

Permalink
fix: tsc dependencies.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
musdotdigital committed Nov 29, 2023
1 parent 98b4dfe commit 68fc31b
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,39 @@ import {factory, Image} from './image'
export function load(dependencies_path: string): [Image, Package[]] {
const content = fs.readFileSync(dependencies_path).toString('utf-8')
const jsonContent = JSON.parse(content)
return [factory(jsonContent.image), packages_from_dict(jsonContent.dependencies)]
return [
factory(jsonContent.image),
packages_from_dict(jsonContent.dependencies)
]
}

export function save(dependencies_path: string, image: string, dependencies: Package[]): void {
export function save(
dependencies_path: string,
image: string,
dependencies: Package[]
): void {
const jsonData = {
image: image,
dependencies: dependencies
};
image,
dependencies
}
const jsonContent = JSON.stringify(jsonData, null, 2)
fs.writeFileSync(dependencies_path, jsonContent)
}

interface StoredJSON {
name: string
version: string
[key: string]: string
}

export class Package {
name: string
version: string
[key: string]: string

constructor(name: string, version: string, extraFields?: {[key: string]: string}) {
constructor(
name: string,
version: string,
extraFields?: {[key: string]: string}
) {
this.name = name
this.version = version
Object.assign(this, extraFields)
Expand All @@ -37,7 +46,9 @@ export class Package {
function packages_from_dict(dict: StoredJSON[]): Package[] {
const packages: Package[] = []
for (const storedPackage of dict) {
packages.push(new Package(storedPackage.name, storedPackage.version, {...storedPackage}))
packages.push(
new Package(storedPackage.name, storedPackage.version, {...storedPackage})
)
}
return packages
}

0 comments on commit 68fc31b

Please sign in to comment.