Skip to content

feat(version): read app info from package.json #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 25, 2022
Merged

feat(version): read app info from package.json #174

merged 7 commits into from
Jul 25, 2022

Conversation

AvinashReddy3108
Copy link
Contributor

Basically, an extension of this commit for other applicable fields in the AppInfo array.

@AvinashReddy3108
Copy link
Contributor Author

One possible extensions to this PR

  • populate AppInfo fields only from package.json .. like so (also removing related variables from the .env file)
const AppInfo = {
  APP_VERSION: readPackageJsonSync().version,
  APP_NAME: readPackageJsonSync().name,
  APP_DESCRIPTION: readPackageJsonSync().description,
  AUTHOR_NAME: readPackageJsonSync().author?.name,
  AUTHOR_EMAIL: readPackageJsonSync().author?.email,
  AUTHOR_WEBSITE: readPackageJsonSync().author?.url
};

But I was hesitant to make this change for now as I don't know the reason behind you using environment variables for these stuff..

@borjapazr
Copy link
Owner

One possible extensions to this PR

  • populate AppInfo fields only from package.json .. like so (also removing related variables from the .env file)
const AppInfo = {
  APP_VERSION: readPackageJsonSync().version,
  APP_NAME: readPackageJsonSync().name,
  APP_DESCRIPTION: readPackageJsonSync().description,
  AUTHOR_NAME: readPackageJsonSync().author?.name,
  AUTHOR_EMAIL: readPackageJsonSync().author?.email,
  AUTHOR_WEBSITE: readPackageJsonSync().author?.url
};

But I was hesitant to make this change for now as I don't know the reason behind you using environment variables for these stuff..

Hi @AvinashReddy3108 ! First of all, thank you for your PR. I think it is a very good idea 👌 Anyway, before merge the PR it is necessary to correct the problems reported by tsc.

The environment variables are there to provide an option to overwrite all this information. For example, imagine that when you are going to deploy the application in a productive environment you prefer to show the information of the company and not of the developer who implemented the application. In this way, unless overwritten, the package.json data will always be shown, but if we want others for any reason, they could be provided in a very simple way.

@AvinashReddy3108
Copy link
Contributor Author

AvinashReddy3108 commented Jul 22, 2022

Anyway, before merge the PR it is necessary to correct the problems reported by tsc.

Never faced those issues in my local machine (node 18.x), but tried to solve them nonetheless.

PS: the PR's commit history looks embarrassing (sorry about that), please "Squash and Merge" if the CI runs pass.

@AvinashReddy3108
Copy link
Contributor Author

The environment variables are there to provide an option to overwrite all this information. For example, imagine that when you are going to deploy the application in a productive environment you prefer to show the information of the company and not of the developer who implemented the application. In this way, unless overwritten, the package.json data will always be shown, but if we want others for any reason, they could be provided in a very simple way.

@borjapazr I also updated the .env file with the related variables (these are commented out by default)

But won't it be better if there's a .env.sample tracked by version control, and then .env in the .gitignore (As the .env contains sensitive info like database passwords and stuff)

@borjapazr borjapazr merged commit 646ca19 into borjapazr:main Jul 25, 2022
borjapazr added a commit that referenced this pull request Jul 25, 2022
* package.json: follow npm Docs guidelines

https://docs.npmjs.com/cli/v8/configuring-npm/package-json#people-fields-author-contributors

* app.config.ts: read more stuff from package.json

The package `read-pkg` allows for it, let's use it :)

* package.json: fix author URL

* fix tsc errors

* fix(appinfo): ran prettier

* Update .env

Co-authored-by: Borja Paz Rodríguez <borjapazr@gmail.com>
@AvinashReddy3108 AvinashReddy3108 deleted the patch-1 branch July 26, 2022 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants