This commit is contained in:
2024-10-21 12:16:09 +02:00
commit c0d81402fb
22 changed files with 7721 additions and 0 deletions

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@idp.global/idp.global',
version: '1.4.2',
description: 'An identity provider software managing user authentications, registrations, and sessions.'
}

View File

@ -0,0 +1,95 @@
import * as plugins from './plugins.js';
import * as paths from './paths.js';
import { logger } from './logging.js';
export interface IPublishModuleOptions {
monoRepoDir: string;
packageSubFolder: string;
packageSubFolderFullPath?: string;
publishModDirFullPath?: string;
name?: string;
version?: string;
dependencies?: {[key: string]: string};
}
export class PublishModule {
public options: IPublishModuleOptions;
constructor(options: IPublishModuleOptions) {
this.options = options;
}
public async init() {
this.options.packageSubFolderFullPath = plugins.path.join(
this.options.monoRepoDir,
this.options.packageSubFolder
);
// check requirements
if (!this.options.packageSubFolder.startsWith('ts')) {
throw new Error('subFolder must start with "ts"');
}
const jsonData = plugins.smartfile.fs.toObjectSync(
plugins.path.join(this.options.packageSubFolderFullPath, 'tspublish.json'),
);
this.options.dependencies = this.options.dependencies || {};
this.options.dependencies = {
...this.options.dependencies,
...jsonData.dependencies,
};
this.options.name = this.options.name || jsonData.name;
this.options.version = plugins.smartfile.fs.toObjectSync(
plugins.path.join(this.options.monoRepoDir, 'package.json')
).version;
// now that we have a name and version, lets check if there is already a package under the same name and version.
const smartnpmInstance = new plugins.smartnpm.NpmRegistry({}); // TODO: pass in options
const packageInfo = await smartnpmInstance.getPackageInfo(this.options.name);
if (packageInfo) {
const availableVersions = packageInfo.allVersions.map(versionArg => versionArg.version);
logger.log('info', `available versions are: ${availableVersions.toString()}`);
if (availableVersions.includes(this.options.version)) {
throw new Error(`package ${this.options.name} already exists with version ${this.options.version}`);
};
}
}
public async getLatestVersionOfPackage(name: string) {
const smartnpmInstance = new plugins.smartnpm.NpmRegistry({}); // TODO: pass in options
const packageInfo = await smartnpmInstance.getPackageInfo(name);
if (!packageInfo) {
throw new Error(`package ${name} not found`);
}
return packageInfo.allVersions[0].version;
}
public async createPackageJson() {
const packageJson = {
name: this.options.name,
version: this.options.version,
description: '',
exports : {
'.': {
import: './dist/index.js',
},
},
scripts: {
build: 'tsbuild tsfolders --allowimplicitany',
},
dependencies: this.options.dependencies,
devDependencies: {
'@git.zone/tsbuild': await this.getLatestVersionOfPackage('@git.zone/tsbuild'),
},
}
}
public async createPublishModuleDir() {
this.options.publishModDirFullPath = plugins.path.join(
this.options.monoRepoDir,
`dist_publish_${this.options.packageSubFolder}`
);
await plugins.smartfile.fs.ensureEmptyDir(publishModDir);
plugins.
}
}

38
ts/classes.tspublish.ts Normal file
View File

@ -0,0 +1,38 @@
import { logger } from './logging.js';
import * as plugins from './plugins.js';
import { PublishModule } from './classes.publishmodule.js';
export class TsPublish {
constructor() {}
public async publish (monorepoDirArg: string) {
const publishModules = await this.readDirectory(monorepoDirArg);
for (const publishModule of publishModules) {
const publishModuleInstance = new PublishModule({
monoRepoDir: monorepoDirArg,
packageSubFolder: publishModule,
});
await publishModuleInstance.init();
}
}
public async readDirectory (dirArg: string) {
const subDirs = await plugins.smartfile.fs.listFolders(dirArg);
const publishModules: string[] = [];
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;
}
logger.log('info', `found publish module: ${subDir}`);
publishModules.push(subDir);
}
logger.log('ok', `found ${publishModules.length} publish modules`);
return publishModules;
}
}

1
ts/index.ts Normal file
View File

@ -0,0 +1 @@
export * from './classes.tspublish.js'

4
ts/logging.ts Normal file
View File

@ -0,0 +1,4 @@
import * as plugins from './plugins.js';
import * as commitinfo from './00_commitinfo_data.js';
export const logger = plugins.smartlog.Smartlog.createForCommitinfo(commitinfo.commitinfo);

7
ts/paths.ts Normal file
View File

@ -0,0 +1,7 @@
import * as plugins from './plugins.js';
export const cwd = process.cwd();
export const packageDir = plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), '..');
export const nogitDir = plugins.path.join(packageDir, '.nogit');

14
ts/plugins.ts Normal file
View File

@ -0,0 +1,14 @@
// node native scope
import * as path from 'path';
export {
path,
}
// @push.rocks scope
import * as smartfile from '@push.rocks/smartfile';
import * as smartcli from '@push.rocks/smartcli';
import * as smartlog from '@push.rocks/smartlog';
import * as smartnpm from '@push.rocks/smartnpm';
import * as smartpath from '@push.rocks/smartpath';
export { smartfile, smartcli, smartlog, smartnpm, smartpath, };