Compare commits

...

9 Commits

Author SHA1 Message Date
71abbbb5f1 1.0.23 2021-04-21 09:25:32 +00:00
9dfa1a789e fix(core): update 2021-04-21 09:25:31 +00:00
c68ea1c8fd 1.0.22 2021-04-19 14:34:27 +00:00
8e943512f8 1.0.21 2021-04-19 14:22:42 +00:00
c010319076 fix(core): update 2021-04-19 14:22:42 +00:00
cf03e58c6f 1.0.20 2021-04-19 12:55:12 +00:00
d59875f23f fix(core): update 2021-04-19 12:55:11 +00:00
6b13e46947 1.0.19 2020-10-02 14:39:47 +00:00
096c38de9e fix(core): update 2020-10-02 14:39:46 +00:00
8 changed files with 7527 additions and 1165 deletions

8609
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartnpm", "name": "@pushrocks/smartnpm",
"version": "1.0.18", "version": "1.0.23",
"private": false, "private": false,
"description": "interface with npm to retrieve package information", "description": "interface with npm to retrieve package information",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
@ -12,19 +12,20 @@
"build": "(tsbuild --web)" "build": "(tsbuild --web)"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.24", "@gitzone/tsbuild": "^2.1.25",
"@gitzone/tsrun": "^1.2.12", "@gitzone/tsrun": "^1.2.12",
"@gitzone/tstest": "^1.0.33", "@gitzone/tstest": "^1.0.52",
"@pushrocks/tapbundle": "^3.2.1", "@pushrocks/tapbundle": "^3.2.14",
"@types/node": "^14.0.14", "@types/node": "^14.14.41",
"tslint": "^6.1.2", "tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/consolecolor": "^2.0.1", "@pushrocks/consolecolor": "^2.0.1",
"@pushrocks/smartarchive": "^1.0.12", "@pushrocks/smartarchive": "^2.0.4",
"@pushrocks/smartfile": "^7.0.12", "@pushrocks/smartfile": "^8.0.9",
"@pushrocks/smartrequest": "^1.1.47", "@pushrocks/smartpromise": "^3.1.3",
"@pushrocks/smartrequest": "^1.1.51",
"package-json": "^6.5.0" "package-json": "^6.5.0"
}, },
"files": [ "files": [

0
qenv.yml Normal file
View File

View File

@ -39,8 +39,9 @@ tap.test('should get package from verdaccio', async () => {
tap.test('should get a specific file from a package', async () => { tap.test('should get a specific file from a package', async () => {
const bundleFile = await verdaccioRegistry.getFileFromPackage( const bundleFile = await verdaccioRegistry.getFileFromPackage(
'@pushrocks/websetup', '@pushrocks/websetup',
'dist_bundle/bundle.js' 'ts/index.ts'
); );
console.log(bundleFile.contentBuffer.toString());
}); });
tap.start(); tap.start();

View File

@ -48,9 +48,9 @@ export class NpmPackage {
} = null; } = null;
public searchScore: number = null; public searchScore: number = null;
public npmRegistry: NpmRegistry; public npmRegistryRef: NpmRegistry;
constructor(npmRegistryArg: NpmRegistry) { constructor(npmRegistryArg: NpmRegistry) {
this.npmRegistry = npmRegistryArg; this.npmRegistryRef = npmRegistryArg;
} }
/** /**
@ -58,6 +58,38 @@ export class NpmPackage {
*/ */
public async saveToDisk(targetDir: string) { public async saveToDisk(targetDir: string) {
const smartarchiveInstance = new plugins.smartarchive.SmartArchive(); const smartarchiveInstance = new plugins.smartarchive.SmartArchive();
await smartarchiveInstance.extractArchiveFromUrl(this.dist.tarball, targetDir); 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;
} }
} }

View File

@ -13,7 +13,6 @@ export interface INpmRegistryConstructorOptions {
export class NpmRegistry { export class NpmRegistry {
public options: INpmRegistryConstructorOptions; public options: INpmRegistryConstructorOptions;
public registry: string;
private searchDomain = 'https://api.npms.io/v2/search?q='; private searchDomain = 'https://api.npms.io/v2/search?q=';
constructor(optionsArg: INpmRegistryConstructorOptions = {}) { constructor(optionsArg: INpmRegistryConstructorOptions = {}) {
@ -45,6 +44,7 @@ export class NpmRegistry {
* @param targetDir * @param targetDir
*/ */
public async savePackageToDisk(packageName: string, targetDir: string): Promise<void> { public async savePackageToDisk(packageName: string, targetDir: string): Promise<void> {
plugins.smartfile.fs.ensureDirSync(paths.nogitDir);
const npmPackage = await this.getPackageInfo(packageName); const npmPackage = await this.getPackageInfo(packageName);
await npmPackage.saveToDisk(targetDir); await npmPackage.saveToDisk(targetDir);
} }
@ -52,15 +52,18 @@ export class NpmRegistry {
/** /**
* gets a file from a package as Smartfile * gets a file from a package as Smartfile
*/ */
public async getFileFromPackage(packageName: string, filePath: string) { public async getFileFromPackage(packageNameArg: string, filePath: string): Promise<plugins.smartfile.Smartfile> {
const baseDir = plugins.path.join(paths.nogitDir, packageName.replace('/', '__')); const npmPackage = await this.getPackageInfo(packageNameArg);
return npmPackage.getFileFromPackage(filePath);
}
public async getPackageAsSmartfileVirtualDir(packageNameArg: string): Promise<plugins.smartfile.VirtualDirectory> {
const baseDir = plugins.path.join(paths.nogitDir, packageNameArg.replace('/', '__'));
await plugins.smartfile.fs.ensureDir(baseDir); await plugins.smartfile.fs.ensureDir(baseDir);
await this.savePackageToDisk(packageName, baseDir); await this.savePackageToDisk(packageNameArg, baseDir);
const smartfile = await plugins.smartfile.Smartfile.fromFilePath( const virtualDir = await plugins.smartfile.VirtualDirectory.fromFsDirPath(baseDir);
plugins.path.join(baseDir, 'package', filePath)
);
await plugins.smartfile.fs.remove(baseDir); await plugins.smartfile.fs.remove(baseDir);
return smartfile; return virtualDir;
} }
/** /**

View File

@ -2,4 +2,3 @@ import * as plugins from './smartnpm.plugins';
export const packageDir = plugins.path.join(__dirname, '../'); export const packageDir = plugins.path.join(__dirname, '../');
export const nogitDir = plugins.path.join(packageDir, '.nogit/'); export const nogitDir = plugins.path.join(packageDir, '.nogit/');
plugins.smartfile.fs.ensureDirSync(nogitDir);

View File

@ -7,9 +7,10 @@ export { path };
import * as consolecolor from '@pushrocks/consolecolor'; import * as consolecolor from '@pushrocks/consolecolor';
import * as smartarchive from '@pushrocks/smartarchive'; import * as smartarchive from '@pushrocks/smartarchive';
import * as smartfile from '@pushrocks/smartfile'; import * as smartfile from '@pushrocks/smartfile';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrequest from '@pushrocks/smartrequest'; import * as smartrequest from '@pushrocks/smartrequest';
export { consolecolor, smartarchive, smartfile, smartrequest }; export { consolecolor, smartarchive, smartfile, smartpromise, smartrequest };
// third party scope // third party scope
import packageJson from 'package-json'; import packageJson from 'package-json';