import { logger, logInfo, logSuccess, logWarn, logError, logHeader, logPackage, logProgress, logSeparator, logStart, logDone } from './logging.js'; 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 { public giteaAssetsInstance: GiteaAssets; constructor() { this.giteaAssetsInstance = new GiteaAssets({ giteaBaseUrl: 'https://code.foss.global', }); } public async publish(monorepoDirArg: string) { logHeader('TSPublish - Module Publisher'); const publishModules = await this.getModuleSubDirs(monorepoDirArg); logInfo(`Found ${Object.keys(publishModules).length} publish modules`); logSeparator(); for (const publishModule of Object.keys(publishModules)) { logPackage('Module found', `${publishModule} → ${publishModules[publishModule].name}`); } for (const publishModule of Object.keys(publishModules)) { // lets check wether there is a name if (!publishModules[publishModule].name) { logWarn(`No name found in tspublish.json for ${publishModule}. Skipping...`); continue; } const publishModuleInstance = new PublishModule(this, { monoRepoDir: monorepoDirArg, packageSubFolder: publishModule, }); const moduleCount = Object.keys(publishModules).indexOf(publishModule) + 1; const totalCount = Object.keys(publishModules).length; logProgress(moduleCount, totalCount, publishModules[publishModule].name || publishModule); await publishModuleInstance.init(); await publishModuleInstance.createPublishModuleDir(); await publishModuleInstance.build(); await publishModuleInstance.publish(); } } public async getModuleSubDirs(dirArg: string) { // List all directories const dirContents = await plugins.smartfs.directory(dirArg).list(); const publishModules: { [key: string]: interfaces.ITsPublishJson } = {}; for (const entry of dirContents) { const subDirName = entry.name; if (!subDirName.startsWith('ts')) { continue; } // Check if this is a directory and has tspublish.json const subDirPath = plugins.path.join(dirArg, subDirName); const tspublishJsonPath = plugins.path.join(subDirPath, 'tspublish.json'); if (!(await plugins.smartfs.file(tspublishJsonPath).exists())) { continue; } logPackage('Found module', subDirName); const tspublishContent = await plugins.smartfs.file(tspublishJsonPath).encoding('utf8').read(); publishModules[subDirName] = JSON.parse(tspublishContent as string); } logSuccess(`Found ${Object.keys(publishModules).length} publish modules`); logInfo('Ordering publish modules...'); return publishModules; } }