import * as plugins from './projectinfo.plugins.js'; export class ProjectinfoNpm { isNpm: boolean = false; packageJson: any = null; name: string = ''; version: string = ''; status: string = ''; license: string = ''; git: plugins.smartstring.GitRepo | null = null; private constructor() {} static async create(cwdArg: string, optionsArg: { gitAccessToken?: string } = {}): Promise { 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; } }