fix(core): update
This commit is contained in:
@ -2,8 +2,11 @@ import * as plugins from './smartnpm.plugins';
|
||||
import { NpmRegistry } from './smartnpm.classes.npmregistry';
|
||||
|
||||
export class NpmPackage {
|
||||
public static async createFromFullMetadata(npmRegistry: NpmRegistry, fullMetadata: plugins.packageJson.FullMetadata) {
|
||||
const npmPackage = new NpmPackage();
|
||||
public static async createFromFullMetadata(
|
||||
npmRegistryArg: NpmRegistry,
|
||||
fullMetadata: plugins.packageJson.FullMetadata
|
||||
) {
|
||||
const npmPackage = new NpmPackage(npmRegistryArg);
|
||||
Object.assign(npmPackage, fullMetadata);
|
||||
return npmPackage;
|
||||
}
|
||||
@ -30,6 +33,11 @@ export class NpmPackage {
|
||||
email: 'npm@git.zone';
|
||||
};
|
||||
public maintainers: any = null;
|
||||
public dist: {
|
||||
integrity: string;
|
||||
shasum: string;
|
||||
tarball: string;
|
||||
};
|
||||
public score: {
|
||||
final: number;
|
||||
detail: {
|
||||
@ -39,4 +47,17 @@ export class NpmPackage {
|
||||
};
|
||||
} = null;
|
||||
public searchScore: number = null;
|
||||
|
||||
public npmRegistry: NpmRegistry;
|
||||
constructor(npmRegistryArg: NpmRegistry) {
|
||||
this.npmRegistry = npmRegistryArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* saves the package to disk
|
||||
*/
|
||||
public async saveToDisk(targetDir: string) {
|
||||
const smartarchiveInstance = new plugins.smartarchive.SmartArchive();
|
||||
await smartarchiveInstance.extractArchiveFromUrl(this.dist.tarball, targetDir);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import * as plugins from './smartnpm.plugins';
|
||||
import * as paths from './smartnpm.paths';
|
||||
|
||||
// interfaces
|
||||
import { ISearchObject } from './smartnpm.interfaces';
|
||||
@ -25,6 +26,10 @@ export class NpmRegistry {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* gets info about a package
|
||||
* @param packageName
|
||||
*/
|
||||
public async getPackageInfo(packageName: string): Promise<NpmPackage> {
|
||||
const fullMetadata = await plugins.packageJson(packageName, {
|
||||
registryUrl: this.options.npmRegistryUrl,
|
||||
@ -34,7 +39,35 @@ export class NpmRegistry {
|
||||
return npmPackage;
|
||||
}
|
||||
|
||||
public async search(searchObjectArg: ISearchObject) {
|
||||
/**
|
||||
* saves a package to disk
|
||||
* @param packageName
|
||||
* @param targetDir
|
||||
*/
|
||||
public async savePackageToDisk(packageName: string, targetDir: string): Promise<void> {
|
||||
const npmPackage = await this.getPackageInfo(packageName);
|
||||
await npmPackage.saveToDisk(targetDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets a file from a package as Smartfile
|
||||
*/
|
||||
public async getFileFromPackage(packageName: string, filePath: string) {
|
||||
const baseDir = plugins.path.join(paths.nogitDir, packageName.replace('/', '__'));
|
||||
await plugins.smartfile.fs.ensureDir(baseDir);
|
||||
await this.savePackageToDisk(packageName, baseDir);
|
||||
const smartfile = await plugins.smartfile.Smartfile.fromFilePath(
|
||||
plugins.path.join(baseDir, 'package', filePath)
|
||||
);
|
||||
await plugins.smartfile.fs.remove(baseDir);
|
||||
return smartfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* searches for a package on npm
|
||||
* @param searchObjectArg
|
||||
*/
|
||||
public async searchOnNpm(searchObjectArg: ISearchObject) {
|
||||
if (this.options.npmRegistryUrl !== 'https://registry.npmjs.org') {
|
||||
throw Error(`cannot search registries other than registry.gitlab.com`);
|
||||
}
|
||||
|
5
ts/smartnpm.paths.ts
Normal file
5
ts/smartnpm.paths.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import * as plugins from './smartnpm.plugins';
|
||||
|
||||
export const packageDir = plugins.path.join(__dirname, '../');
|
||||
export const nogitDir = plugins.path.join(packageDir, '.nogit/');
|
||||
plugins.smartfile.fs.ensureDirSync(nogitDir);
|
@ -1,10 +1,17 @@
|
||||
// node native modules
|
||||
import * as path from 'path';
|
||||
|
||||
export { path };
|
||||
|
||||
// @pushrocks scope
|
||||
import * as consolecolor from '@pushrocks/consolecolor';
|
||||
import * as smartarchive from '@pushrocks/smartarchive';
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
import * as smartlog from '@pushrocks/smartlog';
|
||||
smartlog.defaultLogger.enableConsole();
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
|
||||
export { consolecolor, smartlog, smartrequest };
|
||||
export { consolecolor, smartarchive, smartfile, smartlog, smartrequest };
|
||||
|
||||
// third party scope
|
||||
import packageJson from 'package-json';
|
||||
|
Reference in New Issue
Block a user