feat(projectinfo): migrate project info loading to async factories and update build configuration

This commit is contained in:
2026-03-26 08:35:13 +00:00
parent 9e79ea4e70
commit 4a20f31b99
15 changed files with 7519 additions and 4135 deletions

View File

@@ -1,8 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/projectinfo',
version: '5.0.2',
description: 'gather information about projects. supports npm, git etc.'
version: '5.1.0',
description: 'A tool for gathering project information, supporting npm, git, and more.'
}

View File

@@ -13,8 +13,8 @@ import { ProjectinfoNpm } from './projectinfo.classes.npm.js';
/**
* gets the name from package.json in a specified directory
*/
export let getNpmNameForDir = function (cwdArg) {
let localNpm = new ProjectinfoNpm(cwdArg);
export let getNpmNameForDir = async function (cwdArg: string) {
let localNpm = await ProjectinfoNpm.create(cwdArg);
if (localNpm.status === 'ok') {
return localNpm.name;
}

View File

@@ -1,10 +1,10 @@
import * as plugins from './projectinfo.plugins.js';
export class ProjectinfoGit {
isGit: boolean;
githost: string;
gituser: string;
gitrepo: string;
isGit: boolean = false;
githost: string = '';
gituser: string = '';
gitrepo: string = '';
cwd: string;
constructor(cwdArg: string) {
this.cwd = cwdArg;

View File

@@ -2,31 +2,37 @@ import * as plugins from './projectinfo.plugins.js';
export class ProjectinfoNpm {
isNpm: boolean = false;
packageJson: any;
name: string;
version: string;
status: string;
license: string;
git: plugins.smartstring.GitRepo;
packageJson: any = null;
name: string = '';
version: string = '';
status: string = '';
license: string = '';
git: plugins.smartstring.GitRepo | null = null;
constructor(cwdArg: string, optionsArg: { gitAccessToken?: string } = {}) {
let resolvedCwd = plugins.path.resolve(cwdArg);
if (plugins.smartfile.fs.fileExists(plugins.path.join(resolvedCwd, 'package.json'))) {
this.isNpm = true;
this.packageJson = plugins.smartfile.fs.toObjectSync(
plugins.path.join(resolvedCwd, 'package.json'),
'json'
);
this.name = this.packageJson.name;
this.version = this.packageJson.version;
this.status = 'ok';
this.license = this.packageJson.license;
if (this.packageJson.repository) {
this.git = new plugins.smartstring.GitRepo(
this.packageJson.repository.url,
private constructor() {}
static async create(cwdArg: string, optionsArg: { gitAccessToken?: string } = {}): Promise<ProjectinfoNpm> {
const instance = new ProjectinfoNpm();
const resolvedCwd = plugins.path.resolve(cwdArg);
const smartFsInstance = new plugins.smartfs.SmartFs(new plugins.smartfs.SmartFsProviderNode());
const packageJsonPath = plugins.path.join(resolvedCwd, 'package.json');
const fileExists = await smartFsInstance.file(packageJsonPath).exists();
if (fileExists) {
instance.isNpm = true;
const content = await smartFsInstance.file(packageJsonPath).encoding('utf8').read();
instance.packageJson = JSON.parse(content as string);
instance.name = instance.packageJson.name;
instance.version = instance.packageJson.version;
instance.status = 'ok';
instance.license = instance.packageJson.license;
if (instance.packageJson.repository) {
instance.git = new plugins.smartstring.GitRepo(
instance.packageJson.repository.url,
optionsArg.gitAccessToken
);
}
}
return instance;
}
}

View File

@@ -7,14 +7,21 @@ export type TProjectType = 'git' | 'npm';
* class projectinfo automatically examines a given directory and exposes relevant info about it
*/
export class ProjectInfo {
type: TProjectType;
type: TProjectType = 'git';
npm: ProjectinfoNpm;
git: ProjectinfoGit;
/**
* constructor of class ProjectInfo
*/
constructor(cwdArg: string) {
this.npm = new ProjectinfoNpm(cwdArg);
this.git = new ProjectinfoGit(cwdArg);
private constructor(npm: ProjectinfoNpm, git: ProjectinfoGit) {
this.npm = npm;
this.git = git;
if (npm.isNpm) {
this.type = 'npm';
}
}
static async create(cwdArg: string): Promise<ProjectInfo> {
const npm = await ProjectinfoNpm.create(cwdArg);
const git = new ProjectinfoGit(cwdArg);
return new ProjectInfo(npm, git);
}
}

View File

@@ -1,7 +1,7 @@
import * as path from 'path';
import * as smartpromise from '@push.rocks/smartpromise';
import * as smartfile from '@push.rocks/smartfile';
import * as smartfs from '@push.rocks/smartfs';
import * as smartstring from '@push.rocks/smartstring';
import * as smartpath from '@push.rocks/smartpath';
export { path, smartpromise, smartfile, smartstring, smartpath };
export { path, smartpromise, smartfs, smartstring, smartpath };