@contentful/create-contentful-app 1.8.1 → 1.8.3
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/lib/includeAppAction.js +34 -32
- package/lib/index.js +2 -6
- package/lib/template.js +1 -1
- package/package.json +5 -5
- package/lib/app-actions/typescript/index.js +0 -18
package/lib/includeAppAction.js
CHANGED
|
@@ -17,37 +17,39 @@ const inquirer_1 = __importDefault(require("inquirer"));
|
|
|
17
17
|
const fs_1 = require("fs");
|
|
18
18
|
const path_1 = require("path");
|
|
19
19
|
const constants_1 = require("./constants");
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
20
|
+
const degit_1 = __importDefault(require("degit"));
|
|
21
|
+
const logger_1 = require("./logger");
|
|
22
|
+
function cloneAppAction(destination, templateIsTypescript) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
try {
|
|
25
|
+
console.log((0, logger_1.highlight)('---- Cloning hosted app action.'));
|
|
26
|
+
// Clone the app actions template to the created directory under the folder 'actions'
|
|
27
|
+
const templateSource = (0, path_1.join)('contentful/apps/examples/hosted-app-action-templates', templateIsTypescript ? 'typescript' : 'javascript');
|
|
28
|
+
const appActionDirectoryPath = (0, path_1.resolve)(`${destination}/actions`);
|
|
29
|
+
const d = yield (0, degit_1.default)(templateSource, { mode: 'tar', cache: false });
|
|
30
|
+
yield d.clone(appActionDirectoryPath);
|
|
31
|
+
// move the manifest from the actions folder to the root folder
|
|
32
|
+
(0, fs_1.renameSync)(`${appActionDirectoryPath}/${constants_1.CONTENTFUL_APP_MANIFEST}`, `${destination}/${constants_1.CONTENTFUL_APP_MANIFEST}`);
|
|
33
|
+
// move the build file from the actions folder to the root folder, if necessary
|
|
34
|
+
if (!templateIsTypescript) {
|
|
35
|
+
(0, fs_1.renameSync)(`${appActionDirectoryPath}/build-actions.js`, `${destination}/build-actions.js`);
|
|
36
|
+
}
|
|
37
|
+
// modify package.json build commands
|
|
38
|
+
const packageJsonLocation = (0, path_1.resolve)(`${destination}/package.json`);
|
|
39
|
+
const packageJsonExists = (0, fs_1.existsSync)(packageJsonLocation);
|
|
40
|
+
if (!packageJsonExists) {
|
|
41
|
+
console.error('Failed to add app action build commands.');
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const packageJson = JSON.parse((0, fs_1.readFileSync)(packageJsonLocation, { encoding: 'utf-8' }));
|
|
45
|
+
const updatedPackageJson = Object.assign(Object.assign({}, packageJson), { scripts: Object.assign(Object.assign({}, packageJson.scripts), { 'build-actions': `${templateIsTypescript ? 'tsc actions/*.ts --outDir build/actions' : 'node build-actions.js'}`, build: `${packageJson.scripts.build} && npm run build-actions` }) });
|
|
46
|
+
(0, fs_1.writeFileSync)(packageJsonLocation, JSON.stringify(updatedPackageJson, null, ' '));
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
console.log(e);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
51
53
|
}
|
|
52
54
|
exports.cloneAppAction = cloneAppAction;
|
|
53
55
|
const promptIncludeActionInTemplate = ({ fullAppFolder, templateSource, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -62,7 +64,7 @@ const promptIncludeActionInTemplate = ({ fullAppFolder, templateSource, }) => __
|
|
|
62
64
|
// put app action into the template
|
|
63
65
|
if (includeAppAction) {
|
|
64
66
|
const templateIsTypescript = templateSource.includes('typescript');
|
|
65
|
-
cloneAppAction(
|
|
67
|
+
cloneAppAction(fullAppFolder, templateIsTypescript);
|
|
66
68
|
}
|
|
67
69
|
});
|
|
68
70
|
exports.promptIncludeActionInTemplate = promptIncludeActionInTemplate;
|
package/lib/index.js
CHANGED
|
@@ -107,12 +107,8 @@ function initProject(appName, options) {
|
|
|
107
107
|
interactive: isInteractive,
|
|
108
108
|
});
|
|
109
109
|
yield (0, template_1.cloneTemplateIn)(fullAppFolder, templateSource);
|
|
110
|
-
// // Ask to include a hosted app action if the user has selected a template
|
|
111
|
-
// if (isInteractive && isContentfulTemplate(templateSource)) {
|
|
112
|
-
// await promptIncludeActionInTemplate({ fullAppFolder, templateSource });
|
|
113
|
-
// }
|
|
114
110
|
if (!isInteractive && (0, utils_1.isContentfulTemplate)(templateSource) && normalizedOptions.action) {
|
|
115
|
-
(0, includeAppAction_1.cloneAppAction)(!!normalizedOptions.typescript
|
|
111
|
+
(0, includeAppAction_1.cloneAppAction)(fullAppFolder, !!normalizedOptions.typescript);
|
|
116
112
|
}
|
|
117
113
|
updatePackageName(fullAppFolder);
|
|
118
114
|
const useYarn = normalizedOptions.yarn || (0, utils_1.detectManager)() === 'yarn';
|
|
@@ -157,7 +153,7 @@ function initProject(appName, options) {
|
|
|
157
153
|
`provide a template by its source repository.`,
|
|
158
154
|
`format: URL (HTTPS or SSH) or ${(0, logger_1.code)('vendor:user/repo')} (e.g., ${(0, logger_1.code)('github:user/repo')})`,
|
|
159
155
|
].join('\n'))
|
|
160
|
-
|
|
156
|
+
.option('-a, --action', 'include a hosted app action in the ts or js template')
|
|
161
157
|
.action(initProject);
|
|
162
158
|
yield commander_1.program.parseAsync();
|
|
163
159
|
});
|
package/lib/template.js
CHANGED
|
@@ -46,7 +46,7 @@ function validate(destination) {
|
|
|
46
46
|
JSON.parse((0, fs_1.readFileSync)(packageJSONLocation, 'utf-8'));
|
|
47
47
|
}
|
|
48
48
|
catch (e) {
|
|
49
|
-
throw new Error(`Invalid template: invalid
|
|
49
|
+
throw new Error(`Invalid template: invalid ${packageJSONLocation}.`);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
function cleanUp(destination) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/create-contentful-app",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.3",
|
|
4
4
|
"description": "A template for building Contentful Apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"contentful",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"build": "tsc"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@contentful/app-scripts": "1.8.
|
|
38
|
+
"@contentful/app-scripts": "1.8.2",
|
|
39
39
|
"analytics-node": "^6.2.0",
|
|
40
40
|
"chalk": "4.1.2",
|
|
41
41
|
"commander": "10.0.1",
|
|
@@ -62,12 +62,12 @@
|
|
|
62
62
|
"@types/chalk": "2.2.0",
|
|
63
63
|
"@types/degit": "2.8.3",
|
|
64
64
|
"@types/inquirer": "8.2.1",
|
|
65
|
-
"@types/node": "14.18.
|
|
65
|
+
"@types/node": "14.18.46",
|
|
66
66
|
"@types/node-fetch": "^2.6.2",
|
|
67
67
|
"@types/rimraf": "3.0.2",
|
|
68
68
|
"@types/tildify": "2.0.2",
|
|
69
69
|
"@types/validate-npm-package-name": "4.0.0",
|
|
70
|
-
"contentful-management": "10.
|
|
70
|
+
"contentful-management": "10.35.3"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "43e318bc4b0ce268d1e40cf91b2116debf48e93f"
|
|
73
73
|
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.handler = (payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
-
const { parameters } = payload;
|
|
14
|
-
const response = {
|
|
15
|
-
message: `Hello from your hosted app action. I received the following message as a paramater: ${JSON.stringify(parameters.message)} `,
|
|
16
|
-
};
|
|
17
|
-
return response;
|
|
18
|
-
});
|