Compare commits

..

No commits in common. "master" and "v1.8.0" have entirely different histories.

6 changed files with 35 additions and 83 deletions

View File

@ -1,18 +1,5 @@
# Changelog # 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) ## 2025-01-01 - 1.8.0 - feat(core)
Added GiteaAssets class for managing files in Gitea repositories Added GiteaAssets class for managing files in Gitea repositories

View File

@ -1,6 +1,6 @@
{ {
"name": "@git.zone/tspublish", "name": "@git.zone/tspublish",
"version": "1.9.1", "version": "1.8.0",
"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",
@ -14,7 +14,7 @@
"buildDocs": "(tsdoc)" "buildDocs": "(tsdoc)"
}, },
"bin": { "bin": {
"tspublish": "./cli.js" "tspublish": "cli.js"
}, },
"devDependencies": { "devDependencies": {
"@git.zone/tsbuild": "^2.1.85", "@git.zone/tsbuild": "^2.1.85",

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@git.zone/tspublish', name: '@git.zone/tspublish',
version: '1.9.1', version: '1.8.0',
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

@ -49,7 +49,7 @@ export class GiteaAssets {
{ {
headers: this.headers, headers: this.headers,
method: 'GET', method: 'GET',
queryParams: branch ? { ref: branch } : {}, params: branch ? { ref: branch } : {},
} }
) )
if (!Array.isArray(response.body) && typeof response.body === 'object') { if (!Array.isArray(response.body) && typeof response.body === 'object') {
@ -64,7 +64,7 @@ export class GiteaAssets {
{ {
headers: this.headers, headers: this.headers,
method: 'GET', method: 'GET',
queryParams: branch ? { ref: branch } : {}, params: branch ? { ref: branch } : {},
} }
); );
entry.encoding = response2.body.encoding; entry.encoding = response2.body.encoding;

View File

@ -2,8 +2,11 @@ import * as plugins from './plugins.js';
import * as paths from './paths.js'; import * as paths from './paths.js';
import { logger } from './logging.js'; import { logger } from './logging.js';
import { type ITsPublishJson } from './interfaces/index.js'; export interface ITsPublishJson {
import type { TsPublish } from './classes.tspublish.js'; name: string;
dependencies: string[];
registries: string[];
}
export interface IPublishModuleOptions { export interface IPublishModuleOptions {
monoRepoDir: string; monoRepoDir: string;
@ -17,17 +20,15 @@ export interface IPublishModuleOptions {
} }
export class PublishModule { export class PublishModule {
tsPublishRef: TsPublish;
public options: IPublishModuleOptions; public options: IPublishModuleOptions;
constructor(tsPublishRef: TsPublish, options: IPublishModuleOptions) { constructor(options: IPublishModuleOptions) {
this.tsPublishRef = tsPublishRef;
this.options = options; this.options = options;
} }
public async init() { public async init() {
this.options.packageSubFolderFullPath = plugins.path.join( this.options.packageSubFolderFullPath = plugins.path.join(
this.options.monoRepoDir, this.options.monoRepoDir,
this.options.packageSubFolder this.options.packageSubFolder,
); );
// check requirements // check requirements
@ -35,14 +36,13 @@ export class PublishModule {
throw new Error('subFolder must start with "ts"'); throw new Error('subFolder must start with "ts"');
} }
this.options.tsPublishJson = plugins.smartfile.fs.toObjectSync( 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( 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 = {
...this.options.dependencies, ...this.options.dependencies,
...(() => { ...(() => {
@ -75,7 +75,7 @@ export class PublishModule {
if (availableVersions.includes(this.options.version)) { if (availableVersions.includes(this.options.version)) {
logger.log( logger.log(
'error', '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); process.exit(1);
} }
@ -93,13 +93,12 @@ export class PublishModule {
public async createTsconfigJson() { public async createTsconfigJson() {
const originalTsConfig = plugins.smartfile.fs.toObjectSync( const originalTsConfig = plugins.smartfile.fs.toObjectSync(
plugins.path.join(paths.cwd, 'tsconfig.json') plugins.path.join(paths.cwd, 'tsconfig.json'),
); );
if (originalTsConfig?.compilerOptions?.paths) { if (originalTsConfig?.compilerOptions?.paths) {
for (const path of Object.keys(originalTsConfig.compilerOptions.paths)) { for (const path of Object.keys(originalTsConfig.compilerOptions.paths)) {
originalTsConfig.compilerOptions.paths[ originalTsConfig.compilerOptions.paths[path][0] =
path `.${originalTsConfig.compilerOptions.paths[path][0]}`;
][0] = `.${originalTsConfig.compilerOptions.paths[path][0]}`;
} }
} }
const tsconfigJson = { const tsconfigJson = {
@ -148,15 +147,6 @@ export class PublishModule {
'npmextra.json', 'npmextra.json',
'readme.md', '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); return JSON.stringify(packageJson, null, 2);
} }
@ -164,7 +154,7 @@ export class PublishModule {
public async createPublishModuleDir() { public async createPublishModuleDir() {
this.options.publishModDirFullPath = plugins.path.join( this.options.publishModDirFullPath = plugins.path.join(
this.options.monoRepoDir, this.options.monoRepoDir,
`dist_publish_${this.options.packageSubFolder}` `dist_publish_${this.options.packageSubFolder}`,
); );
await plugins.smartfile.fs.ensureEmptyDir(this.options.publishModDirFullPath); await plugins.smartfile.fs.ensureEmptyDir(this.options.publishModDirFullPath);
@ -172,38 +162,35 @@ export class PublishModule {
const packageJson = await plugins.smartfile.SmartFile.fromString( const packageJson = await plugins.smartfile.SmartFile.fromString(
plugins.path.join(this.options.publishModDirFullPath, 'package.json'), plugins.path.join(this.options.publishModDirFullPath, 'package.json'),
await this.createPackageJson(), await this.createPackageJson(),
'utf8' 'utf8',
); );
await packageJson.write(); await packageJson.write();
// tsconfig.json // tsconfig.json
const tsconfigJson = await plugins.smartfile.SmartFile.fromString( const originalTsConfigJson = await plugins.smartfile.SmartFile.fromString(
plugins.path.join(this.options.publishModDirFullPath, 'tsconfig.json'), plugins.path.join(this.options.publishModDirFullPath, 'tsconfig.json'),
await this.createTsconfigJson(), await this.createTsconfigJson(),
'utf8' 'utf8',
); );
await tsconfigJson.write(); await originalTsConfigJson.write();
// ts subfolder, the folder that contains the source code and is being transpiled // ts folder
await plugins.smartfile.fs.copy( await plugins.smartfile.fs.copy(
this.options.packageSubFolderFullPath, this.options.packageSubFolderFullPath,
plugins.path.join(this.options.publishModDirFullPath, this.options.packageSubFolder) plugins.path.join(this.options.publishModDirFullPath, this.options.packageSubFolder),
); );
// readme // readme
await plugins.smartfile.fs.copy( await plugins.smartfile.fs.copy(
plugins.path.join(this.options.packageSubFolderFullPath, 'readme.md'), 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 // license
await plugins.smartfile.fs.copy( await plugins.smartfile.fs.copy(
plugins.path.join(this.options.monoRepoDir, 'license'), 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() { public async build() {
@ -213,21 +200,6 @@ export class PublishModule {
await smartshellInstance.exec(`cd ${this.options.publishModDirFullPath} && pnpm run build`); 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() { public async publish() {
const smartshellInstance = new plugins.smartshell.Smartshell({ const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash', executor: 'bash',
@ -239,7 +211,7 @@ export class PublishModule {
await smartshellInstance.exec( await smartshellInstance.exec(
`cd ${this.options.publishModDirFullPath} && pnpm publish ${ `cd ${this.options.publishModDirFullPath} && pnpm publish ${
registryAccessLevel === 'public' ? '--access public' : '' registryAccessLevel === 'public' ? '--access public' : ''
} --no-git-checks --registry https://${registryUrl}` } --no-git-checks --registry https://${registryUrl}`,
); );
} }
} }

View File

@ -3,16 +3,9 @@ import * as plugins from './plugins.js';
import * as interfaces from './interfaces/index.js'; import * as interfaces from './interfaces/index.js';
import { PublishModule } from './classes.publishmodule.js'; import { PublishModule } from './classes.publishmodule.js';
import { GiteaAssets } from './classes.giteaassets.js';
export class TsPublish { export class TsPublish {
public giteaAssetsInstance: GiteaAssets; constructor() {}
constructor() {
this.giteaAssetsInstance = new GiteaAssets({
giteaBaseUrl: 'https://code.foss.global',
});
}
public async publish(monorepoDirArg: string) { public async publish(monorepoDirArg: string) {
const publishModules = await this.getModuleSubDirs(monorepoDirArg); const publishModules = await this.getModuleSubDirs(monorepoDirArg);
@ -20,7 +13,7 @@ export class TsPublish {
for (const publishModule of Object.keys(publishModules)) { for (const publishModule of Object.keys(publishModules)) {
logger.log( logger.log(
'info', 'info',
`Publishing module: ${publishModule} -> ${publishModules[publishModule].name}` `Publishing module: ${publishModule} -> ${publishModules[publishModule].name}`,
); );
} }
for (const publishModule of Object.keys(publishModules)) { for (const publishModule of Object.keys(publishModules)) {
@ -29,7 +22,7 @@ export class TsPublish {
logger.log('warn', `no name found in tspublish.json for ${publishModule}. Skipping...`); logger.log('warn', `no name found in tspublish.json for ${publishModule}. Skipping...`);
continue; continue;
} }
const publishModuleInstance = new PublishModule(this, { const publishModuleInstance = new PublishModule({
monoRepoDir: monorepoDirArg, monoRepoDir: monorepoDirArg,
packageSubFolder: publishModule, packageSubFolder: publishModule,
}); });
@ -55,12 +48,12 @@ export class TsPublish {
logger.log('info', `found publish module: ${subDir}`); logger.log('info', `found publish module: ${subDir}`);
publishModules[subDir] = JSON.parse( 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 ${Object.keys(publishModules).length} publish modules`); logger.log('ok', `found ${Object.keys(publishModules).length} publish modules`);
logger.log('info', `Ordering publish modules...`); logger.log('info', `Ordering publish modules...`);
return publishModules; return publishModules;
} }
} }