ic-mops 0.3.0 → 0.3.2
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 +19 -39
- package/commands/install.js +14 -9
- package/commands/search.js +41 -0
- package/mops.js +2 -2
- package/package.json +2 -1
- package/vessel.js +2 -2
package/cli.js
CHANGED
|
@@ -10,12 +10,12 @@ 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, apiVersion
|
|
13
|
+
import {checkApiCompatibility, getHighestVersion, getNetwork, parseGithubURL, readConfig, setNetwork, writeConfig, apiVersion} 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
|
|
18
|
+
import {search} from './commands/search.js';
|
|
19
19
|
|
|
20
20
|
let cwd = process.cwd();
|
|
21
21
|
let configFile = path.join(cwd, 'mops.toml');
|
|
@@ -78,19 +78,25 @@ program
|
|
|
78
78
|
};
|
|
79
79
|
|
|
80
80
|
existingPkg = config.dependencies[pkgDetails.name];
|
|
81
|
-
|
|
82
81
|
}
|
|
83
82
|
else if (!existingPkg || !existingPkg.repo) {
|
|
84
|
-
let
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
|
|
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;
|
|
88
94
|
}
|
|
89
95
|
|
|
90
96
|
pkgDetails = {
|
|
91
97
|
name: pkg,
|
|
92
98
|
repo: '',
|
|
93
|
-
version:
|
|
99
|
+
version: ver,
|
|
94
100
|
};
|
|
95
101
|
|
|
96
102
|
}
|
|
@@ -112,7 +118,10 @@ program
|
|
|
112
118
|
await installFromGithub(name, repo, {verbose: options.verbose});
|
|
113
119
|
}
|
|
114
120
|
else {
|
|
115
|
-
await install(name, version, {verbose: options.verbose});
|
|
121
|
+
let ok = await install(name, version, {verbose: options.verbose});
|
|
122
|
+
if (!ok) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
116
125
|
}
|
|
117
126
|
|
|
118
127
|
config.dependencies[name] = pkgDetails;
|
|
@@ -184,36 +193,7 @@ program
|
|
|
184
193
|
.alias('find')
|
|
185
194
|
.description('Search for packages')
|
|
186
195
|
.action(async (text) => {
|
|
187
|
-
|
|
188
|
-
let res = await actor.search(text);
|
|
189
|
-
|
|
190
|
-
let ellipsis = (text, max) => {
|
|
191
|
-
if (text.length <= max) {
|
|
192
|
-
return text;
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
return text.slice(0, max) + '…';
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
let maxNameLength = Math.max(...res.map(a => a.config.name.length));
|
|
200
|
-
|
|
201
|
-
let table = res.map((item) => {
|
|
202
|
-
return {
|
|
203
|
-
NAME: chalk.bold(item.config.name),
|
|
204
|
-
VERSION: item.config.version,
|
|
205
|
-
DESCRIPTION: ellipsis(item.config.description, process.stdout.columns - 40 - maxNameLength),
|
|
206
|
-
UPDATED: new Date(Number(item.publication.time / 1_000_000n)).toISOString().split('T')[0],
|
|
207
|
-
};
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
console.log('');
|
|
211
|
-
console.log(asTable.configure({
|
|
212
|
-
delimiter: chalk.gray(' | '),
|
|
213
|
-
dash: chalk.gray('─'),
|
|
214
|
-
title: t => chalk.gray.bold(t),
|
|
215
|
-
})(table));
|
|
216
|
-
console.log('');
|
|
196
|
+
await search(text);
|
|
217
197
|
});
|
|
218
198
|
|
|
219
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
|
+
VERSION: item.config.version,
|
|
29
|
+
DESCRIPTION: ellipsis(item.config.description, process.stdout.columns - 40 - maxNameLength),
|
|
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
|
+
}
|
package/mops.js
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.3.2",
|
|
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
|
@@ -130,7 +130,7 @@ export const downloadFromGithub = async (repo, dest, onProgress = null) => {
|
|
|
130
130
|
return promise;
|
|
131
131
|
};
|
|
132
132
|
|
|
133
|
-
export const installFromGithub = async (name, repo, options = {})=>{
|
|
133
|
+
export const installFromGithub = async (name, repo, options = {}) => {
|
|
134
134
|
const {verbose, dep, silent} = options;
|
|
135
135
|
|
|
136
136
|
const {branch} = parseGithubURL(repo);
|
|
@@ -147,7 +147,7 @@ export const installFromGithub = async (name, repo, options = {})=>{
|
|
|
147
147
|
};
|
|
148
148
|
|
|
149
149
|
progress(0, 2 * (1024 ** 2));
|
|
150
|
-
await downloadFromGithub(repo, dir, progress).catch((err)=> {
|
|
150
|
+
await downloadFromGithub(repo, dir, progress).catch((err) => {
|
|
151
151
|
del.sync([dir]);
|
|
152
152
|
console.log(chalk.red('Error: ') + err);
|
|
153
153
|
});
|