Skip to content

Commit 6fcb0a7

Browse files
authored
[feat] Force flag (#19)
* Changed variable name. * Added ttl as an attribute of updateEditorInstallers. * Disabled no-ternary error. * Added force flag to zero out cache TTL. * Added postinstall target for updating the editor installers on isntall. * Update README.md * Use direct path rather than linked command. * Removed period in path. * Added node call before path to node script.
1 parent ee5fb91 commit 6fcb0a7

File tree

5 files changed

+42
-9
lines changed

5 files changed

+42
-9
lines changed

.eslintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"extends": ["@neogeek/eslint-config-standards"]
2+
"extends": ["@neogeek/eslint-config-standards"],
3+
"rules": {
4+
"no-ternary": "off"
5+
}
36
}

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ $ UNITY_URL=$(get-unity --file=ProjectSettings/ProjectVersion.txt)
4545
$ echo $UNITY_URL
4646
```
4747

48+
## Help
49+
50+
```bash
51+
Command line tool for getting the download URL for the latest or specific version of Unity.
52+
53+
Usage
54+
$ get-unity <version> [options]
55+
56+
Options
57+
--file, -f Search file for Unity version number.
58+
--force, -r Force update to local cache of editor versions.
59+
--offline, -o Prevent request to update local cache of editor versions.
60+
--help, -h Display this help message.
61+
--version, -v Display the current installed version.
62+
```
63+
4864
## API
4965

5066
### `checkCacheExpiry(string path, integer ttl)`
@@ -105,12 +121,12 @@ Output:
105121
2019.2.9f1
106122
```
107123

108-
### `updateEditorInstallers([string filePath])`
124+
### `updateEditorInstallers([string filePath, int ttl])`
109125

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

113-
updateEditorInstallers("./data/editor-installers.json").then(() =>
129+
updateEditorInstallers("./data/editor-installers.json", 3600000).then(() =>
114130
console.log("Done")
115131
);
116132
```

bin/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const cli = meow(
2222
2323
Options
2424
${chalk.yellow('--file, -f')} Search file for Unity version number.
25+
${chalk.yellow('--force, -r')} Force update to local cache of editor versions.
2526
${chalk.yellow('--offline, -o')} Prevent request to update local cache of editor versions.
2627
${chalk.yellow('--help, -h')} Display this help message.
2728
${chalk.yellow('--version, -v')} Display the current installed version.
@@ -32,6 +33,11 @@ const cli = meow(
3233
'alias': 'f',
3334
'type': 'string'
3435
},
36+
'force': {
37+
'alias': 'r',
38+
'default': false,
39+
'type': 'boolean'
40+
},
3541
'help': {
3642
'alias': 'h',
3743
'default': false,
@@ -61,6 +67,8 @@ const EDITOR_INSTALLERS_FILE_PATH = join(
6167
'../data/editor-installers.json'
6268
);
6369

70+
const DEFAULT_CACHE_TTL = 3600000;
71+
6472
updateNotifier({pkg}).notify();
6573

6674
if (cli.flags.file) {
@@ -92,7 +100,12 @@ if (cli.flags.offline) {
92100

93101
} else {
94102

95-
updateEditorInstallers(EDITOR_INSTALLERS_FILE_PATH)
103+
updateEditorInstallers(
104+
EDITOR_INSTALLERS_FILE_PATH,
105+
cli.flags.force
106+
? 0
107+
: DEFAULT_CACHE_TTL
108+
)
96109
.catch(({message}) => {
97110

98111
process.stderr.write(`${chalk.red('Error:')} ${message}`);

lib/update-editor-installers.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const EDITOR_INSTALLERS_FILE_PATH = join(
2121

2222
const JSON_TAB_WIDTH = 2;
2323

24-
const CACHE_TTL = 3600000;
24+
const DEFAULT_CACHE_TTL = 3600000;
2525

2626
const parseVersionFromUnityArchive = body => {
2727

@@ -55,16 +55,16 @@ const parseVersionFromUnityArchive = body => {
5555

5656
};
5757

58-
const updateEditorInstallers = (filePath = EDITOR_INSTALLERS_FILE_PATH) =>
58+
const updateEditorInstallers = (filePath = EDITOR_INSTALLERS_FILE_PATH, ttl = DEFAULT_CACHE_TTL) =>
5959
checkCacheExpiry(
6060
filePath,
61-
CACHE_TTL
61+
ttl
6262
)
6363
.catch(() =>
6464
fetchWithLocalCache(
6565
'https://unity3d.com/get-unity/download/archive',
6666
ARCHIVE_FILE_PATH,
67-
CACHE_TTL
67+
ttl
6868
)
6969
.then(parseVersionFromUnityArchive)
7070
.then(data =>

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"jest": "24.9.0"
2626
},
2727
"scripts": {
28-
"test": "jest"
28+
"test": "jest",
29+
"postinstall": "node bin/index.js --force"
2930
},
3031
"keywords": [
3132
"unity"

0 commit comments

Comments
 (0)