diff --git a/deno.lock b/deno.lock index 31ca1e0..5bef393 100644 --- a/deno.lock +++ b/deno.lock @@ -32,6 +32,9 @@ } } }, + "redirects": { + "https://deno.land/x/semver/mod.ts": "https://deno.land/x/semver@v1.4.1/mod.ts" + }, "remote": { "https://cdn.jsdelivr.net/gh/fluentci-io/daggerverse@main/deno-sdk/sdk/deps.ts": "b7ad10566ba7f615d264c0422c7b9a2ad437aeff8eaaaba6ea72c2edc7bf74ac", "https://cdn.jsdelivr.net/gh/fluentci-io/daggerverse@main/deno-sdk/sdk/src/mod/introspect.ts": "c16766ecfa2edae4c2ecd644d1529d4a5ec156ca6fd48965cf76eafaa32c978e", @@ -343,6 +346,47 @@ "https://deno.land/std@0.210.0/path/windows/join.ts": "e6600bf88edeeef4e2276e155b8de1d5dec0435fd526ba2dc4d37986b2882f16", "https://deno.land/std@0.210.0/path/windows/normalize.ts": "9deebbf40c81ef540b7b945d4ccd7a6a2c5a5992f791e6d3377043031e164e69", "https://deno.land/std@0.211.0/streams/merge_readable_streams.ts": "9c541012e130d6e36086b6b8c197078a6053f5446367e33f233b71858a2c03cc", + "https://deno.land/std@0.212.0/semver/_constants.ts": "90879e4ea94a34c49c8ecea3d9c06e13e61ecb7caca80c8f289139440ca9835a", + "https://deno.land/std@0.212.0/semver/_shared.ts": "8d44684775cde4a64bd6bdb99b51f3bc59ed65f10af78ca136cc2eab3f6716f1", + "https://deno.land/std@0.212.0/semver/comparator_format.ts": "96feeab7ffb45df3e7087bf8a84da3401816be5687007e1afd5581dd8043623a", + "https://deno.land/std@0.212.0/semver/comparator_intersects.ts": "a271f3e1caae857e4b8574f43bc926cf7ba906ade0c2d3bd97fcda98be74fbb0", + "https://deno.land/std@0.212.0/semver/comparator_max.ts": "2038cded7cce886e2c81926acb97f625908707f2d66864b603493b9674e2bd58", + "https://deno.land/std@0.212.0/semver/comparator_min.ts": "453d3e449aaee4d59acc9b36fe77eddfcb0c4097ffe7efe11eb2a04a64cc520d", + "https://deno.land/std@0.212.0/semver/compare.ts": "e507146fd997d33ae5abc2675e8b24a1ea84b50ddc9918cb8ddc1b1911c97011", + "https://deno.land/std@0.212.0/semver/compare_build.ts": "e37c2d24bc138b3fdaeb55cf85b1c94e7cf9120f16f64dff0e24659f1ba79de6", + "https://deno.land/std@0.212.0/semver/constants.ts": "a815db7a80bbea2469a1a30cd14aa61d6a58d5c84d44cb0b17febe485563d26c", + "https://deno.land/std@0.212.0/semver/difference.ts": "be4f01b7745406408a16b708185a48c1c652cc87e0244b12a5ca75c5585db668", + "https://deno.land/std@0.212.0/semver/eq.ts": "ae97d41e4068e2dbc151a2fce35bdc9815dcd71cc297a54c9623831c8a4737b9", + "https://deno.land/std@0.212.0/semver/format.ts": "2d0b8690bc0659a5756aa339d0d31385c3783a0bbd7d8d25c210cd6b5e4224f8", + "https://deno.land/std@0.212.0/semver/format_range.ts": "935425c6594c51220cbc5af88209f9b4452cbc3d86db99fb0c1be0fbb958cab6", + "https://deno.land/std@0.212.0/semver/gt.ts": "bdbfe1f77c9c61f7f9aaf5ab2871a65c800bc546db124eead512b06f14faecc1", + "https://deno.land/std@0.212.0/semver/gte.ts": "cf43eafbaa6db6fb9f1b057d81d3a8d2725099e4ee8db824c84a57fb69c8a982", + "https://deno.land/std@0.212.0/semver/gtr.ts": "196618d1bdee2f1b9125338f36a9b57c637780b5c4ca1d834dfb8a170c152a4c", + "https://deno.land/std@0.212.0/semver/increment.ts": "427a043be71d6481e45c1a3939b955e800924d70779cb297b872d9cbf9f0e46d", + "https://deno.land/std@0.212.0/semver/is_comparator.ts": "895e7ecff33d23d7a465074a76b2341eda430f84c4817199f7492c5393e2e54f", + "https://deno.land/std@0.212.0/semver/is_semver.ts": "57914027d6141e593eb04418aaabbfd6f4562a1c53c6c33a1743fa50ada8d849", + "https://deno.land/std@0.212.0/semver/is_semver_range.ts": "c65a83c48a623958039628d61e03e3455f87236c4445e43e52afc0c474547ab2", + "https://deno.land/std@0.212.0/semver/lt.ts": "70fecfbad1dd6b7d42f7589efc81fa039688f15a42bc6b86fb3f0fd1e758ef65", + "https://deno.land/std@0.212.0/semver/lte.ts": "2b59c8d54eb1ddb76ddc373ae2243532a049585e628b479cfb0bb29268bf04bb", + "https://deno.land/std@0.212.0/semver/ltr.ts": "9131cd311acd643ad1ea3c815378373409433f2cb0f9efe3cd910bcf50dadda1", + "https://deno.land/std@0.212.0/semver/max_satisfying.ts": "5440018944e076cc7ad5805896c18132c4f65c6e404a4c72a5a8fcd900a66bb4", + "https://deno.land/std@0.212.0/semver/min_satisfying.ts": "767d8ba8d15c5f891be050ad22b13070575a35c5e5e28d0397730de07b121906", + "https://deno.land/std@0.212.0/semver/mod.ts": "ad2c7fea66f690abcce9fa3c9612ad617d577bca73dde0b849ff8727133953fb", + "https://deno.land/std@0.212.0/semver/neq.ts": "ac2bfcca1a616a1303079fbd1afcf205877ac1e0ca7f2bb3f77595a777bbaef5", + "https://deno.land/std@0.212.0/semver/outside.ts": "a61fa278c204b3e985b6f49be39f7bcb604d3b3134bcb8b9d507ebf75c64b89a", + "https://deno.land/std@0.212.0/semver/parse.ts": "2ba215c9aa3c71be753570724cfad75cc81972f0026dc81836ea3d1986112066", + "https://deno.land/std@0.212.0/semver/parse_comparator.ts": "0dca4bee9695ae30a7f0c4829b0b1b8c287f1b40fdb513e38527343bc331e375", + "https://deno.land/std@0.212.0/semver/parse_range.ts": "3d3f9fc251f4acf7e28781271bd139f436994ad4e4625f30439792af2eab9613", + "https://deno.land/std@0.212.0/semver/range_format.ts": "a7b447090c5bb47f876ec0511d17bb3eb116ef04e8c990c28ae309abd3f6ddba", + "https://deno.land/std@0.212.0/semver/range_intersects.ts": "904adb2b2f135f159d4783e1c220af86c77624938b3bc08cd59bfb4b7b0cf047", + "https://deno.land/std@0.212.0/semver/range_max.ts": "10f354f65a13d4b01be45786a3395c926f2e1dabfeca18d430e315a1c38170eb", + "https://deno.land/std@0.212.0/semver/range_min.ts": "b2ab6b539981689119ca36bb4d329aed795204f2c246bb9a48c55da19b05d196", + "https://deno.land/std@0.212.0/semver/reverse_sort.ts": "6e10806559a2b35415188fc984752dfe2f4ac60b3513e879b28c7b964f9c77cb", + "https://deno.land/std@0.212.0/semver/rsort.ts": "d6dea7ddd078446cd5f75e4d471a4fe006fcc69d05170ce4c27637216bfadb6e", + "https://deno.land/std@0.212.0/semver/sort.ts": "b97c4f392cf688e27d304dc437b1a4d7278fbf5d2554ad6e51f64db6cc405c09", + "https://deno.land/std@0.212.0/semver/test_comparator.ts": "24741dd4fda32c7b712d1509894e37f17b7dc6d62d79612d0f29b68aa61e6494", + "https://deno.land/std@0.212.0/semver/test_range.ts": "43e2f830a5ee6cebe2af98e0125e542111e8513a720819df83e3da3605d192ad", + "https://deno.land/std@0.212.0/semver/types.ts": "bcc7dbd6c96110db5eac98c56c7d57b6ee9b9e929779467cbc24f934632e9feb", "https://deno.land/std@0.52.0/fmt/colors.ts": "ec9d653672a9a3c7b6eafe53c5bc797364a2db2dcf766ab649c1155fea7a80b2", "https://deno.land/std@0.99.0/_util/assert.ts": "2f868145a042a11d5ad0a3c748dcf580add8a0dbc0e876eaa0026303a5488f58", "https://deno.land/std@0.99.0/_util/os.ts": "e282950a0eaa96760c0cf11e7463e66babd15ec9157d4c9ed49cc0925686f6a7", @@ -476,6 +520,7 @@ "https://deno.land/x/media_types@v2.9.0/db.ts": "ba39cddbcefce47d577c0529066787a3a7b39d27750a6d32b5ad53ed487e7b7b", "https://deno.land/x/media_types@v2.9.0/deps.ts": "364b24c35845cfd5c6903ab22b8ba9873bf1022bbbf6bf3d001695332d4bbb4f", "https://deno.land/x/media_types@v2.9.0/mod.ts": "d63583b978d32eff8b76e1ae5d83cba2fb27baa90cc1bcb0ad15a06122ea8c19", + "https://deno.land/x/semver@v1.4.1/mod.ts": "0b79c87562eb8a1f008ab0d98f8bb60076dd65bc06f1f8fdfac2d2dab162c27b", "https://deno.land/x/spinners@v1.1.2/mod.ts": "ed5b3562d4ea6c6887bc7e9844612b08a3bc3a3678ca77cc7dfdf461c362751e", "https://deno.land/x/spinners@v1.1.2/spinner-types.ts": "c67e6962a0c738aa57b4d3ad9fe06c8c0131f93360acbf95456f2ba200fd8826", "https://deno.land/x/spinners@v1.1.2/terminal-spinner.ts": "1cf0c38a423781734e2e538323c1992027830d741e90f0b81f532e5bc993d035", diff --git a/deps.ts b/deps.ts index 1775eae..d2302c6 100644 --- a/deps.ts +++ b/deps.ts @@ -1,12 +1,14 @@ +import * as semver from "https://deno.land/std@0.212.0/semver/mod.ts"; +export { semver }; export { - magenta, + bold, + brightGreen, brightMagenta, cyan, - bold, + gray, green, + magenta, red, - brightGreen, - gray, yellow, } from "https://deno.land/std@0.192.0/fmt/colors.ts"; export { z } from "https://deno.land/x/zod@v3.22.2/mod.ts"; @@ -15,22 +17,22 @@ export { existsSync } from "https://deno.land/std@0.203.0/fs/exists.ts"; export { load } from "https://deno.land/std@0.205.0/dotenv/mod.ts"; export { Secret } from "https://deno.land/x/cliffy@v1.0.0-rc.3/prompt/secret.ts"; export { - prompt, - Input, Confirm, + Input, + prompt, } from "https://deno.land/x/cliffy@v1.0.0-rc.3/prompt/mod.ts"; import dir from "https://deno.land/x/dir@1.5.2/mod.ts"; export { dir }; -export { walkSync, walk } from "https://deno.land/std@0.210.0/fs/walk.ts"; +export { walk, walkSync } from "https://deno.land/std@0.210.0/fs/walk.ts"; export type { WalkEntry } from "https://deno.land/std@0.208.0/fs/walk.ts"; export { BlobReader, BlobWriter, TextReader, TextWriter, + Uint8ArrayReader, ZipReader, ZipWriter, - Uint8ArrayReader, } from "https://deno.land/x/zipjs@v2.7.32/index.js"; import introspect from "https://cdn.jsdelivr.net/gh/fluentci-io/daggerverse@main/deno-sdk/sdk/src/mod/introspect.ts"; export { introspect }; diff --git a/src/cmd/upgrade.ts b/src/cmd/upgrade.ts index c8ae486..91791b9 100644 --- a/src/cmd/upgrade.ts +++ b/src/cmd/upgrade.ts @@ -1,5 +1,5 @@ import { VERSION } from "../consts.ts"; -import { yellow, green } from "../../deps.ts"; +import { green, semver, yellow } from "../../deps.ts"; /** * Upgrades FluentCI by installing the latest version from the Deno registry. @@ -28,36 +28,31 @@ async function upgrade() { export default upgrade; export async function checkForUpdate(options: { checkUpdate: boolean }) { - const { checkUpdate } = options + const { checkUpdate } = options; if (!checkUpdate) { - return + return; } try { - const result = await fetch("https://api.github.com/repos/fluentci-io/fluentci/releases/latest") - const releaseInfo = await result.json() - - if (versionGreaterThan(releaseInfo.tag_name, VERSION)) { + const result = await fetch( + "https://api.github.com/repos/fluentci-io/fluentci/releases/latest", + ); + const releaseInfo = await result.json(); + + const latestVersion = semver.parse(releaseInfo.tag_name); + const currentVersion = semver.parse(VERSION); + + if (semver.gt(latestVersion, currentVersion)) { console.log( - `${green('A new release of fluentci is available:')} ${VERSION} → ${releaseInfo.tag_name} \nTo upgrade: run fluentci upgrade\n${releaseInfo.url} - `) + `${ + green("A new release of fluentci is available:") + } ${VERSION} → ${releaseInfo.tag_name} \nTo upgrade: run fluentci upgrade\n${releaseInfo.url} + `, + ); } } catch (e) { console.log(` - ${yellow('WARNING: ')} checking for udpate failed ${e} - `) - } -} - -export const versionGreaterThan = (v1: string, v2: string): boolean => { - const numbers1 = v1.replace('v', '').split('.').map(Number) - const numbers2 = v2.replace('v', '').split('.').map(Number) - - for (let i = 0; i < 3; i++) { - if (numbers1[i] > numbers2[i]) { - return true; - } + ${yellow("WARNING: ")} checking for udpate failed ${e} + `); } - - return false; } diff --git a/tests/upgrade.test.ts b/tests/upgrade.test.ts deleted file mode 100644 index fcc41d7..0000000 --- a/tests/upgrade.test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { assertEquals } from "https://deno.land/std@0.206.0/assert/mod.ts"; -import { versionGreaterThan } from '../src/cmd/upgrade.ts' - -Deno.test("semver comparasion", () => { - const tests = [ - { - v1: "v0.10.1", - v2: "v0.10.2", - want: false - }, - { - v1: "v0.10.2", - v2: "v0.10.1", - want: true - }, - { - v1: "v2.10.1", - v2: "v0.10.1", - want: true - }, - { - v1: "v0.10.0", - v2: "v0.10.0", - want: false - }, - ] - - tests.forEach((tt) => { - const res = versionGreaterThan(tt.v1, tt.v2) - assertEquals(res, tt.want) - }) -}); \ No newline at end of file