ic-mops 0.34.0-0 → 0.34.1-0
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/api/actors.ts +45 -0
- package/{helpers/download-package-files.ts → api/downloadPackageFiles.ts} +5 -5
- package/api/getHighestVersion.ts +6 -0
- package/api/index.ts +4 -0
- package/api/network.ts +24 -0
- package/{helpers/resolve-version.ts → api/resolveVersion.ts} +1 -1
- package/cli.ts +17 -3
- package/commands/add.ts +2 -1
- package/commands/available-updates.ts +1 -1
- package/commands/init.ts +2 -1
- package/commands/install.ts +4 -2
- package/commands/publish.ts +4 -2
- package/commands/search.ts +1 -1
- package/commands/transfer-ownership.ts +4 -2
- package/commands/user.ts +5 -2
- package/dist/api/actors.d.ts +6 -0
- package/dist/api/actors.js +32 -0
- package/dist/api/downloadPackageFiles.d.ts +12 -0
- package/dist/api/downloadPackageFiles.js +62 -0
- package/dist/api/getHighestVersion.d.ts +1 -0
- package/dist/api/getHighestVersion.js +5 -0
- package/dist/api/index.d.ts +4 -0
- package/dist/api/index.js +4 -0
- package/dist/api/network.d.ts +5 -0
- package/dist/api/network.js +23 -0
- package/dist/api/resolveVersion.d.ts +1 -0
- package/dist/api/resolveVersion.js +11 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +10 -4
- package/dist/commands/add.js +2 -1
- package/dist/commands/available-updates.js +1 -1
- package/dist/commands/init.js +2 -1
- package/dist/commands/install.js +4 -2
- package/dist/commands/publish.js +4 -2
- package/dist/commands/search.js +1 -1
- package/dist/commands/transfer-ownership.js +4 -2
- package/dist/commands/user.js +4 -2
- package/dist/integrity.js +2 -1
- package/dist/mops.d.ts +2 -14
- package/dist/mops.js +11 -72
- package/dist/notify-installs.js +2 -1
- package/dist/package.json +1 -1
- package/integrity.ts +2 -1
- package/mops.ts +14 -88
- package/notify-installs.ts +2 -1
- package/package.json +1 -1
package/api/actors.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {Actor, HttpAgent, Identity} from '@dfinity/agent';
|
|
2
|
+
import {Principal} from '@dfinity/principal';
|
|
3
|
+
|
|
4
|
+
import {idlFactory} from '../declarations/main/index.js';
|
|
5
|
+
import {_SERVICE} from '../declarations/main/main.did.js';
|
|
6
|
+
import {idlFactory as storageIdlFactory} from '../declarations/storage/index.js';
|
|
7
|
+
import {_SERVICE as _STORAGE_SERVICE} from '../declarations/storage/storage.did.js';
|
|
8
|
+
|
|
9
|
+
import {getEndpoint} from './network.js';
|
|
10
|
+
import {getNetwork} from './network.js';
|
|
11
|
+
|
|
12
|
+
export let mainActor = async (identity?: Identity): Promise<_SERVICE> => {
|
|
13
|
+
let network = getNetwork();
|
|
14
|
+
let host = getEndpoint(network).host;
|
|
15
|
+
let canisterId = getEndpoint(network).canisterId;
|
|
16
|
+
|
|
17
|
+
// @ts-ignore exactOptionalPropertyTypes
|
|
18
|
+
let agent = new HttpAgent({host, identity});
|
|
19
|
+
|
|
20
|
+
if (network === 'local') {
|
|
21
|
+
await agent.fetchRootKey();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return Actor.createActor(idlFactory, {
|
|
25
|
+
agent,
|
|
26
|
+
canisterId,
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export let storageActor = async (storageId: Principal, identity?: Identity): Promise<_STORAGE_SERVICE> => {
|
|
31
|
+
let network = getNetwork();
|
|
32
|
+
let host = getEndpoint(network).host;
|
|
33
|
+
|
|
34
|
+
// @ts-ignore exactOptionalPropertyTypes
|
|
35
|
+
let agent = new HttpAgent({host, identity});
|
|
36
|
+
|
|
37
|
+
if (network === 'local') {
|
|
38
|
+
await agent.fetchRootKey();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return Actor.createActor(storageIdlFactory, {
|
|
42
|
+
agent,
|
|
43
|
+
canisterId: storageId,
|
|
44
|
+
});
|
|
45
|
+
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {mainActor, storageActor} from '../mops.js';
|
|
2
|
-
import {parallel} from '../parallel.js';
|
|
3
1
|
import {Principal} from '@dfinity/principal';
|
|
4
|
-
import {
|
|
2
|
+
import {mainActor, storageActor} from './actors.js';
|
|
3
|
+
import {resolveVersion} from './resolveVersion.js';
|
|
4
|
+
import {parallel} from '../parallel.js';
|
|
5
5
|
import {Storage} from '../declarations/storage/storage.did.js';
|
|
6
6
|
|
|
7
|
-
export async function downloadPackageFiles(pkg: string, version = '', threads = 8, onLoad = (_fileIds: string[], _fileId: string) => {}): Promise<Map<string,
|
|
7
|
+
export async function downloadPackageFiles(pkg: string, version = '', threads = 8, onLoad = (_fileIds: string[], _fileId: string) => {}): Promise<Map<string, Array<number>>> {
|
|
8
8
|
version = await resolveVersion(pkg, version);
|
|
9
9
|
|
|
10
10
|
let {storageId, fileIds} = await getPackageFilesInfo(pkg, version);
|
|
11
11
|
let storage = await storageActor(storageId);
|
|
12
12
|
|
|
13
|
-
let filesData = new Map;
|
|
13
|
+
let filesData = new Map<string, Array<number>>();
|
|
14
14
|
await parallel(threads, fileIds, async (fileId: string) => {
|
|
15
15
|
let {path, data} = await downloadFile(storage, fileId);
|
|
16
16
|
filesData.set(path, data);
|
package/api/index.ts
ADDED
package/api/network.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function getNetwork() {
|
|
2
|
+
return globalThis.MOPS_NETWORK || 'ic';
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function getEndpoint(network: string) {
|
|
6
|
+
if (network === 'staging') {
|
|
7
|
+
return {
|
|
8
|
+
host: 'https://icp-api.io',
|
|
9
|
+
canisterId: '2d2zu-vaaaa-aaaak-qb6pq-cai',
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
else if (network === 'ic') {
|
|
13
|
+
return {
|
|
14
|
+
host: 'https://icp-api.io',
|
|
15
|
+
canisterId: 'oknww-riaaa-aaaam-qaf6a-cai',
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return {
|
|
20
|
+
host: 'http://127.0.0.1:4943',
|
|
21
|
+
canisterId: '2d2zu-vaaaa-aaaak-qb6pq-cai',
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
package/cli.ts
CHANGED
|
@@ -9,7 +9,9 @@ import {init} from './commands/init.js';
|
|
|
9
9
|
import {publish} from './commands/publish.js';
|
|
10
10
|
import {importPem} from './commands/import-identity.js';
|
|
11
11
|
import {sources} from './commands/sources.js';
|
|
12
|
-
import {checkApiCompatibility,
|
|
12
|
+
import {checkApiCompatibility, setNetwork, apiVersion, checkConfigFile, getNetworkFile, getIdentity} from './mops.js';
|
|
13
|
+
import {getNetwork} from './api/network.js';
|
|
14
|
+
import {mainActor} from './api/actors.js';
|
|
13
15
|
import {whoami} from './commands/whoami.js';
|
|
14
16
|
import {installAll} from './commands/install-all.js';
|
|
15
17
|
import {search} from './commands/search.js';
|
|
@@ -28,6 +30,17 @@ import {bench} from './commands/bench.js';
|
|
|
28
30
|
import {transferOwnership} from './commands/transfer-ownership.js';
|
|
29
31
|
// import {docs} from './commands/docs.js';
|
|
30
32
|
|
|
33
|
+
declare global {
|
|
34
|
+
// eslint-disable-next-line no-var
|
|
35
|
+
var MOPS_NETWORK: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let networkFile = getNetworkFile();
|
|
39
|
+
if (fs.existsSync(networkFile)) {
|
|
40
|
+
globalThis.MOPS_NETWORK = fs.readFileSync(networkFile).toString() || 'ic';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
31
44
|
program.name('mops');
|
|
32
45
|
|
|
33
46
|
// --version
|
|
@@ -132,7 +145,7 @@ program
|
|
|
132
145
|
.alias('gn')
|
|
133
146
|
.description('Get network')
|
|
134
147
|
.action(async () => {
|
|
135
|
-
console.log(getNetwork()
|
|
148
|
+
console.log(getNetwork());
|
|
136
149
|
});
|
|
137
150
|
|
|
138
151
|
// import-identity
|
|
@@ -276,7 +289,8 @@ program
|
|
|
276
289
|
program
|
|
277
290
|
.command('airdrop <check|claim> [canister]')
|
|
278
291
|
.action(async (sub, canister) => {
|
|
279
|
-
let
|
|
292
|
+
let identity = await getIdentity();
|
|
293
|
+
let main = await mainActor(identity);
|
|
280
294
|
if (sub === 'check') {
|
|
281
295
|
let amount = await main.getAirdropAmount();
|
|
282
296
|
if (amount === 0n) {
|
package/commands/add.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import logUpdate from 'log-update';
|
|
4
|
-
import {checkConfigFile, getGithubCommit,
|
|
4
|
+
import {checkConfigFile, getGithubCommit, parseGithubURL, readConfig, writeConfig} from '../mops.js';
|
|
5
|
+
import {getHighestVersion} from '../api/getHighestVersion.js';
|
|
5
6
|
import {installFromGithub} from '../vessel.js';
|
|
6
7
|
import {install} from './install.js';
|
|
7
8
|
import {notifyInstalls} from '../notify-installs.js';
|
package/commands/init.ts
CHANGED
|
@@ -4,7 +4,8 @@ import {existsSync, readFileSync, writeFileSync} from 'node:fs';
|
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import prompts from 'prompts';
|
|
6
6
|
|
|
7
|
-
import {checkApiCompatibility,
|
|
7
|
+
import {checkApiCompatibility, writeConfig} from '../mops.js';
|
|
8
|
+
import {mainActor} from '../api/actors.js';
|
|
8
9
|
import {installAll} from './install-all.js';
|
|
9
10
|
import {VesselConfig, readVesselConfig} from '../vessel.js';
|
|
10
11
|
import {Config, Dependencies} from '../types.js';
|
package/commands/install.ts
CHANGED
|
@@ -2,11 +2,13 @@ import path from 'node:path';
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import logUpdate from 'log-update';
|
|
4
4
|
import chalk from 'chalk';
|
|
5
|
-
import {checkConfigFile, formatDir,
|
|
5
|
+
import {checkConfigFile, formatDir, progressBar, readConfig} from '../mops.js';
|
|
6
|
+
import {getHighestVersion} from '../api/getHighestVersion.js';
|
|
7
|
+
import {storageActor} from '../api/actors.js';
|
|
6
8
|
import {parallel} from '../parallel.js';
|
|
7
9
|
import {installFromGithub} from '../vessel.js';
|
|
8
10
|
import {addCache, copyCache, isCached} from '../cache.js';
|
|
9
|
-
import {downloadFile, getPackageFilesInfo} from '../
|
|
11
|
+
import {downloadFile, getPackageFilesInfo} from '../api/downloadPackageFiles.js';
|
|
10
12
|
|
|
11
13
|
export async function install(pkg: string, version = '', {verbose = false, silent = false, dep = false} = {}): Promise<Record<string, string> | false> {
|
|
12
14
|
if (!checkConfigFile()) {
|
package/commands/publish.ts
CHANGED
|
@@ -8,7 +8,8 @@ import prompts from 'prompts';
|
|
|
8
8
|
import {fromMarkdown} from 'mdast-util-from-markdown';
|
|
9
9
|
import {toMarkdown} from 'mdast-util-to-markdown';
|
|
10
10
|
|
|
11
|
-
import {checkConfigFile,
|
|
11
|
+
import {checkConfigFile, getIdentity, getRootDir, progressBar, readConfig} from '../mops.js';
|
|
12
|
+
import {mainActor} from '../api/actors.js';
|
|
12
13
|
import {parallel} from '../parallel.js';
|
|
13
14
|
import {docs} from './docs.js';
|
|
14
15
|
import {DependencyV2, PackageConfigV2} from '../declarations/main/main.did.js';
|
|
@@ -266,7 +267,8 @@ export async function publish(options: {docs?: boolean, test?: boolean} = {}) {
|
|
|
266
267
|
}
|
|
267
268
|
|
|
268
269
|
// upload config
|
|
269
|
-
let
|
|
270
|
+
let identity = await getIdentity();
|
|
271
|
+
let actor = await mainActor(identity);
|
|
270
272
|
|
|
271
273
|
progress();
|
|
272
274
|
let publishing = await actor.startPublish(backendPkgConfig);
|
package/commands/search.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
-
import {checkConfigFile,
|
|
2
|
+
import {checkConfigFile, getIdentity, readConfig} from '../mops.js';
|
|
3
|
+
import {mainActor} from '../api/actors.js';
|
|
3
4
|
import {Principal} from '@dfinity/principal';
|
|
4
5
|
import prompts from 'prompts';
|
|
5
6
|
|
|
@@ -30,7 +31,8 @@ export async function transferOwnership(toPrincipal: string) {
|
|
|
30
31
|
return;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
let
|
|
34
|
+
let identity = await getIdentity();
|
|
35
|
+
let actor = await mainActor(identity);
|
|
34
36
|
|
|
35
37
|
let res = await actor.transferOwnership(config.package?.name || '', principal);
|
|
36
38
|
if ('ok' in res) {
|
package/commands/user.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
-
import {getIdentity
|
|
2
|
+
import {getIdentity} from '../mops.js';
|
|
3
|
+
import {mainActor} from '../api/actors.js';
|
|
3
4
|
|
|
4
5
|
export async function getUserProp(prop: string) {
|
|
5
6
|
let actor = await mainActor();
|
|
@@ -14,7 +15,9 @@ export async function getUserProp(prop: string) {
|
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export async function setUserProp(prop: string, value: string) {
|
|
17
|
-
let
|
|
18
|
+
let identity = await getIdentity();
|
|
19
|
+
let actor = await mainActor(identity);
|
|
20
|
+
|
|
18
21
|
let res = await actor.setUserProp(prop, value);
|
|
19
22
|
if ('ok' in res) {
|
|
20
23
|
console.log(chalk.green('Success!'));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Identity } from '@dfinity/agent';
|
|
2
|
+
import { Principal } from '@dfinity/principal';
|
|
3
|
+
import { _SERVICE } from '../declarations/main/main.did.js';
|
|
4
|
+
import { _SERVICE as _STORAGE_SERVICE } from '../declarations/storage/storage.did.js';
|
|
5
|
+
export declare let mainActor: (identity?: Identity) => Promise<_SERVICE>;
|
|
6
|
+
export declare let storageActor: (storageId: Principal, identity?: Identity) => Promise<_STORAGE_SERVICE>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Actor, HttpAgent } from '@dfinity/agent';
|
|
2
|
+
import { idlFactory } from '../declarations/main/index.js';
|
|
3
|
+
import { idlFactory as storageIdlFactory } from '../declarations/storage/index.js';
|
|
4
|
+
import { getEndpoint } from './network.js';
|
|
5
|
+
import { getNetwork } from './network.js';
|
|
6
|
+
export let mainActor = async (identity) => {
|
|
7
|
+
let network = getNetwork();
|
|
8
|
+
let host = getEndpoint(network).host;
|
|
9
|
+
let canisterId = getEndpoint(network).canisterId;
|
|
10
|
+
// @ts-ignore exactOptionalPropertyTypes
|
|
11
|
+
let agent = new HttpAgent({ host, identity });
|
|
12
|
+
if (network === 'local') {
|
|
13
|
+
await agent.fetchRootKey();
|
|
14
|
+
}
|
|
15
|
+
return Actor.createActor(idlFactory, {
|
|
16
|
+
agent,
|
|
17
|
+
canisterId,
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
export let storageActor = async (storageId, identity) => {
|
|
21
|
+
let network = getNetwork();
|
|
22
|
+
let host = getEndpoint(network).host;
|
|
23
|
+
// @ts-ignore exactOptionalPropertyTypes
|
|
24
|
+
let agent = new HttpAgent({ host, identity });
|
|
25
|
+
if (network === 'local') {
|
|
26
|
+
await agent.fetchRootKey();
|
|
27
|
+
}
|
|
28
|
+
return Actor.createActor(storageIdlFactory, {
|
|
29
|
+
agent,
|
|
30
|
+
canisterId: storageId,
|
|
31
|
+
});
|
|
32
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Principal } from '@dfinity/principal';
|
|
2
|
+
import { Storage } from '../declarations/storage/storage.did.js';
|
|
3
|
+
export declare function downloadPackageFiles(pkg: string, version?: string, threads?: number, onLoad?: (_fileIds: string[], _fileId: string) => void): Promise<Map<string, Array<number>>>;
|
|
4
|
+
export declare function getPackageFilesInfo(pkg: string, version: string): Promise<{
|
|
5
|
+
storageId: Principal;
|
|
6
|
+
fileIds: string[];
|
|
7
|
+
}>;
|
|
8
|
+
export declare function getFileIds(pkg: string, version: string): Promise<string[]>;
|
|
9
|
+
export declare function downloadFile(storage: Storage, fileId: string): Promise<{
|
|
10
|
+
path: string;
|
|
11
|
+
data: Array<number>;
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { mainActor, storageActor } from './actors.js';
|
|
2
|
+
import { resolveVersion } from './resolveVersion.js';
|
|
3
|
+
import { parallel } from '../parallel.js';
|
|
4
|
+
export async function downloadPackageFiles(pkg, version = '', threads = 8, onLoad = (_fileIds, _fileId) => { }) {
|
|
5
|
+
version = await resolveVersion(pkg, version);
|
|
6
|
+
let { storageId, fileIds } = await getPackageFilesInfo(pkg, version);
|
|
7
|
+
let storage = await storageActor(storageId);
|
|
8
|
+
let filesData = new Map();
|
|
9
|
+
await parallel(threads, fileIds, async (fileId) => {
|
|
10
|
+
let { path, data } = await downloadFile(storage, fileId);
|
|
11
|
+
filesData.set(path, data);
|
|
12
|
+
onLoad(fileIds, fileId);
|
|
13
|
+
});
|
|
14
|
+
return filesData;
|
|
15
|
+
}
|
|
16
|
+
// get package files meta
|
|
17
|
+
export async function getPackageFilesInfo(pkg, version) {
|
|
18
|
+
let actor = await mainActor();
|
|
19
|
+
let [packageDetailsRes, fileIds] = await Promise.all([
|
|
20
|
+
actor.getPackageDetails(pkg, version),
|
|
21
|
+
getFileIds(pkg, version),
|
|
22
|
+
]);
|
|
23
|
+
if ('err' in packageDetailsRes) {
|
|
24
|
+
throw packageDetailsRes.err;
|
|
25
|
+
}
|
|
26
|
+
let packageDetails = packageDetailsRes.ok;
|
|
27
|
+
return {
|
|
28
|
+
storageId: packageDetails.publication.storage,
|
|
29
|
+
fileIds,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// get package files ids
|
|
33
|
+
export async function getFileIds(pkg, version) {
|
|
34
|
+
let actor = await mainActor();
|
|
35
|
+
let fileIdsRes = await actor.getFileIds(pkg, version);
|
|
36
|
+
if ('err' in fileIdsRes) {
|
|
37
|
+
throw fileIdsRes.err;
|
|
38
|
+
}
|
|
39
|
+
let filesIds = fileIdsRes.ok;
|
|
40
|
+
return filesIds;
|
|
41
|
+
}
|
|
42
|
+
// download single file
|
|
43
|
+
export async function downloadFile(storage, fileId) {
|
|
44
|
+
let fileMetaRes = await storage.getFileMeta(fileId);
|
|
45
|
+
if ('err' in fileMetaRes) {
|
|
46
|
+
throw fileMetaRes.err;
|
|
47
|
+
}
|
|
48
|
+
let fileMeta = fileMetaRes.ok;
|
|
49
|
+
let data = [];
|
|
50
|
+
for (let i = 0n; i < fileMeta.chunkCount; i++) {
|
|
51
|
+
let chunkRes = await storage.downloadChunk(fileId, i);
|
|
52
|
+
if ('err' in chunkRes) {
|
|
53
|
+
throw chunkRes.err;
|
|
54
|
+
}
|
|
55
|
+
let chunk = chunkRes.ok;
|
|
56
|
+
data = [...data, ...chunk];
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
path: fileMeta.path,
|
|
60
|
+
data: data,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getHighestVersion(pkgName: string): Promise<import("../declarations/main/main.did.js").Result_5>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function getNetwork() {
|
|
2
|
+
return globalThis.MOPS_NETWORK || 'ic';
|
|
3
|
+
}
|
|
4
|
+
export function getEndpoint(network) {
|
|
5
|
+
if (network === 'staging') {
|
|
6
|
+
return {
|
|
7
|
+
host: 'https://icp-api.io',
|
|
8
|
+
canisterId: '2d2zu-vaaaa-aaaak-qb6pq-cai',
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
else if (network === 'ic') {
|
|
12
|
+
return {
|
|
13
|
+
host: 'https://icp-api.io',
|
|
14
|
+
canisterId: 'oknww-riaaa-aaaam-qaf6a-cai',
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return {
|
|
19
|
+
host: 'http://127.0.0.1:4943',
|
|
20
|
+
canisterId: '2d2zu-vaaaa-aaaak-qb6pq-cai',
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function resolveVersion(pkg: string, version?: string): Promise<string>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getHighestVersion } from './getHighestVersion.js';
|
|
2
|
+
export async function resolveVersion(pkg, version = '') {
|
|
3
|
+
if (!version) {
|
|
4
|
+
let versionRes = await getHighestVersion(pkg);
|
|
5
|
+
if ('err' in versionRes) {
|
|
6
|
+
throw versionRes.err;
|
|
7
|
+
}
|
|
8
|
+
version = versionRes.ok;
|
|
9
|
+
}
|
|
10
|
+
return version;
|
|
11
|
+
}
|
package/dist/cli.d.ts
CHANGED
package/dist/cli.js
CHANGED
|
@@ -7,7 +7,9 @@ import { init } from './commands/init.js';
|
|
|
7
7
|
import { publish } from './commands/publish.js';
|
|
8
8
|
import { importPem } from './commands/import-identity.js';
|
|
9
9
|
import { sources } from './commands/sources.js';
|
|
10
|
-
import { checkApiCompatibility,
|
|
10
|
+
import { checkApiCompatibility, setNetwork, apiVersion, checkConfigFile, getNetworkFile, getIdentity } from './mops.js';
|
|
11
|
+
import { getNetwork } from './api/network.js';
|
|
12
|
+
import { mainActor } from './api/actors.js';
|
|
11
13
|
import { whoami } from './commands/whoami.js';
|
|
12
14
|
import { installAll } from './commands/install-all.js';
|
|
13
15
|
import { search } from './commands/search.js';
|
|
@@ -24,7 +26,10 @@ import { outdated } from './commands/outdated.js';
|
|
|
24
26
|
import { update } from './commands/update.js';
|
|
25
27
|
import { bench } from './commands/bench.js';
|
|
26
28
|
import { transferOwnership } from './commands/transfer-ownership.js';
|
|
27
|
-
|
|
29
|
+
let networkFile = getNetworkFile();
|
|
30
|
+
if (fs.existsSync(networkFile)) {
|
|
31
|
+
globalThis.MOPS_NETWORK = fs.readFileSync(networkFile).toString() || 'ic';
|
|
32
|
+
}
|
|
28
33
|
program.name('mops');
|
|
29
34
|
// --version
|
|
30
35
|
let packageJson = JSON.parse(fs.readFileSync(new URL('package.json', import.meta.url)).toString());
|
|
@@ -119,7 +124,7 @@ program
|
|
|
119
124
|
.alias('gn')
|
|
120
125
|
.description('Get network')
|
|
121
126
|
.action(async () => {
|
|
122
|
-
console.log(getNetwork()
|
|
127
|
+
console.log(getNetwork());
|
|
123
128
|
});
|
|
124
129
|
// import-identity
|
|
125
130
|
program
|
|
@@ -251,7 +256,8 @@ program
|
|
|
251
256
|
program
|
|
252
257
|
.command('airdrop <check|claim> [canister]')
|
|
253
258
|
.action(async (sub, canister) => {
|
|
254
|
-
let
|
|
259
|
+
let identity = await getIdentity();
|
|
260
|
+
let main = await mainActor(identity);
|
|
255
261
|
if (sub === 'check') {
|
|
256
262
|
let amount = await main.getAirdropAmount();
|
|
257
263
|
if (amount === 0n) {
|
package/dist/commands/add.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import logUpdate from 'log-update';
|
|
4
|
-
import { checkConfigFile, getGithubCommit,
|
|
4
|
+
import { checkConfigFile, getGithubCommit, parseGithubURL, readConfig, writeConfig } from '../mops.js';
|
|
5
|
+
import { getHighestVersion } from '../api/getHighestVersion.js';
|
|
5
6
|
import { installFromGithub } from '../vessel.js';
|
|
6
7
|
import { install } from './install.js';
|
|
7
8
|
import { notifyInstalls } from '../notify-installs.js';
|
package/dist/commands/init.js
CHANGED
|
@@ -3,7 +3,8 @@ import path from 'node:path';
|
|
|
3
3
|
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import prompts from 'prompts';
|
|
6
|
-
import { checkApiCompatibility,
|
|
6
|
+
import { checkApiCompatibility, writeConfig } from '../mops.js';
|
|
7
|
+
import { mainActor } from '../api/actors.js';
|
|
7
8
|
import { installAll } from './install-all.js';
|
|
8
9
|
import { readVesselConfig } from '../vessel.js';
|
|
9
10
|
import { template } from './template.js';
|
package/dist/commands/install.js
CHANGED
|
@@ -2,11 +2,13 @@ import path from 'node:path';
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import logUpdate from 'log-update';
|
|
4
4
|
import chalk from 'chalk';
|
|
5
|
-
import { checkConfigFile, formatDir,
|
|
5
|
+
import { checkConfigFile, formatDir, progressBar, readConfig } from '../mops.js';
|
|
6
|
+
import { getHighestVersion } from '../api/getHighestVersion.js';
|
|
7
|
+
import { storageActor } from '../api/actors.js';
|
|
6
8
|
import { parallel } from '../parallel.js';
|
|
7
9
|
import { installFromGithub } from '../vessel.js';
|
|
8
10
|
import { addCache, copyCache, isCached } from '../cache.js';
|
|
9
|
-
import { downloadFile, getPackageFilesInfo } from '../
|
|
11
|
+
import { downloadFile, getPackageFilesInfo } from '../api/downloadPackageFiles.js';
|
|
10
12
|
export async function install(pkg, version = '', { verbose = false, silent = false, dep = false } = {}) {
|
|
11
13
|
if (!checkConfigFile()) {
|
|
12
14
|
return false;
|
package/dist/commands/publish.js
CHANGED
|
@@ -7,7 +7,8 @@ import { minimatch } from 'minimatch';
|
|
|
7
7
|
import prompts from 'prompts';
|
|
8
8
|
import { fromMarkdown } from 'mdast-util-from-markdown';
|
|
9
9
|
import { toMarkdown } from 'mdast-util-to-markdown';
|
|
10
|
-
import { checkConfigFile,
|
|
10
|
+
import { checkConfigFile, getIdentity, getRootDir, progressBar, readConfig } from '../mops.js';
|
|
11
|
+
import { mainActor } from '../api/actors.js';
|
|
11
12
|
import { parallel } from '../parallel.js';
|
|
12
13
|
import { docs } from './docs.js';
|
|
13
14
|
import { testWithReporter } from './test/test.js';
|
|
@@ -238,7 +239,8 @@ export async function publish(options = {}) {
|
|
|
238
239
|
logUpdate(`Uploading files ${progressBar(step, total)}`);
|
|
239
240
|
}
|
|
240
241
|
// upload config
|
|
241
|
-
let
|
|
242
|
+
let identity = await getIdentity();
|
|
243
|
+
let actor = await mainActor(identity);
|
|
242
244
|
progress();
|
|
243
245
|
let publishing = await actor.startPublish(backendPkgConfig);
|
|
244
246
|
if ('err' in publishing) {
|
package/dist/commands/search.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import asTable from 'as-table';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
-
import { mainActor } from '../
|
|
3
|
+
import { mainActor } from '../api/actors.js';
|
|
4
4
|
export async function search(text) {
|
|
5
5
|
let actor = await mainActor();
|
|
6
6
|
let [packages, _pageCount] = await actor.search(text, [], []);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
-
import { checkConfigFile,
|
|
2
|
+
import { checkConfigFile, getIdentity, readConfig } from '../mops.js';
|
|
3
|
+
import { mainActor } from '../api/actors.js';
|
|
3
4
|
import { Principal } from '@dfinity/principal';
|
|
4
5
|
import prompts from 'prompts';
|
|
5
6
|
export async function transferOwnership(toPrincipal) {
|
|
@@ -24,7 +25,8 @@ export async function transferOwnership(toPrincipal) {
|
|
|
24
25
|
if (!confirm) {
|
|
25
26
|
return;
|
|
26
27
|
}
|
|
27
|
-
let
|
|
28
|
+
let identity = await getIdentity();
|
|
29
|
+
let actor = await mainActor(identity);
|
|
28
30
|
let res = await actor.transferOwnership(config.package?.name || '', principal);
|
|
29
31
|
if ('ok' in res) {
|
|
30
32
|
console.log(chalk.green('Success!'));
|
package/dist/commands/user.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
-
import { getIdentity
|
|
2
|
+
import { getIdentity } from '../mops.js';
|
|
3
|
+
import { mainActor } from '../api/actors.js';
|
|
3
4
|
export async function getUserProp(prop) {
|
|
4
5
|
let actor = await mainActor();
|
|
5
6
|
let identity = await getIdentity();
|
|
@@ -12,7 +13,8 @@ export async function getUserProp(prop) {
|
|
|
12
13
|
console.log(res[0]?.[prop] || '');
|
|
13
14
|
}
|
|
14
15
|
export async function setUserProp(prop, value) {
|
|
15
|
-
let
|
|
16
|
+
let identity = await getIdentity();
|
|
17
|
+
let actor = await mainActor(identity);
|
|
16
18
|
let res = await actor.setUserProp(prop, value);
|
|
17
19
|
if ('ok' in res) {
|
|
18
20
|
console.log(chalk.green('Success!'));
|
package/dist/integrity.js
CHANGED
|
@@ -2,7 +2,8 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { sha256 } from '@noble/hashes/sha256';
|
|
4
4
|
import { bytesToHex } from '@noble/hashes/utils';
|
|
5
|
-
import { getDependencyType, getRootDir
|
|
5
|
+
import { getDependencyType, getRootDir } from './mops.js';
|
|
6
|
+
import { mainActor } from './api/actors.js';
|
|
6
7
|
import { resolvePackages } from './resolve-packages.js';
|
|
7
8
|
export async function checkIntegrity(lock) {
|
|
8
9
|
let force = !!lock;
|
package/dist/mops.d.ts
CHANGED
|
@@ -1,26 +1,15 @@
|
|
|
1
1
|
import { Identity } from '@dfinity/agent';
|
|
2
|
-
import { _SERVICE } from './declarations/main/main.did.js';
|
|
3
|
-
import { _SERVICE as _STORAGE_SERVICE } from './declarations/storage/storage.did.js';
|
|
4
2
|
import { Config } from './types.js';
|
|
5
|
-
import { Principal } from '@dfinity/principal';
|
|
6
|
-
import { downloadPackageFiles } from './helpers/download-package-files.js';
|
|
7
3
|
export declare let apiVersion: string;
|
|
8
4
|
export declare let globalConfigDir: string;
|
|
9
5
|
export declare let globalCacheDir: string;
|
|
6
|
+
export declare function getNetworkFile(): string | URL;
|
|
10
7
|
export declare function setNetwork(network: string): void;
|
|
11
|
-
export declare function getNetwork(): {
|
|
12
|
-
network: string;
|
|
13
|
-
host: string;
|
|
14
|
-
canisterId: string;
|
|
15
|
-
};
|
|
16
8
|
export declare let getIdentity: () => Promise<Identity | undefined>;
|
|
17
|
-
export declare let mainActor: (useIdentity?: boolean) => Promise<_SERVICE>;
|
|
18
|
-
export declare let storageActor: (storageId: Principal, useIdentity?: boolean) => Promise<_STORAGE_SERVICE>;
|
|
19
9
|
export declare function getClosestConfigFile(dir?: string): string;
|
|
20
10
|
export declare function getRootDir(): string;
|
|
21
11
|
export declare function checkConfigFile(): boolean;
|
|
22
12
|
export declare function progressBar(step: number, total: number): string;
|
|
23
|
-
export declare function getHighestVersion(pkgName: string): Promise<import("./declarations/main/main.did.js").Result_5>;
|
|
24
13
|
export declare function parseGithubURL(href: string): {
|
|
25
14
|
org: string;
|
|
26
15
|
gitName: string;
|
|
@@ -28,11 +17,10 @@ export declare function parseGithubURL(href: string): {
|
|
|
28
17
|
commitHash: string;
|
|
29
18
|
};
|
|
30
19
|
export declare function getGithubCommit(repo: string, ref: string): Promise<any>;
|
|
31
|
-
export declare function getDependencyType(version: string): "
|
|
20
|
+
export declare function getDependencyType(version: string): "local" | "mops" | "github";
|
|
32
21
|
export declare function readConfig(configFile?: string): Config;
|
|
33
22
|
export declare function writeConfig(config: Config, configFile?: string): void;
|
|
34
23
|
export declare function formatDir(name: string, version: string): string;
|
|
35
24
|
export declare function formatGithubDir(name: string, repo: string): string;
|
|
36
25
|
export declare function readDfxJson(): any;
|
|
37
26
|
export declare function checkApiCompatibility(): Promise<boolean>;
|
|
38
|
-
export { downloadPackageFiles };
|
package/dist/mops.js
CHANGED
|
@@ -1,27 +1,17 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
|
-
import { Actor, HttpAgent } from '@dfinity/agent';
|
|
4
3
|
import TOML from '@iarna/toml';
|
|
5
4
|
import chalk from 'chalk';
|
|
6
5
|
import prompts from 'prompts';
|
|
7
6
|
import ncp from 'ncp';
|
|
8
7
|
import fetch from 'node-fetch';
|
|
9
|
-
import { idlFactory } from './declarations/main/index.js';
|
|
10
|
-
import { idlFactory as storageIdlFactory } from './declarations/storage/index.js';
|
|
11
8
|
import { decodeFile } from './pem.js';
|
|
12
|
-
import {
|
|
9
|
+
import { mainActor } from './api/actors.js';
|
|
13
10
|
if (!global.fetch) {
|
|
14
11
|
global.fetch = fetch;
|
|
15
12
|
}
|
|
16
13
|
// (!) make changes in pair with backend
|
|
17
14
|
export let apiVersion = '1.2';
|
|
18
|
-
let networkFile = '';
|
|
19
|
-
try {
|
|
20
|
-
networkFile = new URL('./network.txt', import.meta.url);
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
networkFile = path.join(__dirname, 'network.txt');
|
|
24
|
-
}
|
|
25
15
|
export let globalConfigDir = '';
|
|
26
16
|
export let globalCacheDir = '';
|
|
27
17
|
// OS specific dirs
|
|
@@ -70,35 +60,18 @@ if (fs.existsSync(oldGlobalConfigDir) && !fs.existsSync(globalCacheDir)) {
|
|
|
70
60
|
});
|
|
71
61
|
console.log('Moved cache to ' + chalk.green(globalCacheDir));
|
|
72
62
|
}
|
|
73
|
-
export function
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
let network = 'ic';
|
|
78
|
-
if (fs.existsSync(networkFile)) {
|
|
79
|
-
network = fs.readFileSync(networkFile).toString() || 'ic';
|
|
80
|
-
}
|
|
81
|
-
if (network === 'staging') {
|
|
82
|
-
return {
|
|
83
|
-
network,
|
|
84
|
-
host: 'https://icp-api.io',
|
|
85
|
-
canisterId: '2d2zu-vaaaa-aaaak-qb6pq-cai',
|
|
86
|
-
};
|
|
63
|
+
export function getNetworkFile() {
|
|
64
|
+
let networkFile = '';
|
|
65
|
+
try {
|
|
66
|
+
networkFile = new URL('./network.txt', import.meta.url);
|
|
87
67
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
network,
|
|
91
|
-
host: 'https://icp-api.io',
|
|
92
|
-
canisterId: 'oknww-riaaa-aaaam-qaf6a-cai',
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
return {
|
|
97
|
-
network,
|
|
98
|
-
host: 'http://127.0.0.1:4943',
|
|
99
|
-
canisterId: '2d2zu-vaaaa-aaaak-qb6pq-cai',
|
|
100
|
-
};
|
|
68
|
+
catch {
|
|
69
|
+
networkFile = path.join(__dirname, 'network.txt');
|
|
101
70
|
}
|
|
71
|
+
return networkFile;
|
|
72
|
+
}
|
|
73
|
+
export function setNetwork(network) {
|
|
74
|
+
fs.writeFileSync(getNetworkFile(), network);
|
|
102
75
|
}
|
|
103
76
|
export let getIdentity = async () => {
|
|
104
77
|
let identityPem = path.resolve(globalConfigDir, 'identity.pem');
|
|
@@ -116,35 +89,6 @@ export let getIdentity = async () => {
|
|
|
116
89
|
}
|
|
117
90
|
return undefined;
|
|
118
91
|
};
|
|
119
|
-
export let mainActor = async (useIdentity = false) => {
|
|
120
|
-
let network = getNetwork().network;
|
|
121
|
-
let host = getNetwork().host;
|
|
122
|
-
let canisterId = getNetwork().canisterId;
|
|
123
|
-
let identity = useIdentity ? await getIdentity() : undefined;
|
|
124
|
-
// @ts-ignore exactOptionalPropertyTypes
|
|
125
|
-
let agent = new HttpAgent({ host, identity });
|
|
126
|
-
if (network === 'local') {
|
|
127
|
-
await agent.fetchRootKey();
|
|
128
|
-
}
|
|
129
|
-
return Actor.createActor(idlFactory, {
|
|
130
|
-
agent,
|
|
131
|
-
canisterId,
|
|
132
|
-
});
|
|
133
|
-
};
|
|
134
|
-
export let storageActor = async (storageId, useIdentity = false) => {
|
|
135
|
-
let network = getNetwork().network;
|
|
136
|
-
let host = getNetwork().host;
|
|
137
|
-
let identity = useIdentity && await getIdentity();
|
|
138
|
-
// @ts-ignore exactOptionalPropertyTypes
|
|
139
|
-
let agent = new HttpAgent({ host, identity });
|
|
140
|
-
if (network === 'local') {
|
|
141
|
-
await agent.fetchRootKey();
|
|
142
|
-
}
|
|
143
|
-
return Actor.createActor(storageIdlFactory, {
|
|
144
|
-
agent,
|
|
145
|
-
canisterId: storageId,
|
|
146
|
-
});
|
|
147
|
-
};
|
|
148
92
|
export function getClosestConfigFile(dir = process.cwd()) {
|
|
149
93
|
if (!path.basename(dir)) {
|
|
150
94
|
throw '';
|
|
@@ -174,10 +118,6 @@ export function progressBar(step, total) {
|
|
|
174
118
|
let done = Math.round(step / total * 10);
|
|
175
119
|
return `[${':'.repeat(done)}${' '.repeat(Math.max(0, 10 - done))}]`;
|
|
176
120
|
}
|
|
177
|
-
export async function getHighestVersion(pkgName) {
|
|
178
|
-
let actor = await mainActor();
|
|
179
|
-
return actor.getHighestVersion(pkgName);
|
|
180
|
-
}
|
|
181
121
|
export function parseGithubURL(href) {
|
|
182
122
|
const url = new URL(href);
|
|
183
123
|
let branchAndSha = url.hash?.substring(1).split('@');
|
|
@@ -293,4 +233,3 @@ export async function checkApiCompatibility() {
|
|
|
293
233
|
}
|
|
294
234
|
return true;
|
|
295
235
|
}
|
|
296
|
-
export { downloadPackageFiles };
|
package/dist/notify-installs.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { getDependencyType
|
|
1
|
+
import { getDependencyType } from './mops.js';
|
|
2
|
+
import { mainActor } from './api/actors.js';
|
|
2
3
|
import { resolvePackages } from './resolve-packages.js';
|
|
3
4
|
export async function notifyInstalls(names) {
|
|
4
5
|
let resolvedPackages = await resolvePackages();
|
package/dist/package.json
CHANGED
package/integrity.ts
CHANGED
|
@@ -2,7 +2,8 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import {sha256} from '@noble/hashes/sha256';
|
|
4
4
|
import {bytesToHex} from '@noble/hashes/utils';
|
|
5
|
-
import {getDependencyType, getRootDir
|
|
5
|
+
import {getDependencyType, getRootDir} from './mops.js';
|
|
6
|
+
import {mainActor} from './api/actors.js';
|
|
6
7
|
import {resolvePackages} from './resolve-packages.js';
|
|
7
8
|
|
|
8
9
|
type LockFileV1 = {
|
package/mops.ts
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
|
-
import {
|
|
3
|
+
import {Identity} from '@dfinity/agent';
|
|
4
4
|
import TOML from '@iarna/toml';
|
|
5
5
|
import chalk from 'chalk';
|
|
6
6
|
import prompts from 'prompts';
|
|
7
7
|
import ncp from 'ncp';
|
|
8
8
|
import fetch from 'node-fetch';
|
|
9
9
|
|
|
10
|
-
import {idlFactory} from './declarations/main/index.js';
|
|
11
|
-
import {_SERVICE} from './declarations/main/main.did.js';
|
|
12
|
-
import {idlFactory as storageIdlFactory} from './declarations/storage/index.js';
|
|
13
|
-
import {_SERVICE as _STORAGE_SERVICE} from './declarations/storage/storage.did.js';
|
|
14
10
|
import {decodeFile} from './pem.js';
|
|
15
11
|
import {Config} from './types.js';
|
|
16
|
-
import {
|
|
17
|
-
import {downloadPackageFiles} from './helpers/download-package-files.js';
|
|
12
|
+
import {mainActor} from './api/actors.js';
|
|
18
13
|
|
|
19
14
|
|
|
20
15
|
if (!global.fetch) {
|
|
@@ -24,14 +19,6 @@ if (!global.fetch) {
|
|
|
24
19
|
// (!) make changes in pair with backend
|
|
25
20
|
export let apiVersion = '1.2';
|
|
26
21
|
|
|
27
|
-
let networkFile: string | URL = '';
|
|
28
|
-
try {
|
|
29
|
-
networkFile = new URL('./network.txt', import.meta.url);
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
networkFile = path.join(__dirname, 'network.txt');
|
|
33
|
-
}
|
|
34
|
-
|
|
35
22
|
export let globalConfigDir = '';
|
|
36
23
|
export let globalCacheDir = '';
|
|
37
24
|
|
|
@@ -84,37 +71,20 @@ if (fs.existsSync(oldGlobalConfigDir) && !fs.existsSync(globalCacheDir)) {
|
|
|
84
71
|
console.log('Moved cache to ' + chalk.green(globalCacheDir));
|
|
85
72
|
}
|
|
86
73
|
|
|
87
|
-
export function setNetwork(network: string) {
|
|
88
|
-
fs.writeFileSync(networkFile, network);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export function getNetwork() {
|
|
92
|
-
let network = 'ic';
|
|
93
|
-
if (fs.existsSync(networkFile)) {
|
|
94
|
-
network = fs.readFileSync(networkFile).toString() || 'ic';
|
|
95
|
-
}
|
|
96
74
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
canisterId: '2d2zu-vaaaa-aaaak-qb6pq-cai',
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
else if (network === 'ic') {
|
|
105
|
-
return {
|
|
106
|
-
network,
|
|
107
|
-
host: 'https://icp-api.io',
|
|
108
|
-
canisterId: 'oknww-riaaa-aaaam-qaf6a-cai',
|
|
109
|
-
};
|
|
75
|
+
export function getNetworkFile(): string | URL {
|
|
76
|
+
let networkFile: string | URL = '';
|
|
77
|
+
try {
|
|
78
|
+
networkFile = new URL('./network.txt', import.meta.url);
|
|
110
79
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
network,
|
|
114
|
-
host: 'http://127.0.0.1:4943',
|
|
115
|
-
canisterId: '2d2zu-vaaaa-aaaak-qb6pq-cai',
|
|
116
|
-
};
|
|
80
|
+
catch {
|
|
81
|
+
networkFile = path.join(__dirname, 'network.txt');
|
|
117
82
|
}
|
|
83
|
+
return networkFile;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function setNetwork(network: string) {
|
|
87
|
+
fs.writeFileSync(getNetworkFile(), network);
|
|
118
88
|
}
|
|
119
89
|
|
|
120
90
|
export let getIdentity = async (): Promise<Identity | undefined> => {
|
|
@@ -134,43 +104,6 @@ export let getIdentity = async (): Promise<Identity | undefined> => {
|
|
|
134
104
|
return undefined;
|
|
135
105
|
};
|
|
136
106
|
|
|
137
|
-
export let mainActor = async (useIdentity = false): Promise<_SERVICE> => {
|
|
138
|
-
let network = getNetwork().network;
|
|
139
|
-
let host = getNetwork().host;
|
|
140
|
-
let canisterId = getNetwork().canisterId;
|
|
141
|
-
|
|
142
|
-
let identity = useIdentity ? await getIdentity() : undefined;
|
|
143
|
-
// @ts-ignore exactOptionalPropertyTypes
|
|
144
|
-
let agent = new HttpAgent({host, identity});
|
|
145
|
-
|
|
146
|
-
if (network === 'local') {
|
|
147
|
-
await agent.fetchRootKey();
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return Actor.createActor(idlFactory, {
|
|
151
|
-
agent,
|
|
152
|
-
canisterId,
|
|
153
|
-
});
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
export let storageActor = async (storageId: Principal, useIdentity = false): Promise<_STORAGE_SERVICE> => {
|
|
157
|
-
let network = getNetwork().network;
|
|
158
|
-
let host = getNetwork().host;
|
|
159
|
-
|
|
160
|
-
let identity = useIdentity && await getIdentity();
|
|
161
|
-
// @ts-ignore exactOptionalPropertyTypes
|
|
162
|
-
let agent = new HttpAgent({host, identity});
|
|
163
|
-
|
|
164
|
-
if (network === 'local') {
|
|
165
|
-
await agent.fetchRootKey();
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return Actor.createActor(storageIdlFactory, {
|
|
169
|
-
agent,
|
|
170
|
-
canisterId: storageId,
|
|
171
|
-
});
|
|
172
|
-
};
|
|
173
|
-
|
|
174
107
|
export function getClosestConfigFile(dir = process.cwd()) {
|
|
175
108
|
if (!path.basename(dir)) {
|
|
176
109
|
throw '';
|
|
@@ -204,11 +137,6 @@ export function progressBar(step: number, total: number) {
|
|
|
204
137
|
return `[${':'.repeat(done)}${' '.repeat(Math.max(0, 10 - done))}]`;
|
|
205
138
|
}
|
|
206
139
|
|
|
207
|
-
export async function getHighestVersion(pkgName: string) {
|
|
208
|
-
let actor = await mainActor();
|
|
209
|
-
return actor.getHighestVersion(pkgName);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
140
|
export function parseGithubURL(href: string) {
|
|
213
141
|
const url = new URL(href);
|
|
214
142
|
let branchAndSha = url.hash?.substring(1).split('@');
|
|
@@ -339,6 +267,4 @@ export async function checkApiCompatibility() {
|
|
|
339
267
|
console.log('-'.repeat(50));
|
|
340
268
|
}
|
|
341
269
|
return true;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
export {downloadPackageFiles};
|
|
270
|
+
}
|
package/notify-installs.ts
CHANGED