62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
import { logger } from './logging.js';
|
|
import * as plugins from './plugins.js';
|
|
import * as interfaces from './interfaces/index.js';
|
|
|
|
import { PublishModule } from './classes.publishmodule.js';
|
|
|
|
export class TsPublish {
|
|
constructor() {}
|
|
|
|
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)) {
|
|
const publishModuleInstance = new PublishModule({
|
|
monoRepoDir: monorepoDirArg,
|
|
packageSubFolder: 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;
|
|
}
|
|
|
|
// lets check wether there is a name
|
|
const tspublishJson = JSON.parse(
|
|
plugins.smartfile.fs.toStringSync(plugins.path.join(subDir, 'tspublish.json')),
|
|
);
|
|
if (!tspublishJson.name) {
|
|
logger.log('warn', `no name found in tspublish.json for ${subDir}`);
|
|
continue;
|
|
}
|
|
|
|
logger.log('info', `found publish module: ${subDir}`);
|
|
publishModules[subDir] = JSON.parse(
|
|
plugins.smartfile.fs.toStringSync(plugins.path.join(subDir, 'tspublish.json')),
|
|
);
|
|
}
|
|
logger.log('ok', `found ${publishModules.length} publish modules`);
|
|
return publishModules;
|
|
}
|
|
}
|