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) { const subDirs = await plugins.smartfile.fs.listFolders(dirArg); const publishModules: { [key: string]: interfaces.ITsPublishJson } = {}; for (const subDir of subDirs) { if (!subDir.startsWith('ts')) { continue; } const fileTree = await plugins.smartfile.fs.listFileTree(subDir, '**/*'); const hasPublishJson = fileTree.includes('tspublish.json'); if (!hasPublishJson) { continue; } logPackage('Found module', subDir); publishModules[subDir] = JSON.parse( plugins.smartfile.fs.toStringSync(plugins.path.join(subDir, 'tspublish.json')) ); } logSuccess(`Found ${Object.keys(publishModules).length} publish modules`); logInfo('Ordering publish modules...'); return publishModules; } }