带有'@ sap / cds'版本3.x的CDS生成命令不会在SRV模块中放置'csn.json'

时间:2019-06-18 07:28:14

标签: sap hana web-ide

我已经重构了项目,以使用新的Cloud Platform应用程序编程模型。

我的项目结构看起来像这样:

<my_project_name>
  - hdb (db module)
  - srv (service module)
  - ui (ui module)
  - cdsrc.json
  - package.json
  - mta.yaml

cdsrc.json:

{
  "build": {
    "target": ".",
    "tasks": [
      {"src":"hdb","for":"hana","options":{"model":["hdb","srv"]}},
      {"src":"srv","for":"node-cf","options":{"model":["hdb","srv"]}}
    ]
  }
}

package.json:

{
  "name": "<my_project_name>",
  "description": "",
  "version": "1.0.0",
  "engines": {
    "node": "^8.9"
  },
  "files": [
    "hdb",
    "srv"
  ],
  "dependencies": {
    "@sap/cds": "^3.7.1",
    "express": "^4.16.4",
    "hdb": "^0.17.0"
  },
  "devDependencies": {
    "sqlite3": "^4.0.8"
  },
  "scripts": {
    "start": "cds run",
    "build": "cds build/all --clean",
    "deploy": "cds deploy"
  },
  "cds": {
    "requires": {
      "db": {
        "kind": "sqlite",
        "model": [
          "hdb",
          "srv"
        ],
        "credentials": {
          "database": "sqlite.db"
        }
      }
    },
    "folders": {
      "db": "hdb",
      "srv": "srv"
    }
  }
}

srv / package.json:

{
    "name": "srv",
    "dependencies": {
        "@sap/cds": "^3.7.1",
        "@sap/xssec": "^2.1.12",
        <other_packages>
    },
    "scripts": {
        "start": "node server.js"
    },
    "cds": {
        "requires": {
            "db": {
                "kind": "hana",
                "model": "gen/csn.json"
            }
        }
    }
}

srv / server.js:

const cds = require("@sap/cds");
const express = require("express");
//other imports
var app = express();

//other middleware

cds.connect();

cds.serve("gen/csn.json", {
        crashOnError: false
    })
    .in(app)
    .catch((err) => {
        console.log(err);
    });

app.listen(port,  () => {
    console.info(`App listening on port: ${port}`);
});

当我在WebIDE中构建项目时,它会成功构建所有.cds文件,并将这样的输出写入控制台:

> <my_project_name>@1.0.0 build /hana/shared/HXE/xs/controller_data/executionagent/executionroot/269f9533-c450-4f35-ab0e-b62990473bb5/app/META-INF/.sap_java_buildpack/tomcat/temp/builder/sap.cds.mta/builds/build-838087488308692914/<my_project_name>
> cds build/all --clean

[cds] - cds [3.10.0], compiler [1.13.4], home [/hana/shared/HXE/xs/controller_data/executionagent/executionroot/269f9533-c450-4f35-ab0e-b62990473bb5/app/META-INF/.sap_java_buildpack/tomcat/temp/builder/sap.cds.mta/builds/build-838087488308692914/<my_project_name>/node_modules/@sap/cds]

[cds] - building project [/hana/shared/HXE/xs/controller_data/executionagent/executionroot/269f9533-c450-4f35-ab0e-b62990473bb5/app/META-INF/.sap_java_buildpack/tomcat/temp/builder/sap.cds.mta/builds/build-838087488308692914/<my_project_name>], clean [true]

[cds] - building module [hdb] using [Hana DB Module Builder]
[cds] - model: hdb/<file1>.cds, hdb/<file2>.cds, <all_other_cds_files>

[cds] - building module [srv] using [Node CF Module Builder]
[cds] - model: model: hdb/<file1>.cds, hdb/<file2>.cds, <all_other_cds_files>

12:03:53 PM (DIBuild) 
[cds] - done > wrote output to:
  hdb/src/gen/.hdinamespace
  hdb/src/gen/csv/<file1>_<entity1>.hdbcds
  hdb/src/gen/csv/<file1>_<entity2>.hdbcds
  hdb/src/gen/csv/<file2>_<entity1>.hdbcds
  ...
  srv/gen/csn.json
  srv/gen/_i18n/i18n.json

[cds] - time: 2600.051ms

CDS return code: 0

即使“ cds build”命令会在“ hdb / src / gen”和“ srv / gen”文件夹中生成这些文件(我从SSH到安装了SAP Hana的matchine的所有文件都位于从上面的输出:/hana/shared/HXE/xs/controller_data/executionagent/executionroot/269f9533-c450-4f35-ab0e-b62990473bb5/app/META-INF/.sap_java_buildpack/tomcat/temp/builder/sap.cds.mta/builds / build-838087488308692914 /),它们不会显示在WebIDE的项目浏览器中。

当我构建数据库模块(hdb)时,它会将工件部署到HDI容器而没有任何错误,并且我可以使用Database Explorer浏览该容器

但是运行“ srv”模块会出现此错误:

{ Error: Couldn't find a CDS model at: gen/csn.json
    at notFound (/hana/shared/HXE/xs/controller_data/executionagent/executionroot/2dff31be-8521-4d87-a173-f71c65f6b69c/app/node_modules/@sap/cds/lib/models/load.js:59:39)
    at EventEmitter.load (/hana/shared/HXE/xs/controller_data/executionagent/executionroot/2dff31be-8521-4d87-a173-f71c65f6b69c/app/node_modules/@sap/cds/lib/models/load.js:10:50)
    at _loadModel (/hana/shared/HXE/xs/controller_data/executionagent/executionroot/2dff31be-8521-4d87-a173-f71c65f6b69c/app/node_modules/@sap/cds/lib/runtime/serve.js:78:35)
    at <anonymous>
    at runMicrotasksCallback (internal/process/next_tick.js:122:5)
    at _combinedTickCallback (internal/process/next_tick.js:132:7)
    at process._tickCallback (internal/process/next_tick.js:181:9)
    at Function.Module.runMain (module.js:696:11)
    at startup (bootstrap_node.js:225:16)
    at bootstrap_node.js:646:3 code: 'MODEL_NOT_FOUND', model: 'gen/csn.json' }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! serve@ start: `node server.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the serve@ start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.


npm ERR! A complete log of this run can be found in:
npm ERR!     /hana/shared/HXE/xs/controller_data/executionagent/executionroot/2dff31be-8521-4d87-a173-f71c65f6b69c/app/.npm/_logs/2019-06-17T11_49_21_417Z-debug.log

当然,“ cds build”生成csn.json的路径与serve.js希望加载该模型的路径不同。但是,它不是将所有文件自动复制到“ srv”模块执行根目录吗?

我当前的工作流程:

  • 使用VS Code在本地对CDS文件进行更改
  • 构建项目,因此它会生成csn.json
  • 提交更改并推送到Git仓库
  • 在WebIDE中拉动更改
  • CDS构建,因此我可以将更改部署到数据库
  • 在运行“ srv”模块之前,从本地生成的csn.json复制内容,将其粘贴到WebIDE的csn.json中,然后用CDS构建控制台输出中给定的路径替换路径。

感谢您为解决此问题所提供的帮助。 :)

0 个答案:

没有答案