ic-mops 0.3.5 → 0.3.7

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/README.md CHANGED
@@ -38,17 +38,26 @@ mops init
38
38
  ```
39
39
 
40
40
  ### 3. Install Motoko Packages
41
- Install your favorite packages
41
+ Use `mops add` to install a specific package and save it to `mops.toml`
42
42
 
43
43
  ```
44
44
  mops add <package_name>
45
45
  ```
46
46
 
47
+ Use `mops install` to install all packages specified in `mops.toml`
48
+ ```
49
+ mops install
50
+ ```
51
+
47
52
  ### 4. Import Package
48
53
  Now you can import installed packages in your Motoko code
49
54
 
50
55
  ```motoko
51
- import Lib "mo:<package_name>";
56
+ import PackageName "mo:<package_name>";
57
+ ```
58
+ for example
59
+ ```
60
+ import Itertools "mo:itertools/Iter";
52
61
  ```
53
62
 
54
63
  ## Publish a Package
@@ -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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mops": "cli.js"