motoko 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict'
1
+ 'use strict';
2
2
 
3
3
  const debug = require('debug')('motoko');
4
4
 
@@ -6,14 +6,20 @@ const { Motoko } = require('./generated/moc');
6
6
  const { loadPackages } = require('./package');
7
7
 
8
8
  const invoke = (key, unwrap, args) => {
9
+ if (typeof Motoko[key] !== 'function') {
10
+ throw new Error(`Unknown compiler function: '${key}'`);
11
+ }
9
12
  let result;
10
13
  try {
11
14
  result = Motoko[key](...args);
12
- } catch (e) {
15
+ } catch (err) {
16
+ if (err instanceof Error) {
17
+ throw err;
18
+ }
13
19
  throw new Error(
14
20
  `Unable to execute ${key}(${[...args]
15
21
  .map((x) => typeof x)
16
- .join(', ')}):\n${JSON.stringify(e)}`,
22
+ .join(', ')}):\n${JSON.stringify(err)}`,
17
23
  );
18
24
  }
19
25
  if (!unwrap) {
@@ -29,46 +35,37 @@ const invoke = (key, unwrap, args) => {
29
35
  return result.code;
30
36
  };
31
37
 
32
- // for (const key of Object.keys(Motoko)) {
33
- // if (typeof Motoko[key] === 'function') {
34
- // const fn = Motoko[key];
35
- // Motoko[key] = (...args) => {
36
- // debug(key, ...args);
37
- // fn(...args);
38
- // };
39
- // }
40
- // }
41
-
42
38
  module.exports = {
43
39
  Motoko,
44
40
  loadPackages,
45
- addFile(path, content) {
46
- debug('+file', path);
47
- try {
48
- // TEMP
49
- invoke('saveFile', false, [path, content]);
50
- return true;
51
- } catch (e) {
52
- return false;
53
- }
41
+ addFile(file, content) {
42
+ debug('+file', file);
43
+ invoke('saveFile', false, [file, content]);
54
44
  },
55
- removeFile(path) {
56
- debug('-file', path);
57
- invoke('removeFile', false, [path, content]);
45
+ removeFile(file) {
46
+ debug('-file', file);
47
+ invoke('removeFile', false, [file, content]);
58
48
  },
59
- getFiles(path) {
60
- const files = invoke('readDir', false, [path]);
61
-
62
- return files;
49
+ listFiles(directory) {
50
+ return invoke('readDir', false, [directory]);
63
51
  },
64
- addPackage(name, path) {
65
- debug('+package', name, path);
66
- invoke('addPackage', false, [name, path]);
52
+ addPackage(name, file) {
53
+ debug('+package', name, file);
54
+ invoke('addPackage', false, [name, file]);
67
55
  },
68
56
  clearPackages() {
69
57
  debug('-packages');
70
58
  invoke('clearPackage', false, []);
71
59
  },
60
+ check(file) {
61
+ invoke('check', true, [file]);
62
+ },
63
+ candid(file) {
64
+ return invoke('candid', true, [file]);
65
+ },
66
+ wasm(mode, file) {
67
+ return invoke('compileWasm', true, [mode, file]);
68
+ },
72
69
  parse(content) {
73
70
  const ast = invoke('parse', true, [content]);
74
71
  return ast;
@@ -77,8 +74,5 @@ module.exports = {
77
74
  const ast = invoke('parseCandid', true, [content]);
78
75
  return ast;
79
76
  },
80
- candid(path) {
81
- return invoke('candid', true, [path]);
82
- },
83
77
  };
84
78
  exports.default = exports;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "motoko",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Compile Motoko smart contracts in Node.js and the browser.",
5
5
  "author": "Ryan Vandersmith (https://github.com/rvanasa)",
6
6
  "license": "Apache-2.0",
@@ -9,8 +9,8 @@
9
9
  "test": "jest"
10
10
  },
11
11
  "dependencies": {
12
- "cross-fetch": "^3.1.5",
13
- "parse-github-url": "^1.0.2"
12
+ "cross-fetch": "3.1.5",
13
+ "parse-github-url": "git+https://github.com/rvanasa/parse-github-url.git"
14
14
  },
15
15
  "devDependencies": {
16
16
  "cross-env": "^7.0.3",
@@ -1 +0,0 @@
1
- *