ic-mops 0.3.4 → 0.3.6

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 CHANGED
@@ -116,7 +116,7 @@ program
116
116
  // whoami
117
117
  program
118
118
  .command('whoami')
119
- .description('prints your principal')
119
+ .description('Print your principal')
120
120
  .action(async () => {
121
121
  whoami();
122
122
  });
package/commands/add.js CHANGED
@@ -1,10 +1,14 @@
1
1
  import chalk from 'chalk';
2
2
  import logUpdate from 'log-update';
3
- import {getHighestVersion, parseGithubURL, readConfig, writeConfig} from '../mops.js';
3
+ import {checkConfigFile, getHighestVersion, parseGithubURL, readConfig, writeConfig} from '../mops.js';
4
4
  import {installFromGithub} from '../vessel.js';
5
5
  import {install} from './install.js';
6
6
 
7
7
  export async function add(pkg, {verbose, silent} = {}) {
8
+ if (!checkConfigFile()) {
9
+ return false;
10
+ }
11
+
8
12
  let config = readConfig();
9
13
  if (!config.dependencies) {
10
14
  config.dependencies = {};
@@ -11,6 +11,15 @@ export async function install(pkg, version = '', {verbose, silent, dep} = {}) {
11
11
  return false;
12
12
  }
13
13
 
14
+ // progress
15
+ let total = Infinity;
16
+ let step = 0;
17
+ let progress = () => {
18
+ step++;
19
+ silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} ${progressBar(step, total)}`);
20
+ };
21
+ progress();
22
+
14
23
  if (!version) {
15
24
  let versionRes = await getHighestVersion(pkg);
16
25
  if (versionRes.err) {
@@ -29,36 +38,31 @@ export async function install(pkg, version = '', {verbose, silent, dep} = {}) {
29
38
  }
30
39
  // no cache
31
40
  else {
32
- let packageDetailsRes = await actor.getPackageDetails(pkg, version);
41
+ let [packageDetailsRes, filesIdsRes] = await Promise.all([
42
+ actor.getPackageDetails(pkg, version),
43
+ actor.getFileIds(pkg, version),
44
+ ]);
45
+
33
46
  if (packageDetailsRes.err) {
34
47
  console.log(chalk.red('Error: ') + packageDetailsRes.err);
35
48
  return false;
36
49
  }
37
50
  let packageDetails = packageDetailsRes.ok;
38
51
 
39
- let filesIdsRes = await actor.getFileIds(pkg, version);
40
52
  if (filesIdsRes.err) {
41
53
  console.log(chalk.red('Error: ') + filesIdsRes.err);
42
54
  return false;
43
55
  }
44
56
  let filesIds = filesIdsRes.ok;
57
+ total = filesIds.length + 2;
45
58
 
46
59
  let storage = await storageActor(packageDetails.publication.storage);
47
60
 
48
61
  actor.notifyInstall(pkg, version);
49
62
 
50
- // progress
51
- let total = filesIds.length + 1;
52
- let step = 0;
53
- let progress = () => {
54
- step++;
55
- silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} ${progressBar(step, total)}`);
56
- };
57
-
58
63
  // download files
59
- fs.mkdirSync(dir, {recursive: true});
60
- progress();
61
- await parallel(8, filesIds, async (fileId) => {
64
+ let filesData = new Map;
65
+ await parallel(16, filesIds, async (fileId) => {
62
66
  let fileMetaRes = await storage.getFileMeta(fileId);
63
67
  if (fileMetaRes.err) {
64
68
  console.log(chalk.red('ERR: ') + fileMetaRes.err);
@@ -76,11 +80,16 @@ export async function install(pkg, version = '', {verbose, silent, dep} = {}) {
76
80
  let chunk = chunkRes.ok;
77
81
  buffer = Buffer.concat([buffer, Buffer.from(chunk)]);
78
82
  }
79
-
80
- fs.mkdirSync(path.join(dir, path.dirname(fileMeta.path)), {recursive: true});
81
- fs.writeFileSync(path.join(dir, fileMeta.path), buffer);
83
+ filesData.set(fileMeta.path, buffer);
82
84
  progress();
83
85
  });
86
+
87
+ // write files to disk
88
+ for (let [filePath, buffer] of filesData.entries()) {
89
+ fs.mkdirSync(path.join(dir, path.dirname(filePath)), {recursive: true});
90
+ fs.writeFileSync(path.join(dir, filePath), buffer);
91
+ }
92
+ progress();
84
93
  }
85
94
 
86
95
  if (verbose) {
@@ -88,7 +88,7 @@ export interface _SERVICE {
88
88
  'getApiVersion' : ActorMethod<[], Text>,
89
89
  'getDefaultPackages' : ActorMethod<
90
90
  [string],
91
- Array<[PackageName__1, Version]>,
91
+ Array<[PackageName__1, Version]>
92
92
  >,
93
93
  'getFileIds' : ActorMethod<[PackageName__1, Ver], Result_5>,
94
94
  'getHighestVersion' : ActorMethod<[PackageName__1], Result_4>,
@@ -102,11 +102,11 @@ export interface _SERVICE {
102
102
  'search' : ActorMethod<[Text], Array<PackageDetails>>,
103
103
  'startFileUpload' : ActorMethod<
104
104
  [PublishingId, Text, bigint, Uint8Array],
105
- Result_2,
105
+ Result_2
106
106
  >,
107
107
  'startPublish' : ActorMethod<[PackageConfigV2], Result_1>,
108
108
  'uploadFileChunk' : ActorMethod<
109
109
  [PublishingId, FileId, bigint, Uint8Array],
110
- Result,
110
+ Result
111
111
  >,
112
112
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mops": "cli.js"