@net-protocol/cli 0.1.23 → 0.1.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.mjs +111 -2
- package/dist/cli/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { Command } from 'commander';
|
|
|
5
5
|
import { createRequire } from 'module';
|
|
6
6
|
import chalk4 from 'chalk';
|
|
7
7
|
import * as fs4 from 'fs';
|
|
8
|
-
import { readFileSync } from 'fs';
|
|
8
|
+
import { readFileSync, existsSync, mkdirSync, writeFileSync } from 'fs';
|
|
9
9
|
import { OPTIMAL_CHUNK_SIZE, StorageClient, detectFileTypeFromBase64, base64ToDataUri, shouldSuggestXmlStorage, getStorageKeyBytes, encodeStorageKeyForUrl, chunkDataForStorage, CHUNKED_STORAGE_CONTRACT, STORAGE_CONTRACT as STORAGE_CONTRACT$1 } from '@net-protocol/storage';
|
|
10
10
|
import { stringToHex, createWalletClient, http, hexToString, parseEther, encodeFunctionData, publicActions, defineChain } from 'viem';
|
|
11
11
|
import { privateKeyToAccount } from 'viem/accounts';
|
|
@@ -16,8 +16,10 @@ import { isNetrSupportedChain, NetrClient } from '@net-protocol/netr';
|
|
|
16
16
|
import { PROFILE_PICTURE_STORAGE_KEY, PROFILE_METADATA_STORAGE_KEY, parseProfileMetadata, PROFILE_CANVAS_STORAGE_KEY, isValidUrl, getProfilePictureStorageArgs, STORAGE_CONTRACT, isValidXUsername, getProfileMetadataStorageArgs, isValidBio, isValidDisplayName, isValidTokenAddress } from '@net-protocol/profiles';
|
|
17
17
|
import { base } from 'viem/chains';
|
|
18
18
|
import * as path from 'path';
|
|
19
|
+
import { join } from 'path';
|
|
19
20
|
import { BazaarClient } from '@net-protocol/bazaar';
|
|
20
21
|
import * as os from 'os';
|
|
22
|
+
import { homedir } from 'os';
|
|
21
23
|
import * as readline from 'readline';
|
|
22
24
|
|
|
23
25
|
var DEFAULT_CHAIN_ID = 8453;
|
|
@@ -6654,6 +6656,86 @@ function registerFeedCommand(program2) {
|
|
|
6654
6656
|
registerFeedHistoryCommand(feedCommand);
|
|
6655
6657
|
registerAgentRegisterCommand(feedCommand);
|
|
6656
6658
|
}
|
|
6659
|
+
var CACHE_DIR = join(homedir(), ".netp");
|
|
6660
|
+
var CACHE_FILE = join(CACHE_DIR, "update-check.json");
|
|
6661
|
+
var CHECK_INTERVAL_MS = 4 * 60 * 60 * 1e3;
|
|
6662
|
+
var FETCH_TIMEOUT_MS = 5e3;
|
|
6663
|
+
function isNewerVersion(latest, current) {
|
|
6664
|
+
const l = latest.split(".").map(Number);
|
|
6665
|
+
const c = current.split(".").map(Number);
|
|
6666
|
+
for (let i = 0; i < 3; i++) {
|
|
6667
|
+
if ((l[i] || 0) > (c[i] || 0)) return true;
|
|
6668
|
+
if ((l[i] || 0) < (c[i] || 0)) return false;
|
|
6669
|
+
}
|
|
6670
|
+
return false;
|
|
6671
|
+
}
|
|
6672
|
+
function readCache() {
|
|
6673
|
+
try {
|
|
6674
|
+
if (existsSync(CACHE_FILE)) {
|
|
6675
|
+
return JSON.parse(readFileSync(CACHE_FILE, "utf-8"));
|
|
6676
|
+
}
|
|
6677
|
+
} catch {
|
|
6678
|
+
}
|
|
6679
|
+
return null;
|
|
6680
|
+
}
|
|
6681
|
+
function writeCache(cache) {
|
|
6682
|
+
try {
|
|
6683
|
+
if (!existsSync(CACHE_DIR)) {
|
|
6684
|
+
mkdirSync(CACHE_DIR, { recursive: true });
|
|
6685
|
+
}
|
|
6686
|
+
writeFileSync(CACHE_FILE, JSON.stringify(cache));
|
|
6687
|
+
} catch {
|
|
6688
|
+
}
|
|
6689
|
+
}
|
|
6690
|
+
async function fetchLatestVersion(pkg) {
|
|
6691
|
+
try {
|
|
6692
|
+
const controller = new AbortController();
|
|
6693
|
+
const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
6694
|
+
const res = await fetch(
|
|
6695
|
+
`https://registry.npmjs.org/${encodeURIComponent(pkg).replace("%40", "@")}/latest`,
|
|
6696
|
+
{ signal: controller.signal }
|
|
6697
|
+
);
|
|
6698
|
+
clearTimeout(timeout);
|
|
6699
|
+
if (res.ok) {
|
|
6700
|
+
const data = await res.json();
|
|
6701
|
+
return data.version;
|
|
6702
|
+
}
|
|
6703
|
+
} catch {
|
|
6704
|
+
}
|
|
6705
|
+
return null;
|
|
6706
|
+
}
|
|
6707
|
+
async function getUpdateInfo(currentVersion) {
|
|
6708
|
+
const cache = readCache();
|
|
6709
|
+
if (cache && Date.now() - cache.lastCheck < CHECK_INTERVAL_MS) {
|
|
6710
|
+
if (cache.latestVersion && isNewerVersion(cache.latestVersion, currentVersion)) {
|
|
6711
|
+
return { latest: cache.latestVersion };
|
|
6712
|
+
}
|
|
6713
|
+
return null;
|
|
6714
|
+
}
|
|
6715
|
+
const latest = await fetchLatestVersion("@net-protocol/cli");
|
|
6716
|
+
writeCache({
|
|
6717
|
+
lastCheck: Date.now(),
|
|
6718
|
+
latestVersion: latest
|
|
6719
|
+
});
|
|
6720
|
+
if (latest && isNewerVersion(latest, currentVersion)) {
|
|
6721
|
+
return { latest };
|
|
6722
|
+
}
|
|
6723
|
+
return null;
|
|
6724
|
+
}
|
|
6725
|
+
function printUpdateBanner(current, latest) {
|
|
6726
|
+
console.error("");
|
|
6727
|
+
console.error(
|
|
6728
|
+
chalk4.yellow(
|
|
6729
|
+
` Update available: ${chalk4.gray(current)} \u2192 ${chalk4.green(latest)}`
|
|
6730
|
+
)
|
|
6731
|
+
);
|
|
6732
|
+
console.error(
|
|
6733
|
+
chalk4.yellow(
|
|
6734
|
+
` Run ${chalk4.cyan("npm install -g @net-protocol/cli@latest")} to update`
|
|
6735
|
+
)
|
|
6736
|
+
);
|
|
6737
|
+
console.error("");
|
|
6738
|
+
}
|
|
6657
6739
|
|
|
6658
6740
|
// src/cli/index.ts
|
|
6659
6741
|
var proxyUrl = process.env.https_proxy || process.env.HTTPS_PROXY;
|
|
@@ -6673,6 +6755,33 @@ registerTokenCommand(program);
|
|
|
6673
6755
|
registerProfileCommand(program);
|
|
6674
6756
|
registerBazaarCommand(program);
|
|
6675
6757
|
registerFeedCommand(program);
|
|
6676
|
-
program.
|
|
6758
|
+
program.command("update").description("Update netp to the latest version").action(async () => {
|
|
6759
|
+
const { execSync } = await import('child_process');
|
|
6760
|
+
console.log("Updating @net-protocol/cli...");
|
|
6761
|
+
try {
|
|
6762
|
+
execSync("npm install -g @net-protocol/cli@latest", {
|
|
6763
|
+
stdio: "inherit"
|
|
6764
|
+
});
|
|
6765
|
+
console.log(chalk4.green("\n\u2713 netp updated successfully"));
|
|
6766
|
+
} catch {
|
|
6767
|
+
console.error(
|
|
6768
|
+
chalk4.red(
|
|
6769
|
+
"Failed to update. Try manually: npm install -g @net-protocol/cli@latest"
|
|
6770
|
+
)
|
|
6771
|
+
);
|
|
6772
|
+
}
|
|
6773
|
+
});
|
|
6774
|
+
var updatePromise = getUpdateInfo(version).catch(() => null);
|
|
6775
|
+
await program.parseAsync();
|
|
6776
|
+
try {
|
|
6777
|
+
const updateInfo = await Promise.race([
|
|
6778
|
+
updatePromise,
|
|
6779
|
+
new Promise((resolve3) => setTimeout(() => resolve3(null), 1500))
|
|
6780
|
+
]);
|
|
6781
|
+
if (updateInfo) {
|
|
6782
|
+
printUpdateBanner(version, updateInfo.latest);
|
|
6783
|
+
}
|
|
6784
|
+
} catch {
|
|
6785
|
+
}
|
|
6677
6786
|
//# sourceMappingURL=index.mjs.map
|
|
6678
6787
|
//# sourceMappingURL=index.mjs.map
|