diff --git a/.changeset/great-lemons-carry.md b/.changeset/great-lemons-carry.md new file mode 100644 index 0000000..974cb6d --- /dev/null +++ b/.changeset/great-lemons-carry.md @@ -0,0 +1,5 @@ +--- +'@commencis/cli': patch +--- + +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 13b0ef7..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,13 +10,28 @@ 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); - const templateVersion = packageJson.version; - packageJson.name = projectName; - packageJson.version = '1.0.0'; + const { + name: _name, + license: _license, + description: _description, + author: _author, + version: templateVersion, + build, + ...originalPackageJsonData + } = JSON.parse(packageJsonData); + + 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 };