From b6c624c0fd128f020629010b22c2f8f7bd6eea4c Mon Sep 17 00:00:00 2001 From: Pierluigi Viti Date: Thu, 19 Dec 2024 18:17:14 +0100 Subject: [PATCH] chore: add automatic update of license year --- LICENSE | 2 +- gen/generator.ts | 5 ++++- gen/license.ts | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 gen/license.ts diff --git a/LICENSE b/LICENSE index 3b4d2b3..d5971b4 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/gen/generator.ts b/gen/generator.ts index 570c546..feaf29d 100644 --- a/gen/generator.ts +++ b/gen/generator.ts @@ -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 ****/ @@ -161,6 +162,8 @@ const generate = async (localSchema?: boolean) => { updateModelTypes(resources) // updateApiMicroClients(resources) + updateLicense() + console.log(`SDK generation completed [${global.version}].\n`) } @@ -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}'` diff --git a/gen/license.ts b/gen/license.ts new file mode 100644 index 0000000..3b931ca --- /dev/null +++ b/gen/license.ts @@ -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 }) + +}