2 Commits

Author SHA1 Message Date
e26bb2b7dd 1.10.1
Some checks failed
Default (tags) / security (push) Failing after 1s
Default (tags) / test (push) Failing after 1s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2025-08-08 12:17:25 +00:00
88e377c425 fix(core): Refactor smartrequest usage, update dependency versions, and improve documentation and tests 2025-08-08 12:17:25 +00:00
10 changed files with 5264 additions and 1394 deletions

View File

@@ -0,0 +1,39 @@
# SmartRequest API Update - January 2025
## Context
The @push.rocks/smartrequest package (v4.2.1) uses a new chainable API that replaced the old function-based API.
## Changes Made
### Old API (v2.x)
```typescript
const response = await plugins.smartrequest.request(url, {
headers: this.headers,
method: 'GET',
queryParams: { key: value }
});
const data = response.body;
```
### New API (v4.x)
```typescript
const requestBuilder = plugins.smartrequest.SmartRequest.create()
.url(url)
.headers(this.headers)
.query({ key: value });
const response = await requestBuilder.get();
const data = await response.json();
```
## Key Differences
1. **Request Creation**: Use `SmartRequest.create()` instead of direct function call
2. **Chainable Methods**: Configure requests with `.url()`, `.headers()`, `.query()`
3. **HTTP Methods**: Use `.get()`, `.post()`, `.delete()` etc. instead of method parameter
4. **Response Parsing**: Call `.json()` on response to get parsed data (was `.body` before)
## Files Updated
- `ts/classes.giteaassets.ts` - Updated the `getFiles()` method to use new API
## Testing
All tests pass successfully, including the GiteaAssets tests that fetch real data from code.foss.global.

View File

@@ -1,5 +1,15 @@
# Changelog # Changelog
## 2025-08-08 - 1.10.1 - fix(core)
Refactor smartrequest usage, update dependency versions, and improve documentation and tests
- Refactored getFiles method in classes.giteaassets to use SmartRequest builder and handle branch query parameters.
- Updated package.json dependency versions for smartfile, smartlog, tsbuild, tsbundle, and tstest.
- Added pnpm-workspace.yaml configuration for onlyBuiltDependencies.
- Enhanced readme with detailed usage instructions, CI/CD integration examples, and advanced feature descriptions.
- Updated test files to import tapbundle from @git.zone/tstest instead of @push.rocks/tapbundle.
- Added .claude/settings.local.json for managing local permissions.
## 2025-08-08 - 1.10.0 - feat(logging) ## 2025-08-08 - 1.10.0 - feat(logging)
Enhance logging and module publishing with color-coded output, progress tracking, and improved CLI startup Enhance logging and module publishing with color-coded output, progress tracking, and improved CLI startup

View File

