Skip to content

Commit

Permalink
chore: add automatic update of license year
Browse files Browse the repository at this point in the history
  • Loading branch information
pviti committed Dec 19, 2024
1 parent 9ae129b commit b6c624c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) [2023] [Commerce Layer]
Copyright (c) [2024] [Commerce Layer]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 4 additions & 1 deletion gen/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { readFileSync, writeFileSync, existsSync, mkdirSync, readdirSync, rmSync
import { basename } from 'node:path'
import Fixer from './fixer'
import Inflector from './inflector'
import { updateLicense } from './license'


/**** SDK source code generator settings ****/
Expand Down Expand Up @@ -161,6 +162,8 @@ const generate = async (localSchema?: boolean) => {
updateModelTypes(resources)
// updateApiMicroClients(resources)

updateLicense()

console.log(`SDK generation completed [${global.version}].\n`)

}
Expand Down Expand Up @@ -770,7 +773,7 @@ const generateResource = (type: string, name: string, resource: Resource): strin
const impResMod: string[] = Array.from(declaredImportsModels)
.filter(i => !typesArray.includes(i)) // excludes resource self reference
.map(i => {
// Fix singleton type problem in provisioning api
// [TEMP] Fix singleton type problem in provisioning api
const singletonRel = Object.values(global.singletons).includes(i)
const fileRel = Inflector.underscore(singletonRel? i : Inflector.pluralize(i))
return `import type { ${i}${relationshipTypes.has(i) ? `, ${i}Type` : ''} } from './${fileRel}'`
Expand Down
17 changes: 17 additions & 0 deletions gen/license.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { readFileSync, writeFileSync } from "node:fs"
import { resolve } from "node:path"


export const updateLicense = () => {

const encoding = 'utf-8'
const licenseFile = resolve('LICENSE')

const license = readFileSync(licenseFile, { encoding })

const currentYear = new Date().getFullYear()
const updatedLicense = license.replace(/\[\d{4}\]/, `[${currentYear}]`)

writeFileSync(licenseFile, updatedLicense, { encoding })

}

0 comments on commit b6c624c

Please sign in to comment.