ic-mops 0.2.4 → 0.3.1
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/cli.js +31 -8
- package/commands/install.js +14 -9
- package/commands/search.js +41 -0
- package/declarations/main/index.js +3 -3
- package/mops.js +3 -3
- package/package.json +2 -1
- package/vessel.js +6 -7
package/cli.js
CHANGED
|
@@ -10,17 +10,22 @@ import {install} from './commands/install.js';
|
|
|
10
10
|
import {publish} from './commands/publish.js';
|
|
11
11
|
import {importPem} from './commands/import-identity.js';
|
|
12
12
|
import {sources} from './commands/sources.js';
|
|
13
|
-
import {checkApiCompatibility, getHighestVersion, getNetwork, parseGithubURL, readConfig, setNetwork, writeConfig} from './mops.js';
|
|
13
|
+
import {checkApiCompatibility, getHighestVersion, getNetwork, parseGithubURL, readConfig, setNetwork, writeConfig, apiVersion, mainActor} from './mops.js';
|
|
14
14
|
import {whoami} from './commands/whoami.js';
|
|
15
15
|
import {installAll} from './commands/install-all.js';
|
|
16
16
|
import logUpdate from 'log-update';
|
|
17
17
|
import {installFromGithub} from './vessel.js';
|
|
18
|
+
import {search} from './commands/search.js';
|
|
18
19
|
|
|
19
20
|
let cwd = process.cwd();
|
|
20
21
|
let configFile = path.join(cwd, 'mops.toml');
|
|
21
22
|
|
|
22
23
|
program.name('mops');
|
|
23
24
|
|
|
25
|
+
// --version
|
|
26
|
+
let packageJson = JSON.parse(fs.readFileSync(new URL('package.json', import.meta.url)));
|
|
27
|
+
program.version(`CLI ${packageJson.version}\nAPI ${apiVersion}`, '-v --version');
|
|
28
|
+
|
|
24
29
|
// init
|
|
25
30
|
program
|
|
26
31
|
.command('init [name]')
|
|
@@ -73,19 +78,25 @@ program
|
|
|
73
78
|
};
|
|
74
79
|
|
|
75
80
|
existingPkg = config.dependencies[pkgDetails.name];
|
|
76
|
-
|
|
77
81
|
}
|
|
78
82
|
else if (!existingPkg || !existingPkg.repo) {
|
|
79
|
-
let
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
let ver;
|
|
84
|
+
if (pkg.includes('@')) {
|
|
85
|
+
[pkg, ver] = pkg.split('@');
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
let versionRes = await getHighestVersion(pkg);
|
|
89
|
+
if (versionRes.err) {
|
|
90
|
+
console.log(chalk.red('Error: ') + versionRes.err);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
ver = versionRes.ok;
|
|
83
94
|
}
|
|
84
95
|
|
|
85
96
|
pkgDetails = {
|
|
86
97
|
name: pkg,
|
|
87
98
|
repo: '',
|
|
88
|
-
version:
|
|
99
|
+
version: ver,
|
|
89
100
|
};
|
|
90
101
|
|
|
91
102
|
}
|
|
@@ -107,7 +118,10 @@ program
|
|
|
107
118
|
await installFromGithub(name, repo, {verbose: options.verbose});
|
|
108
119
|
}
|
|
109
120
|
else {
|
|
110
|
-
await install(name, version, {verbose: options.verbose});
|
|
121
|
+
let ok = await install(name, version, {verbose: options.verbose});
|
|
122
|
+
if (!ok) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
111
125
|
}
|
|
112
126
|
|
|
113
127
|
config.dependencies[name] = pkgDetails;
|
|
@@ -173,4 +187,13 @@ program
|
|
|
173
187
|
whoami();
|
|
174
188
|
});
|
|
175
189
|
|
|
190
|
+
// search
|
|
191
|
+
program
|
|
192
|
+
.command('search <text>')
|
|
193
|
+
.alias('find')
|
|
194
|
+
.description('Search for packages')
|
|
195
|
+
.action(async (text) => {
|
|
196
|
+
await search(text);
|
|
197
|
+
});
|
|
198
|
+
|
|
176
199
|
program.parse();
|
package/commands/install.js
CHANGED
|
@@ -8,14 +8,14 @@ import {installFromGithub} from '../vessel.js';
|
|
|
8
8
|
|
|
9
9
|
export async function install(pkg, version = '', {verbose, silent, dep} = {}) {
|
|
10
10
|
if (!checkConfigFile()) {
|
|
11
|
-
return;
|
|
11
|
+
return false;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
if (!version) {
|
|
15
15
|
let versionRes = await getHighestVersion(pkg);
|
|
16
16
|
if (versionRes.err) {
|
|
17
17
|
console.log(chalk.red('Error: ') + versionRes.err);
|
|
18
|
-
return;
|
|
18
|
+
return false;
|
|
19
19
|
}
|
|
20
20
|
version = versionRes.ok;
|
|
21
21
|
}
|
|
@@ -29,26 +29,24 @@ export async function install(pkg, version = '', {verbose, silent, dep} = {}) {
|
|
|
29
29
|
}
|
|
30
30
|
// no cache
|
|
31
31
|
else {
|
|
32
|
-
fs.mkdirSync(dir, {recursive: true});
|
|
33
|
-
|
|
34
|
-
actor.notifyInstall(pkg, version);
|
|
35
|
-
|
|
36
32
|
let packageDetailsRes = await actor.getPackageDetails(pkg, version);
|
|
37
33
|
if (packageDetailsRes.err) {
|
|
38
34
|
console.log(chalk.red('Error: ') + packageDetailsRes.err);
|
|
39
|
-
return;
|
|
35
|
+
return false;
|
|
40
36
|
}
|
|
41
37
|
let packageDetails = packageDetailsRes.ok;
|
|
42
38
|
|
|
43
39
|
let filesIdsRes = await actor.getFileIds(pkg, version);
|
|
44
40
|
if (filesIdsRes.err) {
|
|
45
41
|
console.log(chalk.red('Error: ') + filesIdsRes.err);
|
|
46
|
-
return;
|
|
42
|
+
return false;
|
|
47
43
|
}
|
|
48
44
|
let filesIds = filesIdsRes.ok;
|
|
49
45
|
|
|
50
46
|
let storage = await storageActor(packageDetails.publication.storage);
|
|
51
47
|
|
|
48
|
+
actor.notifyInstall(pkg, version);
|
|
49
|
+
|
|
52
50
|
// progress
|
|
53
51
|
let total = filesIds.length + 1;
|
|
54
52
|
let step = 0;
|
|
@@ -58,6 +56,7 @@ export async function install(pkg, version = '', {verbose, silent, dep} = {}) {
|
|
|
58
56
|
};
|
|
59
57
|
|
|
60
58
|
// download files
|
|
59
|
+
fs.mkdirSync(dir, {recursive: true});
|
|
61
60
|
progress();
|
|
62
61
|
await parallel(8, filesIds, async (fileId) => {
|
|
63
62
|
let fileMetaRes = await storage.getFileMeta(fileId);
|
|
@@ -89,13 +88,19 @@ export async function install(pkg, version = '', {verbose, silent, dep} = {}) {
|
|
|
89
88
|
}
|
|
90
89
|
|
|
91
90
|
// install dependencies
|
|
91
|
+
let ok = true;
|
|
92
92
|
let config = readConfig(path.join(dir, 'mops.toml'));
|
|
93
93
|
for (const {name, repo, version} of Object.values(config.dependencies || {})) {
|
|
94
94
|
if (repo) {
|
|
95
95
|
await installFromGithub(name, repo, {verbose});
|
|
96
96
|
}
|
|
97
97
|
else {
|
|
98
|
-
await install(name, version, {verbose});
|
|
98
|
+
let res = await install(name, version, {verbose});
|
|
99
|
+
if (!res) {
|
|
100
|
+
ok = false;
|
|
101
|
+
}
|
|
99
102
|
}
|
|
100
103
|
}
|
|
104
|
+
|
|
105
|
+
return ok;
|
|
101
106
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import asTable from 'as-table';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import {mainActor} from '../mops.js';
|
|
4
|
+
|
|
5
|
+
export async function search(text) {
|
|
6
|
+
let actor = await mainActor();
|
|
7
|
+
let res = await actor.search(text);
|
|
8
|
+
|
|
9
|
+
if (!res.length) {
|
|
10
|
+
console.log('Packages not found');
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let ellipsis = (text, max) => {
|
|
15
|
+
if (text.length <= max) {
|
|
16
|
+
return text;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return text.slice(0, max) + '…';
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
let maxNameLength = Math.max(...res.map(a => a.config.name.length));
|
|
24
|
+
|
|
25
|
+
let table = res.map((item) => {
|
|
26
|
+
return {
|
|
27
|
+
NAME: chalk.bold(item.config.name),
|
|
28
|
+
DESCRIPTION: ellipsis(item.config.description, process.stdout.columns - 40 - maxNameLength),
|
|
29
|
+
VERSION: item.config.version,
|
|
30
|
+
UPDATED: new Date(Number(item.publication.time / 1_000_000n)).toISOString().split('T')[0],
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
console.log('');
|
|
35
|
+
console.log(asTable.configure({
|
|
36
|
+
delimiter: chalk.gray(' | '),
|
|
37
|
+
dash: chalk.gray('─'),
|
|
38
|
+
title: t => chalk.gray.bold(t),
|
|
39
|
+
})(table));
|
|
40
|
+
console.log('');
|
|
41
|
+
}
|
|
@@ -2,7 +2,7 @@ import { Actor, HttpAgent } from "@dfinity/agent";
|
|
|
2
2
|
|
|
3
3
|
// Imports and re-exports candid interface
|
|
4
4
|
import { idlFactory } from './main.did.js';
|
|
5
|
-
export { idlFactory} from './main.did.js';
|
|
5
|
+
export { idlFactory } from './main.did.js';
|
|
6
6
|
// CANISTER_ID is replaced by webpack based on node environment
|
|
7
7
|
export const canisterId = process.env.MAIN_CANISTER_ID;
|
|
8
8
|
|
|
@@ -18,7 +18,7 @@ export const createActor = (canisterId, options = {}) => {
|
|
|
18
18
|
|
|
19
19
|
See https://internetcomputer.org/docs/current/developer-docs/updates/release-notes/ for migration instructions`);
|
|
20
20
|
const agent = options.agent || new HttpAgent({ ...options.agentOptions });
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
// Fetch root key for certificate validation during development
|
|
23
23
|
if (process.env.DFX_NETWORK !== "ic") {
|
|
24
24
|
agent.fetchRootKey().catch(err => {
|
|
@@ -34,7 +34,7 @@ See https://internetcomputer.org/docs/current/developer-docs/updates/release-not
|
|
|
34
34
|
...(options ? options.actorOptions : {}),
|
|
35
35
|
});
|
|
36
36
|
};
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
/**
|
|
39
39
|
* A ready-to-use agent for the main canister
|
|
40
40
|
* @type {import("@dfinity/agent").ActorSubclass<import("./main.did.js")._SERVICE>}
|
package/mops.js
CHANGED
|
@@ -13,7 +13,7 @@ import {decodeFile} from './pem.js';
|
|
|
13
13
|
global.fetch = fetch;
|
|
14
14
|
|
|
15
15
|
// (!) make changes in pair with backend
|
|
16
|
-
let apiVersion = '1.2';
|
|
16
|
+
export let apiVersion = '1.2';
|
|
17
17
|
|
|
18
18
|
let networkFile = new URL('./network.txt', import.meta.url);
|
|
19
19
|
|
|
@@ -126,7 +126,7 @@ export function readConfig(configFile = path.join(process.cwd(), 'mops.toml')) {
|
|
|
126
126
|
|
|
127
127
|
const deps = toml.dependencies || {};
|
|
128
128
|
|
|
129
|
-
Object.entries(deps).forEach(([name, data])=>{
|
|
129
|
+
Object.entries(deps).forEach(([name, data]) => {
|
|
130
130
|
if (!data || typeof data !== 'string') {
|
|
131
131
|
throw Error(`Invalid dependency value ${name} = "${data}"`);
|
|
132
132
|
}
|
|
@@ -144,7 +144,7 @@ export function readConfig(configFile = path.join(process.cwd(), 'mops.toml')) {
|
|
|
144
144
|
export function writeConfig(config, configFile = path.join(process.cwd(), 'mops.toml')) {
|
|
145
145
|
const deps = config.dependencies || {};
|
|
146
146
|
|
|
147
|
-
Object.entries(deps).forEach(([name, {repo, version}])=>{
|
|
147
|
+
Object.entries(deps).forEach(([name, {repo, version}]) => {
|
|
148
148
|
if (repo) {
|
|
149
149
|
deps[name] = repo;
|
|
150
150
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ic-mops",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"mops": "cli.js"
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"@dfinity/identity": "^0.11.0",
|
|
17
17
|
"@dfinity/principal": "^0.11.1",
|
|
18
18
|
"@iarna/toml": "^2.2.5",
|
|
19
|
+
"as-table": "^1.0.55",
|
|
19
20
|
"chalk": "^4.1.2",
|
|
20
21
|
"commander": "^9.2.0",
|
|
21
22
|
"decompress": "^4.2.1",
|
package/vessel.js
CHANGED
|
@@ -32,10 +32,7 @@ const dhallFileToJson = async (filePath) => {
|
|
|
32
32
|
return null;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
-
export const readVesselConfig = async (
|
|
36
|
-
configFile,
|
|
37
|
-
{cache = true} = {cache: true}
|
|
38
|
-
) => {
|
|
35
|
+
export const readVesselConfig = async (configFile, {cache = true} = {cache: true}) => {
|
|
39
36
|
const cachedFile = (configFile || process.cwd()) + '/vessel.json';
|
|
40
37
|
|
|
41
38
|
if (existsSync(cachedFile)) {
|
|
@@ -48,7 +45,9 @@ export const readVesselConfig = async (
|
|
|
48
45
|
dhallFileToJson((configFile || process.cwd()) + '/package-set.dhall')
|
|
49
46
|
]);
|
|
50
47
|
|
|
51
|
-
if (!vessel || !packageSetArray)
|
|
48
|
+
if (!vessel || !packageSetArray) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
52
51
|
|
|
53
52
|
let repos = {};
|
|
54
53
|
for (const {name, repo, version} of packageSetArray) {
|
|
@@ -131,7 +130,7 @@ export const downloadFromGithub = async (repo, dest, onProgress = null) => {
|
|
|
131
130
|
return promise;
|
|
132
131
|
};
|
|
133
132
|
|
|
134
|
-
export const installFromGithub = async (name, repo, options = {})=>{
|
|
133
|
+
export const installFromGithub = async (name, repo, options = {}) => {
|
|
135
134
|
const {verbose, dep, silent} = options;
|
|
136
135
|
|
|
137
136
|
const {branch} = parseGithubURL(repo);
|
|
@@ -148,7 +147,7 @@ export const installFromGithub = async (name, repo, options = {})=>{
|
|
|
148
147
|
};
|
|
149
148
|
|
|
150
149
|
progress(0, 2 * (1024 ** 2));
|
|
151
|
-
await downloadFromGithub(repo, dir, progress).catch((err)=> {
|
|
150
|
+
await downloadFromGithub(repo, dir, progress).catch((err) => {
|
|
152
151
|
del.sync([dir]);
|
|
153
152
|
console.log(chalk.red('Error: ') + err);
|
|
154
153
|
});
|