adobe / adobeio-cna-starter-project

DEPRECATED - Please use https://github.com/adobe/aio-cli to manage your future apps!
https://adobe.io
Apache License 2.0
10 stars 8 forks source link

When using the ZIP action the JavaScript won't be build #22

Closed maximilianvoss closed 5 years ago

maximilianvoss commented 5 years ago
packages:
  __CNA_PACKAGE__:
    license: Apache-2.0
    actions:
      hello:
        function: actions/hello
        web: yes
        runtime: 'nodejs:10'

A ZIP is build, but the JavaScript is never compiled with npm.

moritzraho commented 5 years ago

@maximilianvoss you need to add a package.json file into the actions/hello folder if you want to package your actions as a zip action. Are there any reasons you want to use a zip action? It is usually more efficient to use the bundled action (point to a file)

duynguyen commented 5 years ago

+1 We should discourage the use of zip action, as it has major impact on action execution time (especially cold start).

maximilianvoss commented 5 years ago

Just imagine you want to create an action which authenticates against Adobe IO, where would you put the private key?

maximilianvoss commented 5 years ago

nevertheless, the package.json did the trick. Closing. Thanks a lot

moritzraho commented 5 years ago

The common way of doing this would be to define a default parameter for your action in your manifest.yml, like

packages:
  __CNA_PACKAGE__:
    license: Apache-2.0
    actions:
      hello:
        function: actions/hello/index.js
        web: yes
        runtime: 'nodejs:10'
        input:
          key: ${KEY_VALUE}

And then you save the KEY_VALUE in your .env so that your key is not visible in your repository You can then get the key from your main function args in the action

moritzraho commented 5 years ago

And if you really want to embed additional data in your action and don't use a zip action simply define a config.json file in the hello/ folder and require('./config.json') from your index.js, the bundler will then automatically package it with the action