@@ -1,6 +1,6 @@
{ {
"name": "@git.zone/tspublish", "name": "@git.zone/tspublish",
"version": "1.10.0", "version": "1.10.1",
"private": false, "private": false,
"description": "A tool to publish multiple, concise, and small packages from monorepos, specifically for TypeScript projects within a git environment.", "description": "A tool to publish multiple, concise, and small packages from monorepos, specifically for TypeScript projects within a git environment.",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
@@ -9,7 +9,7 @@
"author": "Task Venture Capital GmbH", "author": "Task Venture Capital GmbH",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "(tstest test/ --web)", "test": "(tstest test/ --verbose --testlog --timeout 30)",
"build": "(tsbuild --web --allowimplicitany)", "build": "(tsbuild --web --allowimplicitany)",
"buildDocs": "(tsdoc)" "buildDocs": "(tsdoc)"
}, },
@@ -17,11 +17,10 @@
"tspublish": "./cli.js" "tspublish": "./cli.js"
}, },
"devDependencies": { "devDependencies": {
"@git.zone/tsbuild": "^2.1.85", "@git.zone/tsbuild": "^2.6.4",
"@git.zone/tsbundle": "^2.1.0", "@git.zone/tsbundle": "^2.5.1",
"@git.zone/tsrun": "^1.3.3", "@git.zone/tsrun": "^1.3.3",
"@git.zone/tstest": "^1.0.44", "@git.zone/tstest": "^2.3.2",
"@push.rocks/tapbundle": "^5.0.15",
"@types/node": "^22.8.7" "@types/node": "^22.8.7"
}, },
"repository": { "repository": {
@@ -51,12 +50,12 @@
"@push.rocks/consolecolor": "^2.0.3", "@push.rocks/consolecolor": "^2.0.3",
"@push.rocks/smartcli": "^4.0.11", "@push.rocks/smartcli": "^4.0.11",
"@push.rocks/smartdelay": "^3.0.5", "@push.rocks/smartdelay": "^3.0.5",
"@push.rocks/smartfile": "^11.0.21", "@push.rocks/smartfile": "^11.2.5",
"@push.rocks/smartlog": "^3.0.7", "@push.rocks/smartlog": "^3.1.8",
"@push.rocks/smartnpm": "^2.0.4", "@push.rocks/smartnpm": "^2.0.4",
"@push.rocks/smartpath": "^5.0.18", "@push.rocks/smartpath": "^6.0.0",
"@push.rocks/smartrequest": "^2.0.23", "@push.rocks/smartrequest": "^4.2.1",
"@push.rocks/smartshell": "^3.0.6" "@push.rocks/smartshell": "^3.2.3"
}, },
"keywords": [ "keywords": [
"typescript", "typescript",

6053
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

4
pnpm-workspace.yaml Normal file
View File

@@ -0,0 +1,4 @@
onlyBuiltDependencies:
- esbuild
- mongodb-memory-server
- puppeteer

472
readme.md
View File

@@ -1,193 +1,375 @@
# @git.zone/tspublish # @git.zone/tspublish 🚀
publish multiple, concise and small packages from monorepos > **Effortlessly publish multiple TypeScript packages from your monorepo**
## Install [![npm version](https://img.shields.io/npm/v/@git.zone/tspublish.svg)](https://www.npmjs.com/package/@git.zone/tspublish)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
To install `@git.zone/tspublish`, you can use npm. To use the latest stable version, run: ## 🌟 What is tspublish?
`@git.zone/tspublish` is your Swiss Army knife for managing and publishing multiple TypeScript packages from a monorepo. It automates the tedious parts of package publishing while giving you full control over the process. Whether you're maintaining a suite of microservices, a component library, or any collection of related packages, tspublish makes your life easier.
### ✨ Key Features
- 📦 **Automatic Package Discovery** - Scans your monorepo for publishable packages
- 🎨 **Beautiful CLI Output** - Color-coded logging with progress indicators
- 🔍 **Version Collision Detection** - Prevents accidental overwrites
- 🏗️ **Build Integration** - Automatically builds TypeScript before publishing
- 🎯 **Smart Dependency Management** - Inherits dependencies from your monorepo
- 🌐 **Multi-Registry Support** - Publish to npm, GitHub packages, or private registries
-**Zero Config** - Works out of the box with sensible defaults
## 📥 Installation
### As a Development Dependency (Recommended)
```bash ```bash
npm install @git.zone/tspublish # Using pnpm (recommended)
pnpm add -D @git.zone/tspublish
# Using npm
npm install --save-dev @git.zone/tspublish
# Using yarn
yarn add -D @git.zone/tspublish
``` ```
Alternatively, if you are using yarn, the equivalent command would be: ### Global Installation
```bash ```bash
yarn add @git.zone/tspublish npm install -g @git.zone/tspublish
``` ```
These commands will add `@git.zone/tspublish` as a dependency in your `package.json` file and install the package into your `node_modules` directory. ## 🚀 Quick Start
## Usage ### 1⃣ Structure Your Monorepo
`@git.zone/tspublish` is designed to manage the publishing of multiple, small-scale packages within monorepos. The following sections will guide you through its usage, from setting up your environment to effectively publishing packages. Organize your packages with the `ts` prefix convention:
### Getting Started with TypeScript and Module Setup
`@git.zone/tspublish` works with monorepos that are organized using TypeScript. The package structure should follow a convention where each submodule intended for publishing is located in a directory prefixed with `ts`, for example, `tsModuleName`. Each submodule directory should contain a `tspublish.json` file to correctly configure the package to be published separately. This file is critical for the `tspublish` process to identify valid package directories and should also include necessary metadata for the package.
Your monorepo structure might resemble:
``` ```
my-monorepo/ my-awesome-monorepo/
├── ts-package1/ ├── package.json # Main monorepo package.json
│ ├── src/ ├── tsconfig.json # Shared TypeScript config
├── tspublish.json ├── ts-core/ # Core package
├── ts-package2/ ├── ts/ # TypeScript source files
│ ├── src/ │ ├── readme.md # Package documentation
── tspublish.json ── tspublish.json # Publishing configuration
├── ts-utils/ # Utilities package
│ ├── ts/
│ ├── readme.md
│ └── tspublish.json
└── ts-cli/ # CLI package
├── ts/
├── readme.md
└── tspublish.json
``` ```
### Configuring `tspublish.json` ### 2 Configure Each Package
Each submodule must include a `tspublish.json` within its directory. This JSON file should include essential details for your publishable package, including its dependencies. Here's a basic example of what `tspublish.json` could look like: Create a `tspublish.json` in each package directory:
```json ```json
{ {
"name": "@myorg/ts-package1", "name": "@myorg/core",
"dependencies": { "order": 1,
"some-dependency": "^1.0.0" "dependencies": [
} "@push.rocks/smartpromise",
"@push.rocks/smartfile"
],
"registries": [
"registry.npmjs.org:public",
"npm.pkg.github.com:private"
],
"bin": ["my-cli"]
} }
``` ```
### Running the CLI #### Configuration Options
`@git.zone/tspublish` includes a CLI that simplifies the publishing process. Begin by importing the CLI runner in a script within your project: | Field | Type | Description |
|-------|------|-------------|
| `name` | string | Package name (required) |
| `order` | number | Build order for interdependent packages |
| `dependencies` | string[] | Dependencies from the monorepo to include |
| `registries` | string[] | Target registries with access level |
| `bin` | string[] | CLI executable names |
```typescript ### 3⃣ Run the Publisher
import { runCli } from '@git.zone/tspublish';
runCli(); #### Command Line
```bash
# From your monorepo root
npx tspublish
``` ```
This function call orchestrates the publishing operation. It reads each directory prefixed with `ts`, looks for a `tspublish.json`, and creates an individual package based on the gathered data. #### Programmatic Usage
### Core Features
#### Publishing Modules
The core functionality provided by `@git.zone/tspublish` involves processing directories to check for valid submodules that are ready to be published. This occurs via the `publish` method in `TsPublish` class. This method does the following:
- **Reads all directories** within the specified monorepo path.
- **Identifies directories** that start with `ts` and validates the presence of `tspublish.json`.
- **Logs** information about found packages for user awareness and debugging.
- **Checks for collisions** with existing versions on the npm registry to prevent overriding published versions.
```typescript ```typescript
import { TsPublish } from '@git.zone/tspublish'; import { TsPublish } from '@git.zone/tspublish';
const tspublish = new TsPublish(); const publisher = new TsPublish();
await tspublish.publish('/path/to/your/monorepo'); await publisher.publish(process.cwd());
``` ```
#### Package Initialization ## 🎯 Advanced Usage
Once valid submodules are identified, the `init` method in the `PublishModule` class initializes the publish module. This includes: ### Custom Publishing Pipeline
- Parsing `tspublish.json` for metadata.
- Constructing full paths for necessary operations.
- Verifying package existence to avoid duplication.
```typescript ```typescript
import { PublishModule } from '@git.zone/tspublish'; import { TsPublish, PublishModule } from '@git.zone/tspublish';
const publishModule = new PublishModule({ // Initialize the publisher
monoRepoDir: '/path/to/monorepo', const publisher = new TsPublish();
packageSubFolder: 'ts-package1',
});
await publishModule.init(); // Get all publishable modules
``` const modules = await publisher.getModuleSubDirs('./my-monorepo');
#### Creating `package.json` // Custom processing for each module
for (const [name, config] of Object.entries(modules)) {
Part of the publishing process involves automatically creating a `package.json` tailored to each submodule. This dynamically generated JSON will incorporate dependencies from `tspublish.json` and associate them with the latest version of `tsbuild` from the registry: const module = new PublishModule(publisher, {
monoRepoDir: './my-monorepo',
```typescript packageSubFolder: name
await publishModule.createPackageJson();
```
This creates a structured `package.json` which includes scripts to build your TypeScript files before publishing.
#### Constructing Publish-ready Directory
After all configurations are verified and the `package.json` is created, the submodule is ready to be published. This step involves setting up a `dist_publish_` directory specific to each module:
```typescript
await publishModule.createPublishModuleDir();
```
The above method ensures that each module's source files are copied and prepared under a dedicated directory meant for packaging and distribution.
### Logging and Debugging
The package includes a structured logging mechanism using `smartlog` which provides insights into the publishing process, helping in runtime debugging and status tracking of operations:
```typescript
import { logger } from '@git.zone/tspublish/logging';
logger.log('info', 'Publishing process initialized');
```
This powerful logging helps in tracking the status of each step and understanding potential issues during the operations.
### Testing with tapbundle
To ensure that your publishing workflow is functioning correctly, you can utilize the test suite set up with `tapbundle`. This library facilitates behavior-driven testing for your monorepo. Below is a basic test setup to verify the import and initial function accessibility of `@git.zone/tspublish`:
```typescript
import { expect, tap } from '@push.rocks/tapbundle';
import * as tspublish from '@git.zone/tspublish';
tap.test('Should run the CLI without errors', async () => {
await tspublish.runCli();
expect(tspublish).toBeTruthy();
});
tap.start();
```
### Comprehensive usage example
Let's combine all the steps into a complete example where you prepare a monorepo, configure each module, and execute the publishing workflow.
Suppose you have a project structure as follows:
```plaintext
my-monorepo/
├── ts-package1/
│ ├── src/
│ ├── tspublish.json
├── ts-package2/
│ ├── src/
│ ├── tspublish.json
```
Follow these steps:
1. Ensure each package has `tspublish.json` properly configured with necessary metadata.
2. Create a CLI script such as `publish.js`:
```typescript
import { runCli } from '@git.zone/tspublish';
runCli()
.then(() => {
console.log('Publishing completed successfully');
})
.catch((error) => {
console.error('Error during publishing:', error);
}); });
// Initialize module
await module.init();
// Create publish directory
await module.createPublishModuleDir();
// Custom build step
console.log(`Building ${config.name}...`);
await module.build();
// Publish to registries
await module.publish();
}
``` ```
3. Execute your CLI script: ### Registry Configuration
```bash TSPublish supports multiple registries with different access levels:
node publish.js
```json
{
"registries": [
"registry.npmjs.org:public", // Public npm package
"npm.pkg.github.com:private", // Private GitHub package
"my-company.jfrog.io/npm:restricted" // Corporate registry
]
}
``` ```
Your script will call `runCli`, which will traverse each `ts-package`, verify their publish readiness, and handle individual publishing processes. ### Build Order Management
By following these comprehensive guidelines and utilizing the structured approach provided by `@git.zone/tspublish`, you can efficiently manage and publish multiple sub-packages from within a monorepo, facilitating organized, modular package management in projects of any scale. When packages depend on each other, use the `order` field to ensure correct build sequence:
undefined
```json
// ts-core/tspublish.json
{
"name": "@myorg/core",
"order": 1,
"dependencies": []
}
// ts-utils/tspublish.json
{
"name": "@myorg/utils",
"order": 2,
"dependencies": ["@myorg/core"]
}
```
### CLI Binary Configuration
For packages that include CLI tools:
```json
{
"name": "@myorg/cli",
"bin": ["my-cli", "my-tool"],
"dependencies": ["commander", "chalk"]
}
```
This automatically generates the necessary `cli.js` wrapper and configures the package.json `bin` field.
## 🎨 Beautiful Output
TSPublish provides rich, colored console output with:
- 📊 Progress bars for multi-package operations
- 🎯 Clear status indicators ( info, ✓ success, ⚠ warning, ✖ error)
- 📦 Package-specific icons and formatting
- 🚀 Visual separators between operation phases
## 🔧 How It Works
1. **Discovery Phase** 🔍
- Scans for directories starting with `ts`
- Validates `tspublish.json` presence
- Orders packages by dependency
2. **Preparation Phase** 📋
- Creates temporary `dist_publish_*` directories
- Generates package.json from tspublish.json
- Copies source files and assets
- Sets up TypeScript configuration
3. **Build Phase** 🔨
- Runs TypeScript compilation
- Generates declaration files
- Prepares distribution bundle
4. **Validation Phase**
- Checks npm registry for existing versions
- Prevents accidental overwrites
- Validates package metadata
5. **Publishing Phase** 🚀
- Publishes to configured registries
- Handles authentication
- Reports success/failure
## 🤝 Integration with CI/CD
### GitHub Actions
```yaml
name: Publish Packages
on:
push:
tags:
- 'v*'
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/setup-node@v3
with:
node-version: '20'
cache: 'pnpm'
- run: pnpm install
- run: pnpm build
- run: npx tspublish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
```
### GitLab CI
```yaml
publish:
stage: deploy
image: node:20
before_script:
- npm install -g pnpm
- pnpm install
script:
- pnpm build
- npx tspublish
only:
- tags
```
## 📚 API Reference
### TsPublish Class
```typescript
class TsPublish {
// Publish all packages in a monorepo
async publish(monorepoDirPath: string): Promise<void>
// Get all publishable module configurations
async getModuleSubDirs(dirPath: string): Promise<{[key: string]: ITsPublishJson}>
}
```
### PublishModule Class
```typescript
class PublishModule {
// Initialize the module for publishing
async init(): Promise<void>
// Create the publishing directory structure
async createPublishModuleDir(): Promise<void>
// Build the TypeScript package
async build(): Promise<void>
// Publish to configured registries
async publish(): Promise<void>
}
```
### ITsPublishJson Interface
```typescript
interface ITsPublishJson {
name: string // Package name
order: number // Build order
dependencies: string[] // Dependencies to include
registries: string[] // Target registries
bin: string[] // CLI binaries
}
```
## 🐛 Troubleshooting
### Common Issues
**Package already exists with version X.X.X**
- TSPublish detected a version collision
- Update your monorepo's package.json version
- Or unpublish the existing version if appropriate
**No publish modules found**
- Ensure your packages follow the `ts-*` naming convention
- Check that each package has a valid `tspublish.json`
**Build failures**
- Verify TypeScript configuration
- Check that all dependencies are installed
- Review the build output for specific errors
## 🔮 Future Features
- 🎯 Selective publishing with pattern matching
- 🔄 Automatic version bumping strategies
- 📊 Dry-run mode with detailed preview
- 🏷️ Git tag integration
- 📝 Changelog generation
- 🔐 Enhanced authentication handling
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**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 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, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require 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.

