@taqueria/plugin-ligo 0.0.0-pr-170-858bc76e → 0.0.0-pr-175-28c88eff

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.
Files changed (2) hide show
  1. package/compile.js +18 -3
  2. package/package.json +1 -1
package/compile.js CHANGED
@@ -2,7 +2,6 @@ const {execCmd, getArch} = require('@taqueria/node-sdk')
2
2
  const {extname, basename, join} = require('path')
3
3
  const glob = require('fast-glob')
4
4
 
5
-
6
5
  const getContractArtifactFilename = (opts) => (sourceFile) => {
7
6
  const outFile = basename(sourceFile, extname(sourceFile))
8
7
  return join(opts.config.artifactsDir, `${outFile}.tz`)
@@ -23,11 +22,21 @@ const getCompileCommand = (opts, arch) => (sourceFile) => {
23
22
  return cmd
24
23
  }
25
24
 
25
+ const getLigoCompilationError = (stderr) => {
26
+ const err = stderr.split("\n").slice(1).join("\n")
27
+ return `There was a compilation error.\n$\n{err}`
28
+ }
29
+
26
30
  const compileContract = (opts) => (sourceFile) =>
27
31
  getArch()
28
32
  .then(arch => getCompileCommand(opts, arch) (sourceFile))
29
33
  .then(execCmd)
30
- .then(() => ({contract: sourceFile, artifact: getContractArtifactFilename(opts) (sourceFile)}))
34
+ .then(result => result.status === 'success'
35
+ ? ({contract: sourceFile, artifact: getContractArtifactFilename(opts) (sourceFile)})
36
+ : Promise.reject({
37
+ errCode: "E_COMPILE", context: result, errMsg: getLigoCompilationError(result.stderr)}
38
+ )
39
+ )
31
40
 
32
41
  const compileAll = parsedArgs => {
33
42
  // TODO: Fetch list of files from SDK
@@ -42,14 +51,20 @@ const compileAll = parsedArgs => {
42
51
  const compile = parsedArgs => {
43
52
  const p = parsedArgs.sourceFile
44
53
  ? compileContract(parsedArgs) (parsedArgs.sourceFile)
54
+ .then(result => [result])
45
55
  : compileAll(parsedArgs)
46
56
 
47
- return p.then(results => ({
57
+ return p
58
+ .then(results => ({
48
59
  status: 'success',
49
60
  stdout: results,
50
61
  stderr: "",
51
62
  render: 'table'
52
63
  }))
64
+ .catch(err => err.errCode
65
+ ? Promise.resolve({status: 'failed', stdout: '', stderr: err.errMsg, previous: err})
66
+ : Promise.resolve({status: 'failed', stderr: err.getMessage(), stdout: '', previous: err})
67
+ )
53
68
  }
54
69
 
55
70
  module.exports = compile
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taqueria/plugin-ligo",
3
- "version": "0.0.0-pr-170-858bc76e",
3
+ "version": "0.0.0-pr-175-28c88eff",
4
4
  "description": "A taqueria plugin for compiling LIGO smart contracts",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",