# @push.rocks/projectinfo

A tool for gathering project information, supporting npm, git, and more.

# readme.md for @push.rocks/projectinfo

A tool for gathering project information, supporting npm, git, and more.

## Issue Reporting and Security

For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.

## Install 📦

Install via npm:

```bash
npm install @push.rocks/projectinfo
```

Or with pnpm:

```bash
pnpm install @push.rocks/projectinfo
```

This module is ESM-only and requires Node.js 18+.

## Usage 🚀

`@push.rocks/projectinfo` provides an async API for extracting npm and git metadata from any project directory. It uses `@push.rocks/smartfs` under the hood for filesystem operations.

All classes use async factory methods — no synchronous constructors.

### Quick Start

```typescript
import { ProjectInfo, ProjectinfoNpm, getNpmNameForDir } from '@push.rocks/projectinfo';
```

### Get Full Project Info

The `ProjectInfo` class is the main entry point. It gathers both npm and git info from a given directory:

```typescript
import { ProjectInfo } from '@push.rocks/projectinfo';

const info = await ProjectInfo.create('./my-project');

// npm info
console.log(info.npm.name);       // e.g. "@push.rocks/projectinfo"
console.log(info.npm.version);    // e.g. "5.0.2"
console.log(info.npm.license);    // e.g. "MIT"
console.log(info.npm.isNpm);      // true if package.json exists

// git info (parsed from directory path)
console.log(info.git.gitrepo);    // e.g. "projectinfo"
console.log(info.git.gituser);    // e.g. "push.rocks"

// project type
console.log(info.type);           // "npm" if package.json found, otherwise "git"
```

### NPM Info Only

Use `ProjectinfoNpm` directly when you only need package.json data:

```typescript
import { ProjectinfoNpm } from '@push.rocks/projectinfo';

const npm = await ProjectinfoNpm.create('/path/to/project');

if (npm.isNpm) {
  console.log(npm.name);           // package name
  console.log(npm.version);        // package version
  console.log(npm.license);        // license field
  console.log(npm.packageJson);    // full parsed package.json object
}
```

#### With Git Access Token

If your `package.json` has a `repository` field, `ProjectinfoNpm` will parse it into a `GitRepo` object. You can provide an access token for authenticated URLs:

```typescript
const npm = await ProjectinfoNpm.create('/path/to/project', {
  gitAccessToken: 'ghp_your_token_here',
});

if (npm.git) {
  console.log(npm.git.httpsUrl);  // e.g. "https://ghp_your_token_here@github.com/user/repo.git"
}
```

### Git Info Only

Use `ProjectinfoGit` for path-based git metadata extraction:

```typescript
import { ProjectinfoGit } from '@push.rocks/projectinfo';

// Parses the directory path to extract git user and repo
const git = new ProjectinfoGit('/home/user/repos/myorg/myrepo');

console.log(git.gituser);  // "myorg"
console.log(git.gitrepo);  // "myrepo"
```

You can also parse a remote URL:

```typescript
git.getGitInfoFromRemote('git+https://github.com/someuser/somerepo.git');
```

### Quick Helper: Get Package Name

A convenience function to quickly get the npm package name from a directory:

```typescript
import { getNpmNameForDir } from '@push.rocks/projectinfo';

const name = await getNpmNameForDir('./my-project');
console.log(name); // e.g. "@push.rocks/projectinfo"
```

Returns `undefined` if no valid `package.json` is found.

### API Reference

| Class / Function | Description |
|---|---|
| `ProjectInfo.create(cwd)` | Async factory — gathers both npm + git info |
| `ProjectinfoNpm.create(cwd, opts?)` | Async factory — parses `package.json` |
| `ProjectinfoGit(cwd)` | Sync constructor — extracts git info from path |
| `getNpmNameForDir(cwd)` | Async helper — returns the npm package name |

### Types

```typescript
type TProjectType = 'git' | 'npm';
```

## License and Legal Information

This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./license) file.

**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

### Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.

Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.

### Company Information

Task Venture Capital GmbH
Registered at District Court Bremen HRB 35230 HB, Germany

For any legal inquiries or further information, please contact us via email at hello@task.vc.

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.

# changelog.md for @push.rocks/projectinfo

## 2026-03-26 - 5.1.0 - feat(projectinfo)
migrate project info loading to async factories and update build configuration

- replace synchronous npm metadata loading with async factory methods in ProjectInfo and ProjectinfoNpm
- switch filesystem access from @push.rocks/smartfile to @push.rocks/smartfs and update helper/tests for async usage
- refresh build tooling and project metadata configuration, including .smartconfig.json and tsbuild script updates

## 2024-05-29 - 5.0.2 - maintenance
Repository metadata and configuration updates across 5.0.2.

- Updated project description
- Updated TypeScript configuration
- Updated npmextra.json githost settings

## 2023-08-08 - 5.0.1 - core
Small core maintenance release with repository organization updates.

- Fixed a core update
- Switched to the new organization scheme

## 2022-04-18 - 5.0.0 - core
Major release introducing an ESM migration.

- BREAKING CHANGE: switched the package to ESM
- Included a core update alongside the release

## 2020-06-01 - 4.0.3-4.0.5 - core
Grouped maintenance releases with repeated core update work.

- 4.0.3 and 4.0.4 delivered routine core fixes
- 4.0.5 introduced a breaking change by switching core packaging behavior toward ESM compatibility

## 2018-09-02 - 4.0.0-4.0.2 - package
Infrastructure and package metadata updates across the 4.0.x line.

- 4.0.0 updated CI configuration
- 4.0.1 fixed the private parameter in package.json
- 4.0.2 delivered another core update

## 2018-09-02 - 3.0.4-3.0.5 - scope
Dependency maintenance followed by a breaking scope adjustment.

- 3.0.4 updated dependencies
- 3.0.5 introduced a BREAKING CHANGE by changing scope

## 2017-09-22 - 3.0.1-3.0.3 - maintenance
Routine maintenance releases focused on dependencies, CI, and documentation.

- 3.0.1 updated dependencies and README
- 3.0.2 updated dependencies
- 3.0.3 updated CI

## 2016-11-26 - 3.0.0 - documentation
Documentation-only release.

- Updated README

## 2016-11-26 - 2.0.0 - core
Feature release introducing the main project information class.

- Added the ProjectInfo main class

## 2016-10-27 - 1.0.3-1.0.4 - maintenance
Project standards, tooling, and documentation improvements.

- 1.0.3 updated smartfile, CI base image, and added README
- 1.0.4 updated the project to meet newer standards

## 2016-06-08 - 1.0.1-1.0.2 - refactor
Dependency and structure updates across early 1.x releases.

- 1.0.1 updated dependencies and restructured code
- 1.0.2 updated dependencies, project structure, and typings configuration

## 2016-02-23 - 1.0.0 - core
Initial stable release with token handling improvements.

- Added token handling correctly
- Included a small lint fix

## 2016-02-21 - 0.0.3-0.0.5 - core
Early project setup and metadata expansion.

- 0.0.3 updated project structure
- 0.0.4 added .license support to the npm class
- 0.0.5 added repository information and git metadata

## 2016-02-20 - 0.0.0-0.0.2 - bootstrap
Initial bootstrap releases establishing the project foundation.

- Added Travis CI setup
- Added a second npm version
- Added the getName function