Tob*_*ore 0 npm firebase circleci google-cloud-functions
在基本的Firebase Functions项目中,将在functions文件夹中创建package.json文件。现在,我们将在项目中使用CircleCI。为了使此配置项正常工作,package.json必须位于存储库的顶部文件夹中,而不是此帖子中所见的任何其他子文件夹中:https : //discuss.circleci.com/t/cant-run- npm-install / 19012
现在,如果我将文件移至根目录并更正所有路径,则可以在项目上构建并使用lint,但是部署因错误而失败,即firebase没有项目的目录路径。似乎firebase-tools中有一个硬编码的方法,它阻止package.json移动到functions文件夹之外。
如果我复制package.json并将其放回functions文件夹,则一切工作正常,但这不是解决方案。
这是我想要的结构:
myproject
|
+- .firebaserc
+- firebase.json
+- package.json
+- tsconfig.json
+- tslint.json
|
+- functions/
|
+- src/
| |
| +- index.ts
|
+- lib/
|
+- index.js
+- index.js.map
Run Code Online (Sandbox Code Playgroud)
package.json
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"main": "functions/lib/index.js",
"dependencies": {
"firebase-admin": "~5.12.0",
"firebase-functions": "^1.0.1"
},
"devDependencies": {
"tslint": "^5.8.0",
"typescript": "^2.5.3"
},
"private": true
}
Run Code Online (Sandbox Code Playgroud)
tsconfig.json
{
"compilerOptions": {
"lib": ["es6"],
"module": "commonjs",
"noImplicitReturns": true,
"outDir": "./functions/lib",
"sourceMap": true,
"target": "es6"
},
"compileOnSave": true,
"include": [
"./functions/src"
]
}
Run Code Online (Sandbox Code Playgroud)
是否有人已经使用CircleCI尝试过Firebase Functions,或者是否有任何线索使其工作?
好的,我已经启动并运行了这个东西。您需要为CircleCI中的每个命令指定工作目录为~/project/functions。现在CircleCI正在查找package.json文件。
这是CircleCI的config.yml:
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/node:6.14
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "./functions/package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
# Install all needed dependencies from package.json
- run:
working_directory: ~/project/functions
command: yarn install
# Save the cache including node_modules folder
- save_cache:
paths:
- ~/project/functions/node_modules
key: v1-dependencies-{{ checksum "./functions/package.json" }}
# Create the folder for your unit test results
- run:
working_directory: ~/project/functions
command: mkdir junit
# run tests with mocha!
- run:
working_directory: ~/project/functions
command: yarn test_ci
environment:
MOCHA_FILE: junit/test-results.xml
when: always
- store_test_results:
path: ~/project/functions/junit
- store_artifacts:
path: ~/project/functions/junit
Run Code Online (Sandbox Code Playgroud)
以及带有用于在CircleCI上进行单元测试的额外命令的package.jsontest_ci:
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
"test": "mocha --require ts-node/register ./src/test/*.spec.ts",
"test_ci": "mocha --require ts-node/register --reporter mocha-junit-reporter ./src/test/*.spec.ts"
},
"main": "lib/index.js",
"dependencies": {
"@google-cloud/firestore": "^0.13.1",
"@google-cloud/storage": "^1.6.0",
"@google-cloud/vision": "^0.17.0",
"firebase-admin": "^5.12.0",
"firebase-functions": "^1.0.1"
},
"devDependencies": {
"@types/chai": "^4.1.3",
"@types/mocha": "^5.2.0",
"@types/sinon": "^4.3.1",
"chai": "^4.1.2",
"firebase-functions-test": "^0.1.1",
"firebase-tools": "^3.18.0",
"mocha": "^5.1.1",
"mocha-junit-reporter": "^1.17.0",
"sinon": "^4.5.0",
"ts-node": "^5.0.1",
"tslint": "^5.8.0",
"typescript": "^2.5.3"
},
"private": true
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
725 次 |
| 最近记录: |