From 3be32827f2d7582ab59a4c53b9c55da6da018e71 Mon Sep 17 00:00:00 2001 From: Emre Portakal Date: Thu, 26 Dec 2024 14:25:48 +0300 Subject: [PATCH 1/5] feat: remove leftover props form package.json --- src/helpers/updatePackageData.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/helpers/updatePackageData.ts b/src/helpers/updatePackageData.ts index 13b0ef7..2029b0a 100644 --- a/src/helpers/updatePackageData.ts +++ b/src/helpers/updatePackageData.ts @@ -13,6 +13,9 @@ export async function updatePackageData( packageJson.name = projectName; packageJson.version = '1.0.0'; + delete packageJson.description; + delete packageJson.author; + delete packageJson.license; const formattedPackageJson = JSON.stringify(packageJson, null, 2) + '\n'; From 74f605789a92a0af52103965c77959caed612664 Mon Sep 17 00:00:00 2001 From: Emre Portakal Date: Thu, 26 Dec 2024 18:45:57 +0300 Subject: [PATCH 2/5] feat: add license and private props to package.json --- src/helpers/updatePackageData.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/helpers/updatePackageData.ts b/src/helpers/updatePackageData.ts index 2029b0a..ddd8497 100644 --- a/src/helpers/updatePackageData.ts +++ b/src/helpers/updatePackageData.ts @@ -8,14 +8,25 @@ export async function updatePackageData( try { const packageJsonPath = path.join(directoryPath, 'package.json'); const packageJsonData = await fs.readFile(packageJsonPath, 'utf-8'); - const packageJson = JSON.parse(packageJsonData); + let packageJson = JSON.parse(packageJsonData); const templateVersion = packageJson.version; packageJson.name = projectName; packageJson.version = '1.0.0'; + + delete packageJson.license; delete packageJson.description; delete packageJson.author; - delete packageJson.license; + + // To add 'private' after common locations such as after 'license' + const { name, version, ...rest } = packageJson; + packageJson = { + name, + version, + license: 'UNLICENSED', + private: true, + ...rest, + }; const formattedPackageJson = JSON.stringify(packageJson, null, 2) + '\n'; From e3e55e1405914ae332d5296cf521e621be527db3 Mon Sep 17 00:00:00 2001 From: Emre Portakal Date: Thu, 26 Dec 2024 18:50:31 +0300 Subject: [PATCH 3/5] build: version patch 1.2.3 -> 1.2.4 --- .changeset/great-lemons-carry.md | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/great-lemons-carry.md diff --git a/.changeset/great-lemons-carry.md b/.changeset/great-lemons-carry.md new file mode 100644 index 0000000..0f056f6 --- /dev/null +++ b/.changeset/great-lemons-carry.md @@ -0,0 +1,5 @@ +--- +'@commencis/cli': patch +--- + +alter package.json file content diff --git a/package.json b/package.json index a139f46..5bfa177 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@commencis/cli", - "version": "1.2.3", + "version": "1.2.4", "description": "Commencis's CLI tool for creating & managing projects", "author": "Commencis WFE Team (https://commencis.com)", "license": "Apache-2.0", From faa2ac9b93d7fa68404e15ff36c425d2d1bd4532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmetcan=20Y=C4=B1lmaz?= Date: Thu, 26 Dec 2024 22:01:55 +0300 Subject: [PATCH 4/5] feat: update package content on creation --- .changeset/great-lemons-carry.md | 2 +- src/constants/index.ts | 1 + src/constants/package.ts | 5 +++++ src/helpers/updatePackageData.ts | 37 +++++++++++++++++--------------- 4 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 src/constants/package.ts diff --git a/.changeset/great-lemons-carry.md b/.changeset/great-lemons-carry.md index 0f056f6..974cb6d 100644 --- a/.changeset/great-lemons-carry.md +++ b/.changeset/great-lemons-carry.md @@ -2,4 +2,4 @@ '@commencis/cli': patch --- -alter package.json file content +feat: update package.json initial values on generation diff --git a/src/constants/index.ts b/src/constants/index.ts index 7f33bb8..dc8766b 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -1,2 +1,3 @@ export * from './commencisLogo'; +export * from './package'; export * from './template'; diff --git a/src/constants/package.ts b/src/constants/package.ts new file mode 100644 index 0000000..5712ebb --- /dev/null +++ b/src/constants/package.ts @@ -0,0 +1,5 @@ +export const PACKAGE_DEFAULTS = { + version: '1.0.0', + license: 'UNLICENSED', + private: true, +}; diff --git a/src/helpers/updatePackageData.ts b/src/helpers/updatePackageData.ts index ddd8497..bf88210 100644 --- a/src/helpers/updatePackageData.ts +++ b/src/helpers/updatePackageData.ts @@ -1,6 +1,8 @@ import fs from 'node:fs/promises'; import path from 'node:path'; +import { PACKAGE_DEFAULTS } from '@/constants'; + export async function updatePackageData( directoryPath: string, projectName: string @@ -8,27 +10,28 @@ export async function updatePackageData( try { const packageJsonPath = path.join(directoryPath, 'package.json'); const packageJsonData = await fs.readFile(packageJsonPath, 'utf-8'); - let packageJson = JSON.parse(packageJsonData); - const templateVersion = packageJson.version; - - packageJson.name = projectName; - packageJson.version = '1.0.0'; - delete packageJson.license; - delete packageJson.description; - delete packageJson.author; + const { + name: _name, + license: _license, + description: _description, + author: _author, + version: templateVersion, + build, + ...originalPackageJsonData + } = JSON.parse(packageJsonData); - // To add 'private' after common locations such as after 'license' - const { name, version, ...rest } = packageJson; - packageJson = { - name, - version, - license: 'UNLICENSED', - private: true, - ...rest, + const updatedPackageJson = { + name: projectName, + version: PACKAGE_DEFAULTS.version, + build, + license: PACKAGE_DEFAULTS.license, + private: PACKAGE_DEFAULTS.private, + ...originalPackageJsonData, }; - const formattedPackageJson = JSON.stringify(packageJson, null, 2) + '\n'; + const formattedPackageJson = + JSON.stringify(updatedPackageJson, null, 2) + '\n'; await fs.writeFile(packageJsonPath, formattedPackageJson, 'utf-8'); return { templateVersion }; From 9fdf741b80ec2f7c33c9efa0312a532b8d7326a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmetcan=20Y=C4=B1lmaz?= Date: Thu, 26 Dec 2024 22:02:42 +0300 Subject: [PATCH 5/5] chore: revert package version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5bfa177..a139f46 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@commencis/cli", - "version": "1.2.4", + "version": "1.2.3", "description": "Commencis's CLI tool for creating & managing projects", "author": "Commencis WFE Team (https://commencis.com)", "license": "Apache-2.0",