ic-mops 0.3.2 → 0.3.4

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
@@ -1,16 +1,87 @@
1
1
  # MOPS
2
- CLI tool for [MOPS](https://mops.one)
3
2
 
4
- ## Usage
3
+ MOPS is a package manager for the Motoko programming language.
5
4
 
6
- **Install cli**
5
+ See https://mops.one
6
+
7
+ ## Setup
8
+
9
+ ### 1. Check system requirements
10
+ - [Node.js](https://nodejs.org/)
11
+ - [DFX](https://internetcomputer.org/docs/current/developer-docs/quickstart/local-quickstart) >= 0.10.0
12
+
13
+ ### 2. Install CLI tool
7
14
  ```
8
15
  npm i -g ic-mops
9
16
  ```
10
17
 
11
- **Install specific Motoko package**
18
+ ## Install Packages
19
+
20
+ ### 1. Configure dfx.json
21
+ Add `mops` as a packtool to your `dfx.json`
22
+
23
+ ```json
24
+ {
25
+ "defaults": {
26
+ "build": {
27
+ "packtool": "mops sources"
28
+ }
29
+ }
30
+ }
12
31
  ```
13
- mops i <package_name>
32
+
33
+ ### 2. Initialize
34
+ Run this command in the root directory of your project (where is `dfx.json` placed)
35
+
14
36
  ```
37
+ mops init
38
+ ```
39
+
40
+ ### 3. Install Motoko Packages
41
+ Install your favorite packages
42
+
43
+ ```
44
+ mops add <package_name>
45
+ ```
46
+
47
+ ### 4. Import Package
48
+ Now you can import installed packages in your Motoko code
49
+
50
+ ```motoko
51
+ import Lib "mo:<package_name>";
52
+ ```
53
+
54
+ ## Publish a Package
55
+
56
+ ### 1. Import Identity
57
+ Create new identity to publish packages
15
58
 
16
- For more docs visit https://mops.one
59
+ ```
60
+ dfx identity new mops
61
+ ```
62
+
63
+ Import identity into `mops`
64
+
65
+ ```
66
+ mops import-identity -- "$(dfx identity export mops)"
67
+ ```
68
+
69
+ ### 2. Initialize
70
+ Run this command in your package root
71
+
72
+ ```
73
+ mops init <your_package_name>
74
+ ```
75
+
76
+ Edit `description` and `repository` fields in `mops.toml` file.
77
+
78
+ Write your package code in `*.mo` source files in the `src/` directory.
79
+
80
+ Create `README.md` file with information on how to use your package.
81
+
82
+ ### 3. Publish
83
+ Publish package to the mops registry!
84
+
85
+ ```
86
+ mops publish
87
+ ```
package/cli.js CHANGED
@@ -6,16 +6,14 @@ import {program} from 'commander';
6
6
  import chalk from 'chalk';
7
7
 
8
8
  import {init} from './commands/init.js';
9
- import {install} from './commands/install.js';
10
9
  import {publish} from './commands/publish.js';
11
10
  import {importPem} from './commands/import-identity.js';
12
11
  import {sources} from './commands/sources.js';
13
- import {checkApiCompatibility, getHighestVersion, getNetwork, parseGithubURL, readConfig, setNetwork, writeConfig, apiVersion} from './mops.js';
12
+ import {checkApiCompatibility, getNetwork, setNetwork, apiVersion} from './mops.js';
14
13
  import {whoami} from './commands/whoami.js';
15
14
  import {installAll} from './commands/install-all.js';
16
- import logUpdate from 'log-update';
17
- import {installFromGithub} from './vessel.js';
18
15
  import {search} from './commands/search.js';
16
+ import {add} from './commands/add.js';
19
17
 
20
18
  let cwd = process.cwd();
21
19
  let configFile = path.join(cwd, 'mops.toml');
@@ -34,103 +32,39 @@ program
34
32
  await init(name);
35
33
  });
36
34
 
35
+ // add
36
+ program
37
+ .command('add <pkg>')
38
+ .description('Install the package and save it to mops.toml')
39
+ .option('--verbose')
40
+ .action(async (pkg, options) => {
41
+ await add(pkg, options);
42
+ });
43
+
37
44
  // install
38
45
  program
39
46
  .command('install [pkg]')
40
47
  .alias('i')
41
- .alias('add')
42
- .description('Install package and save it as a dependency in the mops.toml file')
43
- .option('--verbose', '')
48
+ .description('Install all dependencies specified in mops.toml')
49
+ .option('--verbose')
44
50
  .action(async (pkg, options) => {
45
- let config = {};
46
- let exists = fs.existsSync(configFile);
47
- if (exists) {
48
- config = readConfig(configFile);
49
- }
50
- else {
51
+ if (!fs.existsSync(configFile)) {
51
52
  console.log(chalk.red('Error: ') + `mops.toml not found. Please run ${chalk.green('mops init')} first`);
52
53
  return;
53
54
  }
54
- if (!config.dependencies) {
55
- config.dependencies = {};
56
- }
57
55
 
58
56
  let compatible = await checkApiCompatibility();
59
57
  if (!compatible) {
60
58
  return;
61
59
  }
62
60
 
63
- if (!pkg) {
64
- installAll(options);
65
- return;
66
- }
67
-
68
- let pkgDetails;
69
- let existingPkg = config.dependencies[pkg];
70
-
71
- if (pkg.startsWith('https://github.com') || pkg.split('/') > 1) {
72
- const {org, gitName, branch} = parseGithubURL(pkg);
73
-
74
- pkgDetails = {
75
- name: parseGithubURL(pkg).gitName,
76
- repo: `https://github.com/${org}/${gitName}#${branch}`,
77
- version: ''
78
- };
79
-
80
- existingPkg = config.dependencies[pkgDetails.name];
81
- }
82
- else if (!existingPkg || !existingPkg.repo) {
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;
94
- }
95
-
96
- pkgDetails = {
97
- name: pkg,
98
- repo: '',
99
- version: ver,
100
- };
101
-
102
- }
103
- else {
104
- options.silent || logUpdate(`Installing ${existingPkg.name}@${existingPkg.version} (cache) from Github`);
105
- return;
106
- }
107
-
108
- const {name, repo, version} = pkgDetails;
109
-
110
- if (repo) {
111
- // pkg name conflict with an installed mops pkg
112
- if (existingPkg && !existingPkg.repo) {
113
- console.log(chalk.red('Error: ') + `Conflicting Package Name '${name}`);
114
- console.log('Consider entering the repo url and assigning a new name in the \'mops.toml\' file');
115
- return;
116
- }
117
-
118
- await installFromGithub(name, repo, {verbose: options.verbose});
61
+ if (pkg) {
62
+ console.log(chalk.yellow('Consider using the \'mops add\' command to install a specific package.'));
63
+ await add(pkg, options);
119
64
  }
120
65
  else {
121
- let ok = await install(name, version, {verbose: options.verbose});
122
- if (!ok) {
123
- return;
124
- }
66
+ await installAll(options);
125
67
  }
126
-
127
- config.dependencies[name] = pkgDetails;
128
- writeConfig(config);
129
-
130
- logUpdate.clear();
131
- console.log(
132
- chalk.green('Package installed ') + `${name} = "${repo || version}"`
133
- );
134
68
  });
135
69
 
136
70
  // publish
@@ -174,7 +108,7 @@ program
174
108
  program
175
109
  .command('sources')
176
110
  .description('for dfx packtool')
177
- .option('--verbose', '')
111
+ .option('--verbose')
178
112
  .action(async (options) => {
179
113
  await sources(options);
180
114
  });
@@ -0,0 +1,77 @@
1
+ import chalk from 'chalk';
2
+ import logUpdate from 'log-update';
3
+ import {getHighestVersion, parseGithubURL, readConfig, writeConfig} from '../mops.js';
4
+ import {installFromGithub} from '../vessel.js';
5
+ import {install} from './install.js';
6
+
7
+ export async function add(pkg, {verbose, silent} = {}) {
8
+ let config = readConfig();
9
+ if (!config.dependencies) {
10
+ config.dependencies = {};
11
+ }
12
+
13
+ let pkgDetails;
14
+ let existingPkg = config.dependencies[pkg];
15
+
16
+ if (pkg.startsWith('https://github.com') || pkg.split('/') > 1) {
17
+ const {org, gitName, branch} = parseGithubURL(pkg);
18
+
19
+ pkgDetails = {
20
+ name: parseGithubURL(pkg).gitName,
21
+ repo: `https://github.com/${org}/${gitName}#${branch}`,
22
+ version: ''
23
+ };
24
+
25
+ existingPkg = config.dependencies[pkgDetails.name];
26
+ }
27
+ else if (!existingPkg || !existingPkg.repo) {
28
+ let ver;
29
+ if (pkg.includes('@')) {
30
+ [pkg, ver] = pkg.split('@');
31
+ }
32
+ else {
33
+ let versionRes = await getHighestVersion(pkg);
34
+ if (versionRes.err) {
35
+ console.log(chalk.red('Error: ') + versionRes.err);
36
+ return;
37
+ }
38
+ ver = versionRes.ok;
39
+ }
40
+
41
+ pkgDetails = {
42
+ name: pkg,
43
+ repo: '',
44
+ version: ver,
45
+ };
46
+
47
+ }
48
+ else {
49
+ silent || logUpdate(`Installing ${existingPkg.name}@${existingPkg.version} (cache) from Github`);
50
+ return;
51
+ }
52
+
53
+ const {name, repo, version} = pkgDetails;
54
+
55
+ if (repo) {
56
+ // pkg name conflict with an installed mops pkg
57
+ if (existingPkg && !existingPkg.repo) {
58
+ console.log(chalk.red('Error: ') + `Conflicting Package Name '${name}`);
59
+ console.log('Consider entering the repo url and assigning a new name in the \'mops.toml\' file');
60
+ return;
61
+ }
62
+
63
+ await installFromGithub(name, repo, {verbose: verbose});
64
+ }
65
+ else {
66
+ let ok = await install(name, version, {verbose: verbose});
67
+ if (!ok) {
68
+ return;
69
+ }
70
+ }
71
+
72
+ config.dependencies[name] = pkgDetails;
73
+ writeConfig(config);
74
+
75
+ logUpdate.clear();
76
+ console.log(chalk.green('Package installed ') + `${name} = "${repo || version}"`);
77
+ }
@@ -17,7 +17,10 @@ export async function installAll({verbose} = {}) {
17
17
  await installFromGithub(name, repo, {verbose});
18
18
  }
19
19
  else {
20
- await install(name, version, {verbose});
20
+ let ok = await install(name, version, {verbose});
21
+ if (!ok) {
22
+ return;
23
+ }
21
24
  }
22
25
  }
23
26
 
@@ -25,8 +25,8 @@ export async function search(text) {
25
25
  let table = res.map((item) => {
26
26
  return {
27
27
  NAME: chalk.bold(item.config.name),
28
- VERSION: item.config.version,
29
28
  DESCRIPTION: ellipsis(item.config.description, process.stdout.columns - 40 - maxNameLength),
29
+ VERSION: item.config.version,
30
30
  UPDATED: new Date(Number(item.publication.time / 1_000_000n)).toISOString().split('T')[0],
31
31
  };
32
32
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mops": "cli.js"