Skip to content

Commit

Permalink
Add initial caching of disc-saved packages
Browse files Browse the repository at this point in the history
  • Loading branch information
dmstern committed Dec 5, 2018
1 parent b673239 commit d6f93a1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
35 changes: 35 additions & 0 deletions server/cache-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { promisify } from 'util';
import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
import artifactoryService from './artifactory-service';

const readdir = promisify(fs.readdir);

export default {
tmpDir: path.join(os.homedir(), '.npmfrog', 'package-cache'),

// tslint:disable-next-line:typedef
async fillCacheFromDisc() {
const promises = [];
const scopes = await readdir(this.tmpDir);
for (const scope of scopes) {
const packages = await readdir(path.join(this.tmpDir, scope));
for (const packageName of packages) {
const versions = await readdir(path.join(this.tmpDir, scope, packageName));
for (const version of versions) {
artifactoryService
.getPackageDetail({ scope, packageName, version })
.then(() => {
console.log(`caching ${scope}/${packageName}@${version} from disc`);
})
.catch(() => {
console.warn(
`${scope}/${packageName}@${version} on disc seems to be outdated. Is will not be cached.`,
);
});
}
}
}
},
};
3 changes: 3 additions & 0 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as morgan from 'morgan';
import * as fs from 'fs-extra';
import configService from './config-service';
import artifactoryService from './artifactory-service';
import cacheService from './cache-service';

const portNumber = 30001;

Expand Down Expand Up @@ -117,3 +118,5 @@ app.get('/meta', (req, res) => {
});

app.listen(portNumber);

cacheService.fillCacheFromDisc();

0 comments on commit d6f93a1

Please sign in to comment.