tspublish/ts/classes.tspublish.ts

67 lines
2.3 KiB
TypeScript
Raw Normal View History

2024-10-21 12:16:09 +02:00
import { logger } from './logging.js';
import * as plugins from './plugins.js';
import * as interfaces from './interfaces/index.js';
2024-10-21 12:16:09 +02:00
import { PublishModule } from './classes.publishmodule.js';
import { GiteaAssets } from './classes.giteaassets.js';
2024-10-21 12:16:09 +02:00
export class TsPublish {
public giteaAssetsInstance: GiteaAssets;
constructor() {
this.giteaAssetsInstance = new GiteaAssets({
giteaBaseUrl: 'https://code.foss.global',
});
}
2024-10-21 12:16:09 +02:00
public async publish(monorepoDirArg: string) {
const publishModules = await this.getModuleSubDirs(monorepoDirArg);
logger.log('info', `Found ${Object.keys(publishModules).length} publish modules:`);
for (const publishModule of Object.keys(publishModules)) {
logger.log(
'info',
`Publishing module: ${publishModule} -> ${publishModules[publishModule].name}`
);
}
for (const publishModule of Object.keys(publishModules)) {
// lets check wether there is a name
if (!publishModules[publishModule].name) {
logger.log('warn', `no name found in tspublish.json for ${publishModule}. Skipping...`);
continue;
}
const publishModuleInstance = new PublishModule(this, {
2024-10-21 12:16:09 +02:00
monoRepoDir: monorepoDirArg,
packageSubFolder: publishModule,
});
await publishModuleInstance.init();
await publishModuleInstance.createPublishModuleDir();
await publishModuleInstance.build();
await publishModuleInstance.publish();
2024-10-21 12:16:09 +02:00
}
}
public async getModuleSubDirs(dirArg: string) {
2024-10-21 12:16:09 +02:00
const subDirs = await plugins.smartfile.fs.listFolders(dirArg);
const publishModules: { [key: string]: interfaces.ITsPublishJson } = {};
2024-10-21 12:16:09 +02:00
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;
}
2024-10-21 12:16:09 +02:00
logger.log('info', `found publish module: ${subDir}`);
publishModules[subDir] = JSON.parse(
plugins.smartfile.fs.toStringSync(plugins.path.join(subDir, 'tspublish.json'))
);
2024-10-21 12:16:09 +02:00
}
logger.log('ok', `found ${Object.keys(publishModules).length} publish modules`);
logger.log('info', `Ordering publish modules...`);
2024-10-21 12:16:09 +02:00
return publishModules;
}
}