@contentful/app-scripts 2.4.0-alpha.0 → 2.5.0
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,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function cloneFunction(localPath: string, settings:
|
|
3
|
-
export declare function getCloneURL(settings:
|
|
4
|
-
export declare function touchupAppManifest(localPath: string, settings:
|
|
1
|
+
import { GenerateFunctionSettingsInput } from '../types';
|
|
2
|
+
export declare function cloneFunction(localPath: string, settings: GenerateFunctionSettingsInput): Promise<void>;
|
|
3
|
+
export declare function getCloneURL(settings: GenerateFunctionSettingsInput): string;
|
|
4
|
+
export declare function touchupAppManifest(localPath: string, settings: GenerateFunctionSettingsInput, renameFunctionFile: string): Promise<void>;
|
|
5
5
|
export declare function moveFilesToFinalDirectory(localTmpPath: string, localFunctionsPath: string, localPath: string): void;
|
|
6
|
-
export declare function renameClonedFiles(localTmpPath: string, settings:
|
|
6
|
+
export declare function renameClonedFiles(localTmpPath: string, settings: GenerateFunctionSettingsInput): string;
|
|
7
7
|
export declare function resolvePaths(localPath: string): {
|
|
8
8
|
localTmpPath: string;
|
|
9
9
|
localFunctionsPath: string;
|
|
@@ -32,7 +32,7 @@ async function cloneFunction(localPath, settings) {
|
|
|
32
32
|
const { localTmpPath, localFunctionsPath } = resolvePaths(localPath);
|
|
33
33
|
const cloneURL = getCloneURL(settings);
|
|
34
34
|
// Pass keepPackageJson if available in settings (from GenerateFunctionSettingsCLI)
|
|
35
|
-
const keepPackageJson = 'keepPackageJson' in settings ? settings.keepPackageJson :
|
|
35
|
+
const keepPackageJson = 'keepPackageJson' in settings && typeof settings.keepPackageJson === 'boolean' ? settings.keepPackageJson : false;
|
|
36
36
|
await cloneAndResolveManifests(cloneURL, localTmpPath, localPath, localFunctionsPath, keepPackageJson);
|
|
37
37
|
// now rename the function file. Find the file with a .ts or .js extension
|
|
38
38
|
const renameFunctionFile = renameClonedFiles(localTmpPath, settings);
|
|
@@ -96,19 +96,18 @@ function resolvePaths(localPath) {
|
|
|
96
96
|
const localFunctionsPath = (0, node_path_1.resolve)(localPath, 'functions');
|
|
97
97
|
return { localTmpPath, localFunctionsPath };
|
|
98
98
|
}
|
|
99
|
-
async function cloneAndResolveManifests(cloneURL, localTmpPath, localPath, localFunctionsPath, keepPackageJson) {
|
|
99
|
+
async function cloneAndResolveManifests(cloneURL, localTmpPath, localPath, localFunctionsPath, keepPackageJson = false) {
|
|
100
100
|
const tigedInstance = await clone(cloneURL, localTmpPath);
|
|
101
101
|
// merge the manifest from the template folder to the root folder
|
|
102
102
|
await mergeAppManifest(localPath, localTmpPath);
|
|
103
|
-
//
|
|
103
|
+
// create a deep copy of the IGNORED_CLONED_FILES array
|
|
104
|
+
const ignoredFiles = Array.from(constants_1.IGNORED_CLONED_FILES);
|
|
104
105
|
if (!keepPackageJson) {
|
|
106
|
+
// modify package.json build commands
|
|
105
107
|
await updatePackageJsonWithBuild(localPath, localTmpPath);
|
|
106
|
-
}
|
|
107
|
-
// check if a tsconfig.json file exists already
|
|
108
|
-
const ignoredFiles = [...constants_1.IGNORED_CLONED_FILES];
|
|
109
|
-
if (!keepPackageJson) {
|
|
110
108
|
ignoredFiles.push('package.json');
|
|
111
109
|
}
|
|
110
|
+
// check if a tsconfig.json file exists already
|
|
112
111
|
const tsconfigExists = await (0, file_1.exists)((0, node_path_1.resolve)(localFunctionsPath, 'tsconfig.json'));
|
|
113
112
|
if (tsconfigExists) {
|
|
114
113
|
ignoredFiles.push('tsconfig.json');
|
package/lib/types.d.ts
CHANGED
|
@@ -81,6 +81,7 @@ export interface GenerateFunctionSettings {
|
|
|
81
81
|
export interface GenerateFunctionSettingsCLI extends GenerateFunctionSettings {
|
|
82
82
|
keepPackageJson?: boolean;
|
|
83
83
|
}
|
|
84
|
+
export type GenerateFunctionSettingsInput = GenerateFunctionSettings | GenerateFunctionSettingsCLI;
|
|
84
85
|
export interface AddLocationsOptions {
|
|
85
86
|
organizationId?: string;
|
|
86
87
|
definitionId?: string;
|
|
@@ -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/app-scripts",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
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": "f60bbb2e3b86350ae3ae6125f1cf4a5c1ccf85e6",
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@types/adm-zip": "0.5.7",
|
|
73
73
|
"@types/analytics-node": "3.1.14",
|