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