Skip to content
Open
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
1 change: 1 addition & 0 deletions .env.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHECK_UPDATE_INTERVAL=
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need the default one?

1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHECK_UPDATE_INTERVAL=1
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
last_check_update.txt
last_check_update.txt
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't be better if we use the same .env file do get this too?

.env
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,11 @@
"editor.formatOnSave": true,
"typescriptHero.imports.stringQuoteStyle": "'",
"typescriptHero.imports.organizeOnSave": true,
"typescriptHero.imports.disableImportRemovalOnOrganize": true
"typescriptHero.imports.disableImportRemovalOnOrganize": true,
"[json]": {
"editor.defaultFormatter": "denoland.vscode-deno"
},
"[typescript]": {
"editor.defaultFormatter": "denoland.vscode-deno"
}
}
4 changes: 3 additions & 1 deletion import_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"std/fs": "https://deno.land/std@0.106.0/fs/mod.ts",
"std/path": "https://deno.land/std@0.106.0/path/mod.ts",
"ask": "https://deno.land/x/ask@1.0.6/mod.ts",
"iro": "https://deno.land/x/iro@1.0.3/mod.ts"
"iro": "https://deno.land/x/iro@1.0.3/mod.ts",
"dotenv": "https://deno.land/x/dotenv@v3.2.0/mod.ts",
"mock": "https://deno.land/std@0.136.0/testing/mock.ts"
}
}
9 changes: 5 additions & 4 deletions scripts/self_update.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Ask from 'ask';
import { config } from 'dotenv';
import iro, { bold, yellow } from 'iro';
import { difference, format } from 'std/datetime';
import { dirname, fromFileUrl } from 'std/path';
Expand All @@ -9,11 +10,12 @@ import { printLogo } from '/logo/print_logo.ts';
const cwd = dirname(fromFileUrl(import.meta.url));
const today = format(new Date(), 'yyyy-MM-dd');
const lastCheckUpdateFileName = 'last_check_update.txt';
const { CHECK_UPDATE_INTERVAL } = config({ safe: true, allowEmptyValues: true });

shouldCheckForUpdates();

async function shouldCheckForUpdates() {
const checkUpdateIntervalEnv = Deno.env.get('CHECK_UPDATE_INTERVAL');
export async function shouldCheckForUpdates() {
const checkUpdateIntervalEnv = CHECK_UPDATE_INTERVAL;

if (!checkUpdateIntervalEnv) {
return checkNewVersion();
Expand All @@ -29,7 +31,6 @@ async function shouldCheckForUpdates() {
const daysSinceLastCheckUpdate = difference(lastCheckUpdateDate, new Date(today), {
units: ['days'],
}).days as number;

if (daysSinceLastCheckUpdate >= +checkUpdateIntervalEnv) {
checkNewVersion();
}
Expand All @@ -38,7 +39,7 @@ async function shouldCheckForUpdates() {
}
}

async function checkNewVersion() {
export async function checkNewVersion() {
storeLastCheckUpdateDate();
const _fetch = await Deno.run({ cmd: 'git fetch -q origin main'.split(' '), cwd }).status();

Expand Down
17 changes: 17 additions & 0 deletions tests/self_update.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { spy } from 'mock';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove it and add the tests in a new PR


import { assertEquals } from '../dev_deps.ts';
import { shouldCheckForUpdates } from '../scripts/self_update.ts';

// import { mock, assertEquals } from '/dev_deps.ts';

/**
* should check for updates each x days
* mocks: checkUpdateIntervalEnv, lastCheckUpdateDate
*/
Deno.test('should check for updates each x days', () => {
});

/**
* if the varible is not defined, should check every time
*/