Skip to content

[feat] Force flag #19

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 9 commits into from
Nov 7, 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
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": ["@neogeek/eslint-config-standards"]
"extends": ["@neogeek/eslint-config-standards"],
"rules": {
"no-ternary": "off"
}
}
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ $ UNITY_URL=$(get-unity --file=ProjectSettings/ProjectVersion.txt)
$ echo $UNITY_URL
```

## Help

```bash
Command line tool for getting the download URL for the latest or specific version of Unity.

Usage
$ get-unity <version> [options]

Options
--file, -f Search file for Unity version number.
--force, -r Force update to local cache of editor versions.
--offline, -o Prevent request to update local cache of editor versions.
--help, -h Display this help message.
--version, -v Display the current installed version.
```

## API

### `checkCacheExpiry(string path, integer ttl)`
Expand Down Expand Up @@ -105,12 +121,12 @@ Output:
2019.2.9f1
```

### `updateEditorInstallers([string filePath])`
### `updateEditorInstallers([string filePath, int ttl])`

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

updateEditorInstallers("./data/editor-installers.json").then(() =>
updateEditorInstallers("./data/editor-installers.json", 3600000).then(() =>
console.log("Done")
);
```
15 changes: 14 additions & 1 deletion bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const cli = meow(

Options
${chalk.yellow('--file, -f')} Search file for Unity version number.
${chalk.yellow('--force, -r')} Force update to local cache of editor versions.
${chalk.yellow('--offline, -o')} Prevent request to update local cache of editor versions.
${chalk.yellow('--help, -h')} Display this help message.
${chalk.yellow('--version, -v')} Display the current installed version.
Expand All @@ -32,6 +33,11 @@ const cli = meow(
'alias': 'f',
'type': 'string'
},
'force': {
'alias': 'r',
'default': false,
'type': 'boolean'
},
'help': {
'alias': 'h',
'default': false,
Expand Down Expand Up @@ -61,6 +67,8 @@ const EDITOR_INSTALLERS_FILE_PATH = join(
'../data/editor-installers.json'
);

const DEFAULT_CACHE_TTL = 3600000;

updateNotifier({pkg}).notify();

if (cli.flags.file) {
Expand Down Expand Up @@ -92,7 +100,12 @@ if (cli.flags.offline) {

} else {

updateEditorInstallers(EDITOR_INSTALLERS_FILE_PATH)
updateEditorInstallers(
EDITOR_INSTALLERS_FILE_PATH,
cli.flags.force
? 0
: DEFAULT_CACHE_TTL
)
.catch(({message}) => {

process.stderr.write(`${chalk.red('Error:')} ${message}`);
Expand Down
8 changes: 4 additions & 4 deletions lib/update-editor-installers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const EDITOR_INSTALLERS_FILE_PATH = join(

const JSON_TAB_WIDTH = 2;

const CACHE_TTL = 3600000;
const DEFAULT_CACHE_TTL = 3600000;

const parseVersionFromUnityArchive = body => {

Expand Down Expand Up @@ -55,16 +55,16 @@ const parseVersionFromUnityArchive = body => {

};

const updateEditorInstallers = (filePath = EDITOR_INSTALLERS_FILE_PATH) =>
const updateEditorInstallers = (filePath = EDITOR_INSTALLERS_FILE_PATH, ttl = DEFAULT_CACHE_TTL) =>
checkCacheExpiry(
filePath,
CACHE_TTL
ttl
)
.catch(() =>
fetchWithLocalCache(
'https://unity3d.com/get-unity/download/archive',
ARCHIVE_FILE_PATH,
CACHE_TTL
ttl
)
.then(parseVersionFromUnityArchive)
.then(data =>
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"jest": "24.9.0"
},
"scripts": {
"test": "jest"
"test": "jest",
"postinstall": "node bin/index.js --force"
},
"keywords": [
"unity"
Expand Down