feat(core): Add runCli function to execute TsPublish process

This commit is contained in:
Philipp Kunz 2024-10-21 12:57:54 +02:00
parent c0d81402fb
commit 4f555a2fe9
4 changed files with 47 additions and 16 deletions

13
changelog.md Normal file
View File

@ -0,0 +1,13 @@
# Changelog
## 2024-10-21 - 1.1.0 - feat(core)
Add runCli function to execute TsPublish process
- Introduced runCli function to start publish workflow using TsPublish class.
- Enhanced the process to read directory and create publish module directories.
- Improved logging for better tracking of found publish modules.
## 2024-10-21 - 1.0.1 - Initial Release
Initial release of the project.
- First version of the codebase

View File

@ -2,7 +2,7 @@
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@idp.global/idp.global',
version: '1.4.2',
description: 'An identity provider software managing user authentications, registrations, and sessions.'
name: '@git.zone/tspublish',
version: '1.1.0',
description: 'publish multiple, concise and small packages from monorepos'
}

View File

@ -9,7 +9,7 @@ export interface IPublishModuleOptions {
publishModDirFullPath?: string;
name?: string;
version?: string;
dependencies?: {[key: string]: string};
dependencies?: { [key: string]: string };
}
export class PublishModule {
@ -19,7 +19,6 @@ export class PublishModule {
}
public async init() {
this.options.packageSubFolderFullPath = plugins.path.join(
this.options.monoRepoDir,
this.options.packageSubFolder
@ -30,7 +29,7 @@ export class PublishModule {
throw new Error('subFolder must start with "ts"');
}
const jsonData = plugins.smartfile.fs.toObjectSync(
plugins.path.join(this.options.packageSubFolderFullPath, 'tspublish.json'),
plugins.path.join(this.options.packageSubFolderFullPath, 'tspublish.json')
);
this.options.dependencies = this.options.dependencies || {};
this.options.dependencies = {
@ -46,13 +45,14 @@ export class PublishModule {
const smartnpmInstance = new plugins.smartnpm.NpmRegistry({}); // TODO: pass in options
const packageInfo = await smartnpmInstance.getPackageInfo(this.options.name);
if (packageInfo) {
const availableVersions = packageInfo.allVersions.map(versionArg => versionArg.version);
const availableVersions = packageInfo.allVersions.map((versionArg) => versionArg.version);
logger.log('info', `available versions are: ${availableVersions.toString()}`);
if (availableVersions.includes(this.options.version)) {
throw new Error(`package ${this.options.name} already exists with version ${this.options.version}`);
};
throw new Error(
`package ${this.options.name} already exists with version ${this.options.version}`
);
}
}
}
public async getLatestVersionOfPackage(name: string) {
@ -69,9 +69,9 @@ export class PublishModule {
name: this.options.name,
version: this.options.version,
description: '',
exports : {
exports: {
'.': {
import: './dist/index.js',
import: './dist_${this.options.packageSubFolder}/index.js',
},
},
scripts: {
@ -81,7 +81,8 @@ export class PublishModule {
devDependencies: {
'@git.zone/tsbuild': await this.getLatestVersionOfPackage('@git.zone/tsbuild'),
},
}
};
return JSON.stringify(packageJson, null, 2);
}
public async createPublishModuleDir() {
@ -89,7 +90,16 @@ export class PublishModule {
this.options.monoRepoDir,
`dist_publish_${this.options.packageSubFolder}`
);
await plugins.smartfile.fs.ensureEmptyDir(publishModDir);
plugins.
// package.json
await plugins.smartfile.fs.ensureEmptyDir(this.options.publishModDirFullPath);
const packageJson = await plugins.smartfile.SmartFile.fromString(
plugins.path.join(this.options.publishModDirFullPath, 'package.json'),
await this.createPackageJson(),
'utf8'
);
// ts folder
await plugins.smartfile.fs.copy(this.options.packageSubFolderFullPath, plugins.path.join(this.options.publishModDirFullPath, this.options.packageSubFolder))
}
}

View File

@ -1 +1,9 @@
export * from './classes.tspublish.js'
import * as paths from './paths.js';
import { TsPublish } from './classes.tspublish.js';
export * from './classes.tspublish.js'
export const runCli = async () => {
const tspublish = new TsPublish();
await tspublish.publish(paths.cwd);
}