ic-mops 0.7.4 → 0.8.1

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/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ identity.pem
2
+ network.txt
package/README.md CHANGED
@@ -67,7 +67,7 @@ Now you can import installed packages in your Motoko code
67
67
  import PackageName "mo:<package_name>";
68
68
  ```
69
69
  for example
70
- ```
70
+ ```motoko
71
71
  import Itertools "mo:itertools/Iter";
72
72
  ```
73
73
 
package/cli.js CHANGED
@@ -16,7 +16,8 @@ import {search} from './commands/search.js';
16
16
  import {add} from './commands/add.js';
17
17
  import {cacheSize, cleanCache} from './cache.js';
18
18
  import {test} from './commands/test.js';
19
- // import {upgrade} from './commands/upgrade.js';
19
+ import {template} from './commands/template.js';
20
+ import {upgrade} from './commands/upgrade.js';
20
21
 
21
22
  let cwd = process.cwd();
22
23
  let configFile = path.join(cwd, 'mops.toml');
@@ -155,19 +156,28 @@ program
155
156
 
156
157
  // test
157
158
  program
158
- .command('test')
159
+ .command('test [filter]')
159
160
  .description('Run tests')
160
161
  .option('--watch', 'Enable watch mode')
162
+ .action(async (filter, options) => {
163
+ await test(filter, options);
164
+ });
165
+
166
+ // template
167
+ program
168
+ .command('template')
169
+ .description('Apply template')
161
170
  .action(async (options) => {
162
- await test(options);
171
+ await template(options);
163
172
  });
164
173
 
165
- // // upgrade
166
- // program
167
- // .command('upgrade')
168
- // .description('Upgrade mops CLI to the latest version')
169
- // .action(async () => {
170
- // upgrade();
171
- // });
174
+ // upgrade
175
+ program
176
+ .command('self-update')
177
+ .description('Upgrade mops CLI to the latest version')
178
+ .option('--detached')
179
+ .action(async (options) => {
180
+ upgrade(options);
181
+ });
172
182
 
173
183
  program.parse();
