ic-mops 0.3.7 → 0.5.0

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
@@ -32,16 +32,27 @@ Add `mops` as a packtool to your `dfx.json`
32
32
 
33
33
  ### 2. Initialize
34
34
  Run this command in the root directory of your project (where is `dfx.json` placed)
35
+ If there are Vessel config files, mops will migrate packages from `vessel.dhall` to `mops.toml`
35
36
 
36
37
  ```
37
38
  mops init
38
39
  ```
39
40
 
40
41
  ### 3. Install Motoko Packages
41
- Use `mops add` to install a specific package and save it to `mops.toml`
42
+ Use `mops add <package_name>` to install a specific package and save it to `mops.toml`
42
43
 
43
44
  ```
44
- mops add <package_name>
45
+ mops add base
46
+ ```
47
+
48
+ You can also add packages from GitHub like this
49
+ ```
50
+ mops add https://github.com/dfinity/motoko-base
51
+ ```
52
+
53
+ You can also add local packages like this (put source files inside `src` directory)
54
+ ```
55
+ mops add ./shared
45
56
  ```
46
57
 
47
58
  Use `mops install` to install all packages specified in `mops.toml`
package/cli.js CHANGED
@@ -14,6 +14,7 @@ import {whoami} from './commands/whoami.js';
14
14
  import {installAll} from './commands/install-all.js';
15
15
  import {search} from './commands/search.js';
16
16
  import {add} from './commands/add.js';
17
+ import {upgrade} from './commands/upgrade.js';
17
18
 
18
19
  let cwd = process.cwd();
19
20
  let configFile = path.join(cwd, 'mops.toml');
@@ -124,10 +125,17 @@ program
124
125
  // search
125
126
  program
126
127
  .command('search <text>')
127
- .alias('find')
128
128
  .description('Search for packages')
129
129
  .action(async (text) => {
130
130
  await search(text);
131
131
  });
132
132
 
133
+ // search
134
+ program
135
+ .command('upgrade')
136
+ .description('Upgrade mops CLI to the latest version')
137
+ .action(async () => {
138
+ upgrade();
139
+ });
140
+
133
141
  program.parse();
package/commands/add.js CHANGED
@@ -1,10 +1,11 @@
1
+ import path from 'path';
1
2
  import chalk from 'chalk';
2
3
  import logUpdate from 'log-update';
3
4
  import {checkConfigFile, getHighestVersion, parseGithubURL, readConfig, writeConfig} from '../mops.js';
4
5
  import {installFromGithub} from '../vessel.js';
5
6
  import {install} from './install.js';
6
7
 
