Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
9b3d77189a | |||
eb21dcc4a4 | |||
66145c904e | |||
23f89eabf3 | |||
51ca619151 | |||
6a8c860c79 | |||
9fdbf7f154 | |||
50456fc004 | |||
1cb97cbf95 | |||
f8ceff48b2 | |||
910cb4c8bf | |||
9bddf09aa7 | |||
4e8671a21d | |||
78c73ee713 | |||
5b768288c5 | |||
023aea2494 |
49
changelog.md
49
changelog.md
@ -1,5 +1,54 @@
|
||||
# Changelog
|
||||
|
||||
## 2025-01-02 - 1.9.1 - fix(publishmodule)
|
||||
Fix incorrect CLI script path during publish module creation
|
||||
|
||||
- Updated the `createBinCliSetup` method to correctly adjust the CLI script path.
|
||||
- Replaced path in base64-decoded CLI file content from './dist_ts/index.js' to './dist_<packageSubFolder>/index.js'.
|
||||
|
||||
## 2025-01-02 - 1.9.0 - feat(core)
|
||||
Refactor gitea asset handling and module initialization
|
||||
|
||||
- Introduced GiteaAssets class to handle gitea asset fetching.
|
||||
- Updated TsPublish and PublishModule classes to use GiteaAssets.
|
||||
- Fixed queryParams in getFiles method of GiteaAssets.
|
||||
|
||||
## 2025-01-01 - 1.8.0 - feat(core)
|
||||
Added GiteaAssets class for managing files in Gitea repositories
|
||||
|
||||
- Introduced GiteaAssets class to handle file retrieval from Gitea repositories.
|
||||
- Added tests for GiteaAssets implementation.
|
||||
- Updated plugins module to include smartrequest for HTTP requests.
|
||||
|
||||
## 2024-11-05 - 1.7.7 - fix(core)
|
||||
Fix dependency resolution in package initialization
|
||||
|
||||
- Corrected the resolution of dependencies from tspublish.json against monorepo's package.json.
|
||||
- Ensures unlisted dependencies in monorepo's package.json default to its version.
|
||||
|
||||
## 2024-11-05 - 1.7.6 - fix(tspublish)
|
||||
Fix the logging of the number of found publish modules
|
||||
|
||||
- Corrected the way the number of publish modules is logged by using Object.keys(publishModules).length instead of publishModules.length.
|
||||
|
||||
## 2024-11-05 - 1.7.5 - fix(core)
|
||||
Fix issue with tspublish.json name validation in TsPublish class
|
||||
|
||||
- Resolved incorrect JSON parsing and validation for 'name' property in tspublish.json in the TsPublish.publish method.
|
||||
- Removed redundant JSON parse from plugin.smartfile.fs.toStringSync in publish method.
|
||||
|
||||
## 2024-11-05 - 1.7.4 - fix(classes.tspublish)
|
||||
Refactor getModuleSubDirs method to streamline name validation for publish modules
|
||||
|
||||
- Moved the check for the presence of the 'name' field in tspublish.json from getModuleSubDirs to the publish method.
|
||||
- Added log warning and continue flow if 'name' is not found during the publish process.
|
||||
|
||||
## 2024-11-05 - 1.7.3 - fix(TsPublish)
|
||||
Add validation for tspublish.json name field
|
||||
|
||||
- Ensure that the tspublish.json file contains a valid name field before processing.
|
||||
- Log a warning message if the name is not found in tspublish.json.
|
||||
|
||||
## 2024-11-05 - 1.7.2 - fix(project)
|
||||
Fixed minor formatting issues and improved code consistency.
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@git.zone/tspublish",
|
||||
"version": "1.7.2",
|
||||
"version": "1.9.1",
|
||||
"private": false,
|
||||
"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",
|
||||
@ -14,7 +14,7 @@
|
||||
"buildDocs": "(tsdoc)"
|
||||
},
|
||||
"bin": {
|
||||
"tspublish": "cli.js"
|
||||
"tspublish": "./cli.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@git.zone/tsbuild": "^2.1.85",
|
||||
@ -54,6 +54,7 @@
|
||||
"@push.rocks/smartlog": "^3.0.7",
|
||||
"@push.rocks/smartnpm": "^2.0.4",
|
||||
"@push.rocks/smartpath": "^5.0.18",
|
||||
"@push.rocks/smartrequest": "^2.0.23",
|
||||
"@push.rocks/smartshell": "^3.0.6"
|
||||
},
|
||||
"keywords": [
|
||||
|
7400
pnpm-lock.yaml
generated
7400
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
39
test/test.giteaassets.ts
Normal file
39
test/test.giteaassets.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import * as giteaAssets from '../ts/classes.giteaassets.js';
|
||||
|
||||
let giteaAssetsInstance: giteaAssets.GiteaAssets;
|
||||
|
||||
tap.test('should create a GiteaAssets instance', async () => {
|
||||
giteaAssetsInstance = new giteaAssets.GiteaAssets({
|
||||
giteaBaseUrl: 'https://code.foss.global',
|
||||
});
|
||||
expect(giteaAssetsInstance).toBeInstanceOf(giteaAssets.GiteaAssets);
|
||||
});
|
||||
|
||||
tap.test('should get files from a repository', async () => {
|
||||
const files = await giteaAssetsInstance.getFiles('git.zone', 'cli', 'assets/templates/cli');
|
||||
console.log(files);
|
||||
|
||||
for (const file of files) {
|
||||
if (file.name.endsWith('cli.js')) {
|
||||
console.log(atob(file.base64Content));
|
||||
}
|
||||
}
|
||||
|
||||
expect(files).toBeTruthy();
|
||||
});
|
||||
|
||||
tap.test('should get files from a repository', async () => {
|
||||
const files = await giteaAssetsInstance.getFiles('git.zone', 'cli', 'assets/templates/cli/cli.js');
|
||||
console.log(files);
|
||||
|
||||
for (const file of files) {
|
||||
if (file.name.endsWith('cli.js')) {
|
||||
console.log(atob(file.base64Content));
|
||||
}
|
||||
}
|
||||
|
||||
expect(files).toBeTruthy();
|
||||
});
|
||||
|
||||
tap.start();
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@git.zone/tspublish',
|
||||
version: '1.7.2',
|
||||
version: '1.9.1',
|
||||
description: 'A tool to publish multiple, concise, and small packages from monorepos, specifically for TypeScript projects within a git environment.'
|
||||
}
|
||||
|
103
ts/classes.giteaassets.ts
Normal file
103
ts/classes.giteaassets.ts
Normal file
@ -0,0 +1,103 @@
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
interface IRepoFile {
|
||||
name: string;
|
||||
path: string;
|
||||
type: 'file' | 'dir';
|
||||
download_url: string | null;
|
||||
base64Content: string | null;
|
||||
encoding: string | null;
|
||||
}
|
||||
|
||||
interface IGiteaAssetsOptions {
|
||||
giteaBaseUrl: string; // Base URL of your Gitea instance
|
||||
token?: string; // Optional token for private repositories
|
||||
}
|
||||
|
||||
export class GiteaAssets {
|
||||
private baseUrl: string;
|
||||
private headers: {[key: string]: string} = {};
|
||||
|
||||
constructor(options: IGiteaAssetsOptions) {
|
||||
this.baseUrl = options.giteaBaseUrl
|
||||
if (this.baseUrl.endsWith('/')) {
|
||||
this.baseUrl = this.baseUrl.slice(0, -1);
|
||||
}
|
||||
this.baseUrl += '/api/v1';
|
||||
this.headers = options.token
|
||||
? { ...this.headers, 'Authorization': `token ${options.token}` }
|
||||
: this.headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all files in a directory of a repository
|
||||
* @param owner - Repository owner
|
||||
* @param repo - Repository name
|
||||
* @param directory - Directory path ('' for root)
|
||||
* @param branch - Branch name (optional)
|
||||
* @returns A list of files in the directory
|
||||
*/
|
||||
async getFiles(
|
||||
owner: string,
|
||||
repo: string,
|
||||
directory: string,
|
||||
branch?: string
|
||||
): Promise<IRepoFile[]> {
|
||||
try {
|
||||
const response = await plugins.smartrequest.request(
|
||||
this.baseUrl + `/repos/${owner}/${repo}/contents/${directory}`,
|
||||
{
|
||||
headers: this.headers,
|
||||
method: 'GET',
|
||||
queryParams: branch ? { ref: branch } : {},
|
||||
}
|
||||
)
|
||||
if (!Array.isArray(response.body) && typeof response.body === 'object') {
|
||||
response.body = [response.body];
|
||||
} else if (Array.isArray(response.body)) {
|
||||
for (const entry of response.body) {
|
||||
if (entry.type === 'dir') {
|
||||
continue;
|
||||
} else if (entry.type === 'file') {
|
||||
const response2 = await plugins.smartrequest.request(
|
||||
this.baseUrl + `/repos/${owner}/${repo}/contents/${entry.path}`,
|
||||
{
|
||||
headers: this.headers,
|
||||
method: 'GET',
|
||||
queryParams: branch ? { ref: branch } : {},
|
||||
}
|
||||
);
|
||||
entry.encoding = response2.body.encoding;
|
||||
entry.content = response2.body.content;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// lets map to the IRepoFile interface
|
||||
response.body = response.body.map((entry: any) => {
|
||||
return {
|
||||
name: entry.name,
|
||||
path: entry.path,
|
||||
type: entry.type,
|
||||
download_url: entry.download_url,
|
||||
base64Content: entry.content,
|
||||
encoding: entry.encoding,
|
||||
};
|
||||
});
|
||||
|
||||
return response.body;
|
||||
} catch (error) {
|
||||
console.error('Error fetching repository files:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the current cli entry file from the code.foss.global/git.zone/cli repository
|
||||
* @returns
|
||||
*/
|
||||
public async getBinCliEntryFile() {
|
||||
const files = await this.getFiles('git.zone', 'cli', 'assets/templates/cli/cli.js');
|
||||
return files[0];
|
||||
}
|
||||
}
|
@ -2,11 +2,8 @@ import * as plugins from './plugins.js';
|
||||
import * as paths from './paths.js';
|
||||
import { logger } from './logging.js';
|
||||
|
||||
export interface ITsPublishJson {
|
||||
name: string;
|
||||
dependencies: string[];
|
||||
registries: string[];
|
||||
}
|
||||
import { type ITsPublishJson } from './interfaces/index.js';
|
||||
import type { TsPublish } from './classes.tspublish.js';
|
||||
|
||||
export interface IPublishModuleOptions {
|
||||
monoRepoDir: string;
|
||||
@ -20,15 +17,17 @@ export interface IPublishModuleOptions {
|
||||
}
|
||||
|
||||
export class PublishModule {
|
||||
tsPublishRef: TsPublish;
|
||||
public options: IPublishModuleOptions;
|
||||
constructor(options: IPublishModuleOptions) {
|
||||
constructor(tsPublishRef: TsPublish, options: IPublishModuleOptions) {
|
||||
this.tsPublishRef = tsPublishRef;
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
public async init() {
|
||||
this.options.packageSubFolderFullPath = plugins.path.join(
|
||||
this.options.monoRepoDir,
|
||||
this.options.packageSubFolder,
|
||||
this.options.packageSubFolder
|
||||
);
|
||||
|
||||
// check requirements
|
||||
@ -36,19 +35,24 @@ export class PublishModule {
|
||||
throw new Error('subFolder must start with "ts"');
|
||||
}
|
||||
this.options.tsPublishJson = plugins.smartfile.fs.toObjectSync(
|
||||
plugins.path.join(this.options.packageSubFolderFullPath, 'tspublish.json'),
|
||||
plugins.path.join(this.options.packageSubFolderFullPath, 'tspublish.json')
|
||||
);
|
||||
|
||||
// the package.json of the parent mono repo
|
||||
const monoRepoPackageJson = JSON.parse(
|
||||
plugins.smartfile.fs.toStringSync(
|
||||
plugins.path.join(this.options.monoRepoDir, 'package.json'),
|
||||
),
|
||||
plugins.smartfile.fs.toStringSync(plugins.path.join(this.options.monoRepoDir, 'package.json'))
|
||||
);
|
||||
|
||||
this.options.dependencies = {
|
||||
...this.options.dependencies,
|
||||
...(() => {
|
||||
const resultDependencies = {};
|
||||
for (const dependency of this.options.tsPublishJson.dependencies) {
|
||||
resultDependencies[dependency] = monoRepoPackageJson.dependencies[dependency];
|
||||
if (monoRepoPackageJson.dependencies[dependency]) {
|
||||
resultDependencies[dependency] = monoRepoPackageJson.dependencies[dependency];
|
||||
} else {
|
||||
resultDependencies[dependency] = monoRepoPackageJson.version;
|
||||
}
|
||||
}
|
||||
return resultDependencies;
|
||||
})(),
|
||||
@ -71,7 +75,7 @@ export class PublishModule {
|
||||
if (availableVersions.includes(this.options.version)) {
|
||||
logger.log(
|
||||
'error',
|
||||
`package ${this.options.name} already exists with version ${this.options.version}`,
|
||||
`package ${this.options.name} already exists with version ${this.options.version}`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
@ -89,12 +93,13 @@ export class PublishModule {
|
||||
|
||||
public async createTsconfigJson() {
|
||||
const originalTsConfig = plugins.smartfile.fs.toObjectSync(
|
||||
plugins.path.join(paths.cwd, 'tsconfig.json'),
|
||||
plugins.path.join(paths.cwd, 'tsconfig.json')
|
||||
);
|
||||
if (originalTsConfig?.compilerOptions?.paths) {
|
||||
for (const path of Object.keys(originalTsConfig.compilerOptions.paths)) {
|
||||
originalTsConfig.compilerOptions.paths[path][0] =
|
||||
`.${originalTsConfig.compilerOptions.paths[path][0]}`;
|
||||
originalTsConfig.compilerOptions.paths[
|
||||
path
|
||||
][0] = `.${originalTsConfig.compilerOptions.paths[path][0]}`;
|
||||
}
|
||||
}
|
||||
const tsconfigJson = {
|
||||
@ -143,6 +148,15 @@ export class PublishModule {
|
||||
'npmextra.json',
|
||||
'readme.md',
|
||||
],
|
||||
...this.options.tsPublishJson.bin ? {
|
||||
bin: (() => {
|
||||
const binObject: {[key: string]: string} = {};
|
||||
for (const bin of this.options.tsPublishJson.bin) {
|
||||
binObject[bin] = `./cli.js`;
|
||||
}
|
||||
return binObject;
|
||||
})()
|
||||
} : {},
|
||||
};
|
||||
return JSON.stringify(packageJson, null, 2);
|
||||
}
|
||||
@ -150,7 +164,7 @@ export class PublishModule {
|
||||
public async createPublishModuleDir() {
|
||||
this.options.publishModDirFullPath = plugins.path.join(
|
||||
this.options.monoRepoDir,
|
||||
`dist_publish_${this.options.packageSubFolder}`,
|
||||
`dist_publish_${this.options.packageSubFolder}`
|
||||
);
|
||||
await plugins.smartfile.fs.ensureEmptyDir(this.options.publishModDirFullPath);
|
||||
|
||||
@ -158,35 +172,38 @@ export class PublishModule {
|
||||
const packageJson = await plugins.smartfile.SmartFile.fromString(
|
||||
plugins.path.join(this.options.publishModDirFullPath, 'package.json'),
|
||||
await this.createPackageJson(),
|
||||
'utf8',
|
||||
'utf8'
|
||||
);
|
||||
await packageJson.write();
|
||||
|
||||
// tsconfig.json
|
||||
const originalTsConfigJson = await plugins.smartfile.SmartFile.fromString(
|
||||
const tsconfigJson = await plugins.smartfile.SmartFile.fromString(
|
||||
plugins.path.join(this.options.publishModDirFullPath, 'tsconfig.json'),
|
||||
await this.createTsconfigJson(),
|
||||
'utf8',
|
||||
'utf8'
|
||||
);
|
||||
await originalTsConfigJson.write();
|
||||
await tsconfigJson.write();
|
||||
|
||||
// ts folder
|
||||
// ts subfolder, the folder that contains the source code and is being transpiled
|
||||
await plugins.smartfile.fs.copy(
|
||||
this.options.packageSubFolderFullPath,
|
||||
plugins.path.join(this.options.publishModDirFullPath, this.options.packageSubFolder),
|
||||
plugins.path.join(this.options.publishModDirFullPath, this.options.packageSubFolder)
|
||||
);
|
||||
|
||||
// readme
|
||||
await plugins.smartfile.fs.copy(
|
||||
plugins.path.join(this.options.packageSubFolderFullPath, 'readme.md'),
|
||||
plugins.path.join(this.options.publishModDirFullPath, 'readme.md'),
|
||||
plugins.path.join(this.options.publishModDirFullPath, 'readme.md')
|
||||
);
|
||||
|
||||
// license
|
||||
await plugins.smartfile.fs.copy(
|
||||
plugins.path.join(this.options.monoRepoDir, 'license'),
|
||||
plugins.path.join(this.options.publishModDirFullPath, 'license'),
|
||||
plugins.path.join(this.options.publishModDirFullPath, 'license')
|
||||
);
|
||||
|
||||
// cli stuff
|
||||
this.createBinCliSetup();
|
||||
}
|
||||
|
||||
public async build() {
|
||||
@ -196,6 +213,21 @@ export class PublishModule {
|
||||
await smartshellInstance.exec(`cd ${this.options.publishModDirFullPath} && pnpm run build`);
|
||||
}
|
||||
|
||||
public async createBinCliSetup() {
|
||||
const binSetupApplies: boolean =
|
||||
this.options.tsPublishJson.bin &&
|
||||
Array.isArray(this.options.tsPublishJson.bin) &&
|
||||
this.options.tsPublishJson.bin.length > 0;
|
||||
const files = await this.tsPublishRef.giteaAssetsInstance.getFiles(
|
||||
'git.zone',
|
||||
'cli',
|
||||
'assets/templates/cli/cli.js'
|
||||
);
|
||||
const indexPath = `./dist_${this.options.packageSubFolder}/index.js`;
|
||||
const fileContent = atob(files[0].base64Content).replace('./dist_ts/index.js', indexPath);
|
||||
await plugins.smartfile.memory.toFs(fileContent, plugins.path.join(this.options.publishModDirFullPath, 'cli.js'));
|
||||
}
|
||||
|
||||
public async publish() {
|
||||
const smartshellInstance = new plugins.smartshell.Smartshell({
|
||||
executor: 'bash',
|
||||
@ -207,7 +239,7 @@ export class PublishModule {
|
||||
await smartshellInstance.exec(
|
||||
`cd ${this.options.publishModDirFullPath} && pnpm publish ${
|
||||
registryAccessLevel === 'public' ? '--access public' : ''
|
||||
} --no-git-checks --registry https://${registryUrl}`,
|
||||
} --no-git-checks --registry https://${registryUrl}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,16 @@ import * as plugins from './plugins.js';
|
||||
import * as interfaces from './interfaces/index.js';
|
||||
|
||||
import { PublishModule } from './classes.publishmodule.js';
|
||||
import { GiteaAssets } from './classes.giteaassets.js';
|
||||
|
||||
export class TsPublish {
|
||||
constructor() {}
|
||||
public giteaAssetsInstance: GiteaAssets;
|
||||
|
||||
constructor() {
|
||||
this.giteaAssetsInstance = new GiteaAssets({
|
||||
giteaBaseUrl: 'https://code.foss.global',
|
||||
});
|
||||
}
|
||||
|
||||
public async publish(monorepoDirArg: string) {
|
||||
const publishModules = await this.getModuleSubDirs(monorepoDirArg);
|
||||
@ -13,11 +20,16 @@ export class TsPublish {
|
||||
for (const publishModule of Object.keys(publishModules)) {
|
||||
logger.log(
|
||||
'info',
|
||||
`Publishing module: ${publishModule} -> ${publishModules[publishModule].name}`,
|
||||
`Publishing module: ${publishModule} -> ${publishModules[publishModule].name}`
|
||||
);
|
||||
}
|
||||
for (const publishModule of Object.keys(publishModules)) {
|
||||
const publishModuleInstance = new PublishModule({
|
||||
// lets check wether there is a name
|
||||
if (!publishModules[publishModule].name) {
|
||||
logger.log('warn', `no name found in tspublish.json for ${publishModule}. Skipping...`);
|
||||
continue;
|
||||
}
|
||||
const publishModuleInstance = new PublishModule(this, {
|
||||
monoRepoDir: monorepoDirArg,
|
||||
packageSubFolder: publishModule,
|
||||
});
|
||||
@ -40,12 +52,15 @@ export class TsPublish {
|
||||
if (!hasPublishJson) {
|
||||
continue;
|
||||
}
|
||||
|
||||
logger.log('info', `found publish module: ${subDir}`);
|
||||
publishModules[subDir] = JSON.parse(
|
||||
plugins.smartfile.fs.toStringSync(plugins.path.join(subDir, 'tspublish.json')),
|
||||
plugins.smartfile.fs.toStringSync(plugins.path.join(subDir, 'tspublish.json'))
|
||||
);
|
||||
}
|
||||
logger.log('ok', `found ${publishModules.length} publish modules`);
|
||||
logger.log('ok', `found ${Object.keys(publishModules).length} publish modules`);
|
||||
logger.log('info', `Ordering publish modules...`);
|
||||
|
||||
return publishModules;
|
||||
}
|
||||
}
|
||||
|
@ -6,4 +6,8 @@ export interface ITsPublishJson {
|
||||
name: string;
|
||||
dependencies: string[];
|
||||
registries: string[];
|
||||
/**
|
||||
* allows the sepcification of bin names that invoke cli scripts
|
||||
*/
|
||||
bin: string[];
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import * as smartdelay from '@push.rocks/smartdelay';
|
||||
import * as smartlog from '@push.rocks/smartlog';
|
||||
import * as smartnpm from '@push.rocks/smartnpm';
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
import * as smartrequest from '@push.rocks/smartrequest';
|
||||
import * as smartshell from '@push.rocks/smartshell';
|
||||
|
||||
export { smartfile, smartcli, smartdelay, smartlog, smartnpm, smartpath, smartshell };
|
||||
export { smartfile, smartcli, smartdelay, smartlog, smartnpm, smartpath, smartrequest, smartshell };
|
||||
|
Loading…
x
Reference in New Issue
Block a user