@@ -20,7 +20,7 @@ function rootDir(cwd = process.cwd()) {
20
20
  export async function sources({verbose} = {}) {
21
21
  let root = rootDir();
22
22
  if (!root) {
23
- return;
23
+ return [];
24
24
  }
25
25
 
26
26
  let packages = {};
@@ -0,0 +1,28 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import chalk from 'chalk';
4
+ import prompts from 'prompts';
5
+
6
+ export async function template() {
7
+ let res = await prompts({
8
+ type: 'select',
9
+ name: 'value',
10
+ message: 'Select template:',
11
+ choices: [
12
+ {title: 'GitHub Workflow to run \'mops test\'', value: 'github-workflow:mops-test'},
13
+ {title: '× Cancel', value: ''},
14
+ ],
15
+ initial: 0,
16
+ });
17
+
18
+ if (res.value === 'github-workflow:mops-test') {
19
+ let dest = path.resolve(process.cwd(), '.github/workflows/mops-test.yml');
20
+ if (fs.existsSync(dest)) {
21
+ console.log(chalk.yellow('Workflow already exists:'), dest);
22
+ return;
23
+ }
24
+ let mopsTestYml = new URL('../templates/mops-test.yml', import.meta.url);
25
+ fs.copyFileSync(mopsTestYml, dest);
26
+ console.log(chalk.green('Workflow created:'), dest);
27
+ }
28
+ }
package/commands/test.js CHANGED
@@ -18,14 +18,14 @@ let globConfig = {
18
18
  ignore: ignore,
19
19
  };
20
20
 
21
- export async function test({watch = false} = {}) {
21
+ export async function test(filter = '', {watch = false} = {}) {
22
22
  if (watch) {
23
23
  // todo: run only changed for *.test.mo?
24
24
  // todo: run all for *.mo?
25
25
  let run = debounce(async () => {
26
26
  console.clear();
27
27
  process.stdout.write('\x1Bc');
28
- await runAll();
28
+ await runAll(filter);
29
29
  console.log('-'.repeat(50));
30
30
  console.log('Waiting for file changes...');
31
31
  console.log(chalk.gray((`Press ${chalk.gray('Ctrl+C')} to exit.`)));
@@ -42,7 +42,7 @@ export async function test({watch = false} = {}) {
42
42
  run();
43
43
  }
44
44
  else {
45
- let passed = await runAll();
45
+ let passed = await runAll(filter);
46
46
  if (!passed) {
47
47
  process.exit(1);
48
48
  }
@@ -51,7 +51,7 @@ export async function test({watch = false} = {}) {
51
51
 
52
52
  let dfxCache;
53
53
 
54
- export async function runAll() {
54
+ export async function runAll(filter = '') {
55
55
  let start = Date.now();
56
56
 
57
57
  let files = [];
@@ -60,7 +60,11 @@ export async function runAll() {
60
60
  files = [libFiles[0]];
61
61
  }
62
62
  else {
63
- files = glob.sync('**/test?(s)/**/*.test.mo', globConfig);
63
+ let globStr = '**/test?(s)/**/*.test.mo';
64
+ if (filter) {
65
+ globStr = `**/test?(s)/**/*${filter}*`;
66
+ }
67
+ files = glob.sync(globStr, globConfig);
64
68
  }
65
69
  if (!files.length) {
66
70
  console.log('No test files found');
@@ -72,7 +76,7 @@ export async function runAll() {
72
76
  for (let file of files) {
73
77
  console.log(chalk.gray(`• ${file}`));
74
78
  }
75
- console.log('-'.repeat(50));
79
+ console.log('='.repeat(50));
76
80
 
77
81
  let failed = 0;
78
82
  let passed = 0;
@@ -86,6 +90,7 @@ export async function runAll() {
86
90
  let mmf1 = new MMF1;
87
91
 
88
92
  await new Promise((resolve) => {
93
+ file !== files[0] && console.log('-'.repeat(50));
89
94
  console.log(`Running ${chalk.gray(file)}`);
90
95
 
91
96
  let proc = spawn(`${dfxCache}/moc`, ['-r', '-wasi-system-api', '-ref-system-api', '--hide-warnings', '--error-detail=2', ...sourcesArr.join(' ').split(' '), file]);
@@ -123,7 +128,8 @@ export async function runAll() {
123
128
  failed += mmf1.failed;
124
129
  skipped += mmf1.skipped;
125
130
  }
126
- console.log('-'.repeat(50));
131
+
132
+ console.log('='.repeat(50));
127
133
  if (failed) {
128
134
  console.log(chalk.redBright('Tests failed'));
129
135
  }
@@ -1,6 +1,6 @@
1
1
  import child_process from 'child_process';
2
2
 
3
- export function upgrade() {
3
+ export function upgrade({detached = false} = {}) {
4
4
  console.log('Upgrading mops CLI...');
5
- child_process.execSync('npm i ic-mops -g', {stdio: 'inherit'});
5
+ child_process.execSync('npm i ic-mops -g', {stdio: 'inherit', detached});
6
6
  }
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "0.7.4",
3
+ "version": "0.8.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mops": "cli.js"
7
7
  },
8
+ "files": [
9
+ "*",
10
+ "/templates"
11
+ ],
8
12
  "homepage": "https://mops.one",
9
13
  "repository": {
10
14
  "type": "git",
@@ -0,0 +1,29 @@
1
+ name: mops test
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+
9
+ steps:
10
+ - uses: actions/checkout@v3
11
+ - uses: actions/setup-node@v3
12
+ with:
13
+ node-version: 18
14
+ - uses: aviate-labs/setup-dfx@v0.2.3
15
+ with:
16
+ vessel-version: 0.6.3
17
+ dfx-version: 0.13.0
18
+
19
+ - name: install dfx
20
+ run: dfx cache install
21
+
22
+ - name: install mops
23
+ run: npm i ic-mops -g --yes
24
+
25
+ - name: install mops packages
26
+ run: mops install
27
+
28
+ - name: run tests
29
+ run: mops test