View File

@@ -1,4 +1,4 @@
import { expect, tap } from '@push.rocks/tapbundle'; import { expect, tap } from '@git.zone/tstest/tapbundle';
import * as giteaAssets from '../ts/classes.giteaassets.js'; import * as giteaAssets from '../ts/classes.giteaassets.js';
let giteaAssetsInstance: giteaAssets.GiteaAssets; let giteaAssetsInstance: giteaAssets.GiteaAssets;

View File

@@ -1,4 +1,4 @@
import { expect, expectAsync, tap } from '@push.rocks/tapbundle'; import { expect, tap } from '@git.zone/tstest/tapbundle';
import * as tspublish from '../ts/index.js'; import * as tspublish from '../ts/index.js';
tap.test('first test', async () => { tap.test('first test', async () => {

View File

@@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@git.zone/tspublish', name: '@git.zone/tspublish',
version: '1.10.0', version: '1.10.1',
description: 'A tool to publish multiple, concise, and small packages from monorepos, specifically for TypeScript projects within a git environment.' description: 'A tool to publish multiple, concise, and small packages from monorepos, specifically for TypeScript projects within a git environment.'
} }

View File

@@ -44,37 +44,42 @@ export class GiteaAssets {
branch?: string branch?: string
): Promise<IRepoFile[]> { ): Promise<IRepoFile[]> {
try { try {
const response = await plugins.smartrequest.request( const requestBuilder = plugins.smartrequest.SmartRequest.create()
this.baseUrl + `/repos/${owner}/${repo}/contents/${directory}`, .url(this.baseUrl + `/repos/${owner}/${repo}/contents/${directory}`)
{ .headers(this.headers);
headers: this.headers,
method: 'GET', if (branch) {
queryParams: branch ? { ref: branch } : {}, requestBuilder.query({ ref: branch });
} }
)
if (!Array.isArray(response.body) && typeof response.body === 'object') { const response = await requestBuilder.get();
response.body = [response.body]; let responseBody = await response.json();
} else if (Array.isArray(response.body)) {
for (const entry of response.body) { if (!Array.isArray(responseBody) && typeof responseBody === 'object') {
responseBody = [responseBody];
} else if (Array.isArray(responseBody)) {
for (const entry of responseBody) {
if (entry.type === 'dir') { if (entry.type === 'dir') {
continue; continue;
} else if (entry.type === 'file') { } else if (entry.type === 'file') {
const response2 = await plugins.smartrequest.request( const requestBuilder2 = plugins.smartrequest.SmartRequest.create()
this.baseUrl + `/repos/${owner}/${repo}/contents/${entry.path}`, .url(this.baseUrl + `/repos/${owner}/${repo}/contents/${entry.path}`)
{ .headers(this.headers);
headers: this.headers,
method: 'GET', if (branch) {
queryParams: branch ? { ref: branch } : {}, requestBuilder2.query({ ref: branch });
} }
);
entry.encoding = response2.body.encoding; const response2 = await requestBuilder2.get();
entry.content = response2.body.content; const response2Body = await response2.json();
entry.encoding = response2Body.encoding;
entry.content = response2Body.content;
} }
} }
} }
// lets map to the IRepoFile interface // lets map to the IRepoFile interface
response.body = response.body.map((entry: any) => { responseBody = responseBody.map((entry: any) => {
return { return {
name: entry.name, name: entry.name,
path: entry.path, path: entry.path,
@@ -85,7 +90,7 @@ export class GiteaAssets {
}; };
}); });
return response.body; return responseBody;
} catch (error) { } catch (error) {
console.error('Error fetching repository files:', error); console.error('Error fetching repository files:', error);
throw error; throw error;