Skip to content

[feat] Switched to using raspar utilities for dealing with cache. #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,6 @@ $ echo $UNITY_URL

## API

### `checkCacheExpiry(string path, integer ttl)`

```javascript
const { checkCacheExpiry } = require("get-unity");

checkCacheExpiry("./data/editor-installers.json", 3600000)
.then(() => console.log("Cache is ok."))
.catch(() => console.log("Cache has expired."));
```

### `fetchWithLocalCache(string path, integer ttl)`

```javascript
const { fetchWithLocalCache } = require("get-unity");

fetchWithLocalCache(
"https://unity3d.com/get-unity/download/archive",
"./temp/archive.html",
3600000
).then(response => console.log(response));
```

### `getUnityUrls(string filter [, string filePath])`

```javascript
Expand Down
4 changes: 0 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
const checkCacheExpiry = require('./utils/check-cache-expiry');
const fetchWithLocalCache = require('./utils/fetch-with-local-cache');
const getUnityUrls = require('./lib/get-unity-urls');
const parsers = require('./lib/parsers');
const updateEditorInstallers = require('./lib/update-editor-installers');

module.exports = {
checkCacheExpiry,
fetchWithLocalCache,
getUnityUrls,
parsers,
updateEditorInstallers
Expand Down
41 changes: 12 additions & 29 deletions lib/update-editor-installers.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
const fs = require('fs');
const {join} = require('path');
const {promisify} = require('util');

const writeFile = promisify(fs.writeFile);

const {JSDOM} = require('jsdom');

const checkCacheExpiry = require('../utils/check-cache-expiry');
const fetchWithLocalCache = require('../utils/fetch-with-local-cache');

const ARCHIVE_FILE_PATH = join(
__dirname,
'../temp/archive.html'
);
const {fetch, 'utils': {readCache, writeCache}} = require('raspar');

const EDITOR_INSTALLERS_FILE_PATH = join(
__dirname,
Expand Down Expand Up @@ -56,29 +46,22 @@ const parseVersionFromUnityArchive = body => {
};

const updateEditorInstallers = (filePath = EDITOR_INSTALLERS_FILE_PATH, ttl = DEFAULT_CACHE_TTL) =>
checkCacheExpiry(
readCache(
filePath,
ttl
)
.catch(() =>
fetchWithLocalCache(
'https://unity3d.com/get-unity/download/archive',
ARCHIVE_FILE_PATH,
ttl
)
.then(parseVersionFromUnityArchive)
.then(data =>
writeFile(
filePath,
JSON.stringify(
data,
null,
JSON_TAB_WIDTH
)
)))
.catch(() => {

throw new Error('There was an error fetching the latest versions from unity3d.com');
fetch('https://unity3d.com/get-unity/download/archive')
.then(parseVersionFromUnityArchive)
.then(data => writeCache(
filePath,
JSON.stringify(
data,
null,
JSON_TAB_WIDTH
)
));

});

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"chalk": "2.4.2",
"jsdom": "15.2.1",
"meow": "5.0.0",
"mkdirp": "0.5.1",
"request": "2.88.0",
"raspar": "2.0.0",
"update-notifier": "3.0.1"
},
"devDependencies": {
Expand Down
17 changes: 0 additions & 17 deletions utils/check-cache-expiry.js

This file was deleted.

32 changes: 0 additions & 32 deletions utils/fetch-with-local-cache.js

This file was deleted.