2018-09-01 14:40:42 +00:00
|
|
|
import * as plugins from './smartnpm.plugins';
|
2020-03-08 19:34:36 +00:00
|
|
|
import { NpmRegistry } from './smartnpm.classes.npmregistry';
|
2017-08-14 15:50:48 +00:00
|
|
|
|
2019-09-06 14:29:45 +00:00
|
|
|
export class NpmPackage {
|
2020-03-17 00:38:58 +00:00
|
|
|
public static async createFromFullMetadata(
|
|
|
|
npmRegistryArg: NpmRegistry,
|
|
|
|
fullMetadata: plugins.packageJson.FullMetadata
|
|
|
|
) {
|
|
|
|
const npmPackage = new NpmPackage(npmRegistryArg);
|
2019-09-06 11:22:54 +00:00
|
|
|
Object.assign(npmPackage, fullMetadata);
|
|
|
|
return npmPackage;
|
|
|
|
}
|
|
|
|
|
|
|
|
// INSTANCE
|
|
|
|
public name: string = null;
|
|
|
|
public scope: string = null;
|
|
|
|
public version: string = null;
|
|
|
|
public description: string = null;
|
|
|
|
public keywords: string[] = null;
|
|
|
|
public date: string;
|
|
|
|
public license: string;
|
|
|
|
public links: {
|
2018-09-01 14:40:42 +00:00
|
|
|
npm: string;
|
|
|
|
homepage: string;
|
|
|
|
repository: string;
|
|
|
|
bugs: string;
|
2019-09-06 11:22:54 +00:00
|
|
|
};
|
|
|
|
public author: {
|
2018-09-01 14:40:42 +00:00
|
|
|
name: 'Lossless GmbH';
|
2019-09-06 11:22:54 +00:00
|
|
|
};
|
|
|
|
public publisher: {
|
2018-09-01 14:40:42 +00:00
|
|
|
username: 'gitzone';
|
|
|
|
email: 'npm@git.zone';
|
2019-09-06 11:22:54 +00:00
|
|
|
};
|
|
|
|
public maintainers: any = null;
|
2020-03-17 00:38:58 +00:00
|
|
|
public dist: {
|
|
|
|
integrity: string;
|
|
|
|
shasum: string;
|
|
|
|
tarball: string;
|
|
|
|
};
|
2019-09-06 11:22:54 +00:00
|
|
|
public score: {
|
2018-09-01 14:40:42 +00:00
|
|
|
final: number;
|
2017-08-15 15:03:21 +00:00
|
|
|
detail: {
|
2018-09-01 14:40:42 +00:00
|
|
|
quality: number;
|
|
|
|
popularity: number;
|
|
|
|
maintenance: number;
|
|
|
|
};
|
|
|
|
} = null;
|
2019-09-06 11:22:54 +00:00
|
|
|
public searchScore: number = null;
|
2020-03-17 00:38:58 +00:00
|
|
|
|
2021-04-19 12:55:11 +00:00
|
|
|
public npmRegistryRef: NpmRegistry;
|
2020-03-17 00:38:58 +00:00
|
|
|
constructor(npmRegistryArg: NpmRegistry) {
|
2021-04-19 12:55:11 +00:00
|
|
|
this.npmRegistryRef = npmRegistryArg;
|
2020-03-17 00:38:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* saves the package to disk
|
|
|
|
*/
|
|
|
|
public async saveToDisk(targetDir: string) {
|
|
|
|
const smartarchiveInstance = new plugins.smartarchive.SmartArchive();
|
2021-04-19 12:55:11 +00:00
|
|
|
await smartarchiveInstance.extractArchiveFromUrlToFs(this.dist.tarball, targetDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* saves the package to memory
|
|
|
|
*/
|
|
|
|
public async saveToMemory() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get file from package
|
|
|
|
*/
|
|
|
|
public async getFileFromPackage(filePath: string): Promise<plugins.smartfile.Smartfile> {
|
|
|
|
const done = plugins.smartpromise.defer<plugins.smartfile.Smartfile>();
|
|
|
|
const smartarchiveInstance = new plugins.smartarchive.SmartArchive();
|
|
|
|
const fileObservable = await smartarchiveInstance.extractArchiveFromUrlToObservable(
|
|
|
|
this.dist.tarball
|
|
|
|
);
|
|
|
|
const wantedFilePath = plugins.path.join('package', filePath);
|
|
|
|
const subscription = fileObservable.subscribe(
|
|
|
|
(fileArg) => {
|
|
|
|
if (fileArg.path === wantedFilePath) {
|
|
|
|
done.resolve(fileArg);
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(err) => {
|
|
|
|
console.log(err);
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return done.promise;
|
2020-03-17 00:38:58 +00:00
|
|
|
}
|
2017-08-14 15:50:48 +00:00
|
|
|
}
|