@contentful/app-scripts 2.4.0 → 2.5.1
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.
package/README.md
CHANGED
|
@@ -60,6 +60,40 @@ interface Script<Result, Options> {
|
|
|
60
60
|
>
|
|
61
61
|
> Both interactive and nonInteractive version of the same script is meant to return the same result.
|
|
62
62
|
|
|
63
|
+
### Generate Function
|
|
64
|
+
Allows generating a new function template from our [function examples](https://github.com/contentful/apps/tree/master/function-examples). Automatically updates `contentful-app-manifest.json` and merges scripts/dependencies from `package.json` into existing project.
|
|
65
|
+
|
|
66
|
+
#### Interactive mode:
|
|
67
|
+
|
|
68
|
+
In the interactive mode, the CLI will ask for all required options.
|
|
69
|
+
|
|
70
|
+
> **Example**
|
|
71
|
+
>
|
|
72
|
+
> ```shell
|
|
73
|
+
> $ npx --no-install @contentful/app-scripts generate-function
|
|
74
|
+
> ```
|
|
75
|
+
|
|
76
|
+
#### Non-interactive mode:
|
|
77
|
+
|
|
78
|
+
When passing the `--ci` argument the command will fail when the required variables are not set as arguments.
|
|
79
|
+
|
|
80
|
+
> **Example**
|
|
81
|
+
>
|
|
82
|
+
> ```shell
|
|
83
|
+
> $ npx --no-install @contentful/app-scripts generate-function --ci \
|
|
84
|
+
> --name <name> \
|
|
85
|
+
> --example <example> \
|
|
86
|
+
> --language <javascript/typescript> \
|
|
87
|
+
> ```
|
|
88
|
+
|
|
89
|
+
**Options:**
|
|
90
|
+
|
|
91
|
+
| Argument | Description | Default value |
|
|
92
|
+
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | -------------------- |
|
|
93
|
+
| `--name` | The name of your function. | |
|
|
94
|
+
| `--example` | The name of the example as listed in our [function examples](https://github.com/contentful/apps/tree/master/function-examples) | |
|
|
95
|
+
| `--language` | Choice of javascript or typescript | |
|
|
96
|
+
|
|
63
97
|
### Create App Definition
|
|
64
98
|
|
|
65
99
|
Allows creating a new [AppDefinition](https://www.contentful.com/developers/docs/extensibility/app-framework/app-definition/)
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ActivateSettings } from '../types';
|
|
2
|
-
export declare function activateBundle({ accessToken, organization, definition, bundleId, host, }: ActivateSettings): Promise<void>;
|
|
2
|
+
export declare function activateBundle({ accessToken, organization, definition, bundleId, host, hasFrontend, }: ActivateSettings): Promise<void>;
|
|
@@ -8,10 +8,11 @@ const ora_1 = __importDefault(require("ora"));
|
|
|
8
8
|
const chalk_1 = require("chalk");
|
|
9
9
|
const utils_1 = require("../utils");
|
|
10
10
|
const contentful_management_1 = require("contentful-management");
|
|
11
|
-
async function activateBundle({ accessToken, organization, definition, bundleId, host, }) {
|
|
11
|
+
async function activateBundle({ accessToken, organization, definition, bundleId, host, hasFrontend, }) {
|
|
12
12
|
const activationSpinner = (0, ora_1.default)('Activating your bundle').start();
|
|
13
13
|
const plainClient = (0, contentful_management_1.createClient)({ accessToken, host }, { type: 'plain' });
|
|
14
14
|
const defaultLocations = [{ location: 'dialog' }];
|
|
15
|
+
let doesBundleHaveFrontend = hasFrontend;
|
|
15
16
|
const currentDefinition = await plainClient.appDefinition.get({
|
|
16
17
|
appDefinitionId: definition.value,
|
|
17
18
|
organizationId: organization.value,
|
|
@@ -23,10 +24,29 @@ async function activateBundle({ accessToken, organization, definition, bundleId,
|
|
|
23
24
|
type: 'Link',
|
|
24
25
|
},
|
|
25
26
|
};
|
|
26
|
-
if
|
|
27
|
+
// if `hasFrontend` is not passed in, fetch the bundle to determine if it has a frontend
|
|
28
|
+
let bundle;
|
|
29
|
+
if (doesBundleHaveFrontend === undefined) {
|
|
30
|
+
bundle = await plainClient.appBundle.get({
|
|
31
|
+
appBundleId: bundleId,
|
|
32
|
+
appDefinitionId: definition.value,
|
|
33
|
+
organizationId: organization.value,
|
|
34
|
+
});
|
|
35
|
+
if (bundle.files.length) {
|
|
36
|
+
doesBundleHaveFrontend = true;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
doesBundleHaveFrontend = false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// if the bundle has frontend code in the bundle, remove the src from the definition since the frontend will now be hosted by Contentful
|
|
43
|
+
if (doesBundleHaveFrontend) {
|
|
44
|
+
delete currentDefinition.src;
|
|
45
|
+
}
|
|
46
|
+
// if the bundle has frontend code and there are no locations already on the app definition set the default location to dialog
|
|
47
|
+
if (doesBundleHaveFrontend && !currentDefinition.locations?.length) {
|
|
27
48
|
currentDefinition.locations = defaultLocations;
|
|
28
49
|
}
|
|
29
|
-
delete currentDefinition.src;
|
|
30
50
|
try {
|
|
31
51
|
await plainClient.appDefinition.update({
|
|
32
52
|
appDefinitionId: definition.value,
|
package/lib/types.d.ts
CHANGED
|
@@ -48,9 +48,6 @@ function processCreateAppBundleError(err) {
|
|
|
48
48
|
if (reasons.includes('Not entitled to App Functions.')) {
|
|
49
49
|
return 'Your app seems to be using App Functions, which your organization is not entitled to. Remove your app function, or upgrade your account to proceed with your app upload.';
|
|
50
50
|
}
|
|
51
|
-
else if (reasons.includes('App Functions beta not enabled.')) {
|
|
52
|
-
return 'Your app seems to be using App Functions, which your organization has not enabled in the Preview Center. In the Contentful web app, go to the Account Menu → Preview Center → App Functions to enable and proceed with your app upload.';
|
|
53
|
-
}
|
|
54
51
|
else {
|
|
55
52
|
return reasons;
|
|
56
53
|
}
|
package/lib/upload/index.js
CHANGED
|
@@ -16,7 +16,8 @@ async function uploadAndActivate(settings) {
|
|
|
16
16
|
console.log('Remember that in order to be invoked, your App Event function(s) must be linked to your App Event subscription using the CMA or the Events tab of the App Details page.');
|
|
17
17
|
}
|
|
18
18
|
if (!settings.skipActivation && bundle) {
|
|
19
|
-
|
|
19
|
+
const hasFrontend = bundle.files.length > 0;
|
|
20
|
+
await (0, activate_bundle_1.activateBundle)({ ...settings, bundleId: bundle.sys.id, hasFrontend });
|
|
20
21
|
(0, feedback_1.logFeedbackNudge)();
|
|
21
22
|
}
|
|
22
23
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/app-scripts",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"description": "A collection of scripts for building Contentful Apps",
|
|
5
5
|
"author": "Contentful GmbH",
|
|
6
6
|
"license": "MIT",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"tiged": "^2.12.7",
|
|
68
68
|
"zod": "^3.24.1"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "bebf291cff542d30de78de03eea44f3d5621e3b1",
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@types/adm-zip": "0.5.7",
|
|
73
73
|
"@types/analytics-node": "3.1.14",
|