7
- export async function add(pkg, {verbose, silent} = {}) {
8
+ export async function add(name, {verbose, silent} = {}) {
8
9
  if (!checkConfigFile()) {
9
10
  return false;
10
11
  }
@@ -15,26 +16,37 @@ export async function add(pkg, {verbose, silent} = {}) {
15
16
  }
16
17
 
17
18
  let pkgDetails;
18
- let existingPkg = config.dependencies[pkg];
19
+ let existingPkg = config.dependencies[name];
19
20
 
20
- if (pkg.startsWith('https://github.com') || pkg.split('/') > 1) {
21
- const {org, gitName, branch} = parseGithubURL(pkg);
21
+ // local package
22
+ if (name.startsWith('./') || name.startsWith('../') || name.startsWith('/')) {
23
+ pkgDetails = {
24
+ name: path.parse(name).name === '.' ? '_' : path.parse(name).name,
25
+ path: name,
26
+ repo: '',
27
+ version: '',
28
+ };
29
+ }
30
+ // github package
31
+ else if (name.startsWith('https://github.com') || name.split('/') > 1) {
32
+ const {org, gitName, branch} = parseGithubURL(name);
22
33
 
23
34
  pkgDetails = {
24
- name: parseGithubURL(pkg).gitName,
35
+ name: parseGithubURL(name).gitName,
25
36
  repo: `https://github.com/${org}/${gitName}#${branch}`,
26
- version: ''
37
+ version: '',
27
38
  };
28
39
 
29
40
  existingPkg = config.dependencies[pkgDetails.name];
30
41
  }
42
+ // mops package
31
43
  else if (!existingPkg || !existingPkg.repo) {
32
44
  let ver;
33
- if (pkg.includes('@')) {
34
- [pkg, ver] = pkg.split('@');
45
+ if (name.includes('@')) {
46
+ [name, ver] = name.split('@');
35
47
  }
36
48
  else {
37
- let versionRes = await getHighestVersion(pkg);
49
+ let versionRes = await getHighestVersion(name);
38
50
  if (versionRes.err) {
39
51
  console.log(chalk.red('Error: ') + versionRes.err);
40
52
  return;
@@ -43,7 +55,7 @@ export async function add(pkg, {verbose, silent} = {}) {
43
55
  }
44
56
 
45
57
  pkgDetails = {
46
- name: pkg,
58
+ name: name,
47
59
  repo: '',
48
60
  version: ver,
49
61
  };
@@ -54,28 +66,27 @@ export async function add(pkg, {verbose, silent} = {}) {
54
66
  return;
55
67
  }
56
68
 
57
- const {name, repo, version} = pkgDetails;
58
-
59
- if (repo) {
69
+ if (pkgDetails.repo || pkgDetails.path) {
60
70
  // pkg name conflict with an installed mops pkg
61
71
  if (existingPkg && !existingPkg.repo) {
62
- console.log(chalk.red('Error: ') + `Conflicting Package Name '${name}`);
72
+ console.log(chalk.red('Error: ') + `Conflicting Package Name '${pkgDetails.name}`);
63
73
  console.log('Consider entering the repo url and assigning a new name in the \'mops.toml\' file');
64
74
  return;
65
75
  }
66
-
67
- await installFromGithub(name, repo, {verbose: verbose});
76
+ if (pkgDetails.repo) {
77
+ await installFromGithub(pkgDetails.name, pkgDetails.repo, {verbose: verbose});
78
+ }
68
79
  }
69
80
  else {
70
- let ok = await install(name, version, {verbose: verbose});
81
+ let ok = await install(pkgDetails.name, pkgDetails.version, {verbose: verbose});
71
82
  if (!ok) {
72
83
  return;
73
84
  }
74
85
  }
75
86
 
76
- config.dependencies[name] = pkgDetails;
87
+ config.dependencies[pkgDetails.name] = pkgDetails;
77
88
  writeConfig(config);
78
89
 
79
90
  logUpdate.clear();
80
- console.log(chalk.green('Package installed ') + `${name} = "${repo || version}"`);
91
+ console.log(chalk.green('Package installed ') + `${pkgDetails.name} = "${pkgDetails.repo || pkgDetails.path || pkgDetails.version}"`);
81
92
  }
@@ -12,11 +12,11 @@ export async function installAll({verbose} = {}) {
12
12
  let config = readConfig();
13
13
  const deps = Object.values(config.dependencies || {});
14
14
 
15
- for (let {name, repo, version} of deps) {
15
+ for (let {name, repo, path, version} of deps) {
16
16
  if (repo) {
17
17
  await installFromGithub(name, repo, {verbose});
18
18
  }
19
- else {
19
+ else if (!path) {
20
20
  let ok = await install(name, version, {verbose});
21
21
  if (!ok) {
22
22
  return;
@@ -97,9 +97,19 @@ export async function publish() {
97
97
  }
98
98
  }
99
99
 
100
- if (config.package.dependencies && Object.keys(config.package.dependencies).length > 100) {
101
- console.log(chalk.red('Error: ') + 'max dependencies is 100');
102
- return;
100
+ if (config.dependencies) {
101
+ if (Object.keys(config.dependencies).length > 100) {
102
+ console.log(chalk.red('Error: ') + 'max dependencies is 100');
103
+ return;
104
+ }
105
+
106
+ for (let dep of Object.values(config.dependencies)) {
107
+ if (dep.path) {
108
+ console.log(chalk.red('Error: ') + 'you can\'t publish packages with local dependencies');
109
+ return;
110
+ }
111
+ delete dep.path;
112
+ }
103
113
  }
104
114
 
105
115
  if (config.package.keywords) {
@@ -81,12 +81,14 @@ export async function sources({verbose} = {}) {
81
81
  const dir = formatGithubDir(name, repo);
82
82
  nestedConfig = await readVesselConfig(dir) || {};
83
83
  }
84
- else {
84
+ else if (!pkgDetails.path) {
85
85
  const dir = formatDir(name, version) + '/mops.toml';
86
86
  nestedConfig = readConfig(dir);
87
87
  }
88
88
 
89
- await collectDeps(nestedConfig);
89
+ if (!pkgDetails.path) {
90
+ await collectDeps(nestedConfig);
91
+ }
90
92
 
91
93
  if (!versions[name]) {
92
94
  versions[name] = [];
@@ -115,15 +117,28 @@ export async function sources({verbose} = {}) {
115
117
  }
116
118
 
117
119
  // sources
118
- for (let [name, {repo, version}] of Object.entries(packages)) {
120
+ for (let [name, pkg] of Object.entries(packages)) {
119
121
  let pkgDir;
120
- if (repo) {
121
- pkgDir = path.relative(process.cwd(), formatGithubDir(name, repo)) + '/src';
122
+ if (pkg.path) {
123
+ pkgDir = path.relative(process.cwd(), path.resolve(pkg.path));
124
+ }
125
+ else if (pkg.repo) {
126
+ pkgDir = path.relative(process.cwd(), formatGithubDir(name, pkg.repo));
127
+ }
128
+ else {
129
+ pkgDir = path.relative(process.cwd(), formatDir(name, pkg.version));
130
+ }
131
+
132
+ // append baseDir
133
+ let pkgBaseDir;
134
+ if (fs.existsSync(path.join(pkgDir, 'mops.toml'))) {
135
+ let config = readConfig(path.join(pkgDir, 'mops.toml'));
136
+ pkgBaseDir = path.join(pkgDir, config.package?.baseDir || 'src');
122
137
  }
123
138
  else {
124
- pkgDir = path.relative(process.cwd(), formatDir(name, version)) + '/src';
139
+ pkgBaseDir = path.join(pkgDir, 'src');
125
140
  }
126
141
 
127
- console.log(`--package ${name} ${pkgDir}`);
142
+ console.log(`--package ${name} ${pkgBaseDir}`);
128
143
  }
129
144
  }
@@ -0,0 +1,6 @@
1
+ import child_process from 'child_process';
2
+
3
+ export function upgrade() {
4
+ console.log('Upgrading mops CLI...');
5
+ child_process.execSync('npm i ic-mops -g', {stdio: 'inherit'});
6
+ }
package/mops.js CHANGED
@@ -133,6 +133,9 @@ export function readConfig(configFile = path.join(process.cwd(), 'mops.toml')) {
133
133
  if (data.startsWith('https://github.com/')) {
134
134
  deps[name] = {name, repo: data, version: ''};
135
135
  }
136
+ else if (data.match(/^(\.?\.)?\//)) {
137
+ deps[name] = {name, repo: '', path: data, version: ''};
138
+ }
136
139
  else {
137
140
  deps[name] = {name, repo: '', version: data};
138
141
  }
@@ -144,13 +147,8 @@ export function readConfig(configFile = path.join(process.cwd(), 'mops.toml')) {
144
147
  export function writeConfig(config, configFile = path.join(process.cwd(), 'mops.toml')) {
145
148
  const deps = config.dependencies || {};
146
149
 
147
- Object.entries(deps).forEach(([name, {repo, version}]) => {
148
- if (repo) {
149
- deps[name] = repo;
150
- }
151
- else {
152
- deps[name] = version;
153
- }
150
+ Object.entries(deps).forEach(([name, {repo, path, version}]) => {
151
+ deps[name] = repo || path || version;
154
152
  });
155
153
 
156
154
  fs.writeFileSync(configFile, TOML.stringify(config).trim());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "0.3.7",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mops": "cli.js"
@@ -10,6 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/ZenVoich/mops.git"
12
12
  },
13
+ "author": "Zen Voich <zen.voich@gmail.com>",
13
14
  "dependencies": {
14
15
  "@dfinity/agent": "^0.11.0",
15
16
  "@dfinity/candid": "^0.11.0",