@contentful/create-contentful-app 1.18.7-alpha.0 → 1.18.7
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 +1 -0
- package/lib/getTemplateSource.js +1 -1
- package/lib/includeAppAction.js +70 -0
- package/lib/index.js +6 -1
- package/lib/utils.js +2 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -95,6 +95,7 @@ Options:
|
|
|
95
95
|
-e, --example <example-name> bootstrap an example app from https://github.com/contentful/apps/tree/master/examples
|
|
96
96
|
-s, --source <url> provide a template by its source repository.
|
|
97
97
|
format: URL (HTTPS or SSH) or vendor:user/repo (e.g., github:user/repo)
|
|
98
|
+
-a, --actions includes a hosted app action in ts or js template
|
|
98
99
|
-f, --function <function-template-name> include the specified function template
|
|
99
100
|
-h, --help shows all available CLI options
|
|
100
101
|
```
|
package/lib/getTemplateSource.js
CHANGED
|
@@ -86,7 +86,7 @@ async function makeContentfulExampleSource(options) {
|
|
|
86
86
|
if (options.typescript) {
|
|
87
87
|
return selectTemplate(types_1.ContentfulExample.Typescript);
|
|
88
88
|
}
|
|
89
|
-
if (options.function) {
|
|
89
|
+
if (options.function || options.action) {
|
|
90
90
|
return selectTemplate(types_1.ContentfulExample.Typescript);
|
|
91
91
|
}
|
|
92
92
|
return await promptExampleSelection();
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.promptIncludeActionInTemplate = exports.cloneAppAction = void 0;
|
|
7
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
8
|
+
const promises_1 = require("fs/promises");
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const constants_1 = require("./constants");
|
|
11
|
+
const tiged_1 = __importDefault(require("tiged"));
|
|
12
|
+
const logger_1 = require("./logger");
|
|
13
|
+
const package_1 = require("./utils/package");
|
|
14
|
+
const file_1 = require("./utils/file");
|
|
15
|
+
const addBuildCommand = (0, package_1.getAddBuildCommandFn)({
|
|
16
|
+
name: 'build:actions',
|
|
17
|
+
command: 'node build-actions.js',
|
|
18
|
+
});
|
|
19
|
+
async function cloneAppAction(destination, templateIsJavascript) {
|
|
20
|
+
try {
|
|
21
|
+
console.log((0, logger_1.highlight)('---- Cloning hosted app action.'));
|
|
22
|
+
// Clone the app actions template to the created directory under the folder 'actions'
|
|
23
|
+
const templateSource = (0, path_1.join)('contentful/apps/examples/hosted-app-action-templates', templateIsJavascript ? 'javascript' : 'typescript');
|
|
24
|
+
const appActionDirectoryPath = (0, path_1.resolve)(`${destination}/actions`);
|
|
25
|
+
const d = await (0, tiged_1.default)(templateSource, { mode: 'tar', disableCache: true });
|
|
26
|
+
await d.clone(appActionDirectoryPath);
|
|
27
|
+
// move the manifest from the actions folder to the root folder
|
|
28
|
+
const writeAppManifest = await (0, file_1.mergeJsonIntoFile)({
|
|
29
|
+
source: `${appActionDirectoryPath}/${constants_1.CONTENTFUL_APP_MANIFEST}`,
|
|
30
|
+
destination: `${destination}/${constants_1.CONTENTFUL_APP_MANIFEST}`,
|
|
31
|
+
});
|
|
32
|
+
// move the build file from the actions folder to the root folder
|
|
33
|
+
const copyBuildFile = await (0, promises_1.rename)(`${appActionDirectoryPath}/build-actions.js`, `${destination}/build-actions.js`);
|
|
34
|
+
// modify package.json build commands
|
|
35
|
+
const packageJsonLocation = (0, path_1.resolve)(`${destination}/package.json`);
|
|
36
|
+
const packageJsonExists = await (0, file_1.exists)(packageJsonLocation);
|
|
37
|
+
if (!packageJsonExists) {
|
|
38
|
+
console.error(`Failed to add app action build commands: ${packageJsonLocation} does not exist.`);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const writeBuildCommand = await (0, file_1.mergeJsonIntoFile)({
|
|
42
|
+
source: `${appActionDirectoryPath}/package.json`,
|
|
43
|
+
destination: packageJsonLocation,
|
|
44
|
+
mergeFn: addBuildCommand,
|
|
45
|
+
});
|
|
46
|
+
await Promise.all([writeAppManifest, copyBuildFile, writeBuildCommand]);
|
|
47
|
+
await d.remove(appActionDirectoryPath, destination, { action: 'remove', files: constants_1.IGNORED_CLONED_FILES.map(fileName => `${appActionDirectoryPath}/${fileName}`) });
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
console.log(e);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.cloneAppAction = cloneAppAction;
|
|
55
|
+
const promptIncludeActionInTemplate = async ({ fullAppFolder, templateSource, }) => {
|
|
56
|
+
const { includeAppAction } = await inquirer_1.default.prompt([
|
|
57
|
+
{
|
|
58
|
+
name: 'includeAppAction',
|
|
59
|
+
message: 'Do you want to include a hosted app action?',
|
|
60
|
+
type: 'confirm',
|
|
61
|
+
default: false,
|
|
62
|
+
},
|
|
63
|
+
]);
|
|
64
|
+
// put app action into the template
|
|
65
|
+
if (includeAppAction) {
|
|
66
|
+
const templateIsTypescript = templateSource.includes('typescript');
|
|
67
|
+
cloneAppAction(fullAppFolder, templateIsTypescript);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
exports.promptIncludeActionInTemplate = promptIncludeActionInTemplate;
|
package/lib/index.js
CHANGED
|
@@ -18,6 +18,7 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
18
18
|
const constants_1 = require("./constants");
|
|
19
19
|
const getTemplateSource_1 = require("./getTemplateSource");
|
|
20
20
|
const analytics_1 = require("./analytics");
|
|
21
|
+
const includeAppAction_1 = require("./includeAppAction");
|
|
21
22
|
const includeFunction_1 = require("./includeFunction");
|
|
22
23
|
const DEFAULT_APP_NAME = 'contentful-app';
|
|
23
24
|
function successMessage(folder, useYarn) {
|
|
@@ -86,7 +87,8 @@ async function initProject(appName, options) {
|
|
|
86
87
|
!normalizedOptions.source &&
|
|
87
88
|
!normalizedOptions.javascript &&
|
|
88
89
|
!normalizedOptions.typescript &&
|
|
89
|
-
!normalizedOptions.function
|
|
90
|
+
!normalizedOptions.function &&
|
|
91
|
+
!normalizedOptions.action;
|
|
90
92
|
const templateSource = await (0, getTemplateSource_1.getTemplateSource)(options);
|
|
91
93
|
(0, analytics_1.track)({
|
|
92
94
|
template: templateSource,
|
|
@@ -94,6 +96,9 @@ async function initProject(appName, options) {
|
|
|
94
96
|
interactive: isInteractive,
|
|
95
97
|
});
|
|
96
98
|
await (0, template_1.cloneTemplateIn)(fullAppFolder, templateSource);
|
|
99
|
+
if (!isInteractive && (0, utils_1.isContentfulTemplate)(templateSource) && normalizedOptions.action) {
|
|
100
|
+
await (0, includeAppAction_1.cloneAppAction)(fullAppFolder, !!normalizedOptions.javascript);
|
|
101
|
+
}
|
|
97
102
|
if (!isInteractive && (0, utils_1.isContentfulTemplate)(templateSource) && normalizedOptions.function) {
|
|
98
103
|
// If function flag is specified, but no function name is provided, we default to external-references
|
|
99
104
|
// for legacy support
|
package/lib/utils.js
CHANGED
|
@@ -55,12 +55,14 @@ function normalizeOptions(options) {
|
|
|
55
55
|
delete normalizedOptions.example;
|
|
56
56
|
delete normalizedOptions.typescript;
|
|
57
57
|
delete normalizedOptions.javascript;
|
|
58
|
+
delete normalizedOptions.action;
|
|
58
59
|
delete normalizedOptions.function;
|
|
59
60
|
}
|
|
60
61
|
if (normalizedOptions.example) {
|
|
61
62
|
fallbackOption = '--example';
|
|
62
63
|
delete normalizedOptions.typescript;
|
|
63
64
|
delete normalizedOptions.javascript;
|
|
65
|
+
delete normalizedOptions.action;
|
|
64
66
|
delete normalizedOptions.function;
|
|
65
67
|
}
|
|
66
68
|
if (normalizedOptions.typescript) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/create-contentful-app",
|
|
3
|
-
"version": "1.18.7
|
|
3
|
+
"version": "1.18.7",
|
|
4
4
|
"description": "A template for building Contentful Apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"contentful",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"directory": "packages/contentful--create-contentful-app"
|
|
15
15
|
},
|
|
16
16
|
"engines": {
|
|
17
|
-
"node": ">=
|
|
18
|
-
"npm": ">=
|
|
17
|
+
"node": ">=14.15.0",
|
|
18
|
+
"npm": ">=6"
|
|
19
19
|
},
|
|
20
20
|
"main": "lib/index.js",
|
|
21
21
|
"lint-staged": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"test": "mocha 'test/**/*.spec.{js,ts}'"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@contentful/app-scripts": "
|
|
39
|
+
"@contentful/app-scripts": "2.1.3",
|
|
40
40
|
"@segment/analytics-node": "^2.2.0",
|
|
41
41
|
"chalk": "4.1.2",
|
|
42
42
|
"commander": "12.1.0",
|
|
@@ -74,11 +74,11 @@
|
|
|
74
74
|
"@types/validate-npm-package-name": "4.0.2",
|
|
75
75
|
"chai": "^4.3.7",
|
|
76
76
|
"chai-as-promised": "^7.1.1",
|
|
77
|
-
"contentful-management": "11.
|
|
77
|
+
"contentful-management": "11.48.0",
|
|
78
78
|
"mocha": "^10.2.0",
|
|
79
79
|
"sinon": "^19.0.0",
|
|
80
80
|
"sinon-chai": "^3.7.0",
|
|
81
81
|
"ts-node": "^10.9.2"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "19544e247831ead71d56506298ed3335aa852d4a"
|
|
84
84
|
}
|