From 4f555a2fe9f0c240e5125b5ae147f6b56d01e04a Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Mon, 21 Oct 2024 12:57:54 +0200 Subject: [PATCH] feat(core): Add runCli function to execute TsPublish process --- changelog.md | 13 +++++++++++++ ts/00_commitinfo_data.ts | 6 +++--- ts/classes.publishmodule.ts | 34 ++++++++++++++++++++++------------ ts/index.ts | 10 +++++++++- 4 files changed, 47 insertions(+), 16 deletions(-) create mode 100644 changelog.md diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..d58dc6e --- /dev/null +++ b/changelog.md @@ -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 diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 58c4d1f..989dbed 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -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' } diff --git a/ts/classes.publishmodule.ts b/ts/classes.publishmodule.ts index 4f88291..60d5d43 100644 --- a/ts/classes.publishmodule.ts +++ b/ts/classes.publishmodule.ts @@ -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)) } } diff --git a/ts/index.ts b/ts/index.ts index c272892..7942ca6 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1 +1,9 @@ -export * from './classes.tspublish.js' \ No newline at end of file +